예제 #1
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];
 }
예제 #2
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());
    }
  }