From afb077222931655ed856b71ad74931bef983e6ab Mon Sep 17 00:00:00 2001
From: Michael Haupt <michael.haupt@oracle.com>
Date: Tue, 28 Jan 2014 14:13:59 +0100
Subject: [PATCH] replace storage and parameter passing of RContext by RContext
 singleton use

---
 .../com/oracle/truffle/r/engine/REngine.java  |  6 ++--
 .../truffle/r/nodes/RTruffleVisitor.java      | 27 ++++++++---------
 .../r/nodes/access/ReadVariableNode.java      | 21 ++++++-------
 .../r/nodes/binary/BinaryArithmeticNode.java  |  2 +-
 .../r/nodes/binary/BinaryBooleanNode.java     | 10 +++----
 .../BinaryBooleanNonVectorizedNode.java       |  6 ++--
 .../nodes/binary/CbindFoldOperationNode.java  |  2 +-
 .../binary/CombineFoldOperationNode.java      | 14 ++++-----
 .../nodes/binary/RbindFoldOperationNode.java  |  2 +-
 .../truffle/r/nodes/builtin/RBuiltinNode.java | 30 +++++++------------
 .../r/nodes/builtin/RDefaultPackages.java     |  7 ++---
 .../r/nodes/builtin/RLibraryLoader.java       |  8 ++---
 .../truffle/r/nodes/builtin/RPackage.java     | 13 ++++----
 .../truffle/r/nodes/builtin/RPackages.java    | 14 ++++-----
 .../truffle/r/nodes/builtin/base/All.java     |  6 ++--
 .../truffle/r/nodes/builtin/base/Any.java     |  6 ++--
 .../r/nodes/builtin/base/AsInteger.java       |  8 ++---
 .../r/nodes/builtin/base/AsLogical.java       |  6 ++--
 .../truffle/r/nodes/builtin/base/AsRaw.java   |  4 +--
 .../r/nodes/builtin/base/BasePackage.java     |  5 +---
 .../truffle/r/nodes/builtin/base/Cat.java     |  9 ++----
 .../truffle/r/nodes/builtin/base/Cbind.java   |  2 +-
 .../truffle/r/nodes/builtin/base/Combine.java |  4 +--
 .../r/nodes/builtin/base/CommandArgs.java     |  7 +++--
 .../truffle/r/nodes/builtin/base/Exists.java  |  2 +-
 .../r/nodes/builtin/base/Invisible.java       |  2 +-
 .../truffle/r/nodes/builtin/base/IsNA.java    |  2 +-
 .../r/nodes/builtin/base/IsUnsorted.java      |  2 +-
 .../r/nodes/builtin/base/MatchFun.java        |  2 +-
 .../truffle/r/nodes/builtin/base/Matrix.java  |  6 ++--
 .../truffle/r/nodes/builtin/base/Max.java     |  2 +-
 .../truffle/r/nodes/builtin/base/Min.java     |  2 +-
 .../truffle/r/nodes/builtin/base/Mod.java     |  2 +-
 .../truffle/r/nodes/builtin/base/NewEnv.java  |  2 +-
 .../nodes/builtin/base/PrettyPrinterNode.java |  2 +-
 .../truffle/r/nodes/builtin/base/Print.java   |  4 +--
 .../truffle/r/nodes/builtin/base/Quit.java    |  4 +--
 .../truffle/r/nodes/builtin/base/Rbind.java   |  2 +-
 .../r/nodes/builtin/base/RepeatInternal.java  |  2 +-
 .../truffle/r/nodes/builtin/base/Rnorm.java   |  2 +-
 .../truffle/r/nodes/builtin/base/Runif.java   |  2 +-
 .../truffle/r/nodes/builtin/base/SApply.java  |  6 ++--
 .../truffle/r/nodes/builtin/base/Sd.java      |  4 +--
 .../truffle/r/nodes/builtin/base/SetSeed.java |  3 +-
 .../truffle/r/nodes/builtin/base/Sum.java     |  2 +-
 .../r/nodes/builtin/base/ToString.java        |  2 +-
 .../r/nodes/builtin/base/UpdateAttr.java      |  6 ++--
 .../nodes/builtin/base/UpdateAttributes.java  |  4 +--
 .../r/nodes/builtin/base/UpdateDim.java       |  2 +-
 .../r/nodes/builtin/base/UpdateLength.java    |  2 +-
 .../nodes/builtin/debug/DebugInfoBuiltin.java |  3 +-
 .../r/nodes/builtin/debug/DebugPackage.java   |  8 ++---
 .../truffle/r/nodes/function/CallNode.java    |  8 ++---
 .../r/nodes/unary/CastIntegerNode.java        | 28 ++++++++---------
 .../r/nodes/unary/CastLogicalNode.java        | 12 ++++----
 .../truffle/r/nodes/unary/CastStringNode.java |  2 +-
 .../truffle/r/runtime/RBuiltinLookup.java     |  2 +-
 .../oracle/truffle/r/runtime/RRuntime.java    | 12 ++++----
 .../truffle/r/runtime/ops/na/NACheck.java     | 20 ++++++-------
 59 files changed, 179 insertions(+), 208 deletions(-)

diff --git a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/REngine.java b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/REngine.java
index 114953b6d8..92f93fec98 100644
--- a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/REngine.java
+++ b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/REngine.java
@@ -52,7 +52,7 @@ public final class REngine {
     private REngine(String[] commandArgs, ConsoleHandler consoleHandler) {
         RDefaultPackages defaultPackages = RDefaultPackages.getInstance();
         this.context = RContext.instantiate(defaultPackages, commandArgs, consoleHandler);
-        defaultPackages.load(context);
+        defaultPackages.load();
     }
 
     /**
@@ -97,7 +97,7 @@ public final class REngine {
 
     private Object parseAndEvalImpl(ANTLRStringStream stream, Source source, VirtualFrame globalFrame, boolean printResult) {
         try {
-            RTruffleVisitor transform = new RTruffleVisitor(context);
+            RTruffleVisitor transform = new RTruffleVisitor();
             RNode node = transform.transform(parseAST(stream, source));
             FunctionDefinitionNode rootNode = new FunctionDefinitionNode(null, transform.getEnvironment(), node, RArguments.EMPTY_OBJECT_ARRAY, "<main>");
             CallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);
@@ -156,7 +156,7 @@ public final class REngine {
 
     private void printResult(Object result) {
         if (!(result instanceof RInvisible)) {
-            RFunction function = context.getLookup().lookup(context, "print");
+            RFunction function = context.getLookup().lookup("print");
             function.call(null, RArguments.create(function, new Object[]{result})).toString();
         }
     }
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/RTruffleVisitor.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/RTruffleVisitor.java
index 186e816088..90116c2368 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/RTruffleVisitor.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/RTruffleVisitor.java
@@ -26,22 +26,21 @@ import com.oracle.truffle.api.*;
 import com.oracle.truffle.r.nodes.access.*;
 import com.oracle.truffle.r.nodes.access.ReadVariableNode.ReadSuperVariableNode;
 import com.oracle.truffle.r.nodes.binary.*;
+import com.oracle.truffle.r.nodes.builtin.base.*;
 import com.oracle.truffle.r.nodes.control.*;
 import com.oracle.truffle.r.nodes.function.*;
-import com.oracle.truffle.r.nodes.builtin.base.Invisible;
 import com.oracle.truffle.r.parser.ast.*;
 import com.oracle.truffle.r.parser.ast.Constant.ConstantType;
+import com.oracle.truffle.r.parser.ast.Repeat;
 import com.oracle.truffle.r.parser.tools.*;
 import com.oracle.truffle.r.runtime.*;
 import com.oracle.truffle.r.runtime.data.*;
 
 public final class RTruffleVisitor extends BasicVisitor<RNode> {
 
-    private final RContext context;
     private REnvironment environment;
 
-    public RTruffleVisitor(RContext context) {
-        this.context = context;
+    public RTruffleVisitor() {
         this.environment = new REnvironment();
     }
 
@@ -64,9 +63,9 @@ public final class RTruffleVisitor extends BasicVisitor<RNode> {
         }
         switch (c.getType()) {
             case INT:
-                return ConstantNode.create(src, RRuntime.string2int(context, c.getValues()[0]));
+                return ConstantNode.create(src, RRuntime.string2int(c.getValues()[0]));
             case DOUBLE:
-                return ConstantNode.create(src, RRuntime.string2double(context, c.getValues()[0]));
+                return ConstantNode.create(src, RRuntime.string2double(c.getValues()[0]));
             case BOOL:
                 String value = c.getValues()[0];
                 if (value.equals("NA")) {
@@ -81,7 +80,7 @@ public final class RTruffleVisitor extends BasicVisitor<RNode> {
             case STRING:
                 return ConstantNode.create(src, c.getValues()[0]);
             case COMPLEX:
-                return ConstantNode.create(src, RDataFactory.createComplex(0, RRuntime.string2double(context, c.getValues()[0])));
+                return ConstantNode.create(src, RDataFactory.createComplex(0, RRuntime.string2double(c.getValues()[0])));
             default:
                 throw new UnsupportedOperationException();
         }
@@ -98,7 +97,7 @@ public final class RTruffleVisitor extends BasicVisitor<RNode> {
             nodes[index] = e.getValue() != null ? e.getValue().accept(this) : ConstantNode.create(RMissing.instance);
             index++;
         }
-        return CallNode.createCall(call.getSource(), ReadVariableNode.create(call.getName(), context, true, false), CallArgumentsNode.create(nodes, argumentNames));
+        return CallNode.createCall(call.getSource(), ReadVariableNode.create(call.getName(), true, false), CallArgumentsNode.create(nodes, argumentNames));
     }
 
     @Override
@@ -149,14 +148,14 @@ public final class RTruffleVisitor extends BasicVisitor<RNode> {
     @Override
     public RNode visit(UnaryOperation op) {
         RNode operand = op.getLHS().accept(this);
-        return CallNode.createStaticCall(op.getSource(), context, op.getPrettyOperator(), CallArgumentsNode.createUnnamed(operand));
+        return CallNode.createStaticCall(op.getSource(), op.getPrettyOperator(), CallArgumentsNode.createUnnamed(operand));
     }
 
     @Override
     public RNode visit(BinaryOperation op) {
         RNode left = op.getLHS().accept(this);
         RNode right = op.getRHS().accept(this);
-        return CallNode.createStaticCall(op.getSource(), context, op.getPrettyOperator(), CallArgumentsNode.createUnnamed(left, right));
+        return CallNode.createStaticCall(op.getSource(), op.getPrettyOperator(), CallArgumentsNode.createUnnamed(left, right));
     }
 
     @Override
@@ -272,7 +271,7 @@ public final class RTruffleVisitor extends BasicVisitor<RNode> {
         WriteVariableNode aAssign = WriteVariableNode.create(a, rhs, false, false, true);
 
         // read v, assign tmp
-        ReadVariableNode v = n.isSuper() ? ReadSuperVariableNode.create(vAST.getSource(), vSymbol, context, false, false) : ReadVariableNode.create(vAST.getSource(), vSymbol, context, false, false);
+        ReadVariableNode v = n.isSuper() ? ReadSuperVariableNode.create(vAST.getSource(), vSymbol, false, false) : ReadVariableNode.create(vAST.getSource(), vSymbol, false, false);
         final String tmp = "*tmp*";
         WriteVariableNode tmpAssign = WriteVariableNode.create(tmp, v, false, false);
 
@@ -292,7 +291,7 @@ public final class RTruffleVisitor extends BasicVisitor<RNode> {
 
         // assign v, read a
         WriteVariableNode vAssign = WriteVariableNode.create(vSymbol, replacementFunctionCall, false, n.isSuper());
-        ReadVariableNode aRead = ReadVariableNode.create(a, context, false, false);
+        ReadVariableNode aRead = ReadVariableNode.create(a, false, false);
 
         // assemble
         SequenceNode replacement = new SequenceNode(new RNode[]{aAssign, tmpAssign, vAssign, Invisible.create(aRead)});
@@ -302,12 +301,12 @@ public final class RTruffleVisitor extends BasicVisitor<RNode> {
 
     @Override
     public RNode visit(SimpleAccessVariable n) {
-        return ReadVariableNode.create(n.getSource(), n.getSymbol(), context, false, n.shouldCopyValue());
+        return ReadVariableNode.create(n.getSource(), n.getSymbol(), false, n.shouldCopyValue());
     }
 
     @Override
     public RNode visit(SimpleAccessTempVariable n) {
-        return ReadVariableNode.create(n.getSource(), n.getSymbol(), context, false, false);
+        return ReadVariableNode.create(n.getSource(), n.getSymbol(), false, false);
     }
 
     @Override
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/ReadVariableNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/ReadVariableNode.java
index f249f4f1e7..4cd465545e 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/ReadVariableNode.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/ReadVariableNode.java
@@ -35,7 +35,6 @@ import com.oracle.truffle.r.nodes.access.ReadVariableNodeFactory.ReadAndCopySupe
 import com.oracle.truffle.r.nodes.access.ReadVariableNodeFactory.ReadLocalVariableNodeFactory;
 import com.oracle.truffle.r.nodes.access.ReadVariableNodeFactory.ReadSuperVariableNodeFactory;
 import com.oracle.truffle.r.nodes.access.ReadVariableNodeFactory.UnknownVariableNodeFactory;
-
 import com.oracle.truffle.r.nodes.access.FrameSlotNode.*;
 import com.oracle.truffle.r.runtime.*;
 import com.oracle.truffle.r.runtime.data.*;
@@ -45,12 +44,12 @@ public abstract class ReadVariableNode extends RNode {
 
     public abstract Object execute(VirtualFrame frame, MaterializedFrame enclosingFrame);
 
-    public static ReadVariableNode create(Object symbol, RContext context, boolean functionLookup, boolean shouldCopyValue) {
-        return new UnresolvedReadVariableNode(symbol, context, functionLookup, shouldCopyValue);
+    public static ReadVariableNode create(Object symbol, boolean functionLookup, boolean shouldCopyValue) {
+        return new UnresolvedReadVariableNode(symbol, functionLookup, shouldCopyValue);
     }
 
-    public static ReadVariableNode create(SourceSection src, Object symbol, RContext context, boolean functionLookup, boolean shouldCopyValue) {
-        ReadVariableNode rvn = create(symbol, context, functionLookup, shouldCopyValue);
+    public static ReadVariableNode create(SourceSection src, Object symbol, boolean functionLookup, boolean shouldCopyValue) {
+        ReadVariableNode rvn = create(symbol, functionLookup, shouldCopyValue);
         rvn.assignSourceSection(src);
         return rvn;
     }
@@ -58,7 +57,6 @@ public abstract class ReadVariableNode extends RNode {
     public static final class UnresolvedReadVariableNode extends ReadVariableNode {
 
         private final Object symbol;
-        private final RContext context;
         private final boolean functionLookup;
 
         /**
@@ -72,9 +70,8 @@ public abstract class ReadVariableNode extends RNode {
             copyValue = c;
         }
 
-        public UnresolvedReadVariableNode(Object symbol, RContext context, boolean functionLookup, boolean copyValue) {
+        public UnresolvedReadVariableNode(Object symbol, boolean functionLookup, boolean copyValue) {
             this.symbol = symbol;
-            this.context = context;
             this.functionLookup = functionLookup;
             this.copyValue = copyValue;
         }
@@ -85,7 +82,7 @@ public abstract class ReadVariableNode extends RNode {
             if (enclosingFrame != null) {
                 ReadSuperVariableNode readSuper = copyValue ? ReadAndCopySuperVariableNodeFactory.create(null, new FrameSlotNode.UnresolvedFrameSlotNode(symbol))
                                 : ReadSuperVariableNodeFactory.create(null, new FrameSlotNode.UnresolvedFrameSlotNode(symbol));
-                ReadVariableMaterializedNode readNode = new ReadVariableMaterializedNode(readSuper, new UnresolvedReadVariableNode(symbol, context, functionLookup, copyValue), functionLookup);
+                ReadVariableMaterializedNode readNode = new ReadVariableMaterializedNode(readSuper, new UnresolvedReadVariableNode(symbol, functionLookup, copyValue), functionLookup);
                 return replace(readNode).execute(frame, enclosingFrame);
             } else {
                 return replace(resolveNonFrame()).execute(frame);
@@ -93,7 +90,7 @@ public abstract class ReadVariableNode extends RNode {
         }
 
         private ReadVariableNode resolveNonFrame() {
-            RFunction lookupResult = context.getLookup().lookup(context, symbol.toString());
+            RFunction lookupResult = RContext.getInstance().getLookup().lookup(symbol.toString());
             if (lookupResult != null) {
                 return BuiltinFunctionVariableNodeFactory.create(lookupResult);
             } else {
@@ -109,10 +106,10 @@ public abstract class ReadVariableNode extends RNode {
             if (assumptions == null) {
                 // Found variable in one of the frames; build inline cache.
                 ReadLocalVariableNode actualReadNode = ReadLocalVariableNodeFactory.create(new FrameSlotNode.UnresolvedFrameSlotNode(symbol));
-                readNode = new ReadVariableVirtualNode(actualReadNode, new UnresolvedReadVariableNode(symbol, context, functionLookup, copyValue), functionLookup);
+                readNode = new ReadVariableVirtualNode(actualReadNode, new UnresolvedReadVariableNode(symbol, functionLookup, copyValue), functionLookup);
             } else {
                 // Symbol is missing in all frames; bundle assumption checks and access builtin.
-                readNode = new ReadVariableNonFrameNode(assumptions, resolveNonFrame(), new UnresolvedReadVariableNode(symbol, context, functionLookup, copyValue), symbol);
+                readNode = new ReadVariableNonFrameNode(assumptions, resolveNonFrame(), new UnresolvedReadVariableNode(symbol, functionLookup, copyValue), symbol);
             }
             return replace(readNode).execute(frame);
         }
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/binary/BinaryArithmeticNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/binary/BinaryArithmeticNode.java
index e16455b56a..972f29b03b 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/binary/BinaryArithmeticNode.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/binary/BinaryArithmeticNode.java
@@ -59,7 +59,7 @@ public abstract class BinaryArithmeticNode extends BinaryNode {
     }
 
     public static BinaryArithmeticNode create(BinaryArithmeticFactory arithmetic) {
-        return BinaryArithmeticNodeFactory.create(arithmetic, null, new RNode[2], null, null);
+        return BinaryArithmeticNodeFactory.create(arithmetic, null, new RNode[2], null);
     }
 
     @CreateCast({"arguments"})
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/binary/BinaryBooleanNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/binary/BinaryBooleanNode.java
index 94130d715c..32d7b1ed48 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/binary/BinaryBooleanNode.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/binary/BinaryBooleanNode.java
@@ -1472,7 +1472,7 @@ public abstract class BinaryBooleanNode extends BinaryNode {
         }
         boolean notMultiple = l != 0 || r != 0;
         if (notMultiple) {
-            getContext().setEvalWarning(RError.LENGTH_NOT_MULTI);
+            RContext.getInstance().setEvalWarning(RError.LENGTH_NOT_MULTI);
         }
         RLogicalVector ret = RDataFactory.createLogicalVector(result, leftNACheck.neverSeenNA() && rightNACheck.neverSeenNA());
         ret.setDimensions(left.hasDimensions() ? left.getDimensions() : right.getDimensions(), this.getSourceSection());
@@ -1517,7 +1517,7 @@ public abstract class BinaryBooleanNode extends BinaryNode {
         }
         boolean notMultiple = l != 0 || r != 0;
         if (notMultiple) {
-            getContext().setEvalWarning(RError.LENGTH_NOT_MULTI);
+            RContext.getInstance().setEvalWarning(RError.LENGTH_NOT_MULTI);
         }
         RLogicalVector ret = RDataFactory.createLogicalVector(result, leftNACheck.neverSeenNA() && rightNACheck.neverSeenNA());
         ret.setDimensions(left.hasDimensions() ? left.getDimensions() : right.getDimensions(), this.getSourceSection());
@@ -1562,7 +1562,7 @@ public abstract class BinaryBooleanNode extends BinaryNode {
         }
         boolean notMultiple = l != 0 || r != 0;
         if (notMultiple) {
-            getContext().setEvalWarning(RError.LENGTH_NOT_MULTI);
+            RContext.getInstance().setEvalWarning(RError.LENGTH_NOT_MULTI);
         }
         RLogicalVector ret = RDataFactory.createLogicalVector(result, leftNACheck.neverSeenNA() && rightNACheck.neverSeenNA());
         ret.setDimensions(left.hasDimensions() ? left.getDimensions() : right.getDimensions(), this.getSourceSection());
@@ -1607,7 +1607,7 @@ public abstract class BinaryBooleanNode extends BinaryNode {
         }
         boolean notMultiple = l != 0 || r != 0;
         if (notMultiple) {
-            getContext().setEvalWarning(RError.LENGTH_NOT_MULTI);
+            RContext.getInstance().setEvalWarning(RError.LENGTH_NOT_MULTI);
         }
         RLogicalVector ret = RDataFactory.createLogicalVector(result, leftNACheck.neverSeenNA() && rightNACheck.neverSeenNA());
         ret.setDimensions(left.hasDimensions() ? left.getDimensions() : right.getDimensions(), this.getSourceSection());
@@ -1648,7 +1648,7 @@ public abstract class BinaryBooleanNode extends BinaryNode {
         }
         boolean notMultiple = l != 0 || r != 0;
         if (notMultiple) {
-            getContext().setEvalWarning(RError.LENGTH_NOT_MULTI);
+            RContext.getInstance().setEvalWarning(RError.LENGTH_NOT_MULTI);
         }
         RRawVector ret = RDataFactory.createRawVector(result);
         ret.setDimensions(left.hasDimensions() ? left.getDimensions() : right.getDimensions(), this.getSourceSection());
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/binary/BinaryBooleanNonVectorizedNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/binary/BinaryBooleanNonVectorizedNode.java
index d7c9629ffc..367c415e52 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/binary/BinaryBooleanNonVectorizedNode.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/binary/BinaryBooleanNonVectorizedNode.java
@@ -62,7 +62,7 @@ public abstract class BinaryBooleanNonVectorizedNode extends BinaryNode {
     }
 
     private LeftOpToLogicalScalarCast createCast(RNode child) {
-        return LeftOpToLogicalScalarCastFactory.create(child, getContext(), logic.opName());
+        return LeftOpToLogicalScalarCastFactory.create(child, logic.opName());
     }
 
     @ShortCircuit("arguments[1]")
@@ -242,14 +242,12 @@ public abstract class BinaryBooleanNonVectorizedNode extends BinaryNode {
         return needsRightOperand;
     }
 
-    @NodeFields({@NodeField(name = "context", type = RContext.class), @NodeField(name = "opName", type = String.class)})
+    @NodeField(name = "opName", type = String.class)
     @NodeChild("operand")
     public abstract static class LeftOpToLogicalScalarCast extends RNode {
 
         public abstract byte executeCast(VirtualFrame frame, Object o);
 
-        public abstract RContext getContext();
-
         public abstract String getOpName();
 
         @Specialization
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/binary/CbindFoldOperationNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/binary/CbindFoldOperationNode.java
index dbfc9b2330..8540b9d603 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/binary/CbindFoldOperationNode.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/binary/CbindFoldOperationNode.java
@@ -30,7 +30,7 @@ public final class CbindFoldOperationNode extends FoldOperationNode {
     @Child private CbindBinaryNode cbind;
 
     public CbindFoldOperationNode() {
-        this.cbind = adoptChild(CbindBinaryNodeFactory.create(new RNode[2], null, null));
+        this.cbind = adoptChild(CbindBinaryNodeFactory.create(new RNode[2], null));
     }
 
     private Object executeCbind(VirtualFrame frame, Object left, Object right) {
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/binary/CombineFoldOperationNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/binary/CombineFoldOperationNode.java
index 33319680ea..6f94d37778 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/binary/CombineFoldOperationNode.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/binary/CombineFoldOperationNode.java
@@ -40,7 +40,7 @@ public final class CombineFoldOperationNode extends FoldOperationNode {
     public Object executeComplex(VirtualFrame frame, Object left, Object right) {
         if (combineComplex == null) {
             CompilerDirectives.transferToInterpreter();
-            combineComplex = adoptChild(CombineBinaryComplexNodeFactory.create(new RNode[2], null, null));
+            combineComplex = adoptChild(CombineBinaryComplexNodeFactory.create(new RNode[2], null));
         }
         return combineComplex.executeCombine(frame, left, right);
     }
@@ -49,7 +49,7 @@ public final class CombineFoldOperationNode extends FoldOperationNode {
     public Object executeDouble(VirtualFrame frame, Object left, Object right) {
         if (combineDouble == null) {
             CompilerDirectives.transferToInterpreter();
-            combineDouble = adoptChild(CombineBinaryDoubleNodeFactory.create(new RNode[2], null, null));
+            combineDouble = adoptChild(CombineBinaryDoubleNodeFactory.create(new RNode[2], null));
         }
         return combineDouble.executeCombine(frame, left, right);
     }
@@ -58,7 +58,7 @@ public final class CombineFoldOperationNode extends FoldOperationNode {
     public Object executeInteger(VirtualFrame frame, Object left, Object right) {
         if (combineInteger == null) {
             CompilerDirectives.transferToInterpreter();
-            combineInteger = adoptChild(CombineBinaryIntegerNodeFactory.create(new RNode[2], null, null));
+            combineInteger = adoptChild(CombineBinaryIntegerNodeFactory.create(new RNode[2], null));
         }
         return combineInteger.executeCombine(frame, left, right);
     }
@@ -67,7 +67,7 @@ public final class CombineFoldOperationNode extends FoldOperationNode {
     public Object executeString(VirtualFrame frame, Object left, Object right) {
         if (combineString == null) {
             CompilerDirectives.transferToInterpreter();
-            combineString = adoptChild(CombineBinaryStringNodeFactory.create(new RNode[2], null, null));
+            combineString = adoptChild(CombineBinaryStringNodeFactory.create(new RNode[2], null));
         }
         return combineString.executeCombine(frame, left, right);
     }
@@ -76,7 +76,7 @@ public final class CombineFoldOperationNode extends FoldOperationNode {
     public Object executeLogical(VirtualFrame frame, Object left, Object right) {
         if (combineLogical == null) {
             CompilerDirectives.transferToInterpreter();
-            combineLogical = adoptChild(CombineBinaryLogicalNodeFactory.create(new RNode[2], null, null));
+            combineLogical = adoptChild(CombineBinaryLogicalNodeFactory.create(new RNode[2], null));
         }
         return combineLogical.executeCombine(frame, left, right);
     }
@@ -85,7 +85,7 @@ public final class CombineFoldOperationNode extends FoldOperationNode {
     public Object executeRaw(VirtualFrame frame, Object left, Object right) {
         if (combineRaw == null) {
             CompilerDirectives.transferToInterpreter();
-            combineRaw = adoptChild(CombineBinaryRawNodeFactory.create(new RNode[2], null, null));
+            combineRaw = adoptChild(CombineBinaryRawNodeFactory.create(new RNode[2], null));
         }
         return combineRaw.executeCombine(frame, left, right);
     }
@@ -94,7 +94,7 @@ public final class CombineFoldOperationNode extends FoldOperationNode {
     public Object executeList(VirtualFrame frame, Object left, Object right) {
         if (combineList == null) {
             CompilerDirectives.transferToInterpreter();
-            combineList = adoptChild(CombineBinaryListNodeFactory.create(new RNode[2], null, null));
+            combineList = adoptChild(CombineBinaryListNodeFactory.create(new RNode[2], null));
         }
         return combineList.executeCombine(frame, left, right);
     }
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/binary/RbindFoldOperationNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/binary/RbindFoldOperationNode.java
index 7dfbe1617d..467259bb65 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/binary/RbindFoldOperationNode.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/binary/RbindFoldOperationNode.java
@@ -30,7 +30,7 @@ public final class RbindFoldOperationNode extends FoldOperationNode {
     @Child private RbindBinaryNode rbind;
 
     public RbindFoldOperationNode() {
-        this.rbind = adoptChild(RbindBinaryNodeFactory.create(new RNode[2], null, null));
+        this.rbind = adoptChild(RbindBinaryNodeFactory.create(new RNode[2], null));
     }
 
     private Object executeRbind(VirtualFrame frame, Object left, Object right) {
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/RBuiltinNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/RBuiltinNode.java
index bcef690742..7088ea6b61 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/RBuiltinNode.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/RBuiltinNode.java
@@ -33,14 +33,12 @@ import com.oracle.truffle.r.nodes.builtin.base.*;
 import com.oracle.truffle.r.runtime.*;
 import com.oracle.truffle.r.runtime.data.*;
 
-@NodeFields({@NodeField(name = "context", type = RContext.class), @NodeField(name = "builtin", type = RBuiltinFactory.class)})
+@NodeField(name = "builtin", type = RBuiltinFactory.class)
 @NodeChild(value = "arguments", type = RNode[].class)
 public abstract class RBuiltinNode extends CallNode {
 
     public abstract RNode[] getArguments();
 
-    public abstract RContext getContext();
-
     public abstract RBuiltinFactory getBuiltin();
 
     public Object[] getParameterNames() {
@@ -77,9 +75,9 @@ public abstract class RBuiltinNode extends CallNode {
         return args;
     }
 
-    static CallTarget createArgumentsCallTarget(RContext ctx, RBuiltinFactory builtin) {
+    static CallTarget createArgumentsCallTarget(RBuiltinFactory builtin) {
         RNode[] args = createCallArguments(builtin);
-        RBuiltinNode node = createNode(ctx, builtin, args, null);
+        RBuiltinNode node = createNode(builtin, args, null);
         injectParameterDefaultValues(node);
         RBuiltinRootNode root = new RBuiltinRootNode(node, node.getParameterNames(), new FrameDescriptor());
         node.onCreate();
@@ -100,21 +98,20 @@ public abstract class RBuiltinNode extends CallNode {
         RNode[] builtinArguments;
         // static number of arguments
         builtinArguments = inlineStaticArguments(args);
-        RBuiltinNode builtin = createNode(getContext(), getBuiltin(), builtinArguments, args.getNameCount() == 0 ? null : args.getNames());
+        RBuiltinNode builtin = createNode(getBuiltin(), builtinArguments, args.getNameCount() == 0 ? null : args.getNames());
         builtin.onCreate();
         return builtin;
     }
 
-    private static RBuiltinNode createNode(RContext context, RBuiltinFactory factory, RNode[] builtinArguments, String[] argNames) {
+    private static RBuiltinNode createNode(RBuiltinFactory factory, RNode[] builtinArguments, String[] argNames) {
         boolean isCombine = (factory.getFactory().getClass() == CombineFactory.class || factory.getFactory().getClass() == ListBuiltinFactory.class);
-        Object[] args = new Object[(isCombine ? 4 : 3) + factory.getConstantArguments().length];
+        Object[] args = new Object[(isCombine ? 3 : 2) + factory.getConstantArguments().length];
         int index = 0;
         for (; index < factory.getConstantArguments().length; index++) {
             args[index] = factory.getConstantArguments()[index];
         }
 
         args[index++] = builtinArguments;
-        args[index++] = context;
         args[index++] = factory;
         if (isCombine) {
             args[index++] = argNames;
@@ -216,16 +213,14 @@ public abstract class RBuiltinNode extends CallNode {
 
         @Children protected final RNode[] arguments;
 
-        private final RContext context;
         private final RBuiltinFactory builtin;
 
         public RCustomBuiltinNode(RBuiltinNode prev) {
-            this(prev.getArguments(), prev.getContext(), prev.getBuiltin());
+            this(prev.getArguments(), prev.getBuiltin());
         }
 
-        public RCustomBuiltinNode(RNode[] arguments, RContext context, RBuiltinFactory builtin) {
+        public RCustomBuiltinNode(RNode[] arguments, RBuiltinFactory builtin) {
             this.arguments = adoptChildren(arguments);
-            this.context = context;
             this.builtin = builtin;
         }
 
@@ -234,11 +229,6 @@ public abstract class RBuiltinNode extends CallNode {
             return arguments;
         }
 
-        @Override
-        public RContext getContext() {
-            return context;
-        }
-
         @Override
         public RBuiltinFactory getBuiltin() {
             return builtin;
@@ -250,8 +240,8 @@ public abstract class RBuiltinNode extends CallNode {
 
         @Child protected CallNode snippetCall;
 
-        public RSnippetNode(RNode[] arguments, RContext context, RBuiltinFactory builtin, FunctionExpressionNode function) {
-            super(arguments, context, builtin);
+        public RSnippetNode(RNode[] arguments, RBuiltinFactory builtin, FunctionExpressionNode function) {
+            super(arguments, builtin);
             snippetCall = adoptChild(CallNode.createCall(function, CallArgumentsNode.create(getArguments(), new String[]{})));
         }
 
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/RDefaultPackages.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/RDefaultPackages.java
index 3e0103e181..db09ab18b0 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/RDefaultPackages.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/RDefaultPackages.java
@@ -24,7 +24,6 @@ package com.oracle.truffle.r.nodes.builtin;
 
 import com.oracle.truffle.r.nodes.builtin.base.*;
 import com.oracle.truffle.r.nodes.builtin.debug.*;
-import com.oracle.truffle.r.runtime.*;
 
 public final class RDefaultPackages extends RPackages {
 
@@ -32,9 +31,9 @@ public final class RDefaultPackages extends RPackages {
         // empty
     }
 
-    public void load(RContext context) {
-        load(new BasePackage(context));
-        load(new DebugPackage(context));
+    public void load() {
+        load(new BasePackage());
+        load(new DebugPackage());
     }
 
     private static RDefaultPackages instance;
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/RLibraryLoader.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/RLibraryLoader.java
index f61b44bde9..4cddc47142 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/RLibraryLoader.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/RLibraryLoader.java
@@ -41,11 +41,9 @@ import com.oracle.truffle.r.runtime.data.*;
 public class RLibraryLoader {
 
     private final File libFile;
-    private final RContext context;
 
-    public RLibraryLoader(File libFile, RContext context) {
+    public RLibraryLoader(File libFile) {
         this.libFile = libFile;
-        this.context = context;
     }
 
     public Map<String, FunctionExpressionNode.StaticFunctionExpressionNode> loadLibrary() {
@@ -72,8 +70,8 @@ public class RLibraryLoader {
         ANTLRFileStream stream;
         try {
             stream = new ANTLRFileStream(libFile.getAbsolutePath());
-            RTruffleVisitor transform = new RTruffleVisitor(context);
-            RNode node = transform.transform(parseAST(stream, context.getSourceManager().get(libFile.getAbsolutePath())));
+            RTruffleVisitor transform = new RTruffleVisitor();
+            RNode node = transform.transform(parseAST(stream, RContext.getInstance().getSourceManager().get(libFile.getAbsolutePath())));
             return node;
         } catch (RecognitionException | IOException e) {
             throw new RuntimeException(e.getMessage(), e);
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/RPackage.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/RPackage.java
index 56fa97dd1f..d05a98d612 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/RPackage.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/RPackage.java
@@ -38,7 +38,6 @@ import com.oracle.truffle.r.nodes.*;
 import com.oracle.truffle.r.nodes.builtin.RBuiltin.LastParameterKind;
 import com.oracle.truffle.r.nodes.builtin.RBuiltinNode.RCustomBuiltinNode;
 import com.oracle.truffle.r.nodes.function.*;
-import com.oracle.truffle.r.runtime.*;
 
 /**
  * Intended to be subclassed by definitions of builtin functions.
@@ -46,8 +45,8 @@ import com.oracle.truffle.r.runtime.*;
 public abstract class RPackage {
     private final TreeMap<String, RBuiltinFactory> builtins = new TreeMap<>();
 
-    protected RPackage(RContext context) {
-        loadSnippets(context);
+    protected RPackage() {
+        loadSnippets();
     }
 
     public final RBuiltinFactory lookupByName(String methodName) {
@@ -62,11 +61,11 @@ public abstract class RPackage {
         return builtins;
     }
 
-    public final void loadSnippets(RContext context) {
+    public final void loadSnippets() {
         String rSourceName = getName() + ".r";
         URL rSource = getClass().getResource(rSourceName);
         if (rSource != null) {
-            RLibraryLoader loader = new RLibraryLoader(new File(rSource.getPath()), context);
+            RLibraryLoader loader = new RLibraryLoader(new File(rSource.getPath()));
             Map<String, FunctionExpressionNode.StaticFunctionExpressionNode> builtinDefs = loader.loadLibrary();
             for (Map.Entry<String, FunctionExpressionNode.StaticFunctionExpressionNode> def : builtinDefs.entrySet()) {
                 NodeFactory<RBuiltinNode> nodeFactory = new RSnippetNodeFactory(def.getValue());
@@ -154,7 +153,7 @@ public abstract class RPackage {
 
         public RBuiltinNode createNode(Object... arguments) {
             try {
-                RBuiltinNode builtin = new RCustomBuiltinNode((RNode[]) arguments[0], (RContext) arguments[1], (RBuiltinFactory) arguments[2]);
+                RBuiltinNode builtin = new RCustomBuiltinNode((RNode[]) arguments[0], (RBuiltinFactory) arguments[1]);
                 return constructor.newInstance(builtin);
             } catch (Exception e) {
                 throw new RuntimeException(e);
@@ -194,7 +193,7 @@ public abstract class RPackage {
 
         @Override
         public RBuiltinNode createNode(Object... arguments) {
-            RBuiltinNode builtin = new RBuiltinNode.RSnippetNode((RNode[]) arguments[0], (RContext) arguments[1], (RBuiltinFactory) arguments[2], function);
+            RBuiltinNode builtin = new RBuiltinNode.RSnippetNode((RNode[]) arguments[0], (RBuiltinFactory) arguments[1], function);
             return builtin;
         }
 
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/RPackages.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/RPackages.java
index 927ee33592..3f688c908c 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/RPackages.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/RPackages.java
@@ -20,7 +20,7 @@
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
- /*
+/*
  * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
  * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  */
@@ -45,8 +45,8 @@ public abstract class RPackages implements RBuiltinLookup {
     }
 
     @Override
-    public RFunction lookup(RContext context, String methodName) {
-        RFunction function = context.getCachedFunction(methodName);
+    public RFunction lookup(String methodName) {
+        RFunction function = RContext.getInstance().getCachedFunction(methodName);
         if (function != null) {
             return function;
         }
@@ -55,12 +55,12 @@ public abstract class RPackages implements RBuiltinLookup {
         if (builtin == null) {
             return null;
         }
-        return createFunction(context, builtin, methodName);
+        return createFunction(builtin, methodName);
     }
 
-    private static RFunction createFunction(RContext context, RBuiltinFactory builtin, String methodName) {
-        CallTarget callTarget = RBuiltinNode.createArgumentsCallTarget(context, builtin);
-        return context.putCachedFunction(methodName, new RFunction(builtin.getBuiltinNames()[0], callTarget, true));
+    private static RFunction createFunction(RBuiltinFactory builtin, String methodName) {
+        CallTarget callTarget = RBuiltinNode.createArgumentsCallTarget(builtin);
+        return RContext.getInstance().putCachedFunction(methodName, new RFunction(builtin.getBuiltinNames()[0], callTarget, true));
     }
 
     private RBuiltinFactory lookupBuiltin(String name) {
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/All.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/All.java
index 1bad02af53..dd949fcd8e 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/All.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/All.java
@@ -43,7 +43,7 @@ public abstract class All extends RBuiltinNode {
     private byte castLogical(VirtualFrame frame, Object o) {
         if (castLogicalNode == null) {
             CompilerDirectives.transferToInterpreter();
-            castLogicalNode = adoptChild(CastLogicalNodeFactory.create(null, true, false, getContext()));
+            castLogicalNode = adoptChild(CastLogicalNodeFactory.create(null, true, false));
         }
         return (byte) castLogicalNode.executeByte(frame, o);
     }
@@ -51,7 +51,7 @@ public abstract class All extends RBuiltinNode {
     private RLogicalVector castLogicalVector(VirtualFrame frame, Object o) {
         if (castLogicalNode == null) {
             CompilerDirectives.transferToInterpreter();
-            castLogicalNode = adoptChild(CastLogicalNodeFactory.create(null, true, false, getContext()));
+            castLogicalNode = adoptChild(CastLogicalNodeFactory.create(null, true, false));
         }
         return (RLogicalVector) castLogicalNode.executeLogicalVector(frame, o);
     }
@@ -89,7 +89,7 @@ public abstract class All extends RBuiltinNode {
     @Specialization
     public byte all(VirtualFrame frame, String value) {
         check.enable(value);
-        return check.convertStringToLogical(getContext(), value);
+        return check.convertStringToLogical(value);
     }
 
     @Specialization
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Any.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Any.java
index 83f8909f73..867ea31e95 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Any.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Any.java
@@ -43,7 +43,7 @@ public abstract class Any extends RBuiltinNode {
     private byte castLogical(VirtualFrame frame, Object o) {
         if (castLogicalNode == null) {
             CompilerDirectives.transferToInterpreter();
-            castLogicalNode = adoptChild(CastLogicalNodeFactory.create(null, true, false, getContext()));
+            castLogicalNode = adoptChild(CastLogicalNodeFactory.create(null, true, false));
         }
         return (byte) castLogicalNode.executeByte(frame, o);
     }
@@ -51,7 +51,7 @@ public abstract class Any extends RBuiltinNode {
     private RLogicalVector castLogicalVector(VirtualFrame frame, Object o) {
         if (castLogicalNode == null) {
             CompilerDirectives.transferToInterpreter();
-            castLogicalNode = adoptChild(CastLogicalNodeFactory.create(null, true, false, getContext()));
+            castLogicalNode = adoptChild(CastLogicalNodeFactory.create(null, true, false));
         }
         return (RLogicalVector) castLogicalNode.executeLogicalVector(frame, o);
     }
@@ -89,7 +89,7 @@ public abstract class Any extends RBuiltinNode {
     @Specialization
     public byte any(VirtualFrame frame, String value) {
         check.enable(value);
-        return check.convertStringToLogical(getContext(), value);
+        return check.convertStringToLogical(value);
     }
 
     @Specialization
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/AsInteger.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/AsInteger.java
index fc893ad8b8..0e23f4b37a 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/AsInteger.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/AsInteger.java
@@ -44,7 +44,7 @@ public abstract class AsInteger extends RBuiltinNode {
     private int castInt(VirtualFrame frame, Object o) {
         if (castIntNode == null) {
             CompilerDirectives.transferToInterpreter();
-            castIntNode = adoptChild(CastIntegerNodeFactory.create(null, false, false, getContext()));
+            castIntNode = adoptChild(CastIntegerNodeFactory.create(null, false, false));
         }
         return (int) castIntNode.executeInt(frame, o);
     }
@@ -52,7 +52,7 @@ public abstract class AsInteger extends RBuiltinNode {
     private RIntVector castIntVector(VirtualFrame frame, Object o) {
         if (castIntNode == null) {
             CompilerDirectives.transferToInterpreter();
-            castIntNode = adoptChild(CastIntegerNodeFactory.create(null, false, false, getContext()));
+            castIntNode = adoptChild(CastIntegerNodeFactory.create(null, false, false));
         }
         return (RIntVector) castIntNode.executeIntVector(frame, o);
     }
@@ -65,7 +65,7 @@ public abstract class AsInteger extends RBuiltinNode {
     @Specialization
     public int asInteger(double value) {
         check.enable(value);
-        return check.convertDoubleToInt(getContext(), value);
+        return check.convertDoubleToInt(value);
     }
 
     @Specialization
@@ -76,7 +76,7 @@ public abstract class AsInteger extends RBuiltinNode {
     @Specialization
     public int asInteger(RComplex value) {
         check.enable(value);
-        return check.convertComplexToInt(getContext(), value);
+        return check.convertComplexToInt(value);
     }
 
     @Specialization
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/AsLogical.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/AsLogical.java
index e1030947d6..f10c9d2afa 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/AsLogical.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/AsLogical.java
@@ -45,7 +45,7 @@ public abstract class AsLogical extends RBuiltinNode {
     private byte castLogical(VirtualFrame frame, Object o) {
         if (castLogicalNode == null) {
             CompilerDirectives.transferToInterpreter();
-            castLogicalNode = adoptChild(CastLogicalNodeFactory.create(null, false, false, getContext()));
+            castLogicalNode = adoptChild(CastLogicalNodeFactory.create(null, false, false));
         }
         return (byte) castLogicalNode.executeByte(frame, o);
     }
@@ -53,7 +53,7 @@ public abstract class AsLogical extends RBuiltinNode {
     private RLogicalVector castLogicalVector(VirtualFrame frame, Object o) {
         if (castLogicalNode == null) {
             CompilerDirectives.transferToInterpreter();
-            castLogicalNode = adoptChild(CastLogicalNodeFactory.create(null, false, false, getContext()));
+            castLogicalNode = adoptChild(CastLogicalNodeFactory.create(null, false, false));
         }
         return (RLogicalVector) castLogicalNode.executeLogicalVector(frame, o);
     }
@@ -84,7 +84,7 @@ public abstract class AsLogical extends RBuiltinNode {
     @Specialization
     public byte asLogical(VirtualFrame frame, String value) {
         check.enable(value);
-        return check.convertStringToLogical(getContext(), value);
+        return check.convertStringToLogical(value);
     }
 
     @Specialization
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/AsRaw.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/AsRaw.java
index ebb0caca19..d3343e131d 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/AsRaw.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/AsRaw.java
@@ -81,7 +81,7 @@ public abstract class AsRaw extends RBuiltinNode {
         // TODO: Output NA and out-of-range warning.
         if (castInteger == null) {
             CompilerDirectives.transferToInterpreter();
-            castInteger = adoptChild(CastIntegerNodeFactory.create(null, false, false, getContext()));
+            castInteger = adoptChild(CastIntegerNodeFactory.create(null, false, false));
         }
         return asRaw((int) castInteger.executeInt(frame, value));
     }
@@ -150,7 +150,7 @@ public abstract class AsRaw extends RBuiltinNode {
     public RRawVector asRaw(VirtualFrame frame, RList value) {
         if (asRawRecursive == null) {
             CompilerDirectives.transferToInterpreter();
-            asRawRecursive = adoptChild(AsRawFactory.create(new RNode[1], getContext(), getBuiltin()));
+            asRawRecursive = adoptChild(AsRawFactory.create(new RNode[1], getBuiltin()));
         }
         int length = value.getLength();
         RRawVector result = RDataFactory.createRawVector(length);
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/BasePackage.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/BasePackage.java
index 5f695cded9..49854aea7c 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/BasePackage.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/BasePackage.java
@@ -25,14 +25,11 @@ package com.oracle.truffle.r.nodes.builtin.base;
 import com.oracle.truffle.r.nodes.binary.*;
 import com.oracle.truffle.r.nodes.builtin.*;
 import com.oracle.truffle.r.nodes.unary.*;
-import com.oracle.truffle.r.runtime.*;
 import com.oracle.truffle.r.runtime.ops.*;
 
 public class BasePackage extends RPackage {
 
-    public BasePackage(RContext context) {
-        super(context);
-
+    public BasePackage() {
         // primitive operations
         load(UnaryNotNode.class).names("!");
         load(BinaryArithmeticNode.class).names("+").arguments(BinaryArithmetic.ADD, null);
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Cat.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Cat.java
index 7de6d2d632..4902440951 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Cat.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Cat.java
@@ -57,7 +57,7 @@ public abstract class Cat extends RBuiltinNode {
     private void ensureToString(String sep) {
         if (toString == null || !sep.equals(currentSep)) {
             CompilerDirectives.transferToInterpreter();
-            toString = adoptChild(ToStringFactory.create(new RNode[1], getContext(), getBuiltin()));
+            toString = adoptChild(ToStringFactory.create(new RNode[1], getBuiltin()));
             toString.setSeparator(sep);
             toString.setQuotes(false);
             toString.setIntL(false);
@@ -93,12 +93,9 @@ public abstract class Cat extends RBuiltinNode {
         return RInvisible.INVISIBLE_NULL;
     }
 
-    // This builtin must be allowed to produce output.
-    // CheckStyle: stop system..print check
-
     @SlowPath
-    private void catIntl(String s) {
-        getContext().getConsoleHandler().print(s);
+    private static void catIntl(String s) {
+        RContext.getInstance().getConsoleHandler().print(s);
     }
 
 }
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Cbind.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Cbind.java
index a86cb2c924..14484e2e02 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Cbind.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Cbind.java
@@ -43,7 +43,7 @@ public final class Cbind extends RWrapperBuiltinNode {
 
     @Override
     protected RNode createDelegate() {
-        Combine combine = CombineFactory.create(getArguments(), getContext(), getBuiltin(), null);
+        Combine combine = CombineFactory.create(getArguments(), getBuiltin(), null);
         combine.setFoldOperation(new CbindFoldOperationNode());
         return combine;
     }
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Combine.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Combine.java
index 07bf9ad1dc..a2a9973089 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Combine.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Combine.java
@@ -266,7 +266,7 @@ public abstract class Combine extends RBuiltinNode {
     private Object castInteger(VirtualFrame frame, Object operand) {
         if (castInteger == null) {
             CompilerDirectives.transferToInterpreter();
-            castInteger = adoptChild(CastIntegerNodeFactory.create(null, true, false, getContext()));
+            castInteger = adoptChild(CastIntegerNodeFactory.create(null, true, false));
         }
         return castInteger.executeCast(frame, operand);
     }
@@ -274,7 +274,7 @@ public abstract class Combine extends RBuiltinNode {
     private Object castLogical(VirtualFrame frame, Object operand) {
         if (castLogical == null) {
             CompilerDirectives.transferToInterpreter();
-            castLogical = adoptChild(CastLogicalNodeFactory.create(null, true, false, getContext()));
+            castLogical = adoptChild(CastLogicalNodeFactory.create(null, true, false));
         }
         return castLogical.executeCast(frame, operand);
     }
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/CommandArgs.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/CommandArgs.java
index fc227ffeb7..1b479c9c17 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/CommandArgs.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/CommandArgs.java
@@ -24,6 +24,7 @@ package com.oracle.truffle.r.nodes.builtin.base;
 
 import java.util.*;
 
+import com.oracle.truffle.api.CompilerDirectives.SlowPath;
 import com.oracle.truffle.api.dsl.*;
 import com.oracle.truffle.r.nodes.builtin.*;
 import com.oracle.truffle.r.runtime.*;
@@ -37,9 +38,9 @@ public abstract class CommandArgs extends RBuiltinNode {
         return getCommandArgs(trailingOnly == RRuntime.LOGICAL_TRUE);
     }
 
-    @com.oracle.truffle.api.CompilerDirectives.SlowPath
-    private RStringVector getCommandArgs(boolean trailingOnly) {
-        String[] s = getContext().getCommandArgs();
+    @SlowPath
+    private static RStringVector getCommandArgs(boolean trailingOnly) {
+        String[] s = RContext.getInstance().getCommandArgs();
         if (trailingOnly) {
             int index = s.length;
             for (int i = 0; i < s.length; ++i) {
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Exists.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Exists.java
index e93d387601..66dc116a53 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Exists.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Exists.java
@@ -89,7 +89,7 @@ public abstract class Exists extends RBuiltinNode {
         if (!name.equals(lastName)) {
             CompilerDirectives.transferToInterpreterAndInvalidate();
             lastName = name;
-            lastLookup = getContext().getLookup().lookup(getContext(), name) != null;
+            lastLookup = RContext.getInstance().getLookup().lookup(name) != null;
         }
         // FIXME deal with changes in packages due to deleting symbols
         return lastLookup;
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Invisible.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Invisible.java
index 67adec1391..212f9e5510 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Invisible.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Invisible.java
@@ -34,7 +34,7 @@ public abstract class Invisible extends RBuiltinNode {
     private static final Object[] PARAMETER_NAMES = new Object[]{"x"};
 
     public static RNode create(RNode value) {
-        return InvisibleFactory.create(new RNode[]{value}, null, null);
+        return InvisibleFactory.create(new RNode[]{value}, null);
     }
 
     @Override
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/IsNA.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/IsNA.java
index 2e6bf5a687..a85aa9ac2e 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/IsNA.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/IsNA.java
@@ -40,7 +40,7 @@ public abstract class IsNA extends RBuiltinNode {
     private Object isNARecursive(VirtualFrame frame, Object o) {
         if (recursiveIsNA == null) {
             CompilerDirectives.transferToInterpreter();
-            recursiveIsNA = adoptChild(IsNAFactory.create(new RNode[1], getContext(), getBuiltin()));
+            recursiveIsNA = adoptChild(IsNAFactory.create(new RNode[1], getBuiltin()));
         }
         return recursiveIsNA.execute(frame, o);
     }
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/IsUnsorted.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/IsUnsorted.java
index 59c2944bea..a88b0a0dd4 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/IsUnsorted.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/IsUnsorted.java
@@ -46,7 +46,7 @@ public abstract class IsUnsorted extends RBuiltinNode {
         return new RNode[]{ConstantNode.create(RMissing.instance), ConstantNode.create(RRuntime.LOGICAL_FALSE), ConstantNode.create(RRuntime.LOGICAL_FALSE)};
     }
 
-    @Child protected BinaryBooleanNode ge = adoptChild(BinaryBooleanNodeFactory.create(BinaryCompare.GREATER_EQUAL, new RNode[1], getContext(), getBuiltin()));
+    @Child protected BinaryBooleanNode ge = adoptChild(BinaryBooleanNodeFactory.create(BinaryCompare.GREATER_EQUAL, new RNode[1], getBuiltin()));
 
     @Specialization
     @SuppressWarnings("unused")
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/MatchFun.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/MatchFun.java
index 74954e30a7..0d4d934d5f 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/MatchFun.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/MatchFun.java
@@ -64,7 +64,7 @@ public abstract class MatchFun extends RBuiltinNode {
         if (lookup == null || !fun.equals(lastFun)) {
             CompilerDirectives.transferToInterpreterAndInvalidate();
             lastFun = fun;
-            ReadVariableNode rvn = ReadVariableNode.create(fun, getContext(), true, false);
+            ReadVariableNode rvn = ReadVariableNode.create(fun, true, false);
             lookup = lookup == null ? adoptChild(rvn) : lookup.replace(rvn);
         }
         Object r = lookup.execute(frame);
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Matrix.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Matrix.java
index d28c18e33a..5779e219ce 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Matrix.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Matrix.java
@@ -37,7 +37,7 @@ public abstract class Matrix extends RBuiltinNode {
 
     private static final String[] PARAMETER_NAMES = new String[]{"data", "nrow", "ncol", "byrow", "dimnames"};
 
-    @Child private Transpose transpose = this.adoptChild(TransposeFactory.create(new RNode[1], getContext(), getBuiltin()));
+    @Child private Transpose transpose = this.adoptChild(TransposeFactory.create(new RNode[1], getBuiltin()));
 
     @Override
     public Object[] getParameterNames() {
@@ -53,8 +53,8 @@ public abstract class Matrix extends RBuiltinNode {
     @CreateCast("arguments")
     public RNode[] castArguments(RNode[] arguments) {
         // nrow and ncol (positions 1, 2) are actually int
-        arguments[1] = CastIntegerNodeFactory.create(arguments[1], true, false, getContext());
-        arguments[2] = CastIntegerNodeFactory.create(arguments[2], true, false, getContext());
+        arguments[1] = CastIntegerNodeFactory.create(arguments[1], true, false);
+        arguments[2] = CastIntegerNodeFactory.create(arguments[2], true, false);
         return arguments;
     }
 
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Max.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Max.java
index bdeebaefc0..4557f06065 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Max.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Max.java
@@ -47,7 +47,7 @@ public final class Max extends RWrapperBuiltinNode {
     @Override
     protected RNode createDelegate() {
         ReduceSemantics semantics = new ReduceSemantics(RRuntime.INT_MIN_VALUE, Double.NEGATIVE_INFINITY, false, RError.NO_NONMISSING_MAX);
-        Combine combine = CombineFactory.create(getArguments(), getContext(), getBuiltin(), null);
+        Combine combine = CombineFactory.create(getArguments(), getBuiltin(), null);
         return UnaryArithmeticReduceNodeFactory.create(semantics, BinaryArithmetic.MAX, combine);
     }
 }
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Min.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Min.java
index b690ab7230..8202063c06 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Min.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Min.java
@@ -47,7 +47,7 @@ public final class Min extends RWrapperBuiltinNode {
     @Override
     protected RNode createDelegate() {
         ReduceSemantics semantics = new ReduceSemantics(RRuntime.INT_MAX_VALUE, Double.POSITIVE_INFINITY, false, RError.NO_NONMISSING_MIN);
-        Combine combine = CombineFactory.create(getArguments(), getContext(), getBuiltin(), null);
+        Combine combine = CombineFactory.create(getArguments(), getBuiltin(), null);
         return UnaryArithmeticReduceNodeFactory.create(semantics, BinaryArithmetic.MIN, combine);
     }
 }
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Mod.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Mod.java
index cc7f3e3a0b..bc4d1f886d 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Mod.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Mod.java
@@ -34,7 +34,7 @@ public abstract class Mod extends RBuiltinNode {
 
     @Child protected BinaryArithmeticNode pow = adoptChild(BinaryArithmeticNode.create(BinaryArithmetic.POW));
     @Child protected BinaryArithmeticNode add = adoptChild(BinaryArithmeticNode.create(BinaryArithmetic.ADD));
-    @Child protected Sqrt sqrt = adoptChild(SqrtFactory.create(new RNode[1], getContext(), getBuiltin()));
+    @Child protected Sqrt sqrt = adoptChild(SqrtFactory.create(new RNode[1], getBuiltin()));
 
     @Specialization
     public double mod(RComplex x) {
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/NewEnv.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/NewEnv.java
index 44b01984f9..f9d50b4ab6 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/NewEnv.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/NewEnv.java
@@ -48,7 +48,7 @@ public abstract class NewEnv extends RBuiltinNode {
     @CreateCast("arguments")
     protected RNode[] castStatusArgument(RNode[] arguments) {
         // size argument is at index 2, and an int
-        arguments[2] = CastIntegerNodeFactory.create(arguments[2], true, false, getContext());
+        arguments[2] = CastIntegerNodeFactory.create(arguments[2], true, false);
         return arguments;
     }
 
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/PrettyPrinterNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/PrettyPrinterNode.java
index bbfcd07e5b..e1eff2930b 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/PrettyPrinterNode.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/PrettyPrinterNode.java
@@ -238,7 +238,7 @@ public abstract class PrettyPrinterNode extends RNode {
     private String printMatrix(VirtualFrame frame, RVector vector) {
         if (toString == null) {
             CompilerDirectives.transferToInterpreter();
-            toString = adoptChild(ToStringFactory.create(new RNode[1], null, null));
+            toString = adoptChild(ToStringFactory.create(new RNode[1], null));
         }
         return toString.executeString(frame, vector);
     }
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Print.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Print.java
index 26126474d8..c366a800dc 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Print.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Print.java
@@ -43,8 +43,8 @@ public abstract class Print extends RBuiltinNode {
 
     @Child protected PrettyPrinterNode prettyPrinter = adoptChild(PrettyPrinterNodeFactory.create(null, false));
 
-    private void printHelper(String string) {
-        getContext().getConsoleHandler().println(string);
+    private static void printHelper(String string) {
+        RContext.getInstance().getConsoleHandler().println(string);
     }
 
     @Specialization
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Quit.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Quit.java
index 9d05d3ba15..fcde40a344 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Quit.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Quit.java
@@ -48,14 +48,14 @@ public abstract class Quit extends RBuiltinNode {
     @CreateCast("arguments")
     protected RNode[] castStatusArgument(RNode[] arguments) {
         // status argument is at index 1
-        arguments[1] = CastIntegerNodeFactory.create(arguments[1], true, false, getContext());
+        arguments[1] = CastIntegerNodeFactory.create(arguments[1], true, false);
         return arguments;
     }
 
     @Specialization
     public Object doQuit(final String saveArg, int status, byte runLast) {
         String save = saveArg;
-        RContext.ConsoleHandler consoleHandler = getContext().getConsoleHandler();
+        RContext.ConsoleHandler consoleHandler = RContext.getInstance().getConsoleHandler();
         if (save.equals("default")) {
             if (consoleHandler.isInteractive()) {
                 save = "ask";
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Rbind.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Rbind.java
index 6d9d7f5ac0..c8262195d0 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Rbind.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Rbind.java
@@ -44,7 +44,7 @@ public final class Rbind extends RWrapperBuiltinNode {
 
     @Override
     protected RNode createDelegate() {
-        Combine combine = CombineFactory.create(getArguments(), getContext(), getBuiltin(), null);
+        Combine combine = CombineFactory.create(getArguments(), getBuiltin(), null);
         combine.setFoldOperation(new RbindFoldOperationNode());
         return combine;
     }
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/RepeatInternal.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/RepeatInternal.java
index 1f8a830b65..ea24412b6d 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/RepeatInternal.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/RepeatInternal.java
@@ -37,7 +37,7 @@ public abstract class RepeatInternal extends RBuiltinNode {
     @CreateCast("arguments")
     protected RNode[] castStatusArgument(RNode[] arguments) {
         // times argument is at index 1
-        arguments[1] = CastIntegerNodeFactory.create(arguments[1], true, false, getContext());
+        arguments[1] = CastIntegerNodeFactory.create(arguments[1], true, false);
         return arguments;
     }
 
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Rnorm.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Rnorm.java
index cdb128399e..c5967c95ec 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Rnorm.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Rnorm.java
@@ -38,7 +38,7 @@ public abstract class Rnorm extends RBuiltinNode {
 
     @Specialization
     public RDoubleVector rnorm(int n, double mean, double standardd) {
-        RRandomNumberGenerator rng = getContext().getRandomNumberGenerator();
+        RRandomNumberGenerator rng = RContext.getInstance().getRandomNumberGenerator();
         double[] result = new double[n];
         for (int i = 0; i < n; i++) {
             result[i] = generateNorm(mean, standardd, rng);
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Runif.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Runif.java
index 9ee6a1aba0..30b6017f60 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Runif.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Runif.java
@@ -32,7 +32,7 @@ public abstract class Runif extends RBuiltinNode {
 
     @Specialization
     public RDoubleVector runif(int n) {
-        RRandomNumberGenerator rng = getContext().getRandomNumberGenerator();
+        RRandomNumberGenerator rng = RContext.getInstance().getRandomNumberGenerator();
         double[] result = new double[n];
         for (int i = 0; i < n; i++) {
             result[i] = rng.genrandDouble();
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/SApply.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/SApply.java
index 17e4dfb632..58d99dccd1 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/SApply.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/SApply.java
@@ -201,7 +201,7 @@ public abstract class SApply extends RBuiltinNode {
     private Object call(VirtualFrame frame, RFunction function) {
         if (callNode == null) {
             CompilerDirectives.transferToInterpreter();
-            callNode = adoptChild(CallNode.createCall(null, CallArgumentsNode.createUnnamed(ReadVariableNode.create(temporaryVariableSymbol, getContext(), false, false))));
+            callNode = adoptChild(CallNode.createCall(null, CallArgumentsNode.createUnnamed(ReadVariableNode.create(temporaryVariableSymbol, false, false))));
         }
         return callNode.execute(frame, function);
     }
@@ -209,7 +209,7 @@ public abstract class SApply extends RBuiltinNode {
     private int callInt(VirtualFrame frame, RFunction function) throws UnexpectedResultException {
         if (callNode == null) {
             CompilerDirectives.transferToInterpreter();
-            callNode = adoptChild(CallNode.createCall(null, CallArgumentsNode.createUnnamed(ReadVariableNode.create(temporaryVariableSymbol, getContext(), false, false))));
+            callNode = adoptChild(CallNode.createCall(null, CallArgumentsNode.createUnnamed(ReadVariableNode.create(temporaryVariableSymbol, false, false))));
         }
         return RTypesGen.RTYPES.expectInteger(callNode.execute(frame, function));
     }
@@ -217,7 +217,7 @@ public abstract class SApply extends RBuiltinNode {
     private double callDouble(VirtualFrame frame, RFunction function) throws UnexpectedResultException {
         if (callNode == null) {
             CompilerDirectives.transferToInterpreter();
-            callNode = adoptChild(CallNode.createCall(null, CallArgumentsNode.createUnnamed(ReadVariableNode.create(temporaryVariableSymbol, getContext(), false, false))));
+            callNode = adoptChild(CallNode.createCall(null, CallArgumentsNode.createUnnamed(ReadVariableNode.create(temporaryVariableSymbol, false, false))));
         }
         return RTypesGen.RTYPES.expectDouble(callNode.execute(frame, function));
     }
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Sd.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Sd.java
index c2d7c2b9ea..a694531a69 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Sd.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Sd.java
@@ -46,8 +46,8 @@ public abstract class Sd extends RBuiltinNode {
         return new RNode[]{ConstantNode.create(RMissing.instance), ConstantNode.create(RRuntime.LOGICAL_FALSE)};
     }
 
-    @Child protected Mean mean = adoptChild(MeanFactory.create(new RNode[2], getContext(), getBuiltin()));
-    @Child protected Sqrt sqrt = adoptChild(SqrtFactory.create(new RNode[1], getContext(), getBuiltin()));
+    @Child protected Mean mean = adoptChild(MeanFactory.create(new RNode[2], getBuiltin()));
+    @Child protected Sqrt sqrt = adoptChild(SqrtFactory.create(new RNode[1], getBuiltin()));
     @Child protected BinaryArithmetic add = adoptChild(BinaryArithmetic.ADD.create());
     @Child protected BinaryArithmetic sub = adoptChild(BinaryArithmetic.SUBTRACT.create());
     @Child protected BinaryArithmetic pow = adoptChild(BinaryArithmetic.POW.create());
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/SetSeed.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/SetSeed.java
index ed7d0e97c8..d62d4097b0 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/SetSeed.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/SetSeed.java
@@ -24,6 +24,7 @@ package com.oracle.truffle.r.nodes.builtin.base;
 
 import com.oracle.truffle.api.dsl.*;
 import com.oracle.truffle.r.nodes.builtin.*;
+import com.oracle.truffle.r.runtime.*;
 import com.oracle.truffle.r.runtime.data.*;
 
 @RBuiltin("set.seed")
@@ -31,7 +32,7 @@ public abstract class SetSeed extends RBuiltinNode {
 
     @Specialization
     public RNull setseed(int n) {
-        getContext().getRandomNumberGenerator().setSeed(n);
+        RContext.getInstance().getRandomNumberGenerator().setSeed(n);
         return RNull.instance;
     }
 
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Sum.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Sum.java
index b5b09a174e..129f276315 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Sum.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Sum.java
@@ -57,7 +57,7 @@ public final class Sum extends RWrapperBuiltinNode {
     @Override
     protected RNode createDelegate() {
         ReduceSemantics semantics = new ReduceSemantics(0, 0.0, true, null);
-        Combine combine = CombineFactory.create(getArguments(), getContext(), getBuiltin(), null);
+        Combine combine = CombineFactory.create(getArguments(), getBuiltin(), null);
         return UnaryArithmeticReduceNodeFactory.create(semantics, BinaryArithmetic.ADD, combine);
     }
 }
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/ToString.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/ToString.java
index 5f62d94f88..17893f5825 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/ToString.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/ToString.java
@@ -48,7 +48,7 @@ public abstract class ToString extends RBuiltinNode {
     private String toStringRecursive(VirtualFrame frame, Object o) {
         if (recursiveToString == null) {
             CompilerDirectives.transferToInterpreter();
-            recursiveToString = adoptChild(ToStringFactory.create(new RNode[1], getContext(), getBuiltin()));
+            recursiveToString = adoptChild(ToStringFactory.create(new RNode[1], getBuiltin()));
             recursiveToString.setSeparator(separator);
             recursiveToString.setQuotes(quotes);
             recursiveToString.setIntL(intL);
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/UpdateAttr.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/UpdateAttr.java
index d9b04a360a..db66eedf88 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/UpdateAttr.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/UpdateAttr.java
@@ -48,7 +48,7 @@ public abstract class UpdateAttr extends RBuiltinNode {
     private RAbstractVector updateNames(VirtualFrame frame, RAbstractVector vector, Object o) {
         if (updateNames == null) {
             CompilerDirectives.transferToInterpreter();
-            updateNames = adoptChild(UpdateNamesFactory.create(new RNode[1], getContext(), getBuiltin()));
+            updateNames = adoptChild(UpdateNamesFactory.create(new RNode[1], getBuiltin()));
         }
         return (RAbstractVector) updateNames.executeStringVector(frame, vector, o);
     }
@@ -56,7 +56,7 @@ public abstract class UpdateAttr extends RBuiltinNode {
     private RAbstractVector updateDimNames(VirtualFrame frame, RAbstractVector vector, Object o) {
         if (updateDimNames == null) {
             CompilerDirectives.transferToInterpreter();
-            updateDimNames = adoptChild(UpdateDimNamesFactory.create(new RNode[1], getContext(), getBuiltin()));
+            updateDimNames = adoptChild(UpdateDimNamesFactory.create(new RNode[1], getBuiltin()));
         }
         return (RAbstractVector) updateDimNames.executeList(frame, vector, o);
     }
@@ -64,7 +64,7 @@ public abstract class UpdateAttr extends RBuiltinNode {
     private RAbstractIntVector castInteger(VirtualFrame frame, RAbstractVector vector) {
         if (castInteger == null) {
             CompilerDirectives.transferToInterpreter();
-            castInteger = adoptChild(CastIntegerNodeFactory.create(null, true, false, getContext()));
+            castInteger = adoptChild(CastIntegerNodeFactory.create(null, true, false));
         }
         return (RAbstractIntVector) castInteger.executeCast(frame, vector);
     }
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/UpdateAttributes.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/UpdateAttributes.java
index 2ec056bd9d..b556928b0a 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/UpdateAttributes.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/UpdateAttributes.java
@@ -48,7 +48,7 @@ public abstract class UpdateAttributes extends RBuiltinNode {
     private void updateNamesStringVector(VirtualFrame frame, RAbstractVector vector, Object o) {
         if (updateNames == null) {
             CompilerDirectives.transferToInterpreter();
-            updateNames = adoptChild(UpdateNamesFactory.create(new RNode[1], getContext(), getBuiltin()));
+            updateNames = adoptChild(UpdateNamesFactory.create(new RNode[1], getBuiltin()));
         }
         updateNames.executeStringVector(frame, vector, o);
     }
@@ -56,7 +56,7 @@ public abstract class UpdateAttributes extends RBuiltinNode {
     private RAbstractIntVector castInteger(VirtualFrame frame, RAbstractVector vector) {
         if (castInteger == null) {
             CompilerDirectives.transferToInterpreter();
-            castInteger = adoptChild(CastIntegerNodeFactory.create(null, true, false, getContext()));
+            castInteger = adoptChild(CastIntegerNodeFactory.create(null, true, false));
         }
         return (RAbstractIntVector) castInteger.executeCast(frame, vector);
     }
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/UpdateDim.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/UpdateDim.java
index 08c8b27cc1..6e2fc6e936 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/UpdateDim.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/UpdateDim.java
@@ -42,7 +42,7 @@ public abstract class UpdateDim extends RBuiltinNode {
     private RAbstractIntVector castInteger(VirtualFrame frame, RAbstractVector vector) {
         if (castInteger == null) {
             CompilerDirectives.transferToInterpreter();
-            castInteger = adoptChild(CastIntegerNodeFactory.create(null, true, false, getContext()));
+            castInteger = adoptChild(CastIntegerNodeFactory.create(null, true, false));
         }
         return (RAbstractIntVector) castInteger.executeCast(frame, vector);
     }
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/UpdateLength.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/UpdateLength.java
index ecbf94a712..ac0790a5d2 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/UpdateLength.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/UpdateLength.java
@@ -36,7 +36,7 @@ public abstract class UpdateLength extends RBuiltinNode {
     @CreateCast("arguments")
     protected RNode[] castStatusArgument(RNode[] arguments) {
         // length argument is at index 1, and cast to int
-        arguments[1] = CastIntegerNodeFactory.create(arguments[1], true, false, getContext());
+        arguments[1] = CastIntegerNodeFactory.create(arguments[1], true, false);
         return arguments;
     }
 
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/debug/DebugInfoBuiltin.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/debug/DebugInfoBuiltin.java
index ec61b2554f..4a44e80372 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/debug/DebugInfoBuiltin.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/debug/DebugInfoBuiltin.java
@@ -27,6 +27,7 @@ import java.util.*;
 import com.oracle.truffle.api.CompilerDirectives.*;
 import com.oracle.truffle.api.dsl.*;
 import com.oracle.truffle.r.nodes.builtin.*;
+import com.oracle.truffle.r.runtime.*;
 
 @RBuiltin({"debug.info"})
 @RBuiltinComment("Prints this message.")
@@ -35,7 +36,7 @@ public abstract class DebugInfoBuiltin extends RBuiltinNode {
     @SlowPath
     @Specialization
     public Object printTree() {
-        RPackages packages = (RPackages) getContext().getLookup();
+        RPackages packages = (RPackages) RContext.getInstance().getLookup();
         StringBuilder b = new StringBuilder();
         for (RPackage pack : packages.getPackages()) {
             b.append(createPackageString(pack));
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/debug/DebugPackage.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/debug/DebugPackage.java
index 6af88f97c8..2b59cd21be 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/debug/DebugPackage.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/debug/DebugPackage.java
@@ -23,12 +23,10 @@
 package com.oracle.truffle.r.nodes.builtin.debug;
 
 import com.oracle.truffle.r.nodes.builtin.*;
-import com.oracle.truffle.r.runtime.*;
 
 public class DebugPackage extends RPackage {
 
-    public DebugPackage(RContext context) {
-        super(context);
+    public DebugPackage() {
         load(DebugInfoBuiltin.class);
         load(DebugSource.class);
         load(DebugTreeBuiltin.class);
@@ -43,9 +41,9 @@ public class DebugPackage extends RPackage {
 
     private static DebugPackage instance;
 
-    public static DebugPackage getInstance(RContext context) {
+    public static DebugPackage getInstance() {
         if (instance == null) {
-            instance = new DebugPackage(context);
+            instance = new DebugPackage();
         }
         return instance;
     }
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/CallNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/CallNode.java
index 43de15c362..15801bbb5e 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/CallNode.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/CallNode.java
@@ -61,12 +61,12 @@ public abstract class CallNode extends RNode {
         return RTypesGen.RTYPES.expectDouble(execute(frame, function));
     }
 
-    public static CallNode createStaticCall(RContext context, String function, CallArgumentsNode arguments) {
-        return CallNode.createCall(ReadVariableNode.create(function, context, true, false), arguments);
+    public static CallNode createStaticCall(String function, CallArgumentsNode arguments) {
+        return CallNode.createCall(ReadVariableNode.create(function, true, false), arguments);
     }
 
-    public static CallNode createStaticCall(SourceSection src, RContext context, String function, CallArgumentsNode arguments) {
-        CallNode cn = createStaticCall(context, function, arguments);
+    public static CallNode createStaticCall(SourceSection src, String function, CallArgumentsNode arguments) {
+        CallNode cn = createStaticCall(function, arguments);
         cn.assignSourceSection(src);
         return cn;
     }
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastIntegerNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastIntegerNode.java
index 18b18c399f..578a5707be 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastIntegerNode.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastIntegerNode.java
@@ -30,7 +30,7 @@ import com.oracle.truffle.r.runtime.*;
 import com.oracle.truffle.r.runtime.data.*;
 import com.oracle.truffle.r.runtime.ops.na.*;
 
-@NodeFields({@NodeField(name = "namesPreservation", type = boolean.class), @NodeField(name = "dimensionsPreservation", type = boolean.class), @NodeField(name = "context", type = RContext.class)})
+@NodeFields({@NodeField(name = "namesPreservation", type = boolean.class), @NodeField(name = "dimensionsPreservation", type = boolean.class)})
 public abstract class CastIntegerNode extends CastNode {
 
     private final NACheck check = NACheck.create();
@@ -39,8 +39,6 @@ public abstract class CastIntegerNode extends CastNode {
 
     public abstract Object executeIntVector(VirtualFrame frame, Object o);
 
-    public abstract RContext getContext();
-
     protected abstract boolean isNamesPreservation();
 
     protected abstract boolean isDimensionsPreservation();
@@ -58,7 +56,7 @@ public abstract class CastIntegerNode extends CastNode {
     private Object castIntegerRecursive(VirtualFrame frame, Object o) {
         if (recursiveCastInteger == null) {
             CompilerDirectives.transferToInterpreter();
-            recursiveCastInteger = adoptChild(CastIntegerNodeFactory.create(null, isNamesPreservation(), isDimensionsPreservation(), getContext()));
+            recursiveCastInteger = adoptChild(CastIntegerNodeFactory.create(null, isNamesPreservation(), isDimensionsPreservation()));
         }
         return recursiveCastInteger.executeInt(frame, o);
     }
@@ -81,7 +79,7 @@ public abstract class CastIntegerNode extends CastNode {
     @Specialization
     public int doDouble(double operand) {
         check.enable(operand);
-        return check.convertDoubleToInt(getContext(), operand);
+        return check.convertDoubleToInt(operand);
     }
 
     @Specialization
@@ -97,7 +95,7 @@ public abstract class CastIntegerNode extends CastNode {
     @Specialization
     public int doComplex(RComplex operand) {
         check.enable(operand);
-        return check.convertComplexToInt(getContext(), operand);
+        return check.convertComplexToInt(operand);
     }
 
     @Specialization
@@ -118,9 +116,9 @@ public abstract class CastIntegerNode extends CastNode {
         int length = vector.getLength();
         int[] result = new int[length];
         for (int i = 0; i < length; i++) {
-            result[i] = check.convertComplexToInt(getContext(), vector.getDataAt(i), false);
+            result[i] = check.convertComplexToInt(vector.getDataAt(i), false);
         }
-        getContext().setEvalWarning(RError.IMAGINARY_PARTS_DISCARDED_IN_COERCION);
+        RContext.getInstance().setEvalWarning(RError.IMAGINARY_PARTS_DISCARDED_IN_COERCION);
         return RDataFactory.createIntVector(result, check.neverSeenNA(), vector.getDimensions());
     }
 
@@ -130,9 +128,9 @@ public abstract class CastIntegerNode extends CastNode {
         int length = vector.getLength();
         int[] result = new int[length];
         for (int i = 0; i < length; i++) {
-            result[i] = check.convertComplexToInt(getContext(), vector.getDataAt(i), false);
+            result[i] = check.convertComplexToInt(vector.getDataAt(i), false);
         }
-        getContext().setEvalWarning(RError.IMAGINARY_PARTS_DISCARDED_IN_COERCION);
+        RContext.getInstance().setEvalWarning(RError.IMAGINARY_PARTS_DISCARDED_IN_COERCION);
         return RDataFactory.createIntVector(result, check.neverSeenNA(), vector.getNames());
     }
 
@@ -142,9 +140,9 @@ public abstract class CastIntegerNode extends CastNode {
         int length = vector.getLength();
         int[] result = new int[length];
         for (int i = 0; i < length; i++) {
-            result[i] = check.convertComplexToInt(getContext(), vector.getDataAt(i), false);
+            result[i] = check.convertComplexToInt(vector.getDataAt(i), false);
         }
-        getContext().setEvalWarning(RError.IMAGINARY_PARTS_DISCARDED_IN_COERCION);
+        RContext.getInstance().setEvalWarning(RError.IMAGINARY_PARTS_DISCARDED_IN_COERCION);
         return RDataFactory.createIntVector(result, check.neverSeenNA());
     }
 
@@ -217,21 +215,21 @@ public abstract class CastIntegerNode extends CastNode {
     @Specialization(order = 110, guards = "preserveDimensions")
     public RIntVector doDoubleVectorDims(RDoubleVector vector) {
         check.enable(vector);
-        int[] result = check.convertDoubleVectorToIntData(getContext(), vector);
+        int[] result = check.convertDoubleVectorToIntData(vector);
         return RDataFactory.createIntVector(result, check.neverSeenNA(), vector.getDimensions());
     }
 
     @Specialization(order = 111, guards = "preserveNames")
     public RIntVector doDoubleVectorNames(RDoubleVector vector) {
         check.enable(vector);
-        int[] result = check.convertDoubleVectorToIntData(getContext(), vector);
+        int[] result = check.convertDoubleVectorToIntData(vector);
         return RDataFactory.createIntVector(result, check.neverSeenNA(), vector.getNames());
     }
 
     @Specialization(order = 112)
     public RIntVector doDoubleVector(RDoubleVector vector) {
         check.enable(vector);
-        int[] result = check.convertDoubleVectorToIntData(getContext(), vector);
+        int[] result = check.convertDoubleVectorToIntData(vector);
         return RDataFactory.createIntVector(result, check.neverSeenNA());
     }
 
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastLogicalNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastLogicalNode.java
index e55a77dd9a..eee13c37d3 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastLogicalNode.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastLogicalNode.java
@@ -31,7 +31,7 @@ import com.oracle.truffle.r.runtime.data.*;
 import com.oracle.truffle.r.runtime.data.model.*;
 import com.oracle.truffle.r.runtime.ops.na.*;
 
-@NodeFields({@NodeField(name = "namesPreservation", type = boolean.class), @NodeField(name = "dimensionsPreservation", type = boolean.class), @NodeField(name = "context", type = RContext.class)})
+@NodeFields({@NodeField(name = "namesPreservation", type = boolean.class), @NodeField(name = "dimensionsPreservation", type = boolean.class)})
 public abstract class CastLogicalNode extends CastNode {
 
     private final NACheck naCheck = NACheck.create();
@@ -40,8 +40,6 @@ public abstract class CastLogicalNode extends CastNode {
 
     public abstract Object executeLogicalVector(VirtualFrame frame, Object o);
 
-    public abstract RContext getContext();
-
     protected abstract boolean isNamesPreservation();
 
     protected abstract boolean isDimensionsPreservation();
@@ -79,7 +77,7 @@ public abstract class CastLogicalNode extends CastNode {
     @Specialization
     public byte doString(String operand) {
         naCheck.enable(operand);
-        return naCheck.convertStringToLogical(getContext(), operand);
+        return naCheck.convertStringToLogical(operand);
     }
 
     @Specialization
@@ -118,7 +116,7 @@ public abstract class CastLogicalNode extends CastNode {
         byte[] ddata = new byte[operand.getLength()];
         for (int i = 0; i < operand.getLength(); i++) {
             String value = operand.getDataAt(i);
-            ddata[i] = naCheck.convertStringToLogical(getContext(), value);
+            ddata[i] = naCheck.convertStringToLogical(value);
         }
         return RDataFactory.createLogicalVector(ddata, naCheck.neverSeenNA(), operand.getDimensions());
     }
@@ -129,7 +127,7 @@ public abstract class CastLogicalNode extends CastNode {
         byte[] ddata = new byte[operand.getLength()];
         for (int i = 0; i < operand.getLength(); i++) {
             String value = operand.getDataAt(i);
-            ddata[i] = naCheck.convertStringToLogical(getContext(), value);
+            ddata[i] = naCheck.convertStringToLogical(value);
         }
         return RDataFactory.createLogicalVector(ddata, naCheck.neverSeenNA(), operand.getNames());
     }
@@ -140,7 +138,7 @@ public abstract class CastLogicalNode extends CastNode {
         byte[] ddata = new byte[operand.getLength()];
         for (int i = 0; i < operand.getLength(); i++) {
             String value = operand.getDataAt(i);
-            ddata[i] = naCheck.convertStringToLogical(getContext(), value);
+            ddata[i] = naCheck.convertStringToLogical(value);
         }
         return RDataFactory.createLogicalVector(ddata, naCheck.neverSeenNA());
     }
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastStringNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastStringNode.java
index 6cb3640728..696366bc85 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastStringNode.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastStringNode.java
@@ -33,7 +33,7 @@ import com.oracle.truffle.r.runtime.data.model.*;
                 @NodeField(name = "dimensionsPreservation", type = boolean.class)})
 public abstract class CastStringNode extends CastNode {
 
-    @Child private ToString toString = adoptChild(ToStringFactory.create(new RNode[1], null, null));
+    @Child private ToString toString = adoptChild(ToStringFactory.create(new RNode[1], null));
 
     public abstract Object executeString(VirtualFrame frame, Object o);
 
diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RBuiltinLookup.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RBuiltinLookup.java
index bca0e6037d..3a1efb2f7c 100644
--- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RBuiltinLookup.java
+++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RBuiltinLookup.java
@@ -26,6 +26,6 @@ import com.oracle.truffle.r.runtime.data.*;
 
 public interface RBuiltinLookup {
 
-    RFunction lookup(RContext context, String methodName);
+    RFunction lookup(String methodName);
 
 }
diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RRuntime.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RRuntime.java
index 91ac6519ac..11e856cab2 100644
--- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RRuntime.java
+++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RRuntime.java
@@ -153,13 +153,13 @@ public class RRuntime {
         return !isNAorNaN(d) && !Double.isInfinite(d);
     }
 
-    public static int string2int(RContext context, String s) {
+    public static int string2int(String s) {
         if (s != STRING_NA) {
             // FIXME use R rules
             try {
                 return Integer.decode(s);  // decode supports hex constants
             } catch (NumberFormatException e) {
-                context.getAssumptions().naIntroduced.invalidate();
+                RContext.getInstance().getAssumptions().naIntroduced.invalidate();
             }
         }
         return INT_NA;
@@ -170,7 +170,7 @@ public class RRuntime {
         return longValue == d && ((int) longValue & 0xffffffff) == longValue;
     }
 
-    public static double string2double(RContext context, String v) {
+    public static double string2double(String v) {
         if (v != STRING_NA) {
             // FIXME use R rules
             if ("Inf".equals(v)) {
@@ -187,7 +187,7 @@ public class RRuntime {
                     } catch (NumberFormatException ein) {
                     }
                 }
-                context.getAssumptions().naIntroduced.invalidate();
+                RContext.getInstance().getAssumptions().naIntroduced.invalidate();
             }
         }
         return DOUBLE_NA;
@@ -213,7 +213,7 @@ public class RRuntime {
         return isNA(c) ? LOGICAL_NA : c.getRealPart() == 0.0 && c.getImaginaryPart() == 0.0 ? LOGICAL_FALSE : LOGICAL_TRUE;
     }
 
-    public static byte string2logical(RContext context, String s) {
+    public static byte string2logical(String s) {
         if (s != STRING_NA) {
             if (s.equals("TRUE") || s.equals("T")) {
                 return TRUE;
@@ -227,7 +227,7 @@ public class RRuntime {
             if (s.equals("False") || s.equals("false")) {
                 return FALSE;
             }
-            context.getAssumptions().naIntroduced.invalidate();
+            RContext.getInstance().getAssumptions().naIntroduced.invalidate();
         }
         return LOGICAL_NA;
     }
diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ops/na/NACheck.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ops/na/NACheck.java
index 7f1d355d53..9539985f2d 100644
--- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ops/na/NACheck.java
+++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ops/na/NACheck.java
@@ -291,14 +291,14 @@ public final class NACheck implements RDataCheckClosure {
         return ((int) value.getRealPart()) == 0 ? RRuntime.LOGICAL_FALSE : RRuntime.LOGICAL_TRUE;
     }
 
-    public int convertComplexToInt(RContext context, RComplex right) {
-        return convertComplexToInt(context, right, true);
+    public int convertComplexToInt(RComplex right) {
+        return convertComplexToInt(right, true);
     }
 
     @SuppressWarnings("static-method")
-    public int convertComplexToInt(RContext context, RComplex right, boolean warning) {
+    public int convertComplexToInt(RComplex right, boolean warning) {
         if (warning) {
-            context.setEvalWarning(RError.IMAGINARY_PARTS_DISCARDED_IN_COERCION);
+            RContext.getInstance().setEvalWarning(RError.IMAGINARY_PARTS_DISCARDED_IN_COERCION);
         }
         return (int) right.getRealPart();
     }
@@ -314,7 +314,7 @@ public final class NACheck implements RDataCheckClosure {
         return false;
     }
 
-    public int convertDoubleToInt(RContext context, double value) {
+    public int convertDoubleToInt(double value) {
         if (checkNAorNaN(value)) {
             return RRuntime.INT_NA;
         }
@@ -324,13 +324,13 @@ public final class NACheck implements RDataCheckClosure {
                 CompilerDirectives.transferToInterpreterAndInvalidate();
                 this.conversionOverflowReached = true;
             }
-            context.setEvalWarning(RError.NA_INTRODUCED_COERCION);
+            RContext.getInstance().setEvalWarning(RError.NA_INTRODUCED_COERCION);
             return RRuntime.INT_NA;
         }
         return result;
     }
 
-    public int[] convertDoubleVectorToIntData(RContext context, RDoubleVector vector) {
+    public int[] convertDoubleVectorToIntData(RDoubleVector vector) {
         int length = vector.getLength();
         int[] result = new int[length];
         boolean warning = false;
@@ -351,7 +351,7 @@ public final class NACheck implements RDataCheckClosure {
                 result[i] = intValue;
             }
             if (warning) {
-                context.setEvalWarning(RError.NA_INTRODUCED_COERCION);
+                RContext.getInstance().setEvalWarning(RError.NA_INTRODUCED_COERCION);
             }
         }
         return result;
@@ -368,8 +368,8 @@ public final class NACheck implements RDataCheckClosure {
     }
 
     @SuppressWarnings("static-method")
-    public byte convertStringToLogical(RContext context, String value) {
-        return RRuntime.string2logical(context, value);
+    public byte convertStringToLogical(String value) {
+        return RRuntime.string2logical(value);
     }
 
 }
-- 
GitLab