public LocalVariable getNewLocalVariable(RubySymbol name, int scopeDepth) { return scope.getNewLocalVariable(name, scopeDepth); }
public LocalVariable getNewLocalVariable(RubySymbol name, int scopeDepth) { return scope.getNewLocalVariable(name, scopeDepth); }
public LocalVariable getNewLocalVariable(String name, int depth) { if (isForLoopBody) return getLexicalParent().getNewLocalVariable(name, depth); if (depth == 0) { LocalVariable lvar = new ClosureLocalVariable(this, name, 0, localVars.nextSlot); localVars.putVariable(name, lvar); return lvar; } else { return getLexicalParent().getNewLocalVariable(name, depth-1); } }
protected LocalVariable getArgVariable(IRScope s, String name, int depth) { // For non-loops, this name will override any name that exists in outer scopes return s.isForLoopBody() ? s.getLocalVariable(name, depth) : s.getNewLocalVariable(name, 0); }
public LocalVariable getNewLocalVariable(String name, int depth) { if (isForLoopBody) return getLexicalParent().getNewLocalVariable(name, depth); if (depth == 0) { LocalVariable lvar = new ClosureLocalVariable(this, name, 0, localVars.nextSlot); localVars.putVariable(name, lvar); return lvar; } else { return getLexicalParent().getNewLocalVariable(name, depth-1); } }
protected LocalVariable getArgVariable(IRScope s, String name, int depth) { // For non-loops, this name will override any name that exists in outer scopes return s.isForLoopBody() ? s.getLocalVariable(name, depth) : s.getNewLocalVariable(name, 0); }
/** * Find or create a local variable. By default, scopes are assumed to * only check current depth. Blocks/Closures override this because they * have special nesting rules. */ public LocalVariable getLocalVariable(RubySymbol name, int scopeDepth) { LocalVariable lvar = findExistingLocalVariable(name, scopeDepth); if (lvar == null) { lvar = getNewLocalVariable(name, scopeDepth); } else if (lvar.getScopeDepth() != scopeDepth) { lvar = lvar.cloneForDepth(scopeDepth); } return lvar; }
/** * Find or create a local variable. By default, scopes are assumed to * only check current depth. Blocks/Closures override this because they * have special nesting rules. */ public LocalVariable getLocalVariable(RubySymbol name, int scopeDepth) { LocalVariable lvar = findExistingLocalVariable(name, scopeDepth); if (lvar == null) { lvar = getNewLocalVariable(name, scopeDepth); } else if (lvar.getScopeDepth() != scopeDepth) { lvar = lvar.cloneForDepth(scopeDepth); } return lvar; }
public LocalVariable getNewLocalVariable(RubySymbol name, int depth) { if (depth == 0 && !(this instanceof IRFor)) { LocalVariable lvar = new ClosureLocalVariable(name, 0, getStaticScope().addVariableThisScope(name.idString())); localVars.put(name, lvar); return lvar; } else { // IRFor does not have it's own state if (!(this instanceof IRFor)) flags.add(IRFlags.ACCESS_PARENTS_LOCAL_VARIABLES); IRScope s = this; int d = depth; do { // account for for-loops while (s instanceof IRFor) { depth++; s = s.getLexicalParent(); } // walk up d--; if (d >= 0) s = s.getLexicalParent(); } while (d >= 0); return s.getNewLocalVariable(name, 0).cloneForDepth(depth); } }
public LocalVariable getNewLocalVariable(RubySymbol name, int depth) { if (depth == 0 && !(this instanceof IRFor)) { LocalVariable lvar = new ClosureLocalVariable(name, 0, getStaticScope().addVariableThisScope(name.idString())); localVars.put(name, lvar); return lvar; } else { // IRFor does not have it's own state if (!(this instanceof IRFor)) flags.add(IRFlags.ACCESS_PARENTS_LOCAL_VARIABLES); IRScope s = this; int d = depth; do { // account for for-loops while (s instanceof IRFor) { depth++; s = s.getLexicalParent(); } // walk up d--; if (d >= 0) s = s.getLexicalParent(); } while (d >= 0); return s.getNewLocalVariable(name, 0).cloneForDepth(depth); } }
lvar = s.getNewLocalVariable(name, 0).cloneForDepth(depth); } else {
lvar = s.getNewLocalVariable(name, 0).cloneForDepth(depth); } else {
private void receiveClosureArg(BlockArgNode blockVarNode, IRScope s) { Variable blockVar = null; if (blockVarNode != null) { String blockArgName = blockVarNode.getName(); blockVar = s.getNewLocalVariable(blockArgName, 0); if (s instanceof IRMethod) ((IRMethod)s).addArgDesc("block", blockArgName); s.addInstr(new ReceiveClosureInstr(blockVar)); } // SSS FIXME: This instruction is only needed if there is an yield instr somewhere! // In addition, store the block argument in an implicit block variable Variable implicitBlockArg = s.getImplicitBlockArg(); if (blockVar == null) s.addInstr(new ReceiveClosureInstr(implicitBlockArg)); else s.addInstr(new CopyInstr(implicitBlockArg, blockVar)); }
private void receiveClosureArg(BlockArgNode blockVarNode, IRScope s) { Variable blockVar = null; if (blockVarNode != null) { String blockArgName = blockVarNode.getName(); blockVar = s.getNewLocalVariable(blockArgName, 0); if (s instanceof IRMethod) ((IRMethod)s).addArgDesc("block", blockArgName); s.addInstr(new ReceiveClosureInstr(blockVar)); } // SSS FIXME: This instruction is only needed if there is an yield instr somewhere! // In addition, store the block argument in an implicit block variable Variable implicitBlockArg = s.getImplicitBlockArg(); if (blockVar == null) s.addInstr(new ReceiveClosureInstr(implicitBlockArg)); else s.addInstr(new CopyInstr(implicitBlockArg, blockVar)); }
public void receiveRequiredArg(Node node, IRScope s, int argIndex, boolean post, int numPreReqd, int numPostRead) { switch (node.getNodeType()) { case ARGUMENTNODE: { ArgumentNode a = (ArgumentNode)node; String argName = a.getName(); if (s instanceof IRMethod) ((IRMethod)s).addArgDesc("req", argName); addArgReceiveInstr(s, s.getNewLocalVariable(argName, 0), argIndex, post, numPreReqd, numPostRead); break; } case MULTIPLEASGN19NODE: { MultipleAsgn19Node childNode = (MultipleAsgn19Node) node; Variable v = s.getNewTemporaryVariable(); addArgReceiveInstr(s, v, argIndex, post, numPreReqd, numPostRead); if (s instanceof IRMethod) ((IRMethod)s).addArgDesc("rest", ""); s.addInstr(new ToAryInstr(v, v, manager.getFalse())); buildMultipleAsgn19Assignment(childNode, s, v, null); break; } default: throw new NotCompilableException("Can't build assignment node: " + node); } }
public LocalVariable getImplicitBlockArg() { // SSS: FIXME: Ugly! We cannot use 'getLocalVariable(Variable.BLOCK, getNestingDepth())' because // of scenario 3. below. Can we clean up this code? // // 1. If the variable has previously been defined, return a copy usable at the closure's nesting depth. // 2. If not, and if the closure is ultimately nested within a method, build a local variable that will // be defined in that method. // 3. If not, and if the closure is not nested within a method, the closure can never receive a block. // So, we could return 'null', but it creates problems for IR generation. So, for this scenario, // we simply create a dummy var at depth 0 (meaning, it is local to the closure itself) and return it. LocalVariable blockVar = findExistingLocalVariable(Variable.BLOCK, getNestingDepth()); if (blockVar != null) { // Create a copy of the variable usable at the right depth if (blockVar.getScopeDepth() != getNestingDepth()) blockVar = blockVar.cloneForDepth(getNestingDepth()); } else { IRScope s = this; while (s instanceof IRClosure) s = s.getLexicalParent(); if (s instanceof IRMethod) { blockVar = s.getNewLocalVariable(Variable.BLOCK, 0); // Create a copy of the variable usable at the right depth if (getNestingDepth() != 0) blockVar = blockVar.cloneForDepth(getNestingDepth()); } else { // Dummy var blockVar = getNewLocalVariable(Variable.BLOCK, 0); } } return blockVar; }
AssignableNode kasgn = (AssignableNode)kwarg.getAssignable(); String argName = ((INameNode) kasgn).getName(); Variable av = s.getNewLocalVariable(argName, 0); Label l = s.getNewLabel(); if (keyRest != null) { String argName = keyRest.getName(); Variable av = s.getNewLocalVariable(argName, 0);
public void receiveRequiredArg(Node node, IRScope s, int argIndex, boolean post, int numPreReqd, int numPostRead) { switch (node.getNodeType()) { case ARGUMENTNODE: { ArgumentNode a = (ArgumentNode)node; String argName = a.getName(); if (s instanceof IRMethod) ((IRMethod)s).addArgDesc("req", argName); addArgReceiveInstr(s, s.getNewLocalVariable(argName, 0), argIndex, post, numPreReqd, numPostRead); break; } case MULTIPLEASGN19NODE: { MultipleAsgn19Node childNode = (MultipleAsgn19Node) node; Variable v = s.getNewTemporaryVariable(); addArgReceiveInstr(s, v, argIndex, post, numPreReqd, numPostRead); if (s instanceof IRMethod) ((IRMethod)s).addArgDesc("rest", ""); s.addInstr(new ToAryInstr(v, v, manager.getFalse())); buildMultipleAsgn19Assignment(childNode, s, v, null); break; } default: throw new NotCompilableException("Can't build assignment node: " + node); } }
AssignableNode kasgn = (AssignableNode)kwarg.getAssignable(); String argName = ((INameNode) kasgn).getName(); Variable av = s.getNewLocalVariable(argName, 0); Label l = s.getNewLabel(); if (keyRest != null) { String argName = keyRest.getName(); Variable av = s.getNewLocalVariable(argName, 0);
public LocalVariable getImplicitBlockArg() { // SSS: FIXME: Ugly! We cannot use 'getLocalVariable(Variable.BLOCK, getNestingDepth())' because // of scenario 3. below. Can we clean up this code? // // 1. If the variable has previously been defined, return a copy usable at the closure's nesting depth. // 2. If not, and if the closure is ultimately nested within a method, build a local variable that will // be defined in that method. // 3. If not, and if the closure is not nested within a method, the closure can never receive a block. // So, we could return 'null', but it creates problems for IR generation. So, for this scenario, // we simply create a dummy var at depth 0 (meaning, it is local to the closure itself) and return it. LocalVariable blockVar = findExistingLocalVariable(Variable.BLOCK, getNestingDepth()); if (blockVar != null) { // Create a copy of the variable usable at the right depth if (blockVar.getScopeDepth() != getNestingDepth()) blockVar = blockVar.cloneForDepth(getNestingDepth()); } else { IRScope s = this; while (s instanceof IRClosure) s = s.getLexicalParent(); if (s instanceof IRMethod) { blockVar = s.getNewLocalVariable(Variable.BLOCK, 0); // Create a copy of the variable usable at the right depth if (getNestingDepth() != 0) blockVar = blockVar.cloneForDepth(getNestingDepth()); } else { // Dummy var blockVar = getNewLocalVariable(Variable.BLOCK, 0); } } return blockVar; }