org.jruby.compiler.ir
Class IR_Builder

java.lang.Object
  extended by org.jruby.compiler.ir.IR_Builder

public class IR_Builder
extends java.lang.Object


Constructor Summary
IR_Builder()
           
 
Method Summary
 Operand build(Node node, IR_Scope m)
           
 Operand buildAlias(AliasNode alias, IR_Scope s)
           
 Operand buildAnd(AndNode andNode, IR_Scope m)
           
 void buildArgs(java.util.List<Operand> argsList, Node args, IR_Scope s)
           
 Operand buildArgsCat(ArgsCatNode argsCatNode, IR_Scope s)
           
 void buildArgsCatArguments(java.util.List<Operand> args, ArgsCatNode argsCatNode, IR_Scope s)
           
 Operand buildArgsPush(ArgsPushNode node, IR_Scope m)
           
 void buildArgsPushArguments(java.util.List<Operand> args, ArgsPushNode argsPushNode, IR_Scope m)
           
 void buildArguments(java.util.List<Operand> args, Node node, IR_Scope s)
           
 Operand buildArray(Node node, IR_Scope m)
           
 void buildArrayArguments(java.util.List<Operand> args, Node node, IR_Scope s)
           
 void buildAssignment(Node node, IR_Scope s, Operand values, int argIndex, boolean isSplat)
           
 Operand buildAttrAssignAssignment(Node node, IR_Scope s, Operand value)
           
 Operand buildBackref(BackRefNode node, IR_Scope m)
           
 Operand buildBegin(BeginNode beginNode, IR_Scope s)
           
 Operand buildBignum(BignumNode node, IR_Scope s)
           
 Operand buildBlock(BlockNode node, IR_Scope s)
           
 void buildBlockArgsAssignment(Node node, IR_Scope s, int argIndex, boolean isSplat)
           
 Operand buildBreak(BreakNode breakNode, IR_Scope s)
           
 Operand buildCall(CallNode callNode, IR_Scope s)
           
 Operand buildCase(CaseNode caseNode, IR_Scope m)
           
 Operand buildClass(ClassNode classNode, IR_Scope s)
           
 Operand buildClassVar(ClassVarNode node, IR_Scope s)
          public Operand buildSClass(Node node, IR_Scope m) { final SClassNode sclassNode = (SClassNode) node; CompilerCallback receiverCallback = new CompilerCallback() { public void call(IR_Scope m) { build(sclassNode.getReceiverNode(), m, true); } }; CompilerCallback bodyCallback = new CompilerCallback() { public void call(IR_Scope m) { if (sclassNode.getBodyNode() != null) { build(sclassNode.getBodyNode(), m, true); } else { m.loadNil(); } } }; m.defineClass("SCLASS", sclassNode.getScope(), null, null, bodyCallback, receiverCallback, inspector); }
 Operand buildClassVarAsgn(ClassVarAsgnNode classVarAsgnNode, IR_Scope s)
           
 Operand buildClassVarDecl(ClassVarDeclNode classVarDeclNode, IR_Scope s)
           
 Operand buildColon2(Colon2Node iVisited, IR_Scope s)
           
 Operand buildColon3(Colon3Node node, IR_Scope s)
           
 Operand buildConst(ConstNode node, IR_Scope s)
           
 Operand buildConstDecl(ConstDeclNode node, IR_Scope s)
           
 Operand buildConstDeclAssignment(ConstDeclNode constDeclNode, IR_Scope s, Operand val)
           
 Operand buildDAsgn(DAsgnNode dasgnNode, IR_Scope s)
          public Operand buildGetDefinitionBase(final Node node, IR_Scope m) { switch (node.getNodeType()) { case CLASSVARASGNNODE: case CLASSVARDECLNODE: case CONSTDECLNODE: case DASGNNODE: case GLOBALASGNNODE: case LOCALASGNNODE: case MULTIPLEASGNNODE: case OPASGNNODE: case OPELEMENTASGNNODE: case DVARNODE: case FALSENODE: case TRUENODE: case LOCALVARNODE: case INSTVARNODE: case BACKREFNODE: case SELFNODE: case VCALLNODE: case YIELDNODE: case GLOBALVARNODE: case CONSTNODE: case FCALLNODE: case CLASSVARNODE: // these are all simple cases that don't require the heavier defined logic buildGetDefinition(node, m); break; default: BranchCallback reg = new BranchCallback() { public void branch(IR_Scope m) { m.inDefined(); buildGetDefinition(node, m); } }; BranchCallback out = new BranchCallback() { public void branch(IR_Scope m) { m.outDefined(); } }; m.protect(reg, out, String.class); } } public Operand buildDefined(final Node node, IR_Scope m) { buildGetDefinitionBase(((DefinedNode) node).getExpressionNode(), m); m.stringOrNil(); } public Operand buildGetArgumentDefinition(final Node node, IR_Scope m, String type) { if (node == null) { return new StringLiteral(type); } else if (node instanceof ArrayNode) { Object endToken = m.getNewEnding(); for (int i = 0; i < ((ArrayNode) node).size(); i++) { Node iterNode = ((ArrayNode) node).get(i); buildGetDefinition(iterNode, m); m.ifNull(endToken); } Operand sl = new StringLiteral(type); Object realToken = m.getNewEnding(); m.go(realToken); m.setEnding(endToken); m.pushNull(); m.setEnding(realToken); } else { buildGetDefinition(node, m); Object endToken = m.getNewEnding(); m.ifNull(endToken); Operand sl = new StringLiteral(type); Object realToken = m.getNewEnding(); m.go(realToken); m.setEnding(endToken); m.pushNull(); m.setEnding(realToken); } } public Operand buildGetDefinition(final Node node, IR_Scope m) { switch (node.getNodeType()) { case CLASSVARASGNNODE: case CLASSVARDECLNODE: case CONSTDECLNODE: case DASGNNODE: case GLOBALASGNNODE: case LOCALASGNNODE: case MULTIPLEASGNNODE: case OPASGNNODE: case OPELEMENTASGNNODE: return new StringLiteral("assignment"); case BACKREFNODE: // SSS FIXME! Operand x = m.backref(); return x instanceof RubyMatchData.class ? new StringLiteral("$" + ((BackRefNode) node).getType()) : Nil.NIL; case DVARNODE: return new StringLiteral("local-variable(in-block)"); case FALSENODE: return new StringLiteral("false"); case TRUENODE: return new StringLiteral("true"); case LOCALVARNODE: return new StringLiteral("local-variable"); case MATCH2NODE: case MATCH3NODE: return new StringLiteral("method"); case NILNODE: return new StringLiteral("nil"); case NTHREFNODE: m.isCaptured(((NthRefNode) node).getMatchNumber(), new BranchCallback() { public void branch(IR_Scope m) { return new StringLiteral("$" + ((NthRefNode) node).getMatchNumber()); } }, new BranchCallback() { public void branch(IR_Scope m) { return Nil.NIL; } }); break; case SELFNODE: return new StringLiteral("self"); case VCALLNODE: m.loadSelf(); m.isMethodBound(((VCallNode) node).getName(), new BranchCallback() { public void branch(IR_Scope m) { return new StringLiteral("method"); } }, new BranchCallback() { public void branch(IR_Scope m) { return Nil.NIL; } }); break; case YIELDNODE: m.hasBlock(new BranchCallback() { public void branch(IR_Scope m) { return new StringLiteral("yield"); } }, new BranchCallback() { public void branch(IR_Scope m) { return Nil.NIL; } }); break; case GLOBALVARNODE: m.isGlobalDefined(((GlobalVarNode) node).getName(), new BranchCallback() { public void branch(IR_Scope m) { return new StringLiteral("global-variable"); } }, new BranchCallback() { public void branch(IR_Scope m) { return Nil.NIL; } }); break; case INSTVARNODE: m.isInstanceVariableDefined(((InstVarNode) node).getName(), new BranchCallback() { public void branch(IR_Scope m) { return new StringLiteral("instance-variable"); } }, new BranchCallback() { public void branch(IR_Scope m) { return Nil.NIL; } }); break; case CONSTNODE: m.isConstantDefined(((ConstNode) node).getName(), new BranchCallback() { public void branch(IR_Scope m) { return new StringLiteral("constant"); } }, new BranchCallback() { public void branch(IR_Scope m) { return Nil.NIL; } }); break; case FCALLNODE: m.loadSelf(); m.isMethodBound(((FCallNode) node).getName(), new BranchCallback() { public void branch(IR_Scope m) { buildGetArgumentDefinition(((FCallNode) node).getArgsNode(), m, "method"); } }, new BranchCallback() { public void branch(IR_Scope m) { return Nil.NIL; } }); break; case COLON3NODE: case COLON2NODE: { final Colon3Node iVisited = (Colon3Node) node; final String name = iVisited.getName(); BranchCallback setup = new BranchCallback() { public void branch(IR_Scope m) { if (iVisited instanceof Colon2Node) { final Node leftNode = ((Colon2Node) iVisited).getLeftNode(); build(leftNode, m,true); } else { m.loadObject(); } } }; BranchCallback isConstant = new BranchCallback() { public void branch(IR_Scope m) { return new StringLiteral("constant"); } }; BranchCallback isMethod = new BranchCallback() { public void branch(IR_Scope m) { return new StringLiteral("method"); } }; BranchCallback none = new BranchCallback() { public void branch(IR_Scope m) { return Nil.NIL; } }; m.isConstantBranch(setup, isConstant, isMethod, none, name); break; } case CALLNODE: { final CallNode iVisited = (CallNode) node; Object isnull = m.getNewEnding(); Object ending = m.getNewEnding(); buildGetDefinition(iVisited.getReceiverNode(), m); m.ifNull(isnull); m.rescue(new BranchCallback() { public void branch(IR_Scope m) { build(iVisited.getReceiverNode(), m,true); //[IRubyObject] m.duplicateCurrentValue(); //[IRubyObject, IRubyObject] m.metaclass(); //[IRubyObject, RubyClass] m.duplicateCurrentValue(); //[IRubyObject, RubyClass, RubyClass] m.getVisibilityFor(iVisited.getName()); //[IRubyObject, RubyClass, Visibility] m.duplicateCurrentValue(); //[IRubyObject, RubyClass, Visibility, Visibility] final Object isfalse = m.getNewEnding(); Object isreal = m.getNewEnding(); Object ending = m.getNewEnding(); m.isPrivate(isfalse, 3); //[IRubyObject, RubyClass, Visibility] m.isNotProtected(isreal, 1); //[IRubyObject, RubyClass] m.selfIsKindOf(isreal); //[IRubyObject] m.consumeCurrentValue(); m.go(isfalse); m.setEnding(isreal); //[] m.isMethodBound(iVisited.getName(), new BranchCallback() { public void branch(IR_Scope m) { buildGetArgumentDefinition(iVisited.getArgsNode(), m, "method"); } }, new BranchCallback() { public void branch(IR_Scope m) { m.go(isfalse); } }); m.go(ending); m.setEnding(isfalse); m.pushNull(); m.setEnding(ending); } }, JumpException.class, new BranchCallback() { public void branch(IR_Scope m) { m.pushNull(); } }, String.class); // m.swapValues(); //m.consumeCurrentValue(); m.go(ending); m.setEnding(isnull); m.pushNull(); m.setEnding(ending); break; } case CLASSVARNODE: { ClassVarNode iVisited = (ClassVarNode) node; final Object ending = m.getNewEnding(); final Object failure = m.getNewEnding(); final Object singleton = m.getNewEnding(); Object second = m.getNewEnding(); Object third = m.getNewEnding(); m.loadCurrentModule(); //[RubyClass] m.duplicateCurrentValue(); //[RubyClass, RubyClass] m.ifNotNull(second); //[RubyClass] m.consumeCurrentValue(); //[] m.loadSelf(); //[self] m.metaclass(); //[RubyClass] m.duplicateCurrentValue(); //[RubyClass, RubyClass] m.isClassVarDefined(iVisited.getName(), new BranchCallback() { public void branch(IR_Scope m) { m.consumeCurrentValue(); Operand sl = new StringLiteral("class variable"); m.go(ending); } }, new BranchCallback() { public void branch(IR_Scope m) { } }); m.setEnding(second); //[RubyClass] m.duplicateCurrentValue(); m.isClassVarDefined(iVisited.getName(), new BranchCallback() { public void branch(IR_Scope m) { m.consumeCurrentValue(); Operand sl = new StringLiteral("class variable"); m.go(ending); } }, new BranchCallback() { public void branch(IR_Scope m) { } }); m.setEnding(third); //[RubyClass] m.duplicateCurrentValue(); //[RubyClass, RubyClass] m.ifSingleton(singleton); //[RubyClass] m.consumeCurrentValue();//[] m.go(failure); m.setEnding(singleton); m.attached();//[RubyClass] m.notIsModuleAndClassVarDefined(iVisited.getName(), failure); //[] Operand sl = new StringLiteral("class variable"); m.go(ending); m.setEnding(failure); m.pushNull(); m.setEnding(ending); } break; case ZSUPERNODE: { Object fail = m.getNewEnding(); Object fail2 = m.getNewEnding(); Object fail_easy = m.getNewEnding(); Object ending = m.getNewEnding(); m.getFrameName(); //[String] m.duplicateCurrentValue(); //[String, String] m.ifNull(fail); //[String] m.getFrameKlazz(); //[String, RubyClass] m.duplicateCurrentValue(); //[String, RubyClass, RubyClass] m.ifNull(fail2); //[String, RubyClass] m.superClass(); m.ifNotSuperMethodBound(fail_easy); Operand sl = new StringLiteral("super"); m.go(ending); m.setEnding(fail2); m.consumeCurrentValue(); m.setEnding(fail); m.consumeCurrentValue(); m.setEnding(fail_easy); m.pushNull(); m.setEnding(ending); } break; case SUPERNODE: { Object fail = m.getNewEnding(); Object fail2 = m.getNewEnding(); Object fail_easy = m.getNewEnding(); Object ending = m.getNewEnding(); m.getFrameName(); //[String] m.duplicateCurrentValue(); //[String, String] m.ifNull(fail); //[String] m.getFrameKlazz(); //[String, RubyClass] m.duplicateCurrentValue(); //[String, RubyClass, RubyClass] m.ifNull(fail2); //[String, RubyClass] m.superClass(); m.ifNotSuperMethodBound(fail_easy); buildGetArgumentDefinition(((SuperNode) node).getArgsNode(), m, "super"); m.go(ending); m.setEnding(fail2); m.consumeCurrentValue(); m.setEnding(fail); m.consumeCurrentValue(); m.setEnding(fail_easy); m.pushNull(); m.setEnding(ending); break; } case ATTRASSIGNNODE: { final AttrAssignNode iVisited = (AttrAssignNode) node; Object isnull = m.getNewEnding(); Object ending = m.getNewEnding(); buildGetDefinition(iVisited.getReceiverNode(), m); m.ifNull(isnull); m.rescue(new BranchCallback() { public void branch(IR_Scope m) { build(iVisited.getReceiverNode(), m,true); //[IRubyObject] m.duplicateCurrentValue(); //[IRubyObject, IRubyObject] m.metaclass(); //[IRubyObject, RubyClass] m.duplicateCurrentValue(); //[IRubyObject, RubyClass, RubyClass] m.getVisibilityFor(iVisited.getName()); //[IRubyObject, RubyClass, Visibility] m.duplicateCurrentValue(); //[IRubyObject, RubyClass, Visibility, Visibility] final Object isfalse = m.getNewEnding(); Object isreal = m.getNewEnding(); Object ending = m.getNewEnding(); m.isPrivate(isfalse, 3); //[IRubyObject, RubyClass, Visibility] m.isNotProtected(isreal, 1); //[IRubyObject, RubyClass] m.selfIsKindOf(isreal); //[IRubyObject] m.consumeCurrentValue(); m.go(isfalse); m.setEnding(isreal); //[] m.isMethodBound(iVisited.getName(), new BranchCallback() { public void branch(IR_Scope m) { buildGetArgumentDefinition(iVisited.getArgsNode(), m, "assignment"); } }, new BranchCallback() { public void branch(IR_Scope m) { m.go(isfalse); } }); m.go(ending); m.setEnding(isfalse); m.pushNull(); m.setEnding(ending); } }, JumpException.class, new BranchCallback() { public void branch(IR_Scope m) { m.pushNull(); } }, String.class); m.go(ending); m.setEnding(isnull); m.pushNull(); m.setEnding(ending); break; } default: m.rescue(new BranchCallback() { public void branch(IR_Scope m) { build(node, m,true); m.consumeCurrentValue(); m.pushNull(); } }, JumpException.class, new BranchCallback() { public void branch(IR_Scope m) { m.pushNull(); } }, String.class); m.consumeCurrentValue(); //MPS_FIXME: new StringLiteral("expression"); } }
 Operand buildDefn(MethodDefNode node, IR_Scope s)
           
 Operand buildDefs(MethodDefNode node, IR_Scope s)
           
 Operand buildDot(DotNode dotNode, IR_Scope s)
           
 Operand buildDRegexp(DRegexpNode dregexpNode, IR_Scope s)
           
 Operand buildDStr(DStrNode dstrNode, IR_Scope s)
           
 Operand buildDSymbol(Node node, IR_Scope s)
           
 Operand buildDVar(DVarNode node, IR_Scope m)
           
 Operand buildDXStr(DXStrNode dstrNode, IR_Scope m)
           
 Operand buildEvStr(EvStrNode node, IR_Scope s)
          public Operand buildEnsureNode(Node node, IR_Scope m) { final EnsureNode ensureNode = (EnsureNode) node; if (ensureNode.getEnsureNode() != null) { m.performEnsure(new BranchCallback() { public void branch(IR_Scope m) { if (ensureNode.getBodyNode() != null) { build(ensureNode.getBodyNode(), m, true); } else { m.loadNil(); } } }, new BranchCallback() { public void branch(IR_Scope m) { build(ensureNode.getEnsureNode(), m, false); } }); } else { if (ensureNode.getBodyNode() != null) { build(ensureNode.getBodyNode(), m,true); } else { m.loadNil(); } } // TODO: don't require pop if (!expr) m.consumeCurrentValue(); }
 Operand buildFalse(Node node, IR_Scope s)
           
 Operand buildFCall(FCallNode fcallNode, IR_Scope s)
           
 Operand buildFixnum(FixnumNode node, IR_Scope m)
           
 Operand buildFloat(FloatNode node, IR_Scope m)
          public Operand buildFlip(Node node, IR_Scope m) { final FlipNode flipNode = (FlipNode) node; m.getVariableCompiler().retrieveLocalVariable(flipNode.getIndex(), flipNode.getDepth()); if (flipNode.isExclusive()) { m.performBooleanBranch(new BranchCallback() { public void branch(IR_Scope m) { build(flipNode.getEndNode(), m,true); m.performBooleanBranch(new BranchCallback() { public void branch(IR_Scope m) { m.loadFalse(); m.getVariableCompiler().assignLocalVariable(flipNode.getIndex(), flipNode.getDepth(), false); } }, new BranchCallback() { public void branch(IR_Scope m) { } }); m.loadTrue(); } }, new BranchCallback() { public void branch(IR_Scope m) { build(flipNode.getBeginNode(), m,true); becomeTrueOrFalse(m); m.getVariableCompiler().assignLocalVariable(flipNode.getIndex(), flipNode.getDepth(), true); } }); } else { m.performBooleanBranch(new BranchCallback() { public void branch(IR_Scope m) { build(flipNode.getEndNode(), m,true); m.performBooleanBranch(new BranchCallback() { public void branch(IR_Scope m) { m.loadFalse(); m.getVariableCompiler().assignLocalVariable(flipNode.getIndex(), flipNode.getDepth(), false); } }, new BranchCallback() { public void branch(IR_Scope m) { } }); m.loadTrue(); } }, new BranchCallback() { public void branch(IR_Scope m) { build(flipNode.getBeginNode(), m,true); m.performBooleanBranch(new BranchCallback() { public void branch(IR_Scope m) { build(flipNode.getEndNode(), m,true); flipTrueOrFalse(m); m.getVariableCompiler().assignLocalVariable(flipNode.getIndex(), flipNode.getDepth(), false); m.loadTrue(); } }, new BranchCallback() { public void branch(IR_Scope m) { m.loadFalse(); } }); } }); } // TODO: don't require pop if (!expr) m.consumeCurrentValue(); } private void becomeTrueOrFalse(IR_Scope m) { m.performBooleanBranch(new BranchCallback() { public void branch(IR_Scope m) { m.loadTrue(); } }, new BranchCallback() { public void branch(IR_Scope m) { m.loadFalse(); } }); } private void flipTrueOrFalse(IR_Scope m) { m.performBooleanBranch(new BranchCallback() { public void branch(IR_Scope m) { m.loadFalse(); } }, new BranchCallback() { public void branch(IR_Scope m) { m.loadTrue(); } }); }
 Operand buildFor(ForNode forNode, IR_Scope m)
           
 Operand buildForIter(ForNode forNode, IR_Scope s)
           
static IR_Scope buildFromMain(java.lang.String[] args)
           
 Operand buildGlobalAsgn(GlobalAsgnNode globalAsgnNode, IR_Scope m)
           
 Operand buildGlobalVar(GlobalVarNode node, IR_Scope m)
           
 Operand buildHash(HashNode hashNode, IR_Scope m)
           
 Operand buildIf(IfNode ifNode, IR_Scope s)
           
 Operand buildInstAsgn(InstAsgnNode instAsgnNode, IR_Scope s)
           
 Operand buildInstVar(InstVarNode node, IR_Scope m)
           
 Operand buildIter(IterNode iterNode, IR_Scope s)
           
 Operand buildLocalAsgn(LocalAsgnNode localAsgnNode, IR_Scope s)
           
 Operand buildLocalVar(LocalVarNode node, IR_Scope s)
           
 Operand buildMatch(MatchNode matchNode, IR_Scope m)
           
 Operand buildMatch2(Match2Node matchNode, IR_Scope m)
           
 Operand buildMatch3(Match3Node matchNode, IR_Scope m)
           
 Operand buildModule(ModuleNode moduleNode, IR_Scope s)
           
 Operand buildMultipleAsgn(MultipleAsgnNode multipleAsgnNode, IR_Scope s)
           
 void buildMultipleAsgnAssignment(MultipleAsgnNode multipleAsgnNode, IR_Scope s, Operand values)
           
 Operand buildNewline(NewlineNode node, IR_Scope s)
           
 Operand buildNext(NextNode nextNode, IR_Scope s)
           
 Operand buildNil(Node node, IR_Scope m)
           
 Operand buildNot(NotNode node, IR_Scope m)
           
 Operand buildNthRef(NthRefNode nthRefNode, IR_Scope m)
           
 Operand buildOpAsgn(OpAsgnNode opAsgnNode, IR_Scope s)
           
 Operand buildOpAsgnAnd(OpAsgnAndNode andNode, IR_Scope s)
           
 Operand buildOpAsgnOr(OpAsgnOrNode orNode, IR_Scope s)
           
 Operand buildOr(OrNode orNode, IR_Scope m)
          private class OpElementAsgnArgumentsCallback implements ArgumentsCallback { private Node node; public OpElementAsgnArgumentsCallback(Node node) { this.node = node; } public int getArity() { switch (node.getNodeType()) { case ARGSCATNODE: case ARGSPUSHNODE: case SPLATNODE: return -1; case ARRAYNODE: ArrayNode arrayNode = (ArrayNode)node; if (arrayNode.size() == 0) { return 0; } else if (arrayNode.size() > 3) { return -1; } else { return ((ArrayNode)node).size(); } default: return 1; } } public void call(IR_Scope m) { if (getArity() == 1) { // if arity 1, just build the one element to save us the array cost build(((ArrayNode)node).get(0), m,true); } else { // build into array buildArguments(node, m); } } }; public Operand buildOpElementAsgnWithOr(Node node, IR_Scope m) { final OpElementAsgnNode opElementAsgnNode = (OpElementAsgnNode) node; CompilerCallback receiverCallback = new CompilerCallback() { public void call(IR_Scope m) { build(opElementAsgnNode.getReceiverNode(), m); } }; ArgumentsCallback argsCallback = new OpElementAsgnArgumentsCallback(opElementAsgnNode.getArgsNode()); CompilerCallback valueCallback = new CompilerCallback() { public void call(IR_Scope m) { build(opElementAsgnNode.getValueNode(), m, true); } }; m.getInvocationCompiler().opElementAsgnWithOr(receiverCallback, argsCallback, valueCallback); // TODO: don't require pop if (!expr) m.consumeCurrentValue(); } public Operand buildOpElementAsgnWithAnd(Node node, IR_Scope m) { final OpElementAsgnNode opElementAsgnNode = (OpElementAsgnNode) node; CompilerCallback receiverCallback = new CompilerCallback() { public void call(IR_Scope m) { build(opElementAsgnNode.getReceiverNode(), m); } }; ArgumentsCallback argsCallback = new OpElementAsgnArgumentsCallback(opElementAsgnNode.getArgsNode()); CompilerCallback valueCallback = new CompilerCallback() { public void call(IR_Scope m) { build(opElementAsgnNode.getValueNode(), m); } }; m.getInvocationCompiler().opElementAsgnWithAnd(receiverCallback, argsCallback, valueCallback); } public Operand buildOpElementAsgnWithMethod(Node node, IR_Scope m) { final OpElementAsgnNode opElementAsgnNode = (OpElementAsgnNode) node; CompilerCallback receiverCallback = new CompilerCallback() { public void call(IR_Scope m) { build(opElementAsgnNode.getReceiverNode(), m); } }; ArgumentsCallback argsCallback = setupCallArgs(opElementAsgnNode.getArgsNode()); CompilerCallback valueCallback = new CompilerCallback() { public void call(IR_Scope m) { build(opElementAsgnNode.getValueNode(), m); } }; m.getInvocationCompiler().opElementAsgnWithMethod(receiverCallback, argsCallback, valueCallback, opElementAsgnNode.getOperatorName()); }
 Operand buildRedo(Node node, IR_Scope s)
          public Operand buildPostExe(Node node, IR_Scope m) { final PostExeNode postExeNode = (PostExeNode) node; // create the closure class and instantiate it final CompilerCallback closureBody = new CompilerCallback() { public void call(IR_Scope m) { if (postExeNode.getBodyNode() != null) { build(postExeNode.getBodyNode(), m, true); } else { m.loadNil(); } } }; m.createNewEndBlock(closureBody); } public Operand buildPreExe(Node node, IR_Scope m) { final PreExeNode preExeNode = (PreExeNode) node; // create the closure class and instantiate it final CompilerCallback closureBody = new CompilerCallback() { public void call(IR_Scope m) { if (preExeNode.getBodyNode() != null) { build(preExeNode.getBodyNode(), m,true); } else { m.loadNil(); } } }; m.runBeginBlock(preExeNode.getScope(), closureBody); }
 Operand buildRegexp(RegexpNode reNode, IR_Scope m)
           
 Operand buildReturn(ReturnNode returnNode, IR_Scope m)
          public Operand buildRetry(Node node, IR_Scope s) { // JRuby only supports retry when present in rescue blocks! // 1.9 doesn't support retry anywhere else.
 IR_Scope buildRoot(Node node)
           
 Operand buildSelf(Node node, IR_Scope s)
           
 void buildSpecificArityArguments(java.util.List<Operand> args, Node node, IR_Scope s)
           
 Operand buildSplat(SplatNode splatNode, IR_Scope s)
           
 void buildSplatArguments(java.util.List<Operand> args, SplatNode node, IR_Scope s)
           
 Operand buildStr(StrNode strNode, IR_Scope s)
           
 Operand buildSuper(SuperNode superNode, IR_Scope s)
           
 Operand buildSValue(SValueNode node, IR_Scope s)
           
 Operand buildSymbol(SymbolNode node, IR_Scope s)
           
 Operand buildToAry(ToAryNode node, IR_Scope s)
           
 Operand buildTrue(Node node, IR_Scope m)
           
 java.lang.String buildType(Node typeNode)
           
 Operand buildUntil(UntilNode untilNode, IR_Scope s)
           
 void buildVariableArityArguments(java.util.List<Operand> args, Node node, IR_Scope s)
           
 Operand buildVCall(VCallNode node, IR_Scope s)
          public Operand buildVAlias(Node node, IR_Scope m) { VAliasNode valiasNode = (VAliasNode) node; m.aliasGlobal(valiasNode.getNewName(), valiasNode.getOldName()); }
 Operand buildWhile(WhileNode whileNode, IR_Scope s)
           
 Operand buildXStr(XStrNode node, IR_Scope m)
           
 Operand buildYield(YieldNode node, IR_Scope s)
           
 Operand buildZArray(Node node, IR_Scope m)
           
 Operand buildZSuper(ZSuperNode zsuperNode, IR_Scope s)
           
static void main(java.lang.String[] args)
           
 Operand receiveArgs(ArgsNode argsNode, IR_Scope s)
           
 java.util.List<Operand> setupCallArgs(Node args, IR_Scope s)
           
 java.util.List<Operand> setupCallArgs(Node receiver, Node args, IR_Scope s)
           
static Node skipOverNewlines(Node n)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IR_Builder

public IR_Builder()
Method Detail

skipOverNewlines

public static Node skipOverNewlines(Node n)

main

public static void main(java.lang.String[] args)

buildFromMain

public static IR_Scope buildFromMain(java.lang.String[] args)

build

public Operand build(Node node,
                     IR_Scope m)

buildArguments

public void buildArguments(java.util.List<Operand> args,
                           Node node,
                           IR_Scope s)

buildVariableArityArguments

public void buildVariableArityArguments(java.util.List<Operand> args,
                                        Node node,
                                        IR_Scope s)

buildSpecificArityArguments

public void buildSpecificArityArguments(java.util.List<Operand> args,
                                        Node node,
                                        IR_Scope s)

setupCallArgs

public java.util.List<Operand> setupCallArgs(Node receiver,
                                             Node args,
                                             IR_Scope s)

setupCallArgs

public java.util.List<Operand> setupCallArgs(Node args,
                                             IR_Scope s)

buildArgs

public void buildArgs(java.util.List<Operand> argsList,
                      Node args,
                      IR_Scope s)

buildAssignment

public void buildAssignment(Node node,
                            IR_Scope s,
                            Operand values,
                            int argIndex,
                            boolean isSplat)

buildBlockArgsAssignment

public void buildBlockArgsAssignment(Node node,
                                     IR_Scope s,
                                     int argIndex,
                                     boolean isSplat)

buildAlias

public Operand buildAlias(AliasNode alias,
                          IR_Scope s)

buildAnd

public Operand buildAnd(AndNode andNode,
                        IR_Scope m)

buildArray

public Operand buildArray(Node node,
                          IR_Scope m)

buildArgsCat

public Operand buildArgsCat(ArgsCatNode argsCatNode,
                            IR_Scope s)

buildArgsPush

public Operand buildArgsPush(ArgsPushNode node,
                             IR_Scope m)

buildAttrAssignAssignment

public Operand buildAttrAssignAssignment(Node node,
                                         IR_Scope s,
                                         Operand value)

buildBackref

public Operand buildBackref(BackRefNode node,
                            IR_Scope m)

buildBegin

public Operand buildBegin(BeginNode beginNode,
                          IR_Scope s)

buildBignum

public Operand buildBignum(BignumNode node,
                           IR_Scope s)

buildBlock

public Operand buildBlock(BlockNode node,
                          IR_Scope s)

buildBreak

public Operand buildBreak(BreakNode breakNode,
                          IR_Scope s)

buildCall

public Operand buildCall(CallNode callNode,
                         IR_Scope s)

buildCase

public Operand buildCase(CaseNode caseNode,
                         IR_Scope m)

buildClass

public Operand buildClass(ClassNode classNode,
                          IR_Scope s)

buildClassVar

public Operand buildClassVar(ClassVarNode node,
                             IR_Scope s)
public Operand buildSClass(Node node, IR_Scope m) { final SClassNode sclassNode = (SClassNode) node; CompilerCallback receiverCallback = new CompilerCallback() { public void call(IR_Scope m) { build(sclassNode.getReceiverNode(), m, true); } }; CompilerCallback bodyCallback = new CompilerCallback() { public void call(IR_Scope m) { if (sclassNode.getBodyNode() != null) { build(sclassNode.getBodyNode(), m, true); } else { m.loadNil(); } } }; m.defineClass("SCLASS", sclassNode.getScope(), null, null, bodyCallback, receiverCallback, inspector); }


buildClassVarAsgn

public Operand buildClassVarAsgn(ClassVarAsgnNode classVarAsgnNode,
                                 IR_Scope s)

buildClassVarDecl

public Operand buildClassVarDecl(ClassVarDeclNode classVarDeclNode,
                                 IR_Scope s)

buildConstDecl

public Operand buildConstDecl(ConstDeclNode node,
                              IR_Scope s)

buildConstDeclAssignment

public Operand buildConstDeclAssignment(ConstDeclNode constDeclNode,
                                        IR_Scope s,
                                        Operand val)

buildConst

public Operand buildConst(ConstNode node,
                          IR_Scope s)

buildColon2

public Operand buildColon2(Colon2Node iVisited,
                           IR_Scope s)

buildColon3

public Operand buildColon3(Colon3Node node,
                           IR_Scope s)

buildDAsgn

public Operand buildDAsgn(DAsgnNode dasgnNode,
                          IR_Scope s)
public Operand buildGetDefinitionBase(final Node node, IR_Scope m) { switch (node.getNodeType()) { case CLASSVARASGNNODE: case CLASSVARDECLNODE: case CONSTDECLNODE: case DASGNNODE: case GLOBALASGNNODE: case LOCALASGNNODE: case MULTIPLEASGNNODE: case OPASGNNODE: case OPELEMENTASGNNODE: case DVARNODE: case FALSENODE: case TRUENODE: case LOCALVARNODE: case INSTVARNODE: case BACKREFNODE: case SELFNODE: case VCALLNODE: case YIELDNODE: case GLOBALVARNODE: case CONSTNODE: case FCALLNODE: case CLASSVARNODE: // these are all simple cases that don't require the heavier defined logic buildGetDefinition(node, m); break; default: BranchCallback reg = new BranchCallback() { public void branch(IR_Scope m) { m.inDefined(); buildGetDefinition(node, m); } }; BranchCallback out = new BranchCallback() { public void branch(IR_Scope m) { m.outDefined(); } }; m.protect(reg, out, String.class); } } public Operand buildDefined(final Node node, IR_Scope m) { buildGetDefinitionBase(((DefinedNode) node).getExpressionNode(), m); m.stringOrNil(); } public Operand buildGetArgumentDefinition(final Node node, IR_Scope m, String type) { if (node == null) { return new StringLiteral(type); } else if (node instanceof ArrayNode) { Object endToken = m.getNewEnding(); for (int i = 0; i < ((ArrayNode) node).size(); i++) { Node iterNode = ((ArrayNode) node).get(i); buildGetDefinition(iterNode, m); m.ifNull(endToken); } Operand sl = new StringLiteral(type); Object realToken = m.getNewEnding(); m.go(realToken); m.setEnding(endToken); m.pushNull(); m.setEnding(realToken); } else { buildGetDefinition(node, m); Object endToken = m.getNewEnding(); m.ifNull(endToken); Operand sl = new StringLiteral(type); Object realToken = m.getNewEnding(); m.go(realToken); m.setEnding(endToken); m.pushNull(); m.setEnding(realToken); } } public Operand buildGetDefinition(final Node node, IR_Scope m) { switch (node.getNodeType()) { case CLASSVARASGNNODE: case CLASSVARDECLNODE: case CONSTDECLNODE: case DASGNNODE: case GLOBALASGNNODE: case LOCALASGNNODE: case MULTIPLEASGNNODE: case OPASGNNODE: case OPELEMENTASGNNODE: return new StringLiteral("assignment"); case BACKREFNODE: // SSS FIXME! Operand x = m.backref(); return x instanceof RubyMatchData.class ? new StringLiteral("$" + ((BackRefNode) node).getType()) : Nil.NIL; case DVARNODE: return new StringLiteral("local-variable(in-block)"); case FALSENODE: return new StringLiteral("false"); case TRUENODE: return new StringLiteral("true"); case LOCALVARNODE: return new StringLiteral("local-variable"); case MATCH2NODE: case MATCH3NODE: return new StringLiteral("method"); case NILNODE: return new StringLiteral("nil"); case NTHREFNODE: m.isCaptured(((NthRefNode) node).getMatchNumber(), new BranchCallback() { public void branch(IR_Scope m) { return new StringLiteral("$" + ((NthRefNode) node).getMatchNumber()); } }, new BranchCallback() { public void branch(IR_Scope m) { return Nil.NIL; } }); break; case SELFNODE: return new StringLiteral("self"); case VCALLNODE: m.loadSelf(); m.isMethodBound(((VCallNode) node).getName(), new BranchCallback() { public void branch(IR_Scope m) { return new StringLiteral("method"); } }, new BranchCallback() { public void branch(IR_Scope m) { return Nil.NIL; } }); break; case YIELDNODE: m.hasBlock(new BranchCallback() { public void branch(IR_Scope m) { return new StringLiteral("yield"); } }, new BranchCallback() { public void branch(IR_Scope m) { return Nil.NIL; } }); break; case GLOBALVARNODE: m.isGlobalDefined(((GlobalVarNode) node).getName(), new BranchCallback() { public void branch(IR_Scope m) { return new StringLiteral("global-variable"); } }, new BranchCallback() { public void branch(IR_Scope m) { return Nil.NIL; } }); break; case INSTVARNODE: m.isInstanceVariableDefined(((InstVarNode) node).getName(), new BranchCallback() { public void branch(IR_Scope m) { return new StringLiteral("instance-variable"); } }, new BranchCallback() { public void branch(IR_Scope m) { return Nil.NIL; } }); break; case CONSTNODE: m.isConstantDefined(((ConstNode) node).getName(), new BranchCallback() { public void branch(IR_Scope m) { return new StringLiteral("constant"); } }, new BranchCallback() { public void branch(IR_Scope m) { return Nil.NIL; } }); break; case FCALLNODE: m.loadSelf(); m.isMethodBound(((FCallNode) node).getName(), new BranchCallback() { public void branch(IR_Scope m) { buildGetArgumentDefinition(((FCallNode) node).getArgsNode(), m, "method"); } }, new BranchCallback() { public void branch(IR_Scope m) { return Nil.NIL; } }); break; case COLON3NODE: case COLON2NODE: { final Colon3Node iVisited = (Colon3Node) node; final String name = iVisited.getName(); BranchCallback setup = new BranchCallback() { public void branch(IR_Scope m) { if (iVisited instanceof Colon2Node) { final Node leftNode = ((Colon2Node) iVisited).getLeftNode(); build(leftNode, m,true); } else { m.loadObject(); } } }; BranchCallback isConstant = new BranchCallback() { public void branch(IR_Scope m) { return new StringLiteral("constant"); } }; BranchCallback isMethod = new BranchCallback() { public void branch(IR_Scope m) { return new StringLiteral("method"); } }; BranchCallback none = new BranchCallback() { public void branch(IR_Scope m) { return Nil.NIL; } }; m.isConstantBranch(setup, isConstant, isMethod, none, name); break; } case CALLNODE: { final CallNode iVisited = (CallNode) node; Object isnull = m.getNewEnding(); Object ending = m.getNewEnding(); buildGetDefinition(iVisited.getReceiverNode(), m); m.ifNull(isnull); m.rescue(new BranchCallback() { public void branch(IR_Scope m) { build(iVisited.getReceiverNode(), m,true); //[IRubyObject] m.duplicateCurrentValue(); //[IRubyObject, IRubyObject] m.metaclass(); //[IRubyObject, RubyClass] m.duplicateCurrentValue(); //[IRubyObject, RubyClass, RubyClass] m.getVisibilityFor(iVisited.getName()); //[IRubyObject, RubyClass, Visibility] m.duplicateCurrentValue(); //[IRubyObject, RubyClass, Visibility, Visibility] final Object isfalse = m.getNewEnding(); Object isreal = m.getNewEnding(); Object ending = m.getNewEnding(); m.isPrivate(isfalse, 3); //[IRubyObject, RubyClass, Visibility] m.isNotProtected(isreal, 1); //[IRubyObject, RubyClass] m.selfIsKindOf(isreal); //[IRubyObject] m.consumeCurrentValue(); m.go(isfalse); m.setEnding(isreal); //[] m.isMethodBound(iVisited.getName(), new BranchCallback() { public void branch(IR_Scope m) { buildGetArgumentDefinition(iVisited.getArgsNode(), m, "method"); } }, new BranchCallback() { public void branch(IR_Scope m) { m.go(isfalse); } }); m.go(ending); m.setEnding(isfalse); m.pushNull(); m.setEnding(ending); } }, JumpException.class, new BranchCallback() { public void branch(IR_Scope m) { m.pushNull(); } }, String.class); // m.swapValues(); //m.consumeCurrentValue(); m.go(ending); m.setEnding(isnull); m.pushNull(); m.setEnding(ending); break; } case CLASSVARNODE: { ClassVarNode iVisited = (ClassVarNode) node; final Object ending = m.getNewEnding(); final Object failure = m.getNewEnding(); final Object singleton = m.getNewEnding(); Object second = m.getNewEnding(); Object third = m.getNewEnding(); m.loadCurrentModule(); //[RubyClass] m.duplicateCurrentValue(); //[RubyClass, RubyClass] m.ifNotNull(second); //[RubyClass] m.consumeCurrentValue(); //[] m.loadSelf(); //[self] m.metaclass(); //[RubyClass] m.duplicateCurrentValue(); //[RubyClass, RubyClass] m.isClassVarDefined(iVisited.getName(), new BranchCallback() { public void branch(IR_Scope m) { m.consumeCurrentValue(); Operand sl = new StringLiteral("class variable"); m.go(ending); } }, new BranchCallback() { public void branch(IR_Scope m) { } }); m.setEnding(second); //[RubyClass] m.duplicateCurrentValue(); m.isClassVarDefined(iVisited.getName(), new BranchCallback() { public void branch(IR_Scope m) { m.consumeCurrentValue(); Operand sl = new StringLiteral("class variable"); m.go(ending); } }, new BranchCallback() { public void branch(IR_Scope m) { } }); m.setEnding(third); //[RubyClass] m.duplicateCurrentValue(); //[RubyClass, RubyClass] m.ifSingleton(singleton); //[RubyClass] m.consumeCurrentValue();//[] m.go(failure); m.setEnding(singleton); m.attached();//[RubyClass] m.notIsModuleAndClassVarDefined(iVisited.getName(), failure); //[] Operand sl = new StringLiteral("class variable"); m.go(ending); m.setEnding(failure); m.pushNull(); m.setEnding(ending); } break; case ZSUPERNODE: { Object fail = m.getNewEnding(); Object fail2 = m.getNewEnding(); Object fail_easy = m.getNewEnding(); Object ending = m.getNewEnding(); m.getFrameName(); //[String] m.duplicateCurrentValue(); //[String, String] m.ifNull(fail); //[String] m.getFrameKlazz(); //[String, RubyClass] m.duplicateCurrentValue(); //[String, RubyClass, RubyClass] m.ifNull(fail2); //[String, RubyClass] m.superClass(); m.ifNotSuperMethodBound(fail_easy); Operand sl = new StringLiteral("super"); m.go(ending); m.setEnding(fail2); m.consumeCurrentValue(); m.setEnding(fail); m.consumeCurrentValue(); m.setEnding(fail_easy); m.pushNull(); m.setEnding(ending); } break; case SUPERNODE: { Object fail = m.getNewEnding(); Object fail2 = m.getNewEnding(); Object fail_easy = m.getNewEnding(); Object ending = m.getNewEnding(); m.getFrameName(); //[String] m.duplicateCurrentValue(); //[String, String] m.ifNull(fail); //[String] m.getFrameKlazz(); //[String, RubyClass] m.duplicateCurrentValue(); //[String, RubyClass, RubyClass] m.ifNull(fail2); //[String, RubyClass] m.superClass(); m.ifNotSuperMethodBound(fail_easy); buildGetArgumentDefinition(((SuperNode) node).getArgsNode(), m, "super"); m.go(ending); m.setEnding(fail2); m.consumeCurrentValue(); m.setEnding(fail); m.consumeCurrentValue(); m.setEnding(fail_easy); m.pushNull(); m.setEnding(ending); break; } case ATTRASSIGNNODE: { final AttrAssignNode iVisited = (AttrAssignNode) node; Object isnull = m.getNewEnding(); Object ending = m.getNewEnding(); buildGetDefinition(iVisited.getReceiverNode(), m); m.ifNull(isnull); m.rescue(new BranchCallback() { public void branch(IR_Scope m) { build(iVisited.getReceiverNode(), m,true); //[IRubyObject] m.duplicateCurrentValue(); //[IRubyObject, IRubyObject] m.metaclass(); //[IRubyObject, RubyClass] m.duplicateCurrentValue(); //[IRubyObject, RubyClass, RubyClass] m.getVisibilityFor(iVisited.getName()); //[IRubyObject, RubyClass, Visibility] m.duplicateCurrentValue(); //[IRubyObject, RubyClass, Visibility, Visibility] final Object isfalse = m.getNewEnding(); Object isreal = m.getNewEnding(); Object ending = m.getNewEnding(); m.isPrivate(isfalse, 3); //[IRubyObject, RubyClass, Visibility] m.isNotProtected(isreal, 1); //[IRubyObject, RubyClass] m.selfIsKindOf(isreal); //[IRubyObject] m.consumeCurrentValue(); m.go(isfalse); m.setEnding(isreal); //[] m.isMethodBound(iVisited.getName(), new BranchCallback() { public void branch(IR_Scope m) { buildGetArgumentDefinition(iVisited.getArgsNode(), m, "assignment"); } }, new BranchCallback() { public void branch(IR_Scope m) { m.go(isfalse); } }); m.go(ending); m.setEnding(isfalse); m.pushNull(); m.setEnding(ending); } }, JumpException.class, new BranchCallback() { public void branch(IR_Scope m) { m.pushNull(); } }, String.class); m.go(ending); m.setEnding(isnull); m.pushNull(); m.setEnding(ending); break; } default: m.rescue(new BranchCallback() { public void branch(IR_Scope m) { build(node, m,true); m.consumeCurrentValue(); m.pushNull(); } }, JumpException.class, new BranchCallback() { public void branch(IR_Scope m) { m.pushNull(); } }, String.class); m.consumeCurrentValue(); //MPS_FIXME: new StringLiteral("expression"); } }


buildDefn

public Operand buildDefn(MethodDefNode node,
                         IR_Scope s)

buildDefs

public Operand buildDefs(MethodDefNode node,
                         IR_Scope s)

receiveArgs

public Operand receiveArgs(ArgsNode argsNode,
                           IR_Scope s)

buildType

public java.lang.String buildType(Node typeNode)

buildDot

public Operand buildDot(DotNode dotNode,
                        IR_Scope s)

buildDRegexp

public Operand buildDRegexp(DRegexpNode dregexpNode,
                            IR_Scope s)

buildDStr

public Operand buildDStr(DStrNode dstrNode,
                         IR_Scope s)

buildDSymbol

public Operand buildDSymbol(Node node,
                            IR_Scope s)

buildDVar

public Operand buildDVar(DVarNode node,
                         IR_Scope m)

buildDXStr

public Operand buildDXStr(DXStrNode dstrNode,
                          IR_Scope m)

buildEvStr

public Operand buildEvStr(EvStrNode node,
                          IR_Scope s)
public Operand buildEnsureNode(Node node, IR_Scope m) { final EnsureNode ensureNode = (EnsureNode) node; if (ensureNode.getEnsureNode() != null) { m.performEnsure(new BranchCallback() { public void branch(IR_Scope m) { if (ensureNode.getBodyNode() != null) { build(ensureNode.getBodyNode(), m, true); } else { m.loadNil(); } } }, new BranchCallback() { public void branch(IR_Scope m) { build(ensureNode.getEnsureNode(), m, false); } }); } else { if (ensureNode.getBodyNode() != null) { build(ensureNode.getBodyNode(), m,true); } else { m.loadNil(); } } // TODO: don't require pop if (!expr) m.consumeCurrentValue(); }


buildFalse

public Operand buildFalse(Node node,
                          IR_Scope s)

buildFCall

public Operand buildFCall(FCallNode fcallNode,
                          IR_Scope s)

buildFixnum

public Operand buildFixnum(FixnumNode node,
                           IR_Scope m)

buildFloat

public Operand buildFloat(FloatNode node,
                          IR_Scope m)
public Operand buildFlip(Node node, IR_Scope m) { final FlipNode flipNode = (FlipNode) node; m.getVariableCompiler().retrieveLocalVariable(flipNode.getIndex(), flipNode.getDepth()); if (flipNode.isExclusive()) { m.performBooleanBranch(new BranchCallback() { public void branch(IR_Scope m) { build(flipNode.getEndNode(), m,true); m.performBooleanBranch(new BranchCallback() { public void branch(IR_Scope m) { m.loadFalse(); m.getVariableCompiler().assignLocalVariable(flipNode.getIndex(), flipNode.getDepth(), false); } }, new BranchCallback() { public void branch(IR_Scope m) { } }); m.loadTrue(); } }, new BranchCallback() { public void branch(IR_Scope m) { build(flipNode.getBeginNode(), m,true); becomeTrueOrFalse(m); m.getVariableCompiler().assignLocalVariable(flipNode.getIndex(), flipNode.getDepth(), true); } }); } else { m.performBooleanBranch(new BranchCallback() { public void branch(IR_Scope m) { build(flipNode.getEndNode(), m,true); m.performBooleanBranch(new BranchCallback() { public void branch(IR_Scope m) { m.loadFalse(); m.getVariableCompiler().assignLocalVariable(flipNode.getIndex(), flipNode.getDepth(), false); } }, new BranchCallback() { public void branch(IR_Scope m) { } }); m.loadTrue(); } }, new BranchCallback() { public void branch(IR_Scope m) { build(flipNode.getBeginNode(), m,true); m.performBooleanBranch(new BranchCallback() { public void branch(IR_Scope m) { build(flipNode.getEndNode(), m,true); flipTrueOrFalse(m); m.getVariableCompiler().assignLocalVariable(flipNode.getIndex(), flipNode.getDepth(), false); m.loadTrue(); } }, new BranchCallback() { public void branch(IR_Scope m) { m.loadFalse(); } }); } }); } // TODO: don't require pop if (!expr) m.consumeCurrentValue(); } private void becomeTrueOrFalse(IR_Scope m) { m.performBooleanBranch(new BranchCallback() { public void branch(IR_Scope m) { m.loadTrue(); } }, new BranchCallback() { public void branch(IR_Scope m) { m.loadFalse(); } }); } private void flipTrueOrFalse(IR_Scope m) { m.performBooleanBranch(new BranchCallback() { public void branch(IR_Scope m) { m.loadFalse(); } }, new BranchCallback() { public void branch(IR_Scope m) { m.loadTrue(); } }); }


buildFor

public Operand buildFor(ForNode forNode,
                        IR_Scope m)

buildForIter

public Operand buildForIter(ForNode forNode,
                            IR_Scope s)

buildGlobalAsgn

public Operand buildGlobalAsgn(GlobalAsgnNode globalAsgnNode,
                               IR_Scope m)

buildGlobalVar

public Operand buildGlobalVar(GlobalVarNode node,
                              IR_Scope m)

buildHash

public Operand buildHash(HashNode hashNode,
                         IR_Scope m)

buildIf

public Operand buildIf(IfNode ifNode,
                       IR_Scope s)

buildInstAsgn

public Operand buildInstAsgn(InstAsgnNode instAsgnNode,
                             IR_Scope s)

buildInstVar

public Operand buildInstVar(InstVarNode node,
                            IR_Scope m)

buildIter

public Operand buildIter(IterNode iterNode,
                         IR_Scope s)

buildLocalAsgn

public Operand buildLocalAsgn(LocalAsgnNode localAsgnNode,
                              IR_Scope s)

buildLocalVar

public Operand buildLocalVar(LocalVarNode node,
                             IR_Scope s)

buildMatch

public Operand buildMatch(MatchNode matchNode,
                          IR_Scope m)

buildMatch2

public Operand buildMatch2(Match2Node matchNode,
                           IR_Scope m)

buildMatch3

public Operand buildMatch3(Match3Node matchNode,
                           IR_Scope m)

buildModule

public Operand buildModule(ModuleNode moduleNode,
                           IR_Scope s)

buildMultipleAsgn

public Operand buildMultipleAsgn(MultipleAsgnNode multipleAsgnNode,
                                 IR_Scope s)

buildMultipleAsgnAssignment

public void buildMultipleAsgnAssignment(MultipleAsgnNode multipleAsgnNode,
                                        IR_Scope s,
                                        Operand values)

buildNewline

public Operand buildNewline(NewlineNode node,
                            IR_Scope s)

buildNext

public Operand buildNext(NextNode nextNode,
                         IR_Scope s)

buildNthRef

public Operand buildNthRef(NthRefNode nthRefNode,
                           IR_Scope m)

buildNil

public Operand buildNil(Node node,
                        IR_Scope m)

buildNot

public Operand buildNot(NotNode node,
                        IR_Scope m)

buildOpAsgn

public Operand buildOpAsgn(OpAsgnNode opAsgnNode,
                           IR_Scope s)

buildOpAsgnAnd

public Operand buildOpAsgnAnd(OpAsgnAndNode andNode,
                              IR_Scope s)

buildOpAsgnOr

public Operand buildOpAsgnOr(OpAsgnOrNode orNode,
                             IR_Scope s)

buildOr

public Operand buildOr(OrNode orNode,
                       IR_Scope m)
private class OpElementAsgnArgumentsCallback implements ArgumentsCallback { private Node node; public OpElementAsgnArgumentsCallback(Node node) { this.node = node; } public int getArity() { switch (node.getNodeType()) { case ARGSCATNODE: case ARGSPUSHNODE: case SPLATNODE: return -1; case ARRAYNODE: ArrayNode arrayNode = (ArrayNode)node; if (arrayNode.size() == 0) { return 0; } else if (arrayNode.size() > 3) { return -1; } else { return ((ArrayNode)node).size(); } default: return 1; } } public void call(IR_Scope m) { if (getArity() == 1) { // if arity 1, just build the one element to save us the array cost build(((ArrayNode)node).get(0), m,true); } else { // build into array buildArguments(node, m); } } }; public Operand buildOpElementAsgnWithOr(Node node, IR_Scope m) { final OpElementAsgnNode opElementAsgnNode = (OpElementAsgnNode) node; CompilerCallback receiverCallback = new CompilerCallback() { public void call(IR_Scope m) { build(opElementAsgnNode.getReceiverNode(), m); } }; ArgumentsCallback argsCallback = new OpElementAsgnArgumentsCallback(opElementAsgnNode.getArgsNode()); CompilerCallback valueCallback = new CompilerCallback() { public void call(IR_Scope m) { build(opElementAsgnNode.getValueNode(), m, true); } }; m.getInvocationCompiler().opElementAsgnWithOr(receiverCallback, argsCallback, valueCallback); // TODO: don't require pop if (!expr) m.consumeCurrentValue(); } public Operand buildOpElementAsgnWithAnd(Node node, IR_Scope m) { final OpElementAsgnNode opElementAsgnNode = (OpElementAsgnNode) node; CompilerCallback receiverCallback = new CompilerCallback() { public void call(IR_Scope m) { build(opElementAsgnNode.getReceiverNode(), m); } }; ArgumentsCallback argsCallback = new OpElementAsgnArgumentsCallback(opElementAsgnNode.getArgsNode()); CompilerCallback valueCallback = new CompilerCallback() { public void call(IR_Scope m) { build(opElementAsgnNode.getValueNode(), m); } }; m.getInvocationCompiler().opElementAsgnWithAnd(receiverCallback, argsCallback, valueCallback); } public Operand buildOpElementAsgnWithMethod(Node node, IR_Scope m) { final OpElementAsgnNode opElementAsgnNode = (OpElementAsgnNode) node; CompilerCallback receiverCallback = new CompilerCallback() { public void call(IR_Scope m) { build(opElementAsgnNode.getReceiverNode(), m); } }; ArgumentsCallback argsCallback = setupCallArgs(opElementAsgnNode.getArgsNode()); CompilerCallback valueCallback = new CompilerCallback() { public void call(IR_Scope m) { build(opElementAsgnNode.getValueNode(), m); } }; m.getInvocationCompiler().opElementAsgnWithMethod(receiverCallback, argsCallback, valueCallback, opElementAsgnNode.getOperatorName()); }


buildRedo

public Operand buildRedo(Node node,
                         IR_Scope s)
public Operand buildPostExe(Node node, IR_Scope m) { final PostExeNode postExeNode = (PostExeNode) node; // create the closure class and instantiate it final CompilerCallback closureBody = new CompilerCallback() { public void call(IR_Scope m) { if (postExeNode.getBodyNode() != null) { build(postExeNode.getBodyNode(), m, true); } else { m.loadNil(); } } }; m.createNewEndBlock(closureBody); } public Operand buildPreExe(Node node, IR_Scope m) { final PreExeNode preExeNode = (PreExeNode) node; // create the closure class and instantiate it final CompilerCallback closureBody = new CompilerCallback() { public void call(IR_Scope m) { if (preExeNode.getBodyNode() != null) { build(preExeNode.getBodyNode(), m,true); } else { m.loadNil(); } } }; m.runBeginBlock(preExeNode.getScope(), closureBody); }


buildRegexp

public Operand buildRegexp(RegexpNode reNode,
                           IR_Scope m)

buildReturn

public Operand buildReturn(ReturnNode returnNode,
                           IR_Scope m)
public Operand buildRetry(Node node, IR_Scope s) { // JRuby only supports retry when present in rescue blocks! // 1.9 doesn't support retry anywhere else. s.addInstr(new THREAD_POLL_Instr()); s.addInstr(new RETRY_Instr()); return Nil.NIL; }


buildRoot

public IR_Scope buildRoot(Node node)

buildSelf

public Operand buildSelf(Node node,
                         IR_Scope s)

buildSplat

public Operand buildSplat(SplatNode splatNode,
                          IR_Scope s)

buildStr

public Operand buildStr(StrNode strNode,
                        IR_Scope s)

buildSuper

public Operand buildSuper(SuperNode superNode,
                          IR_Scope s)

buildSValue

public Operand buildSValue(SValueNode node,
                           IR_Scope s)

buildSymbol

public Operand buildSymbol(SymbolNode node,
                           IR_Scope s)

buildToAry

public Operand buildToAry(ToAryNode node,
                          IR_Scope s)

buildTrue

public Operand buildTrue(Node node,
                         IR_Scope m)

buildUntil

public Operand buildUntil(UntilNode untilNode,
                          IR_Scope s)

buildVCall

public Operand buildVCall(VCallNode node,
                          IR_Scope s)
public Operand buildVAlias(Node node, IR_Scope m) { VAliasNode valiasNode = (VAliasNode) node; m.aliasGlobal(valiasNode.getNewName(), valiasNode.getOldName()); }


buildWhile

public Operand buildWhile(WhileNode whileNode,
                          IR_Scope s)

buildXStr

public Operand buildXStr(XStrNode node,
                         IR_Scope m)

buildYield

public Operand buildYield(YieldNode node,
                          IR_Scope s)

buildZArray

public Operand buildZArray(Node node,
                           IR_Scope m)

buildZSuper

public Operand buildZSuper(ZSuperNode zsuperNode,
                           IR_Scope s)

buildArgsCatArguments

public void buildArgsCatArguments(java.util.List<Operand> args,
                                  ArgsCatNode argsCatNode,
                                  IR_Scope s)

buildArgsPushArguments

public void buildArgsPushArguments(java.util.List<Operand> args,
                                   ArgsPushNode argsPushNode,
                                   IR_Scope m)

buildArrayArguments

public void buildArrayArguments(java.util.List<Operand> args,
                                Node node,
                                IR_Scope s)

buildSplatArguments

public void buildSplatArguments(java.util.List<Operand> args,
                                SplatNode node,
                                IR_Scope s)


Copyright © 2002-2009 JRuby Team. All Rights Reserved.