@Override public StaticScope newEvalScope(StaticScope parent, String[] names) { return new IRStaticScope(parent, names, true, true); }
public AssignableNode assign(ISourcePosition position, String name, Node value, StaticScope topScope, int depth) { int slot = exists(name); // We can assign if we already have variable of that name here or we are the only // scope in the chain (which Local scopes always are). if (slot >= 0) { return isBlockOrEval ? new DAsgnNode(position, name, ((depth << 16) | slot), value) : new LocalAsgnNode(position, name, ((depth << 16) | slot), value); } else if (!isBlockOrEval && (topScope == this)) { slot = addVariable(name); return new LocalAsgnNode(position, name, slot , value); } // If we are not a block-scope and we go there, we know that 'topScope' is a block scope // because a local scope cannot be within a local scope // If topScope was itself it would have created a LocalAsgnNode above. return isBlockOrEval ? enclosingScope.assign(position, name, value, topScope, depth + 1) : ((IRStaticScope)topScope).addAssign(position, name, value); }
public IRScriptBody(IRManager manager, String className, String sourceName, StaticScope staticScope) { super(manager, null, sourceName, sourceName, 0, staticScope); if (!getManager().isDryRun()) { if (staticScope != null) ((IRStaticScope)staticScope).setIRScope(this); } }
private static IRScope getEvalContainerScope(Ruby runtime, StaticScope evalScope) { // SSS FIXME: Weirdness here. We cannot get the containing IR scope from evalScope because of static-scope wrapping // that is going on // 1. In all cases, DynamicScope.getEvalScope wraps the executing static scope in a new local scope. // 2. For instance-eval (module-eval, class-eval) scenarios, there is an extra scope that is added to // the stack in ThreadContext.java:preExecuteUnder // I dont know what rule to apply when. However, in both these cases, since there is no IR-scope associated, // I have used the hack below where I first unwrap once and see if I get a non-null IR scope. If that doesn't // work, I unwarp once more and I am guaranteed to get the IR scope I want. IRScope containingIRScope = ((IRStaticScope)evalScope.getEnclosingScope()).getIRScope(); if (containingIRScope == null) containingIRScope = ((IRStaticScope)evalScope.getEnclosingScope().getEnclosingScope()).getIRScope(); return containingIRScope; }
public AssignableNode addAssign(ISourcePosition position, String name, Node value) { int slot = addVariable(name); // No bit math to store level since we know level is zero for this case return new DAsgnNode(position, name, slot, value); }
/** * @see org.jruby.parser.StaticScope#getAllNamesInScope() */ public String[] getAllNamesInScope() { String[] names = getVariables(); if (isBlockOrEval) { String[] ourVariables = names; String[] variables = enclosingScope.getAllNamesInScope(); // we know variables cannot be null since this IRStaticScope always returns a non-null array names = new String[variables.length + ourVariables.length]; System.arraycopy(variables, 0, names, 0, variables.length); System.arraycopy(ourVariables, 0, names, variables.length, ourVariables.length); } return names; }
public AssignableNode assign(ISourcePosition position, String name, Node value, StaticScope topScope, int depth) { int slot = exists(name); // We can assign if we already have variable of that name here or we are the only // scope in the chain (which Local scopes always are). if (slot >= 0) { return isBlockOrEval ? new DAsgnNode(position, name, ((depth << 16) | slot), value) : new LocalAsgnNode(position, name, ((depth << 16) | slot), value); } else if (!isBlockOrEval && (topScope == this)) { slot = addVariable(name); return new LocalAsgnNode(position, name, slot , value); } // If we are not a block-scope and we go there, we know that 'topScope' is a block scope // because a local scope cannot be within a local scope // If topScope was itself it would have created a LocalAsgnNode above. return isBlockOrEval ? enclosingScope.assign(position, name, value, topScope, depth + 1) : ((IRStaticScope)topScope).addAssign(position, name, value); }
public IRScriptBody(IRManager manager, String className, String sourceName, StaticScope staticScope) { super(manager, null, sourceName, sourceName, 0, staticScope); if (!getManager().isDryRun()) { if (staticScope != null) ((IRStaticScope)staticScope).setIRScope(this); } }
private static IRScope getEvalContainerScope(Ruby runtime, StaticScope evalScope) { // SSS FIXME: Weirdness here. We cannot get the containing IR scope from evalScope because of static-scope wrapping // that is going on // 1. In all cases, DynamicScope.getEvalScope wraps the executing static scope in a new local scope. // 2. For instance-eval (module-eval, class-eval) scenarios, there is an extra scope that is added to // the stack in ThreadContext.java:preExecuteUnder // I dont know what rule to apply when. However, in both these cases, since there is no IR-scope associated, // I have used the hack below where I first unwrap once and see if I get a non-null IR scope. If that doesn't // work, I unwarp once more and I am guaranteed to get the IR scope I want. IRScope containingIRScope = ((IRStaticScope)evalScope.getEnclosingScope()).getIRScope(); if (containingIRScope == null) containingIRScope = ((IRStaticScope)evalScope.getEnclosingScope().getEnclosingScope()).getIRScope(); return containingIRScope; }
public AssignableNode addAssign(ISourcePosition position, String name, Node value) { int slot = addVariable(name); // No bit math to store level since we know level is zero for this case return new DAsgnNode(position, name, slot, value); }
/** * @see org.jruby.parser.StaticScope#getAllNamesInScope() */ public String[] getAllNamesInScope() { String[] names = getVariables(); if (isBlockOrEval) { String[] ourVariables = names; String[] variables = enclosingScope.getAllNamesInScope(); // we know variables cannot be null since this IRStaticScope always returns a non-null array names = new String[variables.length + ourVariables.length]; System.arraycopy(variables, 0, names, 0, variables.length); System.arraycopy(ourVariables, 0, names, variables.length, ourVariables.length); } return names; }
@Override public StaticScope newEvalScope(StaticScope parent) { return new IRStaticScope(parent, true, true); }
public IRMethod(IRManager manager, IRScope lexicalParent, String name, boolean isInstanceMethod, int lineNumber, StaticScope staticScope) { super(manager, lexicalParent, name, lexicalParent.getFileName(), lineNumber, staticScope); this.isInstanceMethod = isInstanceMethod; this.callArgs = new ArrayList<Operand>(); this.argDesc = new ArrayList<String[]>(); if (!getManager().isDryRun()) { if (staticScope != null) ((IRStaticScope)staticScope).setIRScope(this); } }
@Override public Object interpret(ThreadContext context, DynamicScope currDynScope, IRubyObject self, Object[] temp, Block aBlock) { DynamicScope argsDynScope = currDynScope; // Find args that need to be passed into super while (!argsDynScope.getStaticScope().isArgumentScope()) argsDynScope = argsDynScope.getNextCapturedScope(); IRScope argsIRScope = ((IRStaticScope)argsDynScope.getStaticScope()).getIRScope(); Operand[] superArgs = (argsIRScope instanceof IRMethod) ? ((IRMethod)argsIRScope).getCallArgs() : ((IRClosure)argsIRScope).getBlockArgs(); // Prepare args -- but look up in 'argsDynScope', not 'currDynScope' IRubyObject[] args = prepareArguments(context, self, superArgs, argsDynScope, temp); // Prepare block -- fetching from the frame stack, if necessary Block block = prepareBlock(context, self, currDynScope, temp); if (block == null || !block.isGiven()) block = context.getFrameBlock(); return interpretSuper(context, self, args, block); }
@Override public StaticScope newBlockScope(StaticScope parent, String[] names) { return new IRStaticScope(parent, names, true, false); }
public IRMethod(IRManager manager, IRScope lexicalParent, String name, boolean isInstanceMethod, int lineNumber, StaticScope staticScope) { super(manager, lexicalParent, name, lexicalParent.getFileName(), lineNumber, staticScope); this.isInstanceMethod = isInstanceMethod; this.callArgs = new ArrayList<Operand>(); this.argDesc = new ArrayList<String[]>(); if (!getManager().isDryRun()) { if (staticScope != null) ((IRStaticScope)staticScope).setIRScope(this); } }
public Node declare(ISourcePosition position, String name, int depth) { int slot = exists(name); if (slot >= 0) { return isBlockOrEval ? new DVarNode(position, ((depth << 16) | slot), name) : new LocalVarNode(position, ((depth << 16) | slot), name); } return isBlockOrEval ? enclosingScope.declare(position, name, depth + 1) : new VCallNode(position, name); }
@Override public Object interpret(ThreadContext context, DynamicScope currDynScope, IRubyObject self, Object[] temp, Block aBlock) { DynamicScope argsDynScope = currDynScope; // Find args that need to be passed into super while (!argsDynScope.getStaticScope().isArgumentScope()) argsDynScope = argsDynScope.getNextCapturedScope(); IRScope argsIRScope = ((IRStaticScope)argsDynScope.getStaticScope()).getIRScope(); Operand[] superArgs = (argsIRScope instanceof IRMethod) ? ((IRMethod)argsIRScope).getCallArgs() : ((IRClosure)argsIRScope).getBlockArgs(); // Prepare args -- but look up in 'argsDynScope', not 'currDynScope' IRubyObject[] args = prepareArguments(context, self, superArgs, argsDynScope, temp); // Prepare block -- fetching from the frame stack, if necessary Block block = prepareBlock(context, self, currDynScope, temp); if (block == null || !block.isGiven()) block = context.getFrameBlock(); return interpretSuper(context, self, args, block); }