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