private Operand startingSearchScope(IRScope s) { IRScope nearestModuleBody = s.getNearestModuleReferencingScope(); return nearestModuleBody == null ? s.getCurrentScopeVariable() : new CurrentScope(nearestModuleBody); }
case BOOLEAN: return org.jruby.ir.operands.Boolean.decode(this); case COMPLEX: return Complex.decode(this); case CURRENT_SCOPE: return CurrentScope.decode(this); case DYNAMIC_SYMBOL: return DynamicSymbol.decode(this); case FILENAME: return Filename.decode(this);
case BOOLEAN: return org.jruby.ir.operands.Boolean.decode(this); case COMPLEX: return Complex.decode(this); case CURRENT_SCOPE: return CurrentScope.decode(this); case DYNAMIC_SYMBOL: return DynamicSymbol.decode(this); case FILENAME: return Filename.decode(this);
private Operand startingSearchScope(IRScope s) { IRScope nearestModuleBody = s.getNearestModuleReferencingScope(); return nearestModuleBody == null ? s.getCurrentScopeVariable() : new CurrentScope(nearestModuleBody); }
public IREvalScript buildEvalRoot(StaticScope staticScope, IRScope containingScope, String file, int lineNumber, RootNode rootNode) { // Top-level script! IREvalScript script = new IREvalScript(manager, containingScope, file, lineNumber, staticScope); // Debug info: record line number script.addInstr(new LineNumberInstr(script, lineNumber)); // Set %current_scope = <current-scope> // Set %current_module = <current-module> script.addInstr(new CopyInstr(script.getCurrentScopeVariable(), new CurrentScope(script))); script.addInstr(new CopyInstr(script.getCurrentModuleVariable(), new ScopeModule(script))); // Build IR for the tree and return the result of the expression tree Operand rval = rootNode.getBodyNode() == null ? manager.getNil() : build(rootNode.getBodyNode(), script); script.addInstr(new ReturnInstr(rval)); return script; }
public IREvalScript buildEvalRoot(StaticScope staticScope, IRScope containingScope, String file, int lineNumber, RootNode rootNode) { // Top-level script! IREvalScript script = new IREvalScript(manager, containingScope, file, lineNumber, staticScope); // Debug info: record line number script.addInstr(new LineNumberInstr(script, lineNumber)); // Set %current_scope = <current-scope> // Set %current_module = <current-module> script.addInstr(new CopyInstr(script.getCurrentScopeVariable(), new CurrentScope(script))); script.addInstr(new CopyInstr(script.getCurrentModuleVariable(), new ScopeModule(script))); // Build IR for the tree and return the result of the expression tree Operand rval = rootNode.getBodyNode() == null ? manager.getNil() : build(rootNode.getBodyNode(), script); script.addInstr(new ReturnInstr(rval)); return script; }
public IRScope buildRoot(RootNode rootNode) { String file = rootNode.getPosition().getFile(); StaticScope staticScope = rootNode.getStaticScope(); // Top-level script! IRScriptBody script = new IRScriptBody(manager, "__file__", file, staticScope); script.addInstr(new ReceiveSelfInstr(script.getSelf())); // Set %current_scope = <current-scope> // Set %current_module = <current-module> script.addInstr(new CopyInstr(script.getCurrentScopeVariable(), new CurrentScope(script))); script.addInstr(new CopyInstr(script.getCurrentModuleVariable(), new ScopeModule(script))); // Build IR for the tree and return the result of the expression tree script.addInstr(new ReturnInstr(build(rootNode.getBodyNode(), script))); return script; }
public IRScope buildRoot(RootNode rootNode) { String file = rootNode.getPosition().getFile(); StaticScope staticScope = rootNode.getStaticScope(); // Top-level script! IRScriptBody script = new IRScriptBody(manager, "__file__", file, staticScope); script.addInstr(new ReceiveSelfInstr(script.getSelf())); // Set %current_scope = <current-scope> // Set %current_module = <current-module> script.addInstr(new CopyInstr(script.getCurrentScopeVariable(), new CurrentScope(script))); script.addInstr(new CopyInstr(script.getCurrentModuleVariable(), new ScopeModule(script))); // Build IR for the tree and return the result of the expression tree script.addInstr(new ReturnInstr(build(rootNode.getBodyNode(), script))); return script; }
public Operand buildPostExe(PostExeNode postExeNode, IRScope s) { IRClosure endClosure = new IRClosure(manager, s, false, postExeNode.getPosition().getStartLine(), postExeNode.getScope(), Arity.procArityOf(postExeNode.getVarNode()), postExeNode.getArgumentType(), !is1_9() && !is2_0()); // Set up %current_scope and %current_module endClosure.addInstr(new CopyInstr(endClosure.getCurrentScopeVariable(), new CurrentScope(endClosure))); endClosure.addInstr(new CopyInstr(endClosure.getCurrentModuleVariable(), new ScopeModule(endClosure))); build(postExeNode.getBodyNode(), endClosure); // Add an instruction to record the end block at runtime s.addInstr(new RecordEndBlockInstr(s, endClosure)); return manager.getNil(); }
public Operand buildPostExe(PostExeNode postExeNode, IRScope s) { IRClosure endClosure = new IRClosure(manager, s, false, postExeNode.getPosition().getStartLine(), postExeNode.getScope(), Arity.procArityOf(postExeNode.getVarNode()), postExeNode.getArgumentType(), !is1_9() && !is2_0()); // Set up %current_scope and %current_module endClosure.addInstr(new CopyInstr(endClosure.getCurrentScopeVariable(), new CurrentScope(endClosure))); endClosure.addInstr(new CopyInstr(endClosure.getCurrentModuleVariable(), new ScopeModule(endClosure))); build(postExeNode.getBodyNode(), endClosure); // Add an instruction to record the end block at runtime s.addInstr(new RecordEndBlockInstr(s, endClosure)); return manager.getNil(); }
public Operand buildPreExe(PreExeNode preExeNode, IRScope s) { IRClosure beginClosure = new IRClosure(manager, s, false, preExeNode.getPosition().getStartLine(), preExeNode.getScope(), Arity.procArityOf(preExeNode.getVarNode()), preExeNode.getArgumentType(), !is1_9() && !is2_0()); // Set up %current_scope and %current_module beginClosure.addInstr(new CopyInstr(beginClosure.getCurrentScopeVariable(), new CurrentScope(beginClosure))); beginClosure.addInstr(new CopyInstr(beginClosure.getCurrentModuleVariable(), new ScopeModule(beginClosure))); build(preExeNode.getBodyNode(), beginClosure); // Record the begin block at IR build time s.getTopLevelScope().recordBeginBlock(beginClosure); return manager.getNil(); }
public Operand buildPreExe(PreExeNode preExeNode, IRScope s) { IRClosure beginClosure = new IRClosure(manager, s, false, preExeNode.getPosition().getStartLine(), preExeNode.getScope(), Arity.procArityOf(preExeNode.getVarNode()), preExeNode.getArgumentType(), !is1_9() && !is2_0()); // Set up %current_scope and %current_module beginClosure.addInstr(new CopyInstr(beginClosure.getCurrentScopeVariable(), new CurrentScope(beginClosure))); beginClosure.addInstr(new CopyInstr(beginClosure.getCurrentModuleVariable(), new ScopeModule(beginClosure))); build(preExeNode.getBodyNode(), beginClosure); // Record the begin block at IR build time s.getTopLevelScope().recordBeginBlock(beginClosure); return manager.getNil(); }
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; }
/** * 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; }
private IRMethod defineNewMethod(MethodDefNode defNode, IRScope s, boolean isInstanceMethod) { IRMethod method = new IRMethod(manager, s, defNode.getName(), isInstanceMethod, defNode.getPosition().getLine(), defNode.getScope()); method.addInstr(new ReceiveSelfInstr(getSelf(s))); // Set %current_scope = <current-scope> // Set %current_module = isInstanceMethod ? %self.metaclass : %self IRScope nearestScope = s.getNearestModuleReferencingScope(); method.addInstr(new CopyInstr(method.getCurrentScopeVariable(), new CurrentScope(nearestScope == null ? s : nearestScope))); method.addInstr(new CopyInstr(method.getCurrentModuleVariable(), new ScopeModule(nearestScope == null ? s : nearestScope))); // Build IR for arguments (including the block arg) receiveMethodArgs(defNode.getArgsNode(), method); // Thread poll on entry to method method.addInstr(new ThreadPollInstr()); // Build IR for body Node bodyNode = defNode.getBodyNode(); if (bodyNode != null) { // Create a new nested builder to ensure this gets its own IR builder state Operand rv = newIRBuilder(manager).build(bodyNode, method); if (rv != null) method.addInstr(new ReturnInstr(rv)); } else { method.addInstr(new ReturnInstr(manager.getNil())); } // If the method can receive non-local returns if (method.canReceiveNonlocalReturns()) { handleNonlocalReturnInMethod(method); } return method; }
private IRMethod defineNewMethod(MethodDefNode defNode, IRScope s, boolean isInstanceMethod) { IRMethod method = new IRMethod(manager, s, defNode.getName(), isInstanceMethod, defNode.getPosition().getLine(), defNode.getScope()); method.addInstr(new ReceiveSelfInstr(getSelf(s))); // Set %current_scope = <current-scope> // Set %current_module = isInstanceMethod ? %self.metaclass : %self IRScope nearestScope = s.getNearestModuleReferencingScope(); method.addInstr(new CopyInstr(method.getCurrentScopeVariable(), new CurrentScope(nearestScope == null ? s : nearestScope))); method.addInstr(new CopyInstr(method.getCurrentModuleVariable(), new ScopeModule(nearestScope == null ? s : nearestScope))); // Build IR for arguments (including the block arg) receiveMethodArgs(defNode.getArgsNode(), method); // Thread poll on entry to method method.addInstr(new ThreadPollInstr()); // Build IR for body Node bodyNode = defNode.getBodyNode(); if (bodyNode != null) { // Create a new nested builder to ensure this gets its own IR builder state Operand rv = newIRBuilder(manager).build(bodyNode, method); if (rv != null) method.addInstr(new ReturnInstr(rv)); } else { method.addInstr(new ReturnInstr(manager.getNil())); } // If the method can receive non-local returns if (method.canReceiveNonlocalReturns()) { handleNonlocalReturnInMethod(method); } return method; }
public Operand buildSClass(SClassNode sclassNode, IRScope s) { // class Foo // ... // class << self // ... // end // ... // end // // Here, the class << self declaration is in Foo's body. // Foo is the class in whose context this is being defined. Operand receiver = build(sclassNode.getReceiverNode(), s); // Create a dummy meta class and record it as being lexically defined in scope s IRModuleBody mc = new IRMetaClassBody(manager, s, manager.getMetaClassName(), sclassNode.getPosition().getLine(), sclassNode.getScope()); Variable classBody = s.getNewTemporaryVariable(); s.addInstr(new DefineMetaClassInstr(classBody, receiver, mc)); Variable ret = s.getNewTemporaryVariable(); s.addInstr(new ProcessModuleBodyInstr(ret, classBody)); mc.addInstr(new ReceiveSelfInstr(mc.getSelf())); // Set %current_scope = <current-scope> // Set %current_module = <current-module> mc.addInstr(new ReceiveClosureInstr(mc.getImplicitBlockArg())); mc.addInstr(new CopyInstr(mc.getCurrentScopeVariable(), new CurrentScope(mc))); mc.addInstr(new CopyInstr(mc.getCurrentModuleVariable(), new ScopeModule(mc))); // Create a new nested builder to ensure this gets its own IR builder state Operand rv = newIRBuilder(manager).build(sclassNode.getBodyNode(), mc); if (rv != null) mc.addInstr(new ReturnInstr(rv)); return ret; }
public Operand buildSClass(SClassNode sclassNode, IRScope s) { // class Foo // ... // class << self // ... // end // ... // end // // Here, the class << self declaration is in Foo's body. // Foo is the class in whose context this is being defined. Operand receiver = build(sclassNode.getReceiverNode(), s); // Create a dummy meta class and record it as being lexically defined in scope s IRModuleBody mc = new IRMetaClassBody(manager, s, manager.getMetaClassName(), sclassNode.getPosition().getLine(), sclassNode.getScope()); Variable classBody = s.getNewTemporaryVariable(); s.addInstr(new DefineMetaClassInstr(classBody, receiver, mc)); Variable ret = s.getNewTemporaryVariable(); s.addInstr(new ProcessModuleBodyInstr(ret, classBody)); mc.addInstr(new ReceiveSelfInstr(mc.getSelf())); // Set %current_scope = <current-scope> // Set %current_module = <current-module> mc.addInstr(new ReceiveClosureInstr(mc.getImplicitBlockArg())); mc.addInstr(new CopyInstr(mc.getCurrentScopeVariable(), new CurrentScope(mc))); mc.addInstr(new CopyInstr(mc.getCurrentModuleVariable(), new ScopeModule(mc))); // Create a new nested builder to ensure this gets its own IR builder state Operand rv = newIRBuilder(manager).build(sclassNode.getBodyNode(), mc); if (rv != null) mc.addInstr(new ReturnInstr(rv)); return ret; }