private void outputExceptionCheck(Operand excType, Operand excObj, Label caughtLabel) { Variable eqqResult = addResultInstr(new RescueEQQInstr(createTemporaryVariable(), excType, excObj)); addInstr(createBranch(eqqResult, manager.getTrue(), caughtLabel)); }
private void outputExceptionCheck(Operand excType, Operand excObj, Label caughtLabel) { Variable eqqResult = addResultInstr(new RescueEQQInstr(createTemporaryVariable(), excType, excObj)); addInstr(createBranch(eqqResult, manager.getTrue(), caughtLabel)); }
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)); }
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 buildGetArgumentDefinition(final Node node, String type) { if (node == null) return new StringLiteral(type); Operand rv = new FrozenString(type); boolean failPathReqd = false; Label failLabel = getNewLabel(); if (node instanceof ArrayNode) { for (int i = 0; i < ((ArrayNode) node).size(); i++) { Node iterNode = ((ArrayNode) node).get(i); Operand def = buildGetDefinition(iterNode); if (def == manager.getNil()) { // Optimization! rv = manager.getNil(); break; } else if (!def.hasKnownValue()) { // Optimization! failPathReqd = true; addInstr(createBranch(def, manager.getNil(), failLabel)); } } } else { Operand def = buildGetDefinition(node); if (def == manager.getNil()) { // Optimization! rv = manager.getNil(); } else if (!def.hasKnownValue()) { // Optimization! failPathReqd = true; addInstr(createBranch(def, manager.getNil(), failLabel)); } } // Optimization! return failPathReqd ? buildDefnCheckIfThenPaths(failLabel, rv) : rv; }
public Operand buildGetArgumentDefinition(final Node node, String type) { if (node == null) return new StringLiteral(type); Operand rv = new FrozenString(type); boolean failPathReqd = false; Label failLabel = getNewLabel(); if (node instanceof ArrayNode) { for (int i = 0; i < ((ArrayNode) node).size(); i++) { Node iterNode = ((ArrayNode) node).get(i); Operand def = buildGetDefinition(iterNode); if (def == manager.getNil()) { // Optimization! rv = manager.getNil(); break; } else if (!def.hasKnownValue()) { // Optimization! failPathReqd = true; addInstr(createBranch(def, manager.getNil(), failLabel)); } } } else { Operand def = buildGetDefinition(node); if (def == manager.getNil()) { // Optimization! rv = manager.getNil(); } else if (!def.hasKnownValue()) { // Optimization! failPathReqd = true; addInstr(createBranch(def, manager.getNil(), failLabel)); } } // Optimization! return failPathReqd ? buildDefnCheckIfThenPaths(failLabel, rv) : rv; }
public Operand buildOpAsgnOr(final OpAsgnOrNode orNode) { Label l1 = getNewLabel(); Label l2 = null; Variable flag = createTemporaryVariable(); Operand v1; boolean needsDefnCheck = orNode.getFirstNode().needsDefinitionCheck(); if (needsDefnCheck) { l2 = getNewLabel(); v1 = buildGetDefinition(orNode.getFirstNode()); addInstr(new CopyInstr(flag, v1)); addInstr(createBranch(flag, manager.getNil(), l2)); // if v1 is undefined, go to v2's computation } v1 = build(orNode.getFirstNode()); // build of 'x' addInstr(new CopyInstr(flag, v1)); Variable result = getValueInTemporaryVariable(v1); if (needsDefnCheck) { addInstr(new LabelInstr(l2)); } addInstr(createBranch(flag, manager.getTrue(), l1)); // if v1 is defined and true, we are done! Operand v2 = build(orNode.getSecondNode()); // This is an AST node that sets x = y, so nothing special to do here. addInstr(new CopyInstr(result, v2)); addInstr(new LabelInstr(l1)); // Return value of x ||= y is always 'x' return result; }
public Operand buildOpAsgnOr(final OpAsgnOrNode orNode) { Label l1 = getNewLabel(); Label l2 = null; Variable flag = createTemporaryVariable(); Operand v1; boolean needsDefnCheck = orNode.getFirstNode().needsDefinitionCheck(); if (needsDefnCheck) { l2 = getNewLabel(); v1 = buildGetDefinition(orNode.getFirstNode()); addInstr(new CopyInstr(flag, v1)); addInstr(createBranch(flag, manager.getNil(), l2)); // if v1 is undefined, go to v2's computation } v1 = build(orNode.getFirstNode()); // build of 'x' addInstr(new CopyInstr(flag, v1)); Variable result = getValueInTemporaryVariable(v1); if (needsDefnCheck) { addInstr(new LabelInstr(l2)); } addInstr(createBranch(flag, manager.getTrue(), l1)); // if v1 is defined and true, we are done! Operand v2 = build(orNode.getSecondNode()); // This is an AST node that sets x = y, so nothing special to do here. addInstr(new CopyInstr(result, v2)); addInstr(new LabelInstr(l1)); // Return value of x ||= y is always 'x' return result; }
if (isLoopHeadCondition) { Operand cv = build(conditionNode); addInstr(createBranch(cv, isWhile ? manager.getFalse() : manager.getTrue(), setupResultLabel)); } else { Operand cv = build(conditionNode); addInstr(createBranch(cv, isWhile ? manager.getTrue() : manager.getFalse(), loop.iterStartLabel));
if (isLoopHeadCondition) { Operand cv = build(conditionNode); addInstr(createBranch(cv, isWhile ? manager.getFalse() : manager.getTrue(), setupResultLabel)); } else { Operand cv = build(conditionNode); addInstr(createBranch(cv, isWhile ? manager.getTrue() : manager.getFalse(), loop.iterStartLabel));
private Operand buildOpElementAsgnWith(OpElementAsgnNode opElementAsgnNode, Boolean truthy) { Node receiver = opElementAsgnNode.getReceiverNode(); CallType callType = receiver instanceof SelfNode ? CallType.FUNCTIONAL : CallType.NORMAL; Operand array = buildWithOrder(receiver, opElementAsgnNode.containsVariableAssignment()); Label endLabel = getNewLabel(); Variable elt = createTemporaryVariable(); Operand[] argList = setupCallArgs(opElementAsgnNode.getArgsNode()); addInstr(CallInstr.create(scope, callType, elt, symbol(ArrayDerefInstr.AREF), array, argList, null)); addInstr(createBranch(elt, truthy, endLabel)); Operand value = build(opElementAsgnNode.getValueNode()); argList = addArg(argList, value); addInstr(CallInstr.create(scope, callType, elt, symbol(ArrayDerefInstr.ASET), array, argList, null)); addInstr(new CopyInstr(elt, value)); addInstr(new LabelInstr(endLabel)); return elt; }
private Operand buildOpElementAsgnWith(OpElementAsgnNode opElementAsgnNode, Boolean truthy) { Node receiver = opElementAsgnNode.getReceiverNode(); CallType callType = receiver instanceof SelfNode ? CallType.FUNCTIONAL : CallType.NORMAL; Operand array = buildWithOrder(receiver, opElementAsgnNode.containsVariableAssignment()); Label endLabel = getNewLabel(); Variable elt = createTemporaryVariable(); Operand[] argList = setupCallArgs(opElementAsgnNode.getArgsNode()); addInstr(CallInstr.create(scope, callType, elt, symbol(ArrayDerefInstr.AREF), array, argList, null)); addInstr(createBranch(elt, truthy, endLabel)); Operand value = build(opElementAsgnNode.getValueNode()); argList = addArg(argList, value); addInstr(CallInstr.create(scope, callType, elt, symbol(ArrayDerefInstr.ASET), array, argList, null)); addInstr(new CopyInstr(elt, value)); addInstr(new LabelInstr(endLabel)); return elt; }
public Operand buildOr(final OrNode orNode) { // lazy evaluation opt. Don't bother building rhs of expr is lhs is unconditionally true. if (orNode.getFirstNode().getNodeType().alwaysTrue()) return build(orNode.getFirstNode()); // lazy evaluation opt. Eliminate conditional logic if we know lhs is always false. if (orNode.getFirstNode().getNodeType().alwaysFalse()) { build(orNode.getFirstNode()); // needs to be executed for potential side-effects return build(orNode.getSecondNode()); // but we return rhs for result. } Label endOfExprLabel = getNewLabel(); Operand left = build(orNode.getFirstNode()); Variable result = getValueInTemporaryVariable(left); addInstr(createBranch(left, manager.getTrue(), endOfExprLabel)); Operand right = build(orNode.getSecondNode()); addInstr(new CopyInstr(result, right)); addInstr(new LabelInstr(endOfExprLabel)); return result; }
public Operand buildAnd(final AndNode andNode) { if (andNode.getFirstNode().getNodeType().alwaysTrue()) { // build first node (and ignore its result) and then second node build(andNode.getFirstNode()); return build(andNode.getSecondNode()); } else if (andNode.getFirstNode().getNodeType().alwaysFalse()) { // build first node only and return its value return build(andNode.getFirstNode()); } else { Label l = getNewLabel(); Operand v1 = build(andNode.getFirstNode()); Variable ret = getValueInTemporaryVariable(v1); addInstr(createBranch(v1, manager.getFalse(), l)); Operand v2 = build(andNode.getSecondNode()); addInstr(new CopyInstr(ret, v2)); addInstr(new LabelInstr(l)); return ret; } }
public Operand buildOr(final OrNode orNode) { // lazy evaluation opt. Don't bother building rhs of expr is lhs is unconditionally true. if (orNode.getFirstNode().getNodeType().alwaysTrue()) return build(orNode.getFirstNode()); // lazy evaluation opt. Eliminate conditional logic if we know lhs is always false. if (orNode.getFirstNode().getNodeType().alwaysFalse()) { build(orNode.getFirstNode()); // needs to be executed for potential side-effects return build(orNode.getSecondNode()); // but we return rhs for result. } Label endOfExprLabel = getNewLabel(); Operand left = build(orNode.getFirstNode()); Variable result = getValueInTemporaryVariable(left); addInstr(createBranch(left, manager.getTrue(), endOfExprLabel)); Operand right = build(orNode.getSecondNode()); addInstr(new CopyInstr(result, right)); addInstr(new LabelInstr(endOfExprLabel)); return result; }
public Operand buildAnd(final AndNode andNode) { if (andNode.getFirstNode().getNodeType().alwaysTrue()) { // build first node (and ignore its result) and then second node build(andNode.getFirstNode()); return build(andNode.getSecondNode()); } else if (andNode.getFirstNode().getNodeType().alwaysFalse()) { // build first node only and return its value return build(andNode.getFirstNode()); } else { Label l = getNewLabel(); Operand v1 = build(andNode.getFirstNode()); Variable ret = getValueInTemporaryVariable(v1); addInstr(createBranch(v1, manager.getFalse(), l)); Operand v2 = build(andNode.getSecondNode()); addInstr(new CopyInstr(ret, v2)); addInstr(new LabelInstr(l)); return ret; } }
Label doneLabel = getNewLabel(); Operand thenResult; addInstr(createBranch(build(actualCondition), manager.getFalse(), falseLabel));
Label doneLabel = getNewLabel(); Operand thenResult; addInstr(createBranch(build(actualCondition), manager.getFalse(), falseLabel));