private Variable addResultInstr(ResultInstr instr) { addInstr((Instr) instr); return instr.getResult(); }
protected void receiveBlockArg(Variable v, Operand argsArray, int argIndex, boolean isSplat) { if (argsArray != null) { // We are in a nested receive situation -- when we are not at the root of a masgn tree // Ex: We are trying to receive (b,c) in this example: "|a, (b,c), d| = ..." if (isSplat) addInstr(new RestArgMultipleAsgnInstr(v, argsArray, argIndex)); else addInstr(new ReqdArgMultipleAsgnInstr(v, argsArray, argIndex)); } else { // argsArray can be null when the first node in the args-node-ast is a multiple-assignment // For example, for-nodes addInstr(isSplat ? new ReceiveRestArgInstr(v, argIndex, argIndex) : new ReceivePreReqdArgInstr(v, argIndex)); } }
protected Variable buildDefnCheckIfThenPaths(Label undefLabel, Operand defVal) { Label defLabel = getNewLabel(); Variable tmpVar = getValueInTemporaryVariable(defVal); addInstr(new JumpInstr(defLabel)); addInstr(new LabelInstr(undefLabel)); addInstr(new CopyInstr(tmpVar, manager.getNil())); addInstr(new LabelInstr(defLabel)); return tmpVar; }
public Operand buildEncoding(EncodingNode node) { Variable ret = createTemporaryVariable(); addInstr(new GetEncodingInstr(ret, node.getEncoding())); return ret; }
protected Variable buildDefinitionCheck(ResultInstr definedInstr, String definedReturnValue) { Label undefLabel = getNewLabel(); addInstr((Instr) definedInstr); addInstr(createBranch(definedInstr.getResult(), manager.getFalse(), undefLabel)); return buildDefnCheckIfThenPaths(undefLabel, new FrozenString(definedReturnValue)); }
protected Variable buildDefinitionCheck(ResultInstr definedInstr, String definedReturnValue) { Label undefLabel = getNewLabel(); addInstr((Instr) definedInstr); addInstr(createBranch(definedInstr.getResult(), manager.getFalse(), undefLabel)); return buildDefnCheckIfThenPaths(undefLabel, new FrozenString(definedReturnValue)); }
private InterpreterContext buildPrePostExeInner(Node body) { // Set up %current_scope and %current_module addInstr(new CopyInstr(scope.getCurrentScopeVariable(), CurrentScope.INSTANCE)); addInstr(new CopyInstr(scope.getCurrentModuleVariable(), SCOPE_MODULE[0])); build(body); // END does not have either explicit or implicit return, so we add one addInstr(new ReturnInstr(new Nil())); return scope.allocateInterpreterContext(instructions); }
public Operand buildOpAsgnAnd(OpAsgnAndNode andNode) { Label l = getNewLabel(); Operand v1 = build(andNode.getFirstNode()); Variable result = getValueInTemporaryVariable(v1); addInstr(createBranch(v1, manager.getFalse(), l)); Operand v2 = build(andNode.getSecondNode()); // This does the assignment! addInstr(new CopyInstr(result, v2)); addInstr(new LabelInstr(l)); return result; }
public Operand buildDefn(MethodDefNode node) { // Instance method IRMethod method = defineNewMethod(node, true); addInstr(new DefineInstanceMethodInstr(method)); return new Symbol(node.getName()); }
private Operand putConstant(Colon3Node node, Operand value) { addInstr(new PutConstInstr(new ObjectClass(), node.getName(), value)); return value; }
public Operand buildDRegexp(Variable result, DRegexpNode node) { Node[] nodePieces = node.children(); Operand[] pieces = new Operand[nodePieces.length]; for (int i = 0; i < pieces.length; i++) { pieces[i] = dynamicPiece(nodePieces[i]); } if (result == null) result = createTemporaryVariable(); addInstr(new BuildDynRegExpInstr(result, pieces, node.getOptions())); return result; }
private void outputExceptionCheck(Operand excType, Operand excObj, Label caughtLabel) { Variable eqqResult = addResultInstr(new RescueEQQInstr(createTemporaryVariable(), excType, excObj)); addInstr(createBranch(eqqResult, manager.getTrue(), caughtLabel)); }
public Operand buildClassVarAsgn(final ClassVarAsgnNode classVarAsgnNode) { Operand val = build(classVarAsgnNode.getValueNode()); addInstr(new PutClassVariableInstr(classVarDefinitionContainer(), classVarAsgnNode.getName(), val)); return val; }
public Operand buildDefs(DefsNode node) { // Class method Operand container = build(node.getReceiverNode()); IRMethod method = defineNewMethod(node, false); addInstr(new DefineClassMethodInstr(container, method)); return new Symbol(node.getName()); }
public Operand buildMultipleAsgn19(MultipleAsgnNode multipleAsgnNode) { Node valueNode = multipleAsgnNode.getValueNode(); Operand values = build(valueNode); Variable ret = getValueInTemporaryVariable(values); if (valueNode instanceof ArrayNode) { buildMultipleAsgn19Assignment(multipleAsgnNode, null, ret); } else { Variable tmp = createTemporaryVariable(); addInstr(new ToAryInstr(tmp, ret)); buildMultipleAsgn19Assignment(multipleAsgnNode, null, tmp); } return ret; }
public Operand buildMultipleAsgn19(MultipleAsgnNode multipleAsgnNode) { Node valueNode = multipleAsgnNode.getValueNode(); Operand values = build(valueNode); Variable ret = getValueInTemporaryVariable(values); if (valueNode instanceof ArrayNode) { buildMultipleAsgn19Assignment(multipleAsgnNode, null, ret); } else { Variable tmp = createTemporaryVariable(); addInstr(new ToAryInstr(tmp, ret)); buildMultipleAsgn19Assignment(multipleAsgnNode, null, tmp); } return ret; }
public Operand buildAttrAssignAssignment(Node node, Operand value) { final AttrAssignNode attrAssignNode = (AttrAssignNode) node; Operand obj = build(attrAssignNode.getReceiverNode()); Operand[] args = setupCallArgs(attrAssignNode.getArgsNode()); args = addArg(args, value); addInstr(AttrAssignInstr.create(scope, obj, attrAssignNode.getName(), args, scope.maybeUsingRefinements())); return value; }
public Operand buildDStr(Variable result, DStrNode node) { Node[] nodePieces = node.children(); Operand[] pieces = new Operand[nodePieces.length]; for (int i = 0; i < pieces.length; i++) { pieces[i] = dynamicPiece(nodePieces[i]); } if (result == null) result = createTemporaryVariable(); boolean debuggingFrozenStringLiteral = manager.getInstanceConfig().isDebuggingFrozenStringLiteral(); addInstr(new BuildCompoundStringInstr(result, pieces, node.getEncoding(), node.isFrozen(), debuggingFrozenStringLiteral, getFileName(), node.getLine())); return result; }
public Operand buildDSymbol(Variable result, DSymbolNode node) { Node[] nodePieces = node.children(); Operand[] pieces = new Operand[nodePieces.length]; for (int i = 0; i < pieces.length; i++) { pieces[i] = dynamicPiece(nodePieces[i]); } if (result == null) result = createTemporaryVariable(); boolean debuggingFrozenStringLiteral = manager.getInstanceConfig().isDebuggingFrozenStringLiteral(); addInstr(new BuildCompoundStringInstr(result, pieces, node.getEncoding(), false, debuggingFrozenStringLiteral, getFileName(), node.getLine())); return copyAndReturnValue(new DynamicSymbol(result)); }