Package org.renjin.sexp

Examples of org.renjin.sexp.Environment$NamedValues


    SEXP val=Null.INSTANCE;
    // char *buf, *bufptr;
    int   lwidth = 0;
    boolean prim_case = false;

    Environment f_env;
    if(fdef instanceof Closure) {
      f_env = ((Closure) fdef).getEnclosingEnvironment();
    } else if(fdef instanceof PrimitiveFunction) {
      fdef = R_primitive_generic(fdef);
      if(!(fdef instanceof Closure)) {
        throw new EvalException("Failed to get the generic for the primitive \"%s\"", fname.asString());
      }
      f_env = ((Closure) fdef).getEnclosingEnvironment();
      prim_case = true;       
    } else {
      throw new EvalException("Expected a generic function or a primitive for dispatch, " +
          "got an object of class \"%s\"", fdef.getImplicitClass());
    }
    SEXP mtable = f_env.getVariable(R_allmtable);
    if(mtable == Symbol.UNBOUND_VALUE) {
      do_mtable(fdef, ev); /* Should initialize the generic */       
      mtable = f_env.getVariable(R_allmtable);
    }
    SEXP sigargs = f_env.getVariable(R_sigargs);
    SEXP siglength = f_env.getVariable(R_siglength);

    if(sigargs == Symbol.UNBOUND_VALUE || siglength == Symbol.UNBOUND_VALUE ||
        mtable == Symbol.UNBOUND_VALUE) {       
      throw new EvalException("Generic \"%s\" seems not to have been initialized for table dispatch---need to have .SigArgs and .AllMtable assigned in its environment",
          fname.asString());
View Full Code Here



  /* C version of the standardGeneric R function. */
  public SEXP R_standardGeneric(Context context, Symbol fsym, Environment ev, SEXP fdef) {
    String fname = fsym.getPrintName();
    Environment f_env = context.getGlobalEnvironment().getBaseEnvironment();
    SEXP mlist = Null.INSTANCE;
    SEXP f;
    SEXP val = Null.INSTANCE;
    int nprotect = 0;

    //    if(!initialized)
    //      R_initMethodDispatch(NULL);

    if(fdef instanceof Closure) {
      f_env = ((Closure) fdef).getEnclosingEnvironment();
      mlist = f_env.getVariable(".Methods");
      if(mlist == Symbol.UNBOUND_VALUE) {
        mlist = Null.INSTANCE;
      }
    } else if(fdef instanceof PrimitiveFunction ) {
      f_env = context.getBaseEnvironment();
View Full Code Here

  public static SEXP R_execMethod(Context context, Closure op, Environment rho)  {

    /* create a new environment frame enclosed by the lexical
       environment of the method */
    Environment newrho = Environment.createChildEnvironment(op.getEnclosingEnvironment());

    /* copy the bindings for the formal environment from the top frame
       of the internal environment of the generic call to the new
       frame.  need to make sure missingness information is preserved
       and the environments for any default expression promises are
       set to the new environment.  should move this to envir.c where
       it can be done more efficiently. */
    for(PairList.Node next : op.getFormals().nodes()) {
      //R_varloc_t loc;
      //int missing;
      // TODO(alex): redo missingness handling
      //      loc = R_findVarLocInFrame(rho,symbol);
      //      if(loc == NULL)
      //       throw new EvalException("could not find symbol \"%s\" in environment of the generic function"),
      //            CHAR(PRINTNAME(symbol)));
      //      missing = R_GetVarLocMISSING(loc);
      //      val = R_GetVarLocValue(loc);

      if(!next.hasTag()) {
        throw new EvalException("closure formal has no tag! op = " + op);
      }
     
      Symbol symbol = next.getTag();
      SEXP val = rho.findVariable(symbol);
      if(val == Symbol.UNBOUND_VALUE) {
        throw new EvalException("could not find symbol \"%s\" in the environment of the generic function", symbol.getPrintName());
      }

      //      SET_FRAME(newrho, CONS(val, FRAME(newrho)));
      //      SET_TAG(FRAME(newrho), symbol);

      newrho.setVariable(symbol, val);

      //      if (missing) {
      //        SET_MISSING(FRAME(newrho), missing);
      //        if (TYPEOF(val) == PROMSXP && PRENV(val) == rho) {
      //          SEXP deflt;
      //          SET_PRENV(val, newrho);
      //          /* find the symbol in the method, copy its expression
      //           * to the promise */
      //          for(deflt = CAR(op); deflt != R_NilValue; deflt = CDR(deflt)) {
      //            if(TAG(deflt) == symbol)
      //              break;
      //          }
      //          if(deflt == R_NilValue)
      //            error(_("symbol \"%s\" not in environment of method"),
      //                CHAR(PRINTNAME(symbol)));
      //          SET_PRCODE(val, CAR(deflt));
      //        }
      //      }
    }

    /* copy the bindings of the spacial dispatch variables in the top
       frame of the generic call to the new frame */
    newrho.setVariable(DOT_DEFINED, rho.getVariable(DOT_DEFINED));
    newrho.setVariable(DOT_METHOD, rho.getVariable(DOT_METHOD));
    newrho.setVariable(DOT_TARGET, rho.getVariable(DOT_TARGET));

    /* copy the bindings for .Generic and .Methods.  We know (I think)
       that they are in the second frame, so we could use that. */
    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();
View Full Code Here

  public void testLoad() throws Exception {
   
    Class<PackageLoader> loaderClass = (Class<PackageLoader>) Class.forName("org.renjin.base.Loader");
    PackageLoader loader = loaderClass.newInstance();
   
    Environment baseEnv = topLevelContext.getEnvironment().getBaseEnvironment();
    loader.load(topLevelContext, baseEnv);
   
    assertThat(baseEnv.getVariable("xor").force(topLevelContext).getClass().getSimpleName(), equalTo("xor"));
    assertThat(eval("xor(TRUE,TRUE)"), equalTo(c(false)));
  }
View Full Code Here

    Session session = new SessionBuilder()
        .bind(PackageLoader.class, new AetherPackageLoader())
        .bind(VectorPipeliner.class, new MultiThreadedVectorPipeliner(threadPool))
        .build();
    Environment replEnv = session.getGlobalEnvironment().insertAbove(new HashFrame());
    loadDefaultPackages(session);
    return session;
  }
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();
View Full Code Here

    /* make sure we're looking at a return context */
    while (!cptr.isTopLevel()  && cptr.getType() != Type.FUNCTION)  {
      cptr = cptr.getParent();
    }

    Environment s = cptr.getCallingEnvironment();

    if(s == cptr.getGlobalEnvironment()) {
      return 0;
    }
    j = 0;
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;
        }
View Full Code Here

  @Override
  public Object interpret(Context context, Object[] temp) {
    Symbol target = ((EnvironmentVariable) getLHS()).getName();
    SEXP rhs = (SEXP) getRHS().retrieveValue(context, temp);
    Environment rho = context.getEnvironment();

    for(Environment env : context.getEnvironment().parents()) {
      if(env.hasVariable(target))  {
        env.setVariable(target, rhs);
        return null;
      }
    }

    // not defined anywhere we can see, define it anew in the current env
    rho.setVariable(target, rhs);

    return null;
  }
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);
   
View Full Code Here

TOP

Related Classes of org.renjin.sexp.Environment$NamedValues

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.