Package org.renjin.sexp

Examples of org.renjin.sexp.Symbol


    ListVector.Builder classListBuilder = ListVector.newBuilder();
    StringVector thisClass;
    StringBuilder buf = new StringBuilder();
   
    for(int i = 0; i < nargs; i++) {
      Symbol arg_sym = sigargs.getElementAsSEXP(i);
      if(is_missing_arg(context, arg_sym, ev)) {
        thisClass = s_missing;
      } else {
        /*  get its class */
        SEXP arg;
        try {
          arg = context.evaluate(arg_sym, ev);
        } catch(EvalException e) {
          throw new EvalException(String.format("error in evaluating the argument '%s' in selecting a " +
              "method for function '%s'",
              arg_sym.getPrintName(), fname.asString()), e);
        }
        thisClass = Methods.R_data_class(arg, true);
      }
      classListBuilder.set(i, thisClass);
      if(i > 0) {
View Full Code Here



  private SEXP do_dispatch(Context context, String fname, SEXP ev, SEXP mlist, boolean firstTry, boolean evalArgs) {
    String klass;
    SEXP arg_slot;
    Symbol arg_sym;
    SEXP method, value = Null.INSTANCE;
    int nprotect = 0;
    /* check for dispatch turned off inside MethodsListSelect */
    if(mlist instanceof Function) {
      return mlist;
    }
    arg_slot = Methods.R_do_slot(context, mlist, s_argument);
    if(arg_slot == Null.INSTANCE) {
      throw new EvalException("object of class \"%s\" used as methods list for function '%s' " +
          "( no 'argument' slot)",
          mlist.toString(), fname);
    }
    if(arg_slot instanceof Symbol) {
      arg_sym = (Symbol) arg_slot;
    } else {
      /* shouldn't happen, since argument in class MethodsList has class
       "name" */
      arg_sym = Symbol.get(arg_slot.asString());
    }
    //    if(arg_sym == Symbols.ELLIPSES || DDVAL(arg_sym) > 0)
    //  error(_("(in selecting a method for function '%s') '...' and related variables cannot be used for methods dispatch"),
    //        CHAR(asChar(fname)));
    //    if(TYPEOF(ev) != ENVSXP) {
    //  error(_("(in selecting a method for function '%s') the 'environment' argument for dispatch must be an R environment; got an object of class \"%s\""),
    //      CHAR(asChar(fname)), class_string(ev));
    //  return(R_NilValue); /* -Wall */
    //    }
    /* find the symbol in the frame, but don't use eval, yet, because
       missing arguments are ok & don't require defaults */
    if(evalArgs) {
      if(is_missing_arg(context, arg_sym, (Environment)ev)) {
        klass = "missing";
      } else {
        /*  get its class */
        SEXP arg, class_obj;
        try {
          arg = context.evaluate(arg_sym, (Environment)ev);
        } catch(EvalException e) {
          throw new EvalException(String.format("error in evaluating the argument '%s' in selecting a method for function '%s'",
              arg_sym.getPrintName(), fname), e);
        }

        class_obj = Methods.R_data_class(arg, true);
        klass = class_obj.asString();
      }
    } else {
      /* the arg contains the class as a string */
      SEXP arg; int check_err;
      try {
        arg = context.evaluate(arg_sym, (Environment)ev);
      } catch(Exception e) {
        throw new EvalException(String.format("error in evaluating the argument '%s' in selecting a method for function '%s'",
            arg_sym.getPrintName(), fname));
     
      klass = arg.asString();
    }
    method = R_find_method(mlist, klass, fname);
    if(method == Null.INSTANCE) {
      if(!firstTry) {
        throw new EvalException("no matching method for function '%s' (argument '%s', with class \"%s\")",
            fname, arg_sym.getPrintName(), klass);
      }
    }
    if(value == Symbol.MISSING_ARG) {/* the check put in before calling
        function  MethodListSelect in R */
      throw new EvalException("recursive use of function '%s' in method selection, with no default method",
View Full Code Here

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

    }
  }

  @Override
  public Object put(String name, Object value) {
    Symbol symbol = Symbol.get(name);
    SEXP previousValue = frame.getVariable(symbol);
    SEXP exp = Converters.get(value.getClass()).convertToR(value);
    frame.setVariable(symbol, exp);
    return previousValue;
  }
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))  {
View Full Code Here

  @Override
  public Expression translateToExpression(IRBodyBuilder builder,
      TranslationContext context, FunctionCall call) {
   
    Expression object = builder.translateExpression(context, call.getArgument(0));
    Symbol index = call.getArgument(1);
    Expression replacement = builder.translateExpression(context, call.getArgument(2));
   
    return new PrimitiveCall(call, "$<-", builder.simplify(object), new Constant(index), replacement);
  }
View Full Code Here

  @Override
  public Expression translateToSetterExpression(IRBodyBuilder builder,
      TranslationContext context, FunctionCall call, Expression rhs) {
   
    Expression object = builder.translateExpression(context, call.getArgument(0));
    Symbol index = call.getArgument(1);
   
    return new PrimitiveCall(call, "$<-", object, new Constant(index), builder.simplify(rhs));
 
  }
View Full Code Here

  @Override
  public Expression translateToExpression(IRBodyBuilder builder,
      TranslationContext context, FunctionCall call) {
    Expression object = builder.translateExpression(context, call.getArgument(0));
    Symbol index = toSymbol(call.getArgument(1));
   
    return new PrimitiveCall(call, "$", builder.simplify(object), new Constant(index) );
  }
View Full Code Here

          mv.visitLdcInsn(call.getArgumentNames().get(i));
        }
       
        if(argument instanceof IRThunk) {
          if(argument.getSExpression() instanceof Symbol) {
            Symbol symbol = (Symbol) argument.getSExpression();
            // create a promise to a variable in this scope
            mv.visitTypeInsn(NEW, "org/renjin/compiler/runtime/VariablePromise");
            mv.visitInsn(DUP);
            loadContext();
            mv.visitLdcInsn(symbol.getPrintName());
            mv.visitMethodInsn(INVOKESPECIAL, "org/renjin/compiler/runtime/VariablePromise", "<init>",
                "(Lorg/renjin/eval/Context;Ljava/lang/String;)V");
           
          } else {
            // instantatiate our compiled thunk class
View Full Code Here

    addForLoop(builder, context, call);
  }
  private void addForLoop(IRBodyBuilder factory, TranslationContext context, FunctionCall call) {
   
    Symbol symbol = call.getArgument(0);
    LocalVariable counter = factory.newLocalVariable();
    Temp length = factory.newTemp();
   
    Variable elementVariable = new EnvironmentVariable(symbol);
   
View Full Code Here

TOP

Related Classes of org.renjin.sexp.Symbol

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.