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