@JRubyMethod public IRubyObject oneof(ThreadContext context, IRubyObject name, Block block) { RubyOneofDescriptor oneofdef = (RubyOneofDescriptor) cOneofDescriptor.newInstance(context, Block.NULL_BLOCK); RubyOneofBuilderContext ctx = (RubyOneofBuilderContext) cOneofBuilderContext.newInstance(context, oneofdef, Block.NULL_BLOCK); oneofdef.setName(context, name); Binding binding = block.getBinding(); binding.setSelf(ctx); block.yieldSpecific(context); descriptor.addOneof(context, oneofdef); return context.runtime.getNil(); }
@JRubyMethod public IRubyObject build(ThreadContext context, Block block) { RubyBuilder ctx = (RubyBuilder) cBuilder.newInstance(context, Block.NULL_BLOCK); if (block.arity() == Arity.ONE_ARGUMENT) { block.yield(context, ctx); } else { Binding binding = block.getBinding(); binding.setSelf(ctx); block.yieldSpecific(context); } ctx.finalizeToPool(context, this); buildFileDescriptor(context); return context.runtime.getNil(); }
@JRubyMethod(name = "add_enum") public IRubyObject addEnum(ThreadContext context, IRubyObject name, Block block) { RubyEnumDescriptor enumDef = (RubyEnumDescriptor) cEnumDescriptor.newInstance(context, Block.NULL_BLOCK); IRubyObject ctx = cEnumBuilderContext.newInstance(context, enumDef, Block.NULL_BLOCK); enumDef.setName(context, name); if (block.isGiven()) { if (block.arity() == Arity.ONE_ARGUMENT) { block.yield(context, ctx); } else { Binding binding = block.getBinding(); binding.setSelf(ctx); block.yieldSpecific(context); } } this.pendingList.add(enumDef); return context.runtime.getNil(); }
@JRubyMethod(name = "add_message") public IRubyObject addMessage(ThreadContext context, IRubyObject name, Block block) { RubyDescriptor msgdef = (RubyDescriptor) cDescriptor.newInstance(context, Block.NULL_BLOCK); IRubyObject ctx = cMessageBuilderContext.newInstance(context, msgdef, this, Block.NULL_BLOCK); msgdef.setName(context, name); if (block.isGiven()) { if (block.arity() == Arity.ONE_ARGUMENT) { block.yield(context, ctx); } else { Binding binding = block.getBinding(); binding.setSelf(ctx); block.yieldSpecific(context); } } this.pendingList.add(msgdef); return context.runtime.getNil(); }
private void yieldRefineBlock(ThreadContext context, RubyModule refinement, Block block) { block.setEvalType(EvalType.MODULE_EVAL); block.getBinding().setSelf(refinement); block.yieldSpecific(context); }
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); }
private void yieldRefineBlock(ThreadContext context, RubyModule refinement, Block block) { block.setEvalType(EvalType.MODULE_EVAL); block.getBinding().setSelf(refinement); block.yieldSpecific(context); }
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); }
private Block setupBlock(Block block) { // FIXME: This is an ugly hack to resolve JRUBY-1381; I'm not proud of it block = block.cloneBlock(); block.getBinding().setSelf(this); block.getBinding().getFrame().setSelf(this); return block; }
private Block setupBlock(Block block) { // FIXME: This is an ugly hack to resolve JRUBY-1381; I'm not proud of it block = block.cloneBlock(); block.getBinding().setSelf(this); block.getBinding().getFrame().setSelf(this); return block; }
public Block cloneBlockForEval(IRubyObject self, EvalType evalType) { Block block = cloneBlock(); block.getBinding().setSelf(self); block.getBinding().getFrame().setSelf(self); block.setEvalType(evalType); return block; }
public Block deepCloneBlockForEval(IRubyObject self, EvalType evalType) { Block block = cloneBlockAndBinding(); block.getBinding().setSelf(self); block.getBinding().getFrame().setSelf(self); block.setEvalType(evalType); return block; }
public Block cloneBlockForEval(IRubyObject self, EvalType evalType) { Block block = cloneBlock(); block.getBinding().setSelf(self); block.getBinding().getFrame().setSelf(self); block.setEvalType(evalType); return block; }
public Block deepCloneBlockForEval(IRubyObject self, EvalType evalType) { Block block = cloneBlockAndBinding(); block.getBinding().setSelf(self); block.getBinding().getFrame().setSelf(self); block.setEvalType(evalType); return block; }
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); } }
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); } }
/** * Will yield to the specific block changing the self to be the * current object instead of the self that is part of the frame * saved in the block frame. This method is the basis for the Ruby * instance_eval and module_eval methods. The arguments sent in to * it in the args array will be yielded to the block. This makes * it possible to emulate both instance_eval and instance_exec * with this implementation. */ protected IRubyObject yieldUnder(final ThreadContext context, RubyModule under, IRubyObject[] args, Block block, EvalType evalType) { context.preExecuteUnder(this, under, block); IRubyObject savedBindingSelf = block.getBinding().getSelf(); IRubyObject savedFrameSelf = block.getBinding().getFrame().getSelf(); Visibility savedVisibility = block.getBinding().getVisibility(); block.getBinding().setVisibility(PUBLIC); try { if (args.length == 1) { IRubyObject valueInYield = args[0]; return setupBlock(block, evalType).yieldNonArray(context, valueInYield, this); // context.getRubyClass()); } else { IRubyObject valueInYield = RubyArray.newArrayMayCopy(context.runtime, args); return setupBlock(block, evalType).yieldArray(context, valueInYield, this); // context.getRubyClass()); } } finally { block.getBinding().setVisibility(savedVisibility); block.getBinding().setSelf(savedBindingSelf); block.getBinding().getFrame().setSelf(savedFrameSelf); context.postExecuteUnder(); } }
/** * Will yield to the specific block changing the self to be the * current object instead of the self that is part of the frame * saved in the block frame. This method is the basis for the Ruby * instance_eval and module_eval methods. The arguments sent in to * it in the args array will be yielded to the block. This makes * it possible to emulate both instance_eval and instance_exec * with this implementation. */ protected IRubyObject yieldUnder(final ThreadContext context, RubyModule under, IRubyObject[] args, Block block, EvalType evalType) { context.preExecuteUnder(this, under, block); IRubyObject savedBindingSelf = block.getBinding().getSelf(); IRubyObject savedFrameSelf = block.getBinding().getFrame().getSelf(); Visibility savedVisibility = block.getBinding().getVisibility(); block.getBinding().setVisibility(PUBLIC); try { if (args.length == 1) { IRubyObject valueInYield = args[0]; return setupBlock(block, evalType).yieldNonArray(context, valueInYield, this); // context.getRubyClass()); } else { IRubyObject valueInYield = RubyArray.newArrayMayCopy(context.runtime, args); return setupBlock(block, evalType).yieldArray(context, valueInYield, this); // context.getRubyClass()); } } finally { block.getBinding().setVisibility(savedVisibility); block.getBinding().setSelf(savedBindingSelf); block.getBinding().getFrame().setSelf(savedFrameSelf); context.postExecuteUnder(); } }