public void print( final PrintStream stream, final int indent, Value[] tests, Integer[] offsets, int defaultIndex) { Iterator it; Interpreter.indentLine(stream, indent); stream.println("<SCOPE>"); Interpreter.indentLine(stream, indent + 1); stream.println("<VARIABLES>"); it = this.getVariables(); while (it.hasNext()) { Variable currentVar = (Variable) it.next(); currentVar.print(stream, indent + 2); } Interpreter.indentLine(stream, indent + 1); stream.println("<COMMANDS>"); int commandCount = this.commands.size(); int testIndex = 0; int testCount = tests.length; for (int index = 0; index < commandCount; ++index) { while (testIndex < testCount) { Value test = tests[testIndex]; Integer offset = offsets[testIndex]; if (offset.intValue() != index) { break; } Interpreter.indentLine(stream, indent + 1); stream.println("<CASE>"); test.print(stream, indent + 2); testIndex++; } if (defaultIndex == index) { Interpreter.indentLine(stream, indent + 1); stream.println("<DEFAULT>"); } ParseTreeNode command = (ParseTreeNode) commands.get(index); command.print(stream, indent + 2); } }
@Override public void aset(final Value key, final Value val, final Interpreter interpreter) { int index = ((RecordType) this.type).indexOf(key); if (index < 0) { throw interpreter.runtimeException("Internal error: field index out of bounds"); } this.aset(index, val, interpreter); }
public Value aref(final int index, final Interpreter interpreter) { RecordType type = (RecordType) this.type; int size = type.fieldCount(); if (index < 0 || index >= size) { throw interpreter.runtimeException("Internal error: field index out of bounds"); } Value[] array = (Value[]) this.content; return array[index]; }
@Override public Value aref(final Value key, final Interpreter interpreter) { int index = ((RecordType) this.type).indexOf(key); if (index < 0) { throw interpreter.runtimeException("Internal error: field index out of bounds"); } Value[] array = (Value[]) this.content; return array[index]; }
@Override public Value remove(final Value key, final Interpreter interpreter) { int index = ((RecordType) this.type).indexOf(key); if (index < 0) { throw interpreter.runtimeException("Internal error: field index out of bounds"); } Value[] array = (Value[]) this.content; Value result = array[index]; array[index] = this.getDataType(key).initialValue(); return result; }
@Override public void print(final PrintStream stream, final int indent) { Interpreter.indentLine(stream, indent); stream.println("<INVOKE " + this.name.toString() + ">"); this.type.print(stream, indent + 1); Iterator it = this.getValues(); while (it.hasNext()) { Value current = (Value) it.next(); current.print(stream, indent + 1); } }
public void aset(final int index, final Value val, final Interpreter interpreter) { RecordType type = (RecordType) this.type; int size = type.fieldCount(); if (index < 0 || index >= size) { throw interpreter.runtimeException("Internal error: field index out of bounds"); } Value[] array = (Value[]) this.content; if (array[index].getType().equals(val.getType())) { array[index] = val; } else if (array[index].getType().equals(DataTypes.TYPE_STRING)) { array[index] = val.toStringValue(); } else if (array[index].getType().equals(DataTypes.TYPE_INT) && val.getType().equals(DataTypes.TYPE_FLOAT)) { array[index] = val.toIntValue(); } else if (array[index].getType().equals(DataTypes.TYPE_FLOAT) && val.getType().equals(DataTypes.TYPE_INT)) { array[index] = val.toFloatValue(); } else { throw interpreter.runtimeException( "Internal error: Cannot assign " + val.getType() + " to " + array[index].getType()); } }
@Override public Value execute(final Interpreter interpreter) { if (!KoLmafia.permitsContinue()) { interpreter.setState(Interpreter.STATE_EXIT); return null; } interpreter.traceIndent(); if (interpreter.isTracing()) { interpreter.trace("Invoke: " + this); interpreter.trace("Function name: " + this.name); } // Get the function name Value funcValue = this.name.execute(interpreter); if (interpreter.isTracing()) { interpreter.trace("[" + interpreter.getState() + "] <- " + funcValue); } if (funcValue == null) { interpreter.traceUnindent(); return null; } interpreter.setLineAndFile(this.fileName, this.lineNumber); String func = funcValue.toString(); Function function = this.scope.findFunction(func, this.params); if (function == null) { throw interpreter.undefinedFunctionException(func, this.params); } if (!Parser.validCoercion(this.type, function.getType(), "return")) { throw interpreter.runtimeException( "Calling \"" + func + "\", which returns " + function.getType() + " but " + this.type + " expected"); } this.target = function; // Invoke it. Value result = super.execute(interpreter); interpreter.traceUnindent(); return result; }
@Override public void print(final PrintStream stream, final int indent) { Interpreter.indentLine(stream, indent); stream.println("<VAR " + this.getType() + " " + this.getName() + ">"); }
@Override public void print(final PrintStream stream, final int indent) { Interpreter.indentLine(stream, indent); stream.println("<TYPE " + this.name + ">"); }