public Operand buildOpAsgnOr(final OpAsgnOrNode orNode, IRScope s) { Label l1 = s.getNewLabel(); Label l2 = null; Variable flag = s.getNewTemporaryVariable(); Operand v1; boolean needsDefnCheck = needsDefinitionCheck(orNode.getFirstNode()); if (needsDefnCheck) { l2 = s.getNewLabel(); v1 = buildGetDefinitionBase(orNode.getFirstNode(), s); s.addInstr(new CopyInstr(flag, v1)); s.addInstr(BEQInstr.create(flag, manager.getNil(), l2)); // if v1 is undefined, go to v2's computation } v1 = build(orNode.getFirstNode(), s); // build of 'x' s.addInstr(new CopyInstr(flag, v1)); Variable result = getValueInTemporaryVariable(s, v1); if (needsDefnCheck) { s.addInstr(new LabelInstr(l2)); } s.addInstr(BEQInstr.create(flag, manager.getTrue(), l1)); // if v1 is defined and true, we are done! Operand v2 = build(orNode.getSecondNode(), s); // This is an AST node that sets x = y, so nothing special to do here. s.addInstr(new CopyInstr(result, v2)); s.addInstr(new LabelInstr(l1)); // Return value of x ||= y is always 'x' return result; }
public Operand buildOpAsgnOr(final OpAsgnOrNode orNode, IRScope s) { Label l1 = s.getNewLabel(); Label l2 = null; Variable flag = s.getNewTemporaryVariable(); Operand v1; boolean needsDefnCheck = needsDefinitionCheck(orNode.getFirstNode()); if (needsDefnCheck) { l2 = s.getNewLabel(); v1 = buildGetDefinitionBase(orNode.getFirstNode(), s); s.addInstr(new CopyInstr(flag, v1)); s.addInstr(BEQInstr.create(flag, manager.getNil(), l2)); // if v1 is undefined, go to v2's computation } v1 = build(orNode.getFirstNode(), s); // build of 'x' s.addInstr(new CopyInstr(flag, v1)); Variable result = getValueInTemporaryVariable(s, v1); if (needsDefnCheck) { s.addInstr(new LabelInstr(l2)); } s.addInstr(BEQInstr.create(flag, manager.getTrue(), l1)); // if v1 is defined and true, we are done! Operand v2 = build(orNode.getSecondNode(), s); // This is an AST node that sets x = y, so nothing special to do here. s.addInstr(new CopyInstr(result, v2)); s.addInstr(new LabelInstr(l1)); // Return value of x ||= y is always 'x' return result; }
case CONSTNODE: return searchConst(s, s, ((ConstNode) node).getName()); case DASGNNODE: return buildDAsgn((DAsgnNode) node, s); case DEFINEDNODE: return buildGetDefinitionBase(((DefinedNode) node).getExpressionNode(), s); case DEFNNODE: return buildDefn((MethodDefNode) node, s); case DEFSNODE: return buildDefs((DefsNode) node, s);
case CONSTNODE: return searchConst(s, s, ((ConstNode) node).getName()); case DASGNNODE: return buildDAsgn((DAsgnNode) node, s); case DEFINEDNODE: return buildGetDefinitionBase(((DefinedNode) node).getExpressionNode(), s); case DEFNNODE: return buildDefn((MethodDefNode) node, s); case DEFSNODE: return buildDefs((DefsNode) node, s);