public Operand buildForIter(final ForNode forNode) { // Create a new closure context IRClosure closure = new IRFor(manager, scope, forNode.getLine(), forNode.getScope(), Signature.from(forNode)); // Create a new nested builder to ensure this gets its own IR builder state like the ensure block stack newIRBuilder(manager, closure).buildForIterInner(forNode); return new WrappedIRClosure(buildSelf(), closure); }
public Operand buildIter(final IterNode iterNode) { IRClosure closure = new IRClosure(manager, scope, iterNode.getLine(), iterNode.getScope(), Signature.from(iterNode), needsCodeCoverage); // Create a new nested builder to ensure this gets its own IR builder state like the ensure block stack newIRBuilder(manager, closure).buildIterInner(iterNode); return new WrappedIRClosure(buildSelf(), closure); }
public Operand buildForIter(final ForNode forNode) { // Create a new closure context IRClosure closure = new IRFor(manager, scope, forNode.getLine(), forNode.getScope(), Signature.from(forNode)); // Create a new nested builder to ensure this gets its own IR builder state like the ensure block stack newIRBuilder(manager, closure).buildForIterInner(forNode); return new WrappedIRClosure(buildSelf(), closure); }
public Operand buildIter(final IterNode iterNode) { IRClosure closure = new IRClosure(manager, scope, iterNode.getLine(), iterNode.getScope(), Signature.from(iterNode), needsCodeCoverage); // Create a new nested builder to ensure this gets its own IR builder state like the ensure block stack newIRBuilder(manager, closure).buildIterInner(iterNode); return new WrappedIRClosure(buildSelf(), closure); }
public Operand buildPreExe(PreExeNode preExeNode) { IRScope topLevel = scope.getRootLexicalScope(); IRClosure beginClosure = new IRFor(manager, scope, preExeNode.getLine(), topLevel.getStaticScope(), Signature.from(preExeNode), IRFor._BEGIN_); // Create a new nested builder to ensure this gets its own IR builder state like the ensure block stack newIRBuilder(manager, beginClosure).buildPrePostExeInner(preExeNode.getBodyNode()); topLevel.recordBeginBlock(beginClosure); // Record the begin block at IR build time return manager.getNil(); }
public Operand buildPreExe(PreExeNode preExeNode) { IRScope topLevel = scope.getRootLexicalScope(); IRClosure beginClosure = new IRFor(manager, scope, preExeNode.getLine(), topLevel.getStaticScope(), Signature.from(preExeNode), IRFor._BEGIN_); // Create a new nested builder to ensure this gets its own IR builder state like the ensure block stack newIRBuilder(manager, beginClosure).buildPrePostExeInner(preExeNode.getBodyNode()); topLevel.recordBeginBlock(beginClosure); // Record the begin block at IR build time return manager.getNil(); }
public Operand buildLambda(LambdaNode node) { IRClosure closure = new IRClosure(manager, scope, node.getLine(), node.getScope(), Signature.from(node), needsCodeCoverage); // Create a new nested builder to ensure this gets its own IR builder state like the ensure block stack newIRBuilder(manager, closure).buildLambdaInner(node); Variable lambda = createTemporaryVariable(); WrappedIRClosure lambdaBody = new WrappedIRClosure(closure.getSelf(), closure); addInstr(new BuildLambdaInstr(lambda, lambdaBody, scope.getFile(), node.getLine())); return lambda; }
public Operand buildLambda(LambdaNode node) { IRClosure closure = new IRClosure(manager, scope, node.getLine(), node.getScope(), Signature.from(node), needsCodeCoverage); // Create a new nested builder to ensure this gets its own IR builder state like the ensure block stack newIRBuilder(manager, closure).buildLambdaInner(node); Variable lambda = createTemporaryVariable(); WrappedIRClosure lambdaBody = new WrappedIRClosure(closure.getSelf(), closure); addInstr(new BuildLambdaInstr(lambda, lambdaBody, scope.getFile(), node.getLine())); return lambda; }
public Operand buildModule(ModuleNode moduleNode) { Colon3Node cpath = moduleNode.getCPath(); RubySymbol moduleName = cpath.getName(); Operand container = getContainerFromCPath(cpath); IRModuleBody body = new IRModuleBody(manager, scope, moduleName, moduleNode.getLine(), moduleNode.getScope()); Variable moduleVar = addResultInstr(new DefineModuleInstr(createTemporaryVariable(), body, container)); Variable processBodyResult = addResultInstr(new ProcessModuleBodyInstr(createTemporaryVariable(), moduleVar, NullBlock.INSTANCE)); newIRBuilder(manager, body).buildModuleOrClassBody(moduleNode.getBodyNode(), moduleNode.getLine(), moduleNode.getEndLine()); return processBodyResult; }
public Operand buildPostExe(PostExeNode postExeNode) { IRScope topLevel = scope.getRootLexicalScope(); IRScope nearestLVarScope = scope.getNearestTopLocalVariableScope(); IRClosure endClosure = new IRClosure(manager, scope, postExeNode.getLine(), nearestLVarScope.getStaticScope(), Signature.from(postExeNode), CommonByteLists._END_, true); // Create a new nested builder to ensure this gets its own IR builder state like the ensure block stack newIRBuilder(manager, endClosure).buildPrePostExeInner(postExeNode.getBodyNode()); // Add an instruction in 's' to record the end block in the 'topLevel' scope. // SSS FIXME: IR support for end-blocks that access vars in non-toplevel-scopes // might be broken currently. We could either fix it or consider dropping support // for END blocks altogether or only support them in the toplevel. Not worth the pain. addInstr(new RecordEndBlockInstr(topLevel, new WrappedIRClosure(buildSelf(), endClosure))); return manager.getNil(); }
public Operand buildPostExe(PostExeNode postExeNode) { IRScope topLevel = scope.getRootLexicalScope(); IRScope nearestLVarScope = scope.getNearestTopLocalVariableScope(); IRClosure endClosure = new IRClosure(manager, scope, postExeNode.getLine(), nearestLVarScope.getStaticScope(), Signature.from(postExeNode), CommonByteLists._END_, true); // Create a new nested builder to ensure this gets its own IR builder state like the ensure block stack newIRBuilder(manager, endClosure).buildPrePostExeInner(postExeNode.getBodyNode()); // Add an instruction in 's' to record the end block in the 'topLevel' scope. // SSS FIXME: IR support for end-blocks that access vars in non-toplevel-scopes // might be broken currently. We could either fix it or consider dropping support // for END blocks altogether or only support them in the toplevel. Not worth the pain. addInstr(new RecordEndBlockInstr(topLevel, new WrappedIRClosure(buildSelf(), endClosure))); return manager.getNil(); }
public Operand buildModule(ModuleNode moduleNode) { Colon3Node cpath = moduleNode.getCPath(); RubySymbol moduleName = cpath.getName(); Operand container = getContainerFromCPath(cpath); IRModuleBody body = new IRModuleBody(manager, scope, moduleName, moduleNode.getLine(), moduleNode.getScope()); Variable moduleVar = addResultInstr(new DefineModuleInstr(createTemporaryVariable(), body, container)); Variable processBodyResult = addResultInstr(new ProcessModuleBodyInstr(createTemporaryVariable(), moduleVar, NullBlock.INSTANCE)); newIRBuilder(manager, body).buildModuleOrClassBody(moduleNode.getBodyNode(), moduleNode.getLine(), moduleNode.getEndLine()); return processBodyResult; }
public Operand buildSClass(SClassNode sclassNode) { Operand receiver = build(sclassNode.getReceiverNode()); // FIXME: metaclass name should be a bytelist IRModuleBody body = new IRMetaClassBody(manager, scope, manager.getMetaClassName(), sclassNode.getLine(), sclassNode.getScope()); Variable sClassVar = addResultInstr(new DefineMetaClassInstr(createTemporaryVariable(), receiver, body)); // sclass bodies inherit the block of their containing method Variable processBodyResult = addResultInstr(new ProcessModuleBodyInstr(createTemporaryVariable(), sClassVar, scope.getYieldClosureVariable())); newIRBuilder(manager, body).buildModuleOrClassBody(sclassNode.getBodyNode(), sclassNode.getLine(), sclassNode.getEndLine()); return processBodyResult; }
public Operand buildSClass(SClassNode sclassNode) { Operand receiver = build(sclassNode.getReceiverNode()); // FIXME: metaclass name should be a bytelist IRModuleBody body = new IRMetaClassBody(manager, scope, manager.getMetaClassName(), sclassNode.getLine(), sclassNode.getScope()); Variable sClassVar = addResultInstr(new DefineMetaClassInstr(createTemporaryVariable(), receiver, body)); // sclass bodies inherit the block of their containing method Variable processBodyResult = addResultInstr(new ProcessModuleBodyInstr(createTemporaryVariable(), sClassVar, scope.getYieldClosureVariable())); newIRBuilder(manager, body).buildModuleOrClassBody(sclassNode.getBodyNode(), sclassNode.getLine(), sclassNode.getEndLine()); return processBodyResult; }
/** * Build a new class and add it to the current scope (s). */ public Operand buildClass(ClassNode classNode) { Node superNode = classNode.getSuperNode(); Colon3Node cpath = classNode.getCPath(); Operand superClass = (superNode == null) ? null : build(superNode); RubySymbol className = cpath.getName(); Operand container = getContainerFromCPath(cpath); IRClassBody body = new IRClassBody(manager, scope, className, classNode.getLine(), classNode.getScope()); Variable classVar = addResultInstr(new DefineClassInstr(createTemporaryVariable(), body, container, superClass)); Variable processBodyResult = addResultInstr(new ProcessModuleBodyInstr(createTemporaryVariable(), classVar, NullBlock.INSTANCE)); newIRBuilder(manager, body).buildModuleOrClassBody(classNode.getBodyNode(), classNode.getLine(), classNode.getEndLine()); return processBodyResult; }
/** * Build a new class and add it to the current scope (s). */ public Operand buildClass(ClassNode classNode) { Node superNode = classNode.getSuperNode(); Colon3Node cpath = classNode.getCPath(); Operand superClass = (superNode == null) ? null : build(superNode); RubySymbol className = cpath.getName(); Operand container = getContainerFromCPath(cpath); IRClassBody body = new IRClassBody(manager, scope, className, classNode.getLine(), classNode.getScope()); Variable classVar = addResultInstr(new DefineClassInstr(createTemporaryVariable(), body, container, superClass)); Variable processBodyResult = addResultInstr(new ProcessModuleBodyInstr(createTemporaryVariable(), classVar, NullBlock.INSTANCE)); newIRBuilder(manager, body).buildModuleOrClassBody(classNode.getBodyNode(), classNode.getLine(), classNode.getEndLine()); return processBodyResult; }
public Operand buildModule(ModuleNode moduleNode, IRScope s) { Colon3Node cpath = moduleNode.getCPath(); String moduleName = cpath.getName(); Operand container = getContainerFromCPath(cpath, s); // Build the new module IRModuleBody m = new IRModuleBody(manager, s, moduleName, moduleNode.getPosition().getLine(), moduleNode.getScope()); Variable moduleBody = s.getNewTemporaryVariable(); s.addInstr(new DefineModuleInstr(moduleBody, m, container)); Variable ret = s.getNewTemporaryVariable(); s.addInstr(new ProcessModuleBodyInstr(ret, moduleBody)); m.addInstr(new ReceiveSelfInstr(m.getSelf())); // Set %current_scope = <c> // Set %current_module = module<c> m.addInstr(new CopyInstr(m.getCurrentScopeVariable(), new CurrentScope(m))); m.addInstr(new CopyInstr(m.getCurrentModuleVariable(), new ScopeModule(m))); // Create a new nested builder to ensure this gets its own IR builder state Operand rv = newIRBuilder(manager).build(moduleNode.getBodyNode(), m); if (rv != null) m.addInstr(new ReturnInstr(rv)); return ret; }
public Operand buildModule(ModuleNode moduleNode, IRScope s) { Colon3Node cpath = moduleNode.getCPath(); String moduleName = cpath.getName(); Operand container = getContainerFromCPath(cpath, s); // Build the new module IRModuleBody m = new IRModuleBody(manager, s, moduleName, moduleNode.getPosition().getLine(), moduleNode.getScope()); Variable moduleBody = s.getNewTemporaryVariable(); s.addInstr(new DefineModuleInstr(moduleBody, m, container)); Variable ret = s.getNewTemporaryVariable(); s.addInstr(new ProcessModuleBodyInstr(ret, moduleBody)); m.addInstr(new ReceiveSelfInstr(m.getSelf())); // Set %current_scope = <c> // Set %current_module = module<c> m.addInstr(new CopyInstr(m.getCurrentScopeVariable(), new CurrentScope(m))); m.addInstr(new CopyInstr(m.getCurrentModuleVariable(), new ScopeModule(m))); // Create a new nested builder to ensure this gets its own IR builder state Operand rv = newIRBuilder(manager).build(moduleNode.getBodyNode(), m); if (rv != null) m.addInstr(new ReturnInstr(rv)); return ret; }
/** * Build a new class and add it to the current scope (s). */ public Operand buildClass(ClassNode classNode, IRScope s) { Node superNode = classNode.getSuperNode(); Colon3Node cpath = classNode.getCPath(); Operand superClass = (superNode == null) ? null : build(superNode, s); String className = cpath.getName(); Operand container = getContainerFromCPath(cpath, s); IRClassBody c = new IRClassBody(manager, s, className, classNode.getPosition().getLine(), classNode.getScope()); Variable classBody = s.getNewTemporaryVariable(); s.addInstr(new DefineClassInstr(classBody, c, container, superClass)); Variable ret = s.getNewTemporaryVariable(); s.addInstr(new ProcessModuleBodyInstr(ret, classBody)); c.addInstr(new ReceiveSelfInstr(c.getSelf())); // Set %current_scope = <c> // Set %current_module = module<c> c.addInstr(new CopyInstr(c.getCurrentScopeVariable(), new CurrentScope(c))); c.addInstr(new CopyInstr(c.getCurrentModuleVariable(), new ScopeModule(c))); // Create a new nested builder to ensure this gets its own IR builder state Operand rv = newIRBuilder(manager).build(classNode.getBodyNode(), c); if (rv != null) c.addInstr(new ReturnInstr(rv)); return ret; }
public Operand buildIter(final IterNode iterNode, IRScope s) { IRClosure closure = new IRClosure(manager, s, false, iterNode.getPosition().getStartLine(), iterNode.getScope(), Arity.procArityOf(iterNode.getVarNode()), iterNode.getArgumentType(), !is1_9() && !is2_0()); s.addClosure(closure); // Create a new nested builder to ensure this gets its own IR builder state // like the ensure block stack IRBuilder closureBuilder = newIRBuilder(manager); // Receive self closure.addInstr(new ReceiveSelfInstr(getSelf(closure))); // Build args NodeType argsNodeId = BlockBody.getArgumentTypeWackyHack(iterNode); if ((iterNode.getVarNode() != null) && (argsNodeId != null)) closureBuilder.receiveBlockArgs(iterNode, closure); closureBuilder.receiveBlockClosureArg(iterNode.getBlockVarNode(), closure); // Set %current_scope = <current-scope> // Set %current_module = <current-module> closure.addInstr(new CopyInstr(closure.getCurrentScopeVariable(), new CurrentScope(closure))); closure.addInstr(new CopyInstr(closure.getCurrentModuleVariable(), new ScopeModule(closure))); // Thread poll on entry of closure closure.addInstr(new ThreadPollInstr()); // start label -- used by redo! closure.addInstr(new LabelInstr(closure.startLabel)); // Build closure body and return the result of the closure Operand closureRetVal = iterNode.getBodyNode() == null ? manager.getNil() : closureBuilder.build(iterNode.getBodyNode(), closure); if (closureRetVal != U_NIL) { // can be U_NIL if the node is an if node with returns in both branches. closure.addInstr(new ReturnInstr(closureRetVal)); } return new WrappedIRClosure(closure); }