Exemplo n.º 1
0
 public SEXP evaluate(SEXP expression, Environment rho) {
   if (expression instanceof Symbol) {
     return evaluateSymbol((Symbol) expression, rho);
   } else if (expression instanceof ExpressionVector) {
     return evaluateExpressionVector((ExpressionVector) expression, rho);
   } else if (expression instanceof FunctionCall) {
     return evaluateCall((FunctionCall) expression, rho);
   } else if (expression instanceof Promise) {
     return expression.force(this);
   } else if (expression != Null.INSTANCE && expression instanceof PromisePairList) {
     throw new EvalException("'...' used in an incorrect context");
   } else {
     clearInvisibleFlag();
     return expression;
   }
 }
Exemplo n.º 2
0
  private SEXP evaluateSymbol(Symbol symbol, Environment rho) {
    clearInvisibleFlag();

    if (symbol == Symbol.MISSING_ARG) {
      return symbol;
    }
    SEXP value = rho.findVariable(symbol);
    if (value == Symbol.UNBOUND_VALUE) {
      throw new EvalException(String.format("object '%s' not found", symbol.getPrintName()));
    }

    if (value instanceof Promise) {
      return evaluate(value, rho);
    } else {
      return value;
    }
  }
Exemplo n.º 3
0
 private SEXP evaluateCall(FunctionCall call, Environment rho) {
   clearInvisibleFlag();
   Function functionExpr = evaluateFunction(call.getFunction(), rho);
   return functionExpr.apply(this, rho, call, call.getArguments());
 }