protected final void installInstancePrimitive( final String selector, final NodeFactory<? extends ExpressionNode> nodeFactory) { SSymbol signature = universe.symbolFor(selector); SInvokable prim = constructPrimitive(signature, nodeFactory, universe, holder); // Install the given primitive as an instance primitive in the holder class holder.addInstancePrimitive(prim, displayWarning); }
public static SInvokable constructPrimitive( final SSymbol signature, final NodeFactory<? extends ExpressionNode> nodeFactory, final Universe universe, final SClass holder) { CompilerAsserts.neverPartOfCompilation(); int numArgs = signature.getNumberOfSignatureArguments(); MethodGenerationContext mgen = new MethodGenerationContext(null); ExpressionNode[] args = new ExpressionNode[numArgs]; for (int i = 0; i < numArgs; i++) { args[i] = new LocalArgumentReadNode(i, null); } ExpressionNode primNode; switch (numArgs) { case 1: primNode = nodeFactory.createNode(args[0]); break; case 2: // HACK for node class where we use `executeWith` if (nodeFactory == PutAllNodeFactory.getInstance()) { primNode = nodeFactory.createNode(args[0], args[1], LengthPrimFactory.create(null)); } else { primNode = nodeFactory.createNode(args[0], args[1]); } break; case 3: // HACK for node class where we use `executeWith` if (nodeFactory == InvokeOnPrimFactory.getInstance()) { primNode = nodeFactory.createNode( args[0], args[1], args[2], ToArgumentsArrayNodeGen.create(null, null)); } else { primNode = nodeFactory.createNode(args[0], args[1], args[2]); } break; case 4: primNode = nodeFactory.createNode(args[0], args[1], args[2], args[3]); break; default: throw new RuntimeException("Not supported by SOM."); } Primitive primMethodNode = new Primitive( primNode, mgen.getCurrentLexicalScope().getFrameDescriptor(), (ExpressionNode) primNode.deepCopy()); SInvokable prim = Universe.newMethod(signature, primMethodNode, true, new SMethod[0]); return prim; }
public static SInvokable constructEmptyPrimitive(final SSymbol signature) { CompilerAsserts.neverPartOfCompilation(); MethodGenerationContext mgen = new MethodGenerationContext(null); ExpressionNode primNode = EmptyPrim.create(new LocalArgumentReadNode(0, null)); Primitive primMethodNode = new Primitive( primNode, mgen.getCurrentLexicalScope().getFrameDescriptor(), (ExpressionNode) primNode.deepCopy()); SInvokable prim = Universe.newMethod(signature, primMethodNode, true, new SMethod[0]); return prim; }
public Primitives(final boolean displayWarning) { this.universe = Universe.current(); this.displayWarning = displayWarning; }
public static SInvokable getEmptyPrimitive(final String selector, final Universe universe) { SSymbol signature = universe.symbolFor(selector); return constructEmptyPrimitive(signature); }