public Operand buildVCall(Variable result, VCallNode node) { if (result == null) result = createTemporaryVariable(); return addResultInstr(CallInstr.create(scope, CallType.VARIABLE, result, node.getName(), buildSelf(), NO_ARGS, null)); }
public Operand buildInstVar(InstVarNode node) { return addResultInstr(new GetFieldInstr(createTemporaryVariable(), buildSelf(), node.getName())); }
public Operand buildInstVar(InstVarNode node) { return addResultInstr(new GetFieldInstr(createTemporaryVariable(), buildSelf(), node.getName())); }
private Operand buildSuperInScriptBody() { return addResultInstr(new UnresolvedSuperInstr(scope, createTemporaryVariable(), buildSelf(), NO_ARGS, null, scope.maybeUsingRefinements())); }
public Operand buildVCall(Variable result, VCallNode node) { if (result == null) result = createTemporaryVariable(); return addResultInstr(CallInstr.create(scope, CallType.VARIABLE, result, node.getName(), buildSelf(), NO_ARGS, null)); }
private Operand buildSuperInScriptBody() { return addResultInstr(new UnresolvedSuperInstr(scope, createTemporaryVariable(), buildSelf(), NO_ARGS, null, scope.maybeUsingRefinements())); }
public Operand buildInstAsgn(final InstAsgnNode instAsgnNode) { Operand val = build(instAsgnNode.getValueNode()); // NOTE: if 's' happens to the a class, this is effectively an assignment of a class instance variable addInstr(new PutFieldInstr(buildSelf(), instAsgnNode.getName(), val)); return val; }
public Operand buildInstAsgn(final InstAsgnNode instAsgnNode) { Operand val = build(instAsgnNode.getValueNode()); // NOTE: if 's' happens to the a class, this is effectively an assignment of a class instance variable addInstr(new PutFieldInstr(buildSelf(), instAsgnNode.getName(), val)); return val; }
public Operand buildForIter(final ForNode forNode) { // Create a new closure context IRClosure closure = new IRFor(manager, scope, forNode.getLine(), forNode.getScope(), Signature.from(forNode)); // Create a new nested builder to ensure this gets its own IR builder state like the ensure block stack newIRBuilder(manager, closure).buildForIterInner(forNode); return new WrappedIRClosure(buildSelf(), closure); }
public Operand buildForIter(final ForNode forNode) { // Create a new closure context IRClosure closure = new IRFor(manager, scope, forNode.getLine(), forNode.getScope(), Signature.from(forNode)); // Create a new nested builder to ensure this gets its own IR builder state like the ensure block stack newIRBuilder(manager, closure).buildForIterInner(forNode); return new WrappedIRClosure(buildSelf(), closure); }
public Operand buildIter(final IterNode iterNode) { IRClosure closure = new IRClosure(manager, scope, iterNode.getLine(), iterNode.getScope(), Signature.from(iterNode), needsCodeCoverage); // Create a new nested builder to ensure this gets its own IR builder state like the ensure block stack newIRBuilder(manager, closure).buildIterInner(iterNode); return new WrappedIRClosure(buildSelf(), closure); }
public Operand buildIter(final IterNode iterNode) { IRClosure closure = new IRClosure(manager, scope, iterNode.getLine(), iterNode.getScope(), Signature.from(iterNode), needsCodeCoverage); // Create a new nested builder to ensure this gets its own IR builder state like the ensure block stack newIRBuilder(manager, closure).buildIterInner(iterNode); return new WrappedIRClosure(buildSelf(), closure); }
public Operand classVarContainer(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. * ------------------------------------------------------------------------------- */ int n = 0; IRScope cvarScope = scope; while (cvarScope != null && !(cvarScope instanceof IREvalScript) && !cvarScope.isNonSingletonClassBody()) { // For loops don't get their own static scope if (!(cvarScope instanceof IRFor)) { n++; } cvarScope = cvarScope.getLexicalParent(); } if (cvarScope != null && cvarScope.isNonSingletonClassBody()) { return ScopeModule.ModuleFor(n); } else { return addResultInstr(new GetClassVarContainerModuleInstr(createTemporaryVariable(), scope.getCurrentScopeVariable(), declContext ? null : buildSelf())); } }
public Operand classVarContainer(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. * ------------------------------------------------------------------------------- */ int n = 0; IRScope cvarScope = scope; while (cvarScope != null && !(cvarScope instanceof IREvalScript) && !cvarScope.isNonSingletonClassBody()) { // For loops don't get their own static scope if (!(cvarScope instanceof IRFor)) { n++; } cvarScope = cvarScope.getLexicalParent(); } if (cvarScope != null && cvarScope.isNonSingletonClassBody()) { return ScopeModule.ModuleFor(n); } else { return addResultInstr(new GetClassVarContainerModuleInstr(createTemporaryVariable(), scope.getCurrentScopeVariable(), declContext ? null : buildSelf())); } }
public Operand buildPostExe(PostExeNode postExeNode) { IRScope topLevel = scope.getRootLexicalScope(); IRScope nearestLVarScope = scope.getNearestTopLocalVariableScope(); IRClosure endClosure = new IRClosure(manager, scope, postExeNode.getLine(), nearestLVarScope.getStaticScope(), Signature.from(postExeNode), CommonByteLists._END_, true); // Create a new nested builder to ensure this gets its own IR builder state like the ensure block stack newIRBuilder(manager, endClosure).buildPrePostExeInner(postExeNode.getBodyNode()); // Add an instruction in 's' to record the end block in the 'topLevel' scope. // SSS FIXME: IR support for end-blocks that access vars in non-toplevel-scopes // might be broken currently. We could either fix it or consider dropping support // for END blocks altogether or only support them in the toplevel. Not worth the pain. addInstr(new RecordEndBlockInstr(topLevel, new WrappedIRClosure(buildSelf(), endClosure))); return manager.getNil(); }
private Operand buildSuperInstr(Operand block, Operand[] args) { CallInstr superInstr; Variable ret = createTemporaryVariable(); if (scope instanceof IRMethod && scope.getLexicalParent() instanceof IRClassBody) { if (((IRMethod) scope).isInstanceMethod) { superInstr = new InstanceSuperInstr(scope, ret, scope.getCurrentModuleVariable(), getName(), args, block, scope.maybeUsingRefinements()); } else { superInstr = new ClassSuperInstr(scope, ret, scope.getCurrentModuleVariable(), getName(), args, block, scope.maybeUsingRefinements()); } } 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(scope, ret, buildSelf(), args, block, scope.maybeUsingRefinements()); } receiveBreakException(block, superInstr); return ret; }
public Operand buildPostExe(PostExeNode postExeNode) { IRScope topLevel = scope.getRootLexicalScope(); IRScope nearestLVarScope = scope.getNearestTopLocalVariableScope(); IRClosure endClosure = new IRClosure(manager, scope, postExeNode.getLine(), nearestLVarScope.getStaticScope(), Signature.from(postExeNode), CommonByteLists._END_, true); // Create a new nested builder to ensure this gets its own IR builder state like the ensure block stack newIRBuilder(manager, endClosure).buildPrePostExeInner(postExeNode.getBodyNode()); // Add an instruction in 's' to record the end block in the 'topLevel' scope. // SSS FIXME: IR support for end-blocks that access vars in non-toplevel-scopes // might be broken currently. We could either fix it or consider dropping support // for END blocks altogether or only support them in the toplevel. Not worth the pain. addInstr(new RecordEndBlockInstr(topLevel, new WrappedIRClosure(buildSelf(), endClosure))); return manager.getNil(); }
List<KeyValuePair<Operand, Operand>> kwargs = buildKeywordArguments(keywordArgs); block = setupCallClosure(fcallNode.getIterNode()); callInstr = CallInstr.createWithKwargs(scope, CallType.FUNCTIONAL, result, fcallNode.getName(), buildSelf(), args, block, kwargs); } else { Operand[] args = setupCallArgs(callArgsNode); callInstr = CallInstr.create(scope, CallType.FUNCTIONAL, result, fcallNode.getName(), buildSelf(), args, block);
private Operand buildSuperInstr(Operand block, Operand[] args) { CallInstr superInstr; Variable ret = createTemporaryVariable(); if (scope instanceof IRMethod && scope.getLexicalParent() instanceof IRClassBody) { if (((IRMethod) scope).isInstanceMethod) { superInstr = new InstanceSuperInstr(scope, ret, scope.getCurrentModuleVariable(), getName(), args, block, scope.maybeUsingRefinements()); } else { superInstr = new ClassSuperInstr(scope, ret, scope.getCurrentModuleVariable(), getName(), args, block, scope.maybeUsingRefinements()); } } 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(scope, ret, buildSelf(), args, block, scope.maybeUsingRefinements()); } receiveBreakException(block, superInstr); return ret; }
List<KeyValuePair<Operand, Operand>> kwargs = buildKeywordArguments(keywordArgs); block = setupCallClosure(fcallNode.getIterNode()); callInstr = CallInstr.createWithKwargs(scope, CallType.FUNCTIONAL, result, fcallNode.getName(), buildSelf(), args, block, kwargs); } else { Operand[] args = setupCallArgs(callArgsNode); callInstr = CallInstr.create(scope, CallType.FUNCTIONAL, result, fcallNode.getName(), buildSelf(), args, block);