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; }
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; }