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; } }
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; } }
private SEXP evaluateCall(FunctionCall call, Environment rho) { clearInvisibleFlag(); Function functionExpr = evaluateFunction(call.getFunction(), rho); return functionExpr.apply(this, rho, call, call.getArguments()); }