Exemplo n.º 1
0
  @Override
  @SuppressWarnings("unchecked")
  public <U extends IValue, V extends IValue> Result<U> subscript(Result<?>[] subscripts) {
    if (subscripts.length > 1) {
      throw new UnsupportedSubscriptArityError(getType(), subscripts.length, ctx.getCurrentAST());
    }
    Result<IValue> subsBase = (Result<IValue>) subscripts[0];
    if (subsBase == null)
      /*
       * Wild card not allowed as tuple subscript
       */
      throw new UnsupportedSubscriptError(type, null, ctx.getCurrentAST());
    if (!subsBase.getType().isIntegerType()) {
      throw new UnsupportedSubscriptError(
          getTypeFactory().integerType(), subsBase.getType(), ctx.getCurrentAST());
    }
    IInteger index = (IInteger) subsBase.getValue();
    if (index.intValue() >= getValue().arity()) {
      throw RuntimeExceptionFactory.indexOutOfBounds(
          index, ctx.getCurrentAST(), ctx.getStackTrace());
    }

    Type elementType = getType().getFieldType(index.intValue());
    IValue element = getValue().get(index.intValue());
    return makeResult(elementType, element, ctx);
  }
Exemplo n.º 2
0
 public void arbSeed(IInteger seed) {
   random.setSeed(seed.intValue());
 }
Exemplo n.º 3
0
 public IValue arbInt(IInteger limit)
       // @doc{arbInt -- return an arbitrary integer value in the interval [0, limit).}
     {
   // TODO allow big ints
   return values.integer(random.nextInt(limit.intValue()));
 }
Exemplo n.º 4
0
 public IValue toReal(IInteger n)
       // @doc{toReal -- convert a rational value to a integer value.}
     {
   return values.real(n.intValue());
 }
Exemplo n.º 5
0
 public IValue setPrecision(IInteger precision) {
   return values.integer(values.setPrecision(precision.intValue()));
 }
Exemplo n.º 6
0
 public IValue precision(INumber x, IInteger precision) {
   return values.real(x.toString(), precision.intValue());
 }