public Operand buildSelf(Node node, IRScope s) { return getSelf(s); }
public Operand buildSelf(Node node, IRScope s) { return getSelf(s); }
private Operand buildSuperInScriptBody(IRScope s) { Variable ret = s.getNewTemporaryVariable(); s.addInstr(new UnresolvedSuperInstr(ret, getSelf(s), NO_ARGS, null)); return ret; }
private Operand buildSuperInScriptBody(IRScope s) { Variable ret = s.getNewTemporaryVariable(); s.addInstr(new UnresolvedSuperInstr(ret, getSelf(s), NO_ARGS, null)); return ret; }
public Operand buildInstVar(InstVarNode node, IRScope s) { Variable ret = s.getNewTemporaryVariable(); s.addInstr(new GetFieldInstr(ret, getSelf(s), node.getName())); return ret; }
public Operand buildInstVar(InstVarNode node, IRScope s) { Variable ret = s.getNewTemporaryVariable(); s.addInstr(new GetFieldInstr(ret, getSelf(s), node.getName())); return ret; }
public Operand buildFCall(FCallNode fcallNode, IRScope s) { Node callArgsNode = fcallNode.getArgsNode(); List<Operand> args = setupCallArgs(callArgsNode, s); Operand block = setupCallClosure(fcallNode.getIterNode(), s); Variable callResult = s.getNewTemporaryVariable(); CallInstr callInstr = CallInstr.create(CallType.FUNCTIONAL, callResult, new MethAddr(fcallNode.getName()), getSelf(s), args.toArray(new Operand[args.size()]), block); receiveBreakException(s, block, callInstr); return callResult; }
public Operand buildFCall(FCallNode fcallNode, IRScope s) { Node callArgsNode = fcallNode.getArgsNode(); List<Operand> args = setupCallArgs(callArgsNode, s); Operand block = setupCallClosure(fcallNode.getIterNode(), s); Variable callResult = s.getNewTemporaryVariable(); CallInstr callInstr = CallInstr.create(CallType.FUNCTIONAL, callResult, new MethAddr(fcallNode.getName()), getSelf(s), args.toArray(new Operand[args.size()]), block); receiveBreakException(s, block, callInstr); return callResult; }
public Operand buildInstAsgn(final InstAsgnNode instAsgnNode, IRScope s) { Operand val = build(instAsgnNode.getValueNode(), s); // NOTE: if 's' happens to the a class, this is effectively an assignment of a class instance variable s.addInstr(new PutFieldInstr(getSelf(s), instAsgnNode.getName(), val)); return val; }
public Operand buildInstAsgn(final InstAsgnNode instAsgnNode, IRScope s) { Operand val = build(instAsgnNode.getValueNode(), s); // NOTE: if 's' happens to the a class, this is effectively an assignment of a class instance variable s.addInstr(new PutFieldInstr(getSelf(s), instAsgnNode.getName(), val)); return val; }
public Operand buildVCall(VCallNode node, IRScope s) { Variable callResult = s.getNewTemporaryVariable(); Instr callInstr = CallInstr.create(CallType.VARIABLE, callResult, new MethAddr(node.getName()), getSelf(s), NO_ARGS, null); s.addInstr(callInstr); return callResult; }
public Operand buildVCall(VCallNode node, IRScope s) { Variable callResult = s.getNewTemporaryVariable(); Instr callInstr = CallInstr.create(CallType.VARIABLE, callResult, new MethAddr(node.getName()), getSelf(s), NO_ARGS, null); s.addInstr(callInstr); return callResult; }
public Operand buildAlias(final AliasNode alias, IRScope s) { Operand newName = build(alias.getNewName(), s); Operand oldName = build(alias.getOldName(), s); s.addInstr(new AliasInstr(getSelf(s), newName, oldName)); return manager.getNil(); }
public Operand buildAlias(final AliasNode alias, IRScope s) { Operand newName = build(alias.getNewName(), s); Operand oldName = build(alias.getOldName(), s); s.addInstr(new AliasInstr(getSelf(s), newName, oldName)); return manager.getNil(); }
public Operand classVarContainer(IRScope s, boolean declContext) { /* ------------------------------------------------------------------------------- * We are looking for the nearest enclosing scope that is a non-singleton class body * without running into an eval-scope in between. * * Stop lexical scope walking at an eval script boundary. Evals are essentially * a way for a programmer to splice an entire tree of lexical scopes at the point * where the eval happens. So, when we hit an eval-script boundary at compile-time, * defer scope traversal to when we know where this scope has been spliced in. * ------------------------------------------------------------------------------- */ IRScope cvarScope = s; while (cvarScope != null && !(cvarScope instanceof IREvalScript) && !cvarScope.isNonSingletonClassBody()) { cvarScope = cvarScope.getLexicalParent(); } if ((cvarScope != null) && cvarScope.isNonSingletonClassBody()) { return new ScopeModule(cvarScope); } else { Variable tmp = s.getNewTemporaryVariable(); s.addInstr(new GetClassVarContainerModuleInstr(tmp, s.getCurrentScopeVariable(), declContext ? null : getSelf(s))); return tmp; } }
public Operand classVarContainer(IRScope s, boolean declContext) { /* ------------------------------------------------------------------------------- * We are looking for the nearest enclosing scope that is a non-singleton class body * without running into an eval-scope in between. * * Stop lexical scope walking at an eval script boundary. Evals are essentially * a way for a programmer to splice an entire tree of lexical scopes at the point * where the eval happens. So, when we hit an eval-script boundary at compile-time, * defer scope traversal to when we know where this scope has been spliced in. * ------------------------------------------------------------------------------- */ IRScope cvarScope = s; while (cvarScope != null && !(cvarScope instanceof IREvalScript) && !cvarScope.isNonSingletonClassBody()) { cvarScope = cvarScope.getLexicalParent(); } if ((cvarScope != null) && cvarScope.isNonSingletonClassBody()) { return new ScopeModule(cvarScope); } else { Variable tmp = s.getNewTemporaryVariable(); s.addInstr(new GetClassVarContainerModuleInstr(tmp, s.getCurrentScopeVariable(), declContext ? null : getSelf(s))); return tmp; } }
private Operand buildSuperInstr(IRScope s, Operand block, Operand[] args) { CallInstr superInstr; Variable ret = s.getNewTemporaryVariable(); if ((s instanceof IRMethod) && (s.getLexicalParent() instanceof IRClassBody)) { IRMethod m = (IRMethod)s; if (m.isInstanceMethod) { superInstr = new InstanceSuperInstr(ret, s.getCurrentModuleVariable(), new MethAddr(s.getName()), args, block); } else { superInstr = new ClassSuperInstr(ret, s.getCurrentModuleVariable(), new MethAddr(s.getName()), args, block); } } else { // We dont always know the method name we are going to be invoking if the super occurs in a closure. // This is because the super can be part of a block that will be used by 'define_method' to define // a new method. In that case, the method called by super will be determined by the 'name' argument // to 'define_method'. superInstr = new UnresolvedSuperInstr(ret, getSelf(s), args, block); } receiveBreakException(s, block, superInstr); return ret; }
private Operand buildSuperInstr(IRScope s, Operand block, Operand[] args) { CallInstr superInstr; Variable ret = s.getNewTemporaryVariable(); if ((s instanceof IRMethod) && (s.getLexicalParent() instanceof IRClassBody)) { IRMethod m = (IRMethod)s; if (m.isInstanceMethod) { superInstr = new InstanceSuperInstr(ret, s.getCurrentModuleVariable(), new MethAddr(s.getName()), args, block); } else { superInstr = new ClassSuperInstr(ret, s.getCurrentModuleVariable(), new MethAddr(s.getName()), args, block); } } else { // We dont always know the method name we are going to be invoking if the super occurs in a closure. // This is because the super can be part of a block that will be used by 'define_method' to define // a new method. In that case, the method called by super will be determined by the 'name' argument // to 'define_method'. superInstr = new UnresolvedSuperInstr(ret, getSelf(s), args, block); } receiveBreakException(s, block, superInstr); 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; }