Package org.renjin.eval

Examples of org.renjin.eval.Context


public class PackageArtifactTest {

  @Ignore("Commenting test out because other tests verify that we can run library, and cannot reproduce the test failure.")
  @Test
  public void test() throws IOException {
      Context context = Context.newTopLevelContext();
      context.init();
   
      context.evaluate(RParser.parseSource("library(aspect, verbose=TRUE)\n"));
  }
View Full Code Here


    //      return args.getElementAsSEXP(1);
    //    }
    /* else use sys.function (this is fairly expensive-- would be good
     * to force a second argument if possible) */

    Context cptr = context;
    int n = cptr.getFrameDepth();
    for(int i=0;i<n;++i) {
      SEXP rval = Contexts.R_sysfunction(i, context);
      if(rval.isObject()) {
        SEXP generic = rval.getAttribute(MethodDispatch.GENERIC);
        if(generic instanceof StringVector && generic.asString().equals(fname)) {
View Full Code Here

    if(fun == Symbol.UNBOUND_VALUE) {
      throw new EvalException("unable to find a non-generic version of function \"%s\"",
         name);
    }
   
    Context cptr = context;
    /* check this is the right context */
    while (!cptr.isTopLevel()) {
      if (cptr.getType() == Type.FUNCTION) {
        if (cptr.getEnvironment() == env) {
          break;
        }
      }
      cptr = cptr.getParent();
    }

//    PROTECT(e = duplicate(R_syscall(0, cptr)));
//    SETCAR(e, fun);
    /* evaluate a call the non-generic with the same arguments and from
         the same environment as the call to the generic version */
    return context.evaluate(FunctionCall.newCall(fun, cptr.getArguments(), cptr.getCallingEnvironment()));
  }
View Full Code Here

    newrho.setVariable(Symbols.GENERIC, newrho.getVariable(".Generic"));
    newrho.setVariable(DOT_METHODS, newrho.getVariable(DOT_METHODS));

    /* Find the calling context.  Should be R_GlobalContext unless
       profiling has inserted a CTXT_BUILTIN frame. */
    Context cptr = context;
    //    cptr = R_GlobalContext;
    //    if (cptr->callflag & CTXT_BUILTIN)
    //      cptr = cptr->nextcontext;

    /* The calling environment should either be the environment of the
       generic, rho, or the environment of the caller of the generic,
       the current sysparent. */
    Environment callerenv = cptr.getCallingEnvironment(); /* or rho? */

    /* get the rest of the stuff we need from the current context,
       execute the method, and return the result */
    FunctionCall call = cptr.getCall();
    PairList arglist = cptr.getArguments();
    SEXP val = R_execClosure(context, call, op, arglist, callerenv, newrho);
    return val;
  }
View Full Code Here

  @Ignore("todo")
  @Test
  public void test() throws Exception {
   
    Context tlContext = Context.newTopLevelContext();
    Namespace ns = tlContext.getNamespaceRegistry().createNamespace(new TestPackage());
   
    Context ctx = tlContext.beginEvalContext(ns.getNamespaceEnvironment());
    ctx.evaluate(RParser.parseSource("f <- function(x) x*x*42\n"));
   
    File envFile = File.createTempFile("nstest", ".RData");
    envFile.deleteOnExit();
   
    LazyLoadFrameBuilder builder = new LazyLoadFrameBuilder(tlContext);
View Full Code Here

    .withFileSystemManager(fsm)
    .build();
   
    session.setWorkingDirectory(FileSystemUtils.workingDirectory(fsm));
  
    Context context = session.getTopLevelContext();

    context.evaluate( Symbol.get("search") );
  }
View Full Code Here

    }

    // note that we actually climb n+1 parents in order to
    // skip the closure that makes the .Internal(parent.frame()) call

    Context cptr = context;
    Environment t = cptr.getCallingEnvironment();
    while (!cptr.isTopLevel()){
      if (cptr.getType() == Type.FUNCTION ) {
        if (cptr.getEnvironment() == t) {
          if (n == 1) {
            return cptr.getCallingEnvironment();
          }
          n--;
          t = cptr.getCallingEnvironment();
        }
      }
      cptr = cptr.getParent();
    }
    return context.getGlobalEnvironment();
  }
View Full Code Here

 
  @Internal("sys.parent")
  public static int sysParent(@Current Context context, int n) {
   
    Context cptr = findStartingContext(context);
   
    int i, nframe;
    i = nframe = cptr.getFrameDepth();
    /* This is a pretty awful kludge, but the alternative would be
       a major redesign of everything... -pd */
    while (n-- > 0)
        i = R_sysparent(nframe - i + 1, cptr);
    return i;
View Full Code Here

 
  }

  public static Context findStartingContext(Context context) {
    /* first find the context that sys.xxx needs to be evaluated in */
    Context cptr = context;
    Environment t = cptr.getCallingEnvironment();
    while (!cptr.isTopLevel()) {
      if(cptr.getType() == Type.FUNCTION) {
        if(cptr.getEnvironment() == t) {
          break;
        }
      }
      cptr = cptr.getParent();
    }
    return cptr;
  }
View Full Code Here

    }

    // we need to create a new context for the evaluated code, otherwise sys.parent
    // calls and the like will not be able to access this root environment of the script
   
    Context evalContext = context.beginEvalContext(rho);
   
    SEXP result = evalContext.evaluate( expression, rho);
   
    evalContext.exit();
   
    return result;
  }
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.