Esempio n. 1
0
  @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);
  }
Esempio n. 2
0
 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];
 }
Esempio n. 3
0
 @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];
 }
Esempio n. 4
0
 @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 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;
  }
Esempio n. 6
0
  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());
    }
  }