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