public Operand buildMultipleAsgn19(MultipleAsgn19Node multipleAsgnNode, IRScope s) { Operand values = build(multipleAsgnNode.getValueNode(), s); Variable ret = getValueInTemporaryVariable(s, values); s.addInstr(new ToAryInstr(ret, ret, manager.getFalse())); buildMultipleAsgn19Assignment(multipleAsgnNode, s, null, ret); return ret; }
@Override public void receiveBlockArgs(final IterNode node, IRScope s) { Node args = node.getVarNode(); if (args instanceof ArgsNode) { // regular blocks ((IRClosure)s).setParameterList(Helpers.encodeParameterList((ArgsNode) args).split(";")); receiveArgs((ArgsNode)args, s); } else { // for loops -- reuse code in IRBuilder:buildBlockArgsAssignment buildBlockArgsAssignment(args, s, null, 0, false, false, false); } }
@Override protected Operand buildVersionSpecificNodes(Node node, IRScope s) { switch (node.getNodeType()) { case ENCODINGNODE: return buildEncoding((EncodingNode)node, s); case MULTIPLEASGN19NODE: return buildMultipleAsgn19((MultipleAsgn19Node) node, s); case LAMBDANODE: return buildLambda((LambdaNode)node, s); default: throw new NotCompilableException("Unknown node encountered in builder: " + node.getClass()); } }
return buildDefinitionCheck(s, new BackrefIsMatchDataInstr(s.getNewTemporaryVariable()), "global-variable"); Operand v = super.buildVersionSpecificGetDefinitionIR(node, s); Label doneLabel = s.getNewLabel(); Variable tmpVar = getValueInTemporaryVariable(s, v); s.addInstr(BNEInstr.create(tmpVar, manager.getNil(), doneLabel)); s.addInstr(new CopyInstr(tmpVar, new StringLiteral("expression"))); Operand v = buildGetDefinitionBase(((NotNode)node).getConditionNode(), s); Label doneLabel = s.getNewLabel(); Variable tmpVar = getValueInTemporaryVariable(s, v); s.addInstr(BEQInstr.create(tmpVar, manager.getNil(), doneLabel)); s.addInstr(new CopyInstr(tmpVar, new StringLiteral("method"))); return buildDefnCheckIfThenPaths(s, undefLabel, new StringLiteral("global-variable")); return buildGenericGetDefinitionIR(node, s);
public void receiveRequiredArg(Node node, IRScope s, int argIndex, boolean post, int numPreReqd, int numPostRead) { switch (node.getNodeType()) { case ARGUMENTNODE: { ArgumentNode a = (ArgumentNode)node; String argName = a.getName(); if (s instanceof IRMethod) ((IRMethod)s).addArgDesc("req", argName); addArgReceiveInstr(s, s.getNewLocalVariable(argName, 0), argIndex, post, numPreReqd, numPostRead); break; } case MULTIPLEASGN19NODE: { MultipleAsgn19Node childNode = (MultipleAsgn19Node) node; Variable v = s.getNewTemporaryVariable(); addArgReceiveInstr(s, v, argIndex, post, numPreReqd, numPostRead); if (s instanceof IRMethod) ((IRMethod)s).addArgDesc("rest", ""); s.addInstr(new ToAryInstr(v, v, manager.getFalse())); buildMultipleAsgn19Assignment(childNode, s, v, null); break; } default: throw new NotCompilableException("Can't build assignment node: " + node); } }
for (Node an: masgnPre.childNodes()) { if (values == null) { buildArgsMasgn(an, s, argsArray, false, -1, -1, i, false); } else { Variable rhsVal = s.getNewTemporaryVariable(); s.addInstr(new ReqdArgMultipleAsgnInstr(rhsVal, values, i)); buildAssignment(an, s, rhsVal); buildArgsMasgn(restNode, s, argsArray, false, i, postArgsCount, 0, true); // rest of the argument array! } else { Variable rhsVal = s.getNewTemporaryVariable(); s.addInstr(new RestArgMultipleAsgnInstr(rhsVal, values, i, postArgsCount, 0)); buildAssignment(restNode, s, rhsVal); // rest of the argument array! for (Node an: masgnPost.childNodes()) { if (values == null) { buildArgsMasgn(an, s, argsArray, false, i, postArgsCount, j, false); } else { Variable rhsVal = s.getNewTemporaryVariable(); s.addInstr(new ReqdArgMultipleAsgnInstr(rhsVal, values, i, postArgsCount, j)); // Fetch from the end buildAssignment(an, s, rhsVal);
receiveRequiredArg(preArgs.get(i), s, argIndex, false, -1, -1); build(n.getValue(), s); s.addInstr(new LabelInstr(l)); receiveRequiredArg(postArgs.get(i), s, i, true, numPreReqd, numPostReqd);
public IRBuilder newIRBuilder(IRManager manager) { if (is2_0()) { return new IRBuilder20(manager); } else if (is1_9()) { return new IRBuilder19(manager); } else { return new IRBuilder(manager); } }
@Override public void buildVersionSpecificBlockArgsAssignment(Node node, IRScope s, Operand argsArray, int argIndex, boolean isMasgnRoot, boolean isClosureArg, boolean isSplat) { IRClosure cl = (IRClosure)s; if (!cl.isForLoopBody()) throw new NotCompilableException("Should not have come here for block args assignment in 1.9 mode: " + node); // Argh! For-loop bodies and regular iterators are different in terms of block-args! switch (node.getNodeType()) { case MULTIPLEASGN19NODE: { ListNode sourceArray = ((MultipleAsgn19Node) node).getPre(); int i = 0; for (Node an: sourceArray.childNodes()) { // Use 1.8 mode version for this buildBlockArgsAssignment(an, s, null, i, false, false, false); i++; } break; } default: throw new NotCompilableException("Can't build assignment node: " + node); } }
return buildDefinitionCheck(s, new BackrefIsMatchDataInstr(s.getNewTemporaryVariable()), "global-variable"); Operand v = super.buildVersionSpecificGetDefinitionIR(node, s); Label doneLabel = s.getNewLabel(); Variable tmpVar = getValueInTemporaryVariable(s, v); s.addInstr(BNEInstr.create(tmpVar, manager.getNil(), doneLabel)); s.addInstr(new CopyInstr(tmpVar, new StringLiteral("expression"))); Operand v = buildGetDefinitionBase(((NotNode)node).getConditionNode(), s); Label doneLabel = s.getNewLabel(); Variable tmpVar = getValueInTemporaryVariable(s, v); s.addInstr(BEQInstr.create(tmpVar, manager.getNil(), doneLabel)); s.addInstr(new CopyInstr(tmpVar, new StringLiteral("method"))); return buildDefnCheckIfThenPaths(s, undefLabel, new StringLiteral("global-variable")); return buildGenericGetDefinitionIR(node, s);
public void receiveRequiredArg(Node node, IRScope s, int argIndex, boolean post, int numPreReqd, int numPostRead) { switch (node.getNodeType()) { case ARGUMENTNODE: { ArgumentNode a = (ArgumentNode)node; String argName = a.getName(); if (s instanceof IRMethod) ((IRMethod)s).addArgDesc("req", argName); addArgReceiveInstr(s, s.getNewLocalVariable(argName, 0), argIndex, post, numPreReqd, numPostRead); break; } case MULTIPLEASGN19NODE: { MultipleAsgn19Node childNode = (MultipleAsgn19Node) node; Variable v = s.getNewTemporaryVariable(); addArgReceiveInstr(s, v, argIndex, post, numPreReqd, numPostRead); if (s instanceof IRMethod) ((IRMethod)s).addArgDesc("rest", ""); s.addInstr(new ToAryInstr(v, v, manager.getFalse())); buildMultipleAsgn19Assignment(childNode, s, v, null); break; } default: throw new NotCompilableException("Can't build assignment node: " + node); } }
for (Node an: masgnPre.childNodes()) { if (values == null) { buildArgsMasgn(an, s, argsArray, false, -1, -1, i, false); } else { Variable rhsVal = s.getNewTemporaryVariable(); s.addInstr(new ReqdArgMultipleAsgnInstr(rhsVal, values, i)); buildAssignment(an, s, rhsVal); buildArgsMasgn(restNode, s, argsArray, false, i, postArgsCount, 0, true); // rest of the argument array! } else { Variable rhsVal = s.getNewTemporaryVariable(); s.addInstr(new RestArgMultipleAsgnInstr(rhsVal, values, i, postArgsCount, 0)); buildAssignment(restNode, s, rhsVal); // rest of the argument array! for (Node an: masgnPost.childNodes()) { if (values == null) { buildArgsMasgn(an, s, argsArray, false, i, postArgsCount, j, false); } else { Variable rhsVal = s.getNewTemporaryVariable(); s.addInstr(new ReqdArgMultipleAsgnInstr(rhsVal, values, i, postArgsCount, j)); // Fetch from the end buildAssignment(an, s, rhsVal);
receiveRequiredArg(preArgs.get(i), s, argIndex, false, -1, -1); build(n.getValue(), s); s.addInstr(new LabelInstr(l)); receiveRequiredArg(postArgs.get(i), s, i, true, numPreReqd, numPostReqd);
public IRBuilder newIRBuilder(IRManager manager) { if (is2_0()) { return new IRBuilder20(manager); } else if (is1_9()) { return new IRBuilder19(manager); } else { return new IRBuilder(manager); } }
@Override public void buildVersionSpecificBlockArgsAssignment(Node node, IRScope s, Operand argsArray, int argIndex, boolean isMasgnRoot, boolean isClosureArg, boolean isSplat) { IRClosure cl = (IRClosure)s; if (!cl.isForLoopBody()) throw new NotCompilableException("Should not have come here for block args assignment in 1.9 mode: " + node); // Argh! For-loop bodies and regular iterators are different in terms of block-args! switch (node.getNodeType()) { case MULTIPLEASGN19NODE: { ListNode sourceArray = ((MultipleAsgn19Node) node).getPre(); int i = 0; for (Node an: sourceArray.childNodes()) { // Use 1.8 mode version for this buildBlockArgsAssignment(an, s, null, i, false, false, false); i++; } break; } default: throw new NotCompilableException("Can't build assignment node: " + node); } }
public Operand buildMultipleAsgn19(MultipleAsgn19Node multipleAsgnNode, IRScope s) { Operand values = build(multipleAsgnNode.getValueNode(), s); Variable ret = getValueInTemporaryVariable(s, values); s.addInstr(new ToAryInstr(ret, ret, manager.getFalse())); buildMultipleAsgn19Assignment(multipleAsgnNode, s, null, ret); return ret; }
@Override protected Operand buildVersionSpecificNodes(Node node, IRScope s) { switch (node.getNodeType()) { case ENCODINGNODE: return buildEncoding((EncodingNode)node, s); case MULTIPLEASGN19NODE: return buildMultipleAsgn19((MultipleAsgn19Node) node, s); case LAMBDANODE: return buildLambda((LambdaNode)node, s); default: throw new NotCompilableException("Unknown node encountered in builder: " + node.getClass()); } }
@Override public void receiveBlockArgs(final IterNode node, IRScope s) { Node args = node.getVarNode(); if (args instanceof ArgsNode) { // regular blocks ((IRClosure)s).setParameterList(Helpers.encodeParameterList((ArgsNode) args).split(";")); receiveArgs((ArgsNode)args, s); } else { // for loops -- reuse code in IRBuilder:buildBlockArgsAssignment buildBlockArgsAssignment(args, s, null, 0, false, false, false); } }