Package org.renjin.eval

Examples of org.renjin.eval.Context


  @Override
  public SEXP apply(Context context, Environment rho, FunctionCall call,
      PairList args) {
   
    // this is an .Internal function, so we need to go up one context.
    Context originalContext = context.getParent();
   
    Closure closure = originalContext.getClosure();
    if(closure == null) {
      throw new EvalException("Recall() must be called from within a closure");
    }
   
    PairList newArguments = (PairList)rho.getVariable(Symbols.ELLIPSES);
    FunctionCall newCall = new FunctionCall(originalContext.getCall().getFunction(), newArguments);
   
    return closure.apply(originalContext,
          originalContext.getEnvironment(),
          newCall,
          newArguments);
  }
View Full Code Here


  }

  @Builtin("as.environment")
  public static Environment asEnvironment(@Current Context context, int pos) {
    Environment env;
    Context cptr;

    if (IntVector.isNA(pos) || pos < -1 || pos == 0) {
        throw new EvalException("invalid 'pos' argument");
    } else if (pos == -1) {
      /* make sure the context is a funcall */
      cptr = context;
      while( context.getType() != Context.Type.FUNCTION && !cptr.isTopLevel() ) {
        cptr = cptr.getParent();
      }
      if( cptr.getType() != Context.Type.FUNCTION) {
        throw new EvalException("no enclosing environment");
      }
      env = cptr.getCallingEnvironment();
      if (env == null) {
        throw new EvalException("invalid 'pos' argument");
      }
    } else {
      for (env = context.getGlobalEnvironment(); env != Environment.EMPTY && pos > 1;
View Full Code Here

 
    Session session = new SessionBuilder()
    .withoutBasePackage()
    .build();
   
    Context context = session.getTopLevelContext();
    Environment baseNamespaceEnv = context.getNamespaceRegistry().getBase().getNamespaceEnvironment();
    Context evalContext = context.beginEvalContext(baseNamespaceEnv);
   
    File baseSourceRoot = new File("src/main/R/base");
    evalSources(evalContext, baseSourceRoot);
   
    evalContext.evaluate(FunctionCall.newCall(Symbol.get(".onLoad")))
   
    // now serialize them to a lazy-loadable frame
   
    final List<String> omit = Lists.newArrayList(
        ".Last.value", ".AutoloadEnv", ".BaseNamespaceEnv",
View Full Code Here

    sb.append(main.toString());
    return sb.toString();
  }
 
  public SEXP evaluate() throws IOException {
    Context context = Context.newTopLevelContext();
    context.init();
    return main.evaluate(context);
  }
View Full Code Here

    List<File> sources = getRSources();
    if(isUpToDate(sources)) {
      return;
    }
   
    Context context = initContext();

    Namespace namespace = context.getNamespaceRegistry().createNamespace(new InitializingPackage(name));
    evaluateSources(context, getRSources(), namespace.getNamespaceEnvironment());
    serializeEnvironment(context, namespace.getNamespaceEnvironment(), environmentFile);
  }
View Full Code Here

    return false;
  }

  private Context initContext()  {
    SessionBuilder builder = new SessionBuilder();
    Context context = builder.build().getTopLevelContext();
    if(defaultPackages != null) {
      for(String name : defaultPackages) {
        context.evaluate(FunctionCall.newCall(Symbol.get("library"), StringVector.valueOf(name)));
      }
    }
    return context;
  }
View Full Code Here

  }
 

  public SEXP matchAndApply(Context callingContext, Environment callingEnvironment, FunctionCall call,
      PairList promisedArgs) {
    Context functionContext = callingContext.beginFunction(callingEnvironment, call, this, promisedArgs);
    Environment functionEnvironment = functionContext.getEnvironment();   

    ClosureDispatcher.matchArgumentsInto(getFormals(), promisedArgs, functionContext, functionEnvironment);

    SEXP result;
    try {
      result = doApply(functionContext);
    } catch(ReturnException e) {
      if(functionEnvironment != e.getEnvironment()) {
        throw e;
      }
      result = e.getValue();
    } finally {
      functionContext.exit();
    }
    return result;
  }
View Full Code Here



  @Test
  public void testLibrariesFromJar() throws IOException, URISyntaxException {
    Context context = Context.newTopLevelContext();
    context.init();

    System.out.println(getClass().getResource("/org/renjin/sexp/SEXP.class").getFile());

  }
View Full Code Here

TOP

Related Classes of org.renjin.eval.Context

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.