Package org.renjin.compiler.ir.tac.statements

Source Code of org.renjin.compiler.ir.tac.statements.Reassignment

package org.renjin.compiler.ir.tac.statements;

import org.renjin.compiler.ir.tac.expressions.EnvironmentVariable;
import org.renjin.compiler.ir.tac.expressions.Expression;
import org.renjin.eval.Context;
import org.renjin.sexp.Environment;
import org.renjin.sexp.SEXP;
import org.renjin.sexp.Symbol;


public class Reassignment extends Assignment {
  public Reassignment(EnvironmentVariable lhs, Expression rhs) {
    super(lhs, rhs);
  }
  @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;
  }
 
}
TOP

Related Classes of org.renjin.compiler.ir.tac.statements.Reassignment

TOP
Copyright © 2018 www.massapi.com. 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.