public final IRubyObject call(ThreadContext context, IRubyObject[] args, IRubyObject self, Block passedBlock) { assert args != null; Block newBlock; // bind to new self, if given if (self == null) { newBlock = block; } else { newBlock = block.cloneBlockAndFrame(); newBlock.getBinding().setSelf(self); } return newBlock.call(context, args, passedBlock); }
public final IRubyObject call(ThreadContext context, IRubyObject[] args, IRubyObject self, Block passedBlock) { assert args != null; Block newBlock; // bind to new self, if given if (self == null) { newBlock = block; } else { newBlock = block.cloneBlockAndFrame(); newBlock.getBinding().setSelf(self); } return newBlock.call(context, args, passedBlock); }
@JRubyMethod(name = {"module_exec", "class_exec"}, rest = true, reads = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE}, writes = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE}) public IRubyObject module_exec(ThreadContext context, IRubyObject[] args, Block block) { if (block.isGiven()) { return yieldUnder(context, this, args, block.cloneBlockAndFrame(), EvalType.MODULE_EVAL); } else { throw context.runtime.newLocalJumpErrorNoBlock(); } }
@JRubyMethod(name = {"module_exec", "class_exec"}, reads = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE}, writes = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE}) public IRubyObject module_exec(ThreadContext context, Block block) { if (block.isGiven()) { return yieldUnder(context, this, IRubyObject.NULL_ARRAY, block.cloneBlockAndFrame(), EvalType.MODULE_EVAL); } else { throw context.runtime.newLocalJumpErrorNoBlock(); } }
@JRubyMethod(name = {"module_exec", "class_exec"}, reads = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE}, writes = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE}) public IRubyObject module_exec(ThreadContext context, Block block) { if (block.isGiven()) { return yieldUnder(context, this, IRubyObject.NULL_ARRAY, block.cloneBlockAndFrame(), EvalType.MODULE_EVAL); } else { throw context.runtime.newLocalJumpErrorNoBlock(); } }
@JRubyMethod(name = {"module_exec", "class_exec"}, rest = true, reads = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE}, writes = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE}) public IRubyObject module_exec(ThreadContext context, IRubyObject[] args, Block block) { if (block.isGiven()) { return yieldUnder(context, this, args, block.cloneBlockAndFrame(), EvalType.MODULE_EVAL); } else { throw context.runtime.newLocalJumpErrorNoBlock(); } }
public IRubyObject call(ThreadContext context, IRubyObject[] args, IRubyObject self, Block passedBlock) { assert args != null; Block newBlock; // bind to new self, if given if (self == null) { newBlock = block; } else { newBlock = block.cloneBlockAndFrame(); newBlock.getBinding().setSelf(self); } int jumpTarget = newBlock.getBinding().getFrame().getJumpTarget(); try { return newBlock.call(context, args, passedBlock); } catch (NullPointerException npe) { npe.printStackTrace(); throw npe; } catch (JumpException.BreakJump bj) { return handleBreakJump(getRuntime(), newBlock, bj, jumpTarget); } catch (JumpException.ReturnJump rj) { return handleReturnJump(context, rj, jumpTarget); } catch (JumpException.RetryJump rj) { return handleRetryJump(getRuntime(), rj); } }
private DynamicMethod createProcMethod(Ruby runtime, String name, Visibility visibility, Block block) { block = block.cloneBlockAndFrame(); block.getBinding().getFrame().setKlazz(this); block.getBinding().getFrame().setName(name); block.getBinding().setMethod(name); // a normal block passed to define_method changes to do arity checking; make it a lambda RubyProc proc = runtime.newProc(Block.Type.LAMBDA, block); // various instructions can tell this scope is not an ordinary block but a block representing // a method definition. block.getBody().getStaticScope().makeArgumentScope(); return new ProcMethod(this, proc, visibility, name); }
@JRubyMethod(name = "define_method", visibility = PRIVATE, reads = VISIBILITY) public IRubyObject define_method(ThreadContext context, IRubyObject arg0, Block block) { Ruby runtime = context.runtime; String name = TypeConverter.convertToIdentifier(arg0); DynamicMethod newMethod = null; Visibility visibility = PUBLIC; // We need our identifier to be retrievable and creatable as a symbol. This side-effect // populates this name into our symbol table so it will exist later if needed. The // reason for this hack/side-effect is that symbols store their values as raw bytes. We lose encoding // info so we need to make an entry so any accesses with raw bytes later gets proper symbol. RubySymbol.newSymbol(runtime, arg0); if (!block.isGiven()) { throw getRuntime().newArgumentError("tried to create Proc object without a block"); } block = block.cloneBlockAndFrame(); RubyProc proc = runtime.newProc(Block.Type.LAMBDA, block); // a normal block passed to define_method changes to do arity checking; make it a lambda proc.getBlock().type = Block.Type.LAMBDA; newMethod = createProcMethod(name, visibility, proc); Helpers.addInstanceMethod(this, name, newMethod, visibility, context, runtime); return proc; }
private DynamicMethod createProcMethod(Ruby runtime, String name, Visibility visibility, Block block) { block = block.cloneBlockAndFrame(); block.getBinding().getFrame().setKlazz(this); block.getBinding().getFrame().setName(name); block.getBinding().setMethod(name); // a normal block passed to define_method changes to do arity checking; make it a lambda RubyProc proc = runtime.newProc(Block.Type.LAMBDA, block); // various instructions can tell this scope is not an ordinary block but a block representing // a method definition. block.getBody().getStaticScope().makeArgumentScope(); return new ProcMethod(this, proc, visibility, name); }
@JRubyMethod(name = "define_method", visibility = PRIVATE, reads = VISIBILITY) public IRubyObject define_method(ThreadContext context, IRubyObject arg0, Block block) { Ruby runtime = context.runtime; String name = TypeConverter.convertToIdentifier(arg0); DynamicMethod newMethod = null; Visibility visibility = PUBLIC; // We need our identifier to be retrievable and creatable as a symbol. This side-effect // populates this name into our symbol table so it will exist later if needed. The // reason for this hack/side-effect is that symbols store their values as raw bytes. We lose encoding // info so we need to make an entry so any accesses with raw bytes later gets proper symbol. RubySymbol.newSymbol(runtime, arg0); if (!block.isGiven()) { throw getRuntime().newArgumentError("tried to create Proc object without a block"); } block = block.cloneBlockAndFrame(); RubyProc proc = runtime.newProc(Block.Type.LAMBDA, block); // a normal block passed to define_method changes to do arity checking; make it a lambda proc.getBlock().type = Block.Type.LAMBDA; newMethod = createProcMethod(name, visibility, proc); Helpers.addInstanceMethod(this, name, newMethod, visibility, context, runtime); return proc; }
public IRubyObject call(ThreadContext context, IRubyObject[] args, IRubyObject self, Block passedBlock) { assert args != null; Block newBlock; // bind to new self, if given if (self == null) { newBlock = block; } else { newBlock = block.cloneBlockAndFrame(); newBlock.getBinding().setSelf(self); } int jumpTarget = newBlock.getBinding().getFrame().getJumpTarget(); try { return newBlock.call(context, args, passedBlock); } catch (JumpException.BreakJump bj) { return handleBreakJump(getRuntime(), newBlock, bj, jumpTarget); } catch (JumpException.ReturnJump rj) { return handleReturnJump(context, rj, jumpTarget); } catch (JumpException.RetryJump rj) { return handleRetryJump(getRuntime(), rj); } }