private IRClosure getLambdaBody() { return ((WrappedIRClosure) operands[0]).getClosure(); }
private IRClosure getLambdaBody() { return ((WrappedIRClosure) operands[0]).getClosure(); }
public void WrappedIRClosure(WrappedIRClosure wrappedirclosure) { print(wrappedirclosure.getClosure().getId()); }
public void WrappedIRClosure(WrappedIRClosure wrappedirclosure) { print(wrappedirclosure.getClosure().getId()); }
/** * Wrapped IRClosures in dead BB are lexically rooted to that dead BB so they can * be removed from the parent scope if the BB they live in died. */ private void removeNestedScopesFromBB(BasicBlock bb) { for (Instr instr: bb.getInstrs()) { for (Operand oper: instr.getOperands()) { if (oper instanceof WrappedIRClosure) { scope.removeClosure(((WrappedIRClosure) oper).getClosure()); break; // Only one WrappedIRClosure possible per instr } } } }
/** * Wrapped IRClosures in dead BB are lexically rooted to that dead BB so they can * be removed from the parent scope if the BB they live in died. */ private void removeNestedScopesFromBB(BasicBlock bb) { for (Instr instr: bb.getInstrs()) { for (Operand oper: instr.getOperands()) { if (oper instanceof WrappedIRClosure) { scope.removeClosure(((WrappedIRClosure) oper).getClosure()); break; // Only one WrappedIRClosure possible per instr } } } }
private void collectNonLocalDirtyVars(IRClosure cl, Set<LocalVariable> vars, int minDepth) { for (BasicBlock bb: cl.getCFG().getBasicBlocks()) { for (Instr i: bb.getInstrs()) { // Collect local vars belonging to an outer scope dirtied here if (i instanceof ResultInstr) { Variable res = ((ResultInstr)i).getResult(); if (res instanceof LocalVariable && ((LocalVariable)res).getScopeDepth() > minDepth) { vars.add((LocalVariable)res); } } // When encountering nested closures, increase minDepth by 1 // so that we continue to collect vars belong to outer scopes. if (i instanceof ClosureAcceptingInstr) { Operand clArg = ((ClosureAcceptingInstr)i).getClosureArg(); if (clArg instanceof WrappedIRClosure) { collectNonLocalDirtyVars(((WrappedIRClosure)clArg).getClosure(), vars, minDepth+1); } } } } }
private void collectNonLocalDirtyVars(IRClosure cl, Set<LocalVariable> vars, int minDepth) { for (BasicBlock bb: cl.getCFG().getBasicBlocks()) { for (Instr i: bb.getInstrs()) { // Collect local vars belonging to an outer scope dirtied here if (i instanceof ResultInstr) { Variable res = ((ResultInstr)i).getResult(); if (res instanceof LocalVariable && ((LocalVariable)res).getScopeDepth() > minDepth) { vars.add((LocalVariable)res); } } // When encountering nested closures, increase minDepth by 1 // so that we continue to collect vars belong to outer scopes. if (i instanceof ClosureAcceptingInstr) { Operand clArg = ((ClosureAcceptingInstr)i).getClosureArg(); if (clArg instanceof WrappedIRClosure) { collectNonLocalDirtyVars(((WrappedIRClosure)clArg).getClosure(), vars, minDepth+1); } } } } }
@Override public Object interpret(ThreadContext context, StaticScope currScope, DynamicScope currDynScope, IRubyObject self, Object[] temp) { // SSS FIXME: Copied this from ast/LambdaNode ... Is this required here as well? // // JRUBY-5686: do this before executing so first time sets cref module ((WrappedIRClosure) getLambdaBody()).getClosure().getStaticScope().determineModule(); // CON: This must not be happening, because nil would never cast to Block // IRClosure body = getLambdaBody().getClosure(); // Block block = (Block) (body == null ? context.runtime.getIRManager().getNil() : getLambdaBody()).retrieve(context, self, currScope, currDynScope, temp); Block block = (Block)getLambdaBody().retrieve(context, self, currScope, currDynScope, temp); // ENEBO: Now can live nil be passed as block reference? // SSS FIXME: Should we do the same %self retrieval as in the case of WrappedIRClosure? Or are lambdas special?? return RubyProc.newProc(context.runtime, block, Block.Type.LAMBDA, getFile(), getLine()); }
public BasicBlock cloneForInlinedClosure(InlinerInfo ii) { // Update cfg for this bb IRScope hostScope = ii.getInlineHostScope(); BasicBlock clonedBB = ii.getOrCreateRenamedBB(this); // Process instructions for (Instr i: getInstrs()) { Instr clonedInstr = i.cloneForInlinedClosure(ii); if (clonedInstr != null) { clonedBB.addInstr(clonedInstr); if (clonedInstr instanceof CallBase) { CallBase call = (CallBase)clonedInstr; Operand block = call.getClosureArg(null); if (block instanceof WrappedIRClosure) hostScope.addClosure(((WrappedIRClosure)block).getClosure()); } } } return clonedBB; }
public BasicBlock cloneForInlinedClosure(InlinerInfo ii) { // Update cfg for this bb IRScope hostScope = ii.getInlineHostScope(); BasicBlock clonedBB = ii.getOrCreateRenamedBB(this); // Process instructions for (Instr i: getInstrs()) { Instr clonedInstr = i.cloneForInlinedClosure(ii); if (clonedInstr != null) { clonedBB.addInstr(clonedInstr); if (clonedInstr instanceof CallBase) { CallBase call = (CallBase)clonedInstr; Operand block = call.getClosureArg(null); if (block instanceof WrappedIRClosure) hostScope.addClosure(((WrappedIRClosure)block).getClosure()); } } } return clonedBB; }
@Override public Object interpret(ThreadContext context, StaticScope currScope, DynamicScope currDynScope, IRubyObject self, Object[] temp) { // SSS FIXME: Copied this from ast/LambdaNode ... Is this required here as well? // // JRUBY-5686: do this before executing so first time sets cref module ((WrappedIRClosure) getLambdaBody()).getClosure().getStaticScope().determineModule(); // CON: This must not be happening, because nil would never cast to Block // IRClosure body = getLambdaBody().getClosure(); // Block block = (Block) (body == null ? context.runtime.getIRManager().getNil() : getLambdaBody()).retrieve(context, self, currScope, currDynScope, temp); Block block = (Block)getLambdaBody().retrieve(context, self, currScope, currDynScope, temp); // ENEBO: Now can live nil be passed as block reference? // SSS FIXME: Should we do the same %self retrieval as in the case of WrappedIRClosure? Or are lambdas special?? return RubyProc.newProc(context.runtime, block, Block.Type.LAMBDA, getFile(), getLine()); }
public BasicBlock cloneForInlinedMethod(InlinerInfo ii) { IRScope hostScope = ii.getInlineHostScope(); BasicBlock clonedBB = ii.getOrCreateRenamedBB(this); for (Instr i: getInstrs()) { Instr clonedInstr = i.cloneForInlinedScope(ii); if (clonedInstr != null) { clonedBB.addInstr(clonedInstr); if (clonedInstr instanceof YieldInstr) ii.recordYieldSite(clonedBB, (YieldInstr)clonedInstr); if (clonedInstr instanceof CallBase) { CallBase call = (CallBase)clonedInstr; Operand block = call.getClosureArg(null); if (block instanceof WrappedIRClosure) hostScope.addClosure(((WrappedIRClosure)block).getClosure()); } } } return clonedBB; }
public BasicBlock cloneForInlinedMethod(InlinerInfo ii) { IRScope hostScope = ii.getInlineHostScope(); BasicBlock clonedBB = ii.getOrCreateRenamedBB(this); for (Instr i: getInstrs()) { Instr clonedInstr = i.cloneForInlinedScope(ii); if (clonedInstr != null) { clonedBB.addInstr(clonedInstr); if (clonedInstr instanceof YieldInstr) ii.recordYieldSite(clonedBB, (YieldInstr)clonedInstr); if (clonedInstr instanceof CallBase) { CallBase call = (CallBase)clonedInstr; Operand block = call.getClosureArg(null); if (block instanceof WrappedIRClosure) hostScope.addClosure(((WrappedIRClosure)block).getClosure()); } } } return clonedBB; }
@Override public void WrappedIRClosure(WrappedIRClosure wrappedirclosure) { IRClosure closure = wrappedirclosure.getClosure(); jvmMethod().loadContext(); visit(closure.getSelf()); jvmLoadLocal(DYNAMIC_SCOPE); jvmMethod().prepareBlock(closure.getHandle(), closure.getSignature(), jvm.clsData().clsName); }
@Override public void WrappedIRClosure(WrappedIRClosure wrappedirclosure) { IRClosure closure = wrappedirclosure.getClosure(); jvmMethod().loadContext(); visit(closure.getSelf()); jvmLoadLocal(DYNAMIC_SCOPE); jvmMethod().prepareBlock(closure.getHandle(), closure.getSignature(), jvm.clsData().clsName); }
private Operand receiveBreakException(Operand block, CodeBlock codeBlock) { // Check if we have to handle a break if (block == null || !(block instanceof WrappedIRClosure) || !(((WrappedIRClosure)block).getClosure()).flags.contains(IRFlags.HAS_BREAK_INSTRS)) { // No protection needed -- add the call and return return codeBlock.run(); } Label rBeginLabel = getNewLabel(); Label rEndLabel = getNewLabel(); Label rescueLabel = getNewLabel(); // Protected region addInstr(new LabelInstr(rBeginLabel)); addInstr(new ExceptionRegionStartMarkerInstr(rescueLabel)); Variable callResult = (Variable)codeBlock.run(); addInstr(new JumpInstr(rEndLabel)); addInstr(new ExceptionRegionEndMarkerInstr()); // Receive exceptions (could be anything, but the handler only processes IRBreakJumps) addInstr(new LabelInstr(rescueLabel)); Variable exc = createTemporaryVariable(); addInstr(new ReceiveJRubyExceptionInstr(exc)); // Handle break using runtime helper // --> IRRuntimeHelpers.handlePropagatedBreak(context, scope, bj, blockType) addInstr(new RuntimeHelperCall(callResult, HANDLE_PROPAGATED_BREAK, new Operand[]{exc} )); // End addInstr(new LabelInstr(rEndLabel)); return callResult; }
@Override public void BuildLambdaInstr(BuildLambdaInstr buildlambdainstr) { jvmMethod().loadRuntime(); IRClosure body = ((WrappedIRClosure)buildlambdainstr.getLambdaBody()).getClosure(); if (body == null) { jvmMethod().pushNil(); } else { visit(buildlambdainstr.getLambdaBody()); } jvmAdapter().getstatic(p(Block.Type.class), "LAMBDA", ci(Block.Type.class)); jvmAdapter().ldc(buildlambdainstr.getFile()); jvmAdapter().pushInt(buildlambdainstr.getLine()); jvmAdapter().invokestatic(p(RubyProc.class), "newProc", sig(RubyProc.class, Ruby.class, Block.class, Block.Type.class, String.class, int.class)); jvmStoreLocal(buildlambdainstr.getResult()); }
@Override public void BuildLambdaInstr(BuildLambdaInstr buildlambdainstr) { jvmMethod().loadRuntime(); IRClosure body = ((WrappedIRClosure)buildlambdainstr.getLambdaBody()).getClosure(); if (body == null) { jvmMethod().pushNil(); } else { visit(buildlambdainstr.getLambdaBody()); } jvmAdapter().getstatic(p(Block.Type.class), "LAMBDA", ci(Block.Type.class)); jvmAdapter().ldc(buildlambdainstr.getFile()); jvmAdapter().pushInt(buildlambdainstr.getLine()); jvmAdapter().invokestatic(p(RubyProc.class), "newProc", sig(RubyProc.class, Ruby.class, Block.class, Block.Type.class, String.class, int.class)); jvmStoreLocal(buildlambdainstr.getResult()); }
IRClosure closure = ((WrappedIRClosure) block).getClosure();