private Operand dynamicPiece(Node pieceNode) { Operand piece = pieceNode instanceof StrNode ? buildStrRaw((StrNode) pieceNode) : build(pieceNode); if (piece instanceof StringLiteral) { piece = ((StringLiteral)piece).frozenString; } return piece == null ? manager.getNil() : piece; }
public Operand buildBlock(BlockNode node) { Operand retVal = null; for (Node child : node.children()) { retVal = build(child); } // Value of the last expression in the block return retVal; }
public Operand buildFor(ForNode forNode) { Variable result = createTemporaryVariable(); Operand receiver = build(forNode.getIterNode()); Operand forBlock = buildForIter(forNode); CallInstr callInstr = new CallInstr(scope, CallType.NORMAL, result, manager.runtime.newSymbol(CommonByteLists.EACH), receiver, NO_ARGS, forBlock, scope.maybeUsingRefinements()); receiveBreakException(forBlock, callInstr); return result; }
public Operand buildBlock(BlockNode node) { Operand retVal = null; for (Node child : node.children()) { retVal = build(child); } // Value of the last expression in the block return retVal; }
public Operand buildFor(ForNode forNode) { Variable result = createTemporaryVariable(); Operand receiver = build(forNode.getIterNode()); Operand forBlock = buildForIter(forNode); CallInstr callInstr = new CallInstr(scope, CallType.NORMAL, result, manager.runtime.newSymbol(CommonByteLists.EACH), receiver, NO_ARGS, forBlock, scope.maybeUsingRefinements()); receiveBreakException(forBlock, callInstr); return result; }
private List<KeyValuePair<Operand, Operand>> buildKeywordArguments(HashNode keywordArgs) { List<KeyValuePair<Operand, Operand>> kwargs = new ArrayList<>(); for (KeyValuePair<Node, Node> pair: keywordArgs.getPairs()) { kwargs.add(new KeyValuePair<Operand, Operand>((Symbol) build(pair.getKey()), build(pair.getValue()))); } return kwargs; }
public Operand buildMatch3(Variable result, Match3Node matchNode) { Operand receiver = build(matchNode.getReceiverNode()); Operand value = build(matchNode.getValueNode()); if (result == null) result = createTemporaryVariable(); return addResultInstr(new MatchInstr(scope, result, receiver, value)); }
public Operand buildMatch3(Variable result, Match3Node matchNode) { Operand receiver = build(matchNode.getReceiverNode()); Operand value = build(matchNode.getValueNode()); if (result == null) result = createTemporaryVariable(); return addResultInstr(new MatchInstr(scope, result, receiver, value)); }
public Operand buildColon2(final Colon2Node colon2) { Node lhs = colon2.getLeftNode(); // Colon2ImplicitNode - (module|class) Foo. Weird, but it is a wrinkle of AST inheritance. if (lhs == null) return searchConst(colon2.getName()); // Colon2ConstNode (Left::name) return searchModuleForConst(build(lhs), colon2.getName()); }
public Operand buildClassVarAsgn(final ClassVarAsgnNode classVarAsgnNode) { Operand val = build(classVarAsgnNode.getValueNode()); addInstr(new PutClassVariableInstr(classVarDefinitionContainer(), classVarAsgnNode.getName(), val)); return val; }
public Operand buildColon2(final Colon2Node colon2) { Node lhs = colon2.getLeftNode(); // Colon2ImplicitNode - (module|class) Foo. Weird, but it is a wrinkle of AST inheritance. if (lhs == null) return searchConst(colon2.getName()); // Colon2ConstNode (Left::name) return searchModuleForConst(build(lhs), colon2.getName()); }
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 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 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 buildMatch(Variable result, MatchNode matchNode) { Operand regexp = build(matchNode.getRegexpNode()); Variable tempLastLine = createTemporaryVariable(); addResultInstr(new GetGlobalVariableInstr(tempLastLine, symbol("$_"))); if (result == null) result = createTemporaryVariable(); return addResultInstr(new MatchInstr(scope, result, regexp, tempLastLine)); }
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 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; }
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); }