public boolean isNestedClosuresSafeForMethodConversion() { for (IRClosure closure: getClosures()) { if (!closure.isNestedClosuresSafeForMethodConversion()) return false; } return !getFlags().contains(IRFlags.ACCESS_PARENTS_LOCAL_VARIABLES); }
public boolean isNestedClosuresSafeForMethodConversion() { for (IRClosure closure: getClosures()) { if (!closure.isNestedClosuresSafeForMethodConversion()) return false; } return !getFlags().contains(IRFlags.ACCESS_PARENTS_LOCAL_VARIABLES); }
public IRMethod convertToMethod(RubySymbol name) { // We want variable scoping to be the same as a method and not see outside itself. if (source == null || getFlags().contains(IRFlags.ACCESS_PARENTS_LOCAL_VARIABLES) || // Built methods cannot search down past method scope getFlags().contains(IRFlags.RECEIVES_CLOSURE_ARG) || // we pass in captured block at define_method as block so explicits ones not supported !isNestedClosuresSafeForMethodConversion()) { source = null; return null; } DefNode def = source; source = null; // FIXME: This should be bytelist from param vs being made (see above). return new IRMethod(getManager(), getLexicalParent(), def, name, true, getLine(), getStaticScope(), getFlags().contains(IRFlags.CODE_COVERAGE)); }
public IRMethod convertToMethod(RubySymbol name) { // We want variable scoping to be the same as a method and not see outside itself. if (source == null || getFlags().contains(IRFlags.ACCESS_PARENTS_LOCAL_VARIABLES) || // Built methods cannot search down past method scope getFlags().contains(IRFlags.RECEIVES_CLOSURE_ARG) || // we pass in captured block at define_method as block so explicits ones not supported !isNestedClosuresSafeForMethodConversion()) { source = null; return null; } DefNode def = source; source = null; // FIXME: This should be bytelist from param vs being made (see above). return new IRMethod(getManager(), getLexicalParent(), def, name, true, getLine(), getStaticScope(), getFlags().contains(IRFlags.CODE_COVERAGE)); }
private void identifyUndefinedVarsInClosure(Set<Variable> undefinedVars, IRClosure cl, int nestingLevel) { int clBaseDepth = nestingLevel + (cl.getFlags().contains(IRFlags.REUSE_PARENT_DYNSCOPE) ? 0 : 1); cl.setUpUseDefLocalVarMaps(); for (LocalVariable lv: cl.getUsedLocalVariables()) { // This can happen where an outer scope variable // is not used in this scope but is used in a nested // scope. Ex: ~jruby/bin/ast:21 if (problem.getDFVar(lv) == null) { continue; } // Find variables which belong to the problem.getScope() if (lv.getScopeDepth() == clBaseDepth && !tmp.get(problem.getDFVar(lv))) { // We want lv suitable for initializing in this scope undefinedVars.add(!lv.isOuterScopeVar() ? lv : lv.cloneForDepth(0)); tmp.set(problem.getDFVar(lv)); } } // Recurse for (IRClosure nestedCl: cl.getClosures()) { identifyUndefinedVarsInClosure(undefinedVars, nestedCl, nestingLevel + 1); } }
private void identifyUndefinedVarsInClosure(Set<Variable> undefinedVars, IRClosure cl, int nestingLevel) { int clBaseDepth = nestingLevel + (cl.getFlags().contains(IRFlags.REUSE_PARENT_DYNSCOPE) ? 0 : 1); cl.setUpUseDefLocalVarMaps(); for (LocalVariable lv: cl.getUsedLocalVariables()) { // This can happen where an outer scope variable // is not used in this scope but is used in a nested // scope. Ex: ~jruby/bin/ast:21 if (problem.getDFVar(lv) == null) { continue; } // Find variables which belong to the problem.getScope() if (lv.getScopeDepth() == clBaseDepth && !tmp.get(problem.getDFVar(lv))) { // We want lv suitable for initializing in this scope undefinedVars.add(!lv.isOuterScopeVar() ? lv : lv.cloneForDepth(0)); tmp.set(problem.getDFVar(lv)); } } // Recurse for (IRClosure nestedCl: cl.getClosures()) { identifyUndefinedVarsInClosure(undefinedVars, nestedCl, nestingLevel + 1); } }
public IRClosure(IRManager manager, IRScope lexicalParent, int lineNumber, StaticScope staticScope, Signature signature, ByteList prefix, boolean isBeginEndBlock, boolean needsCoverage) { this(manager, lexicalParent, lineNumber, staticScope, prefix); this.signature = signature; lexicalParent.addClosure(this); if (getManager().isDryRun()) { this.body = null; } else { boolean shouldJit = manager.getInstanceConfig().getCompileMode().shouldJIT(); this.body = shouldJit ? new MixedModeIRBlockBody(this, signature) : new InterpretedIRBlockBody(this, signature); if (staticScope != null && !isBeginEndBlock) { staticScope.setIRScope(this); staticScope.setScopeType(this.getScopeType()); } } if (needsCoverage) getFlags().add(IRFlags.CODE_COVERAGE); }
public IRClosure(IRManager manager, IRScope lexicalParent, int lineNumber, StaticScope staticScope, Signature signature, ByteList prefix, boolean isBeginEndBlock, boolean needsCoverage) { this(manager, lexicalParent, lineNumber, staticScope, prefix); this.signature = signature; lexicalParent.addClosure(this); if (getManager().isDryRun()) { this.body = null; } else { boolean shouldJit = manager.getInstanceConfig().getCompileMode().shouldJIT(); this.body = shouldJit ? new MixedModeIRBlockBody(this, signature) : new InterpretedIRBlockBody(this, signature); if (staticScope != null && !isBeginEndBlock) { staticScope.setIRScope(this); staticScope.setScopeType(this.getScopeType()); } } if (needsCoverage) getFlags().add(IRFlags.CODE_COVERAGE); }
if (!closure.getFlags().contains(IRFlags.ACCESS_PARENTS_LOCAL_VARIABLES) && fcallNode.getIterNode() instanceof IterNode) { closure.setSource((IterNode) fcallNode.getIterNode());
if (!closure.getFlags().contains(IRFlags.ACCESS_PARENTS_LOCAL_VARIABLES) && fcallNode.getIterNode() instanceof IterNode) { closure.setSource((IterNode) fcallNode.getIterNode());