@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 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 each(ThreadContext context, Block block) { for (Map.Entry<String, RubyFieldDescriptor> entry : fieldDefMap.entrySet()) { block.yield(context, entry.getValue()); } return context.runtime.getNil(); }
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"}, 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(); } }
@Override public IRubyObject size(IRubyObject[] args) { return block.call(context, args); } };
@JRubyMethod public IRubyObject each_char(final ThreadContext context, final Block block) { if (!block.isGiven()) return enumeratorize(context.runtime, this, "each_char"); IRubyObject c; while (!(c = getc(context)).isNil()) { block.yieldSpecific(context, c); } return this; }
/** rb_ary_cycle * */ @JRubyMethod(name = "cycle") public IRubyObject cycle(ThreadContext context, Block block) { if (!block.isGiven()) return enumeratorizeWithSize(context, this, "cycle", cycleSizeFn(context)); return cycleCommon(context, -1, block); }
private void yieldRefineBlock(ThreadContext context, RubyModule refinement, Block block) { block.setEvalType(EvalType.MODULE_EVAL); block.getBinding().setSelf(refinement); block.yieldSpecific(context); }
private Block setupBlock(Block block, EvalType evalType) { if (block.getProcObject() == null) { // FIXME: This is an ugly hack to resolve JRUBY-1381; I'm not proud of it block = block.cloneBlockForEval(this, evalType); } else { block = block.deepCloneBlockForEval(this, evalType); } block.getBinding().setVisibility(PUBLIC); return block; }
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 public IRubyObject each(ThreadContext context, Block block) { for (IRubyObject key : table.keySet()) { block.yieldSpecific(context, key, table.get(key)); } return context.runtime.getNil(); }
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 cloneBlock() { Block newBlock = new Block(body, binding); newBlock.type = type; newBlock.escapeBlock = this; return newBlock; }
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 deepCloneBlockForEval(IRubyObject self, EvalType evalType) { Block block = cloneBlockAndBinding(); block.getBinding().setSelf(self); block.getBinding().getFrame().setSelf(self); block.setEvalType(evalType); return block; }
@Interp @JIT public static IRubyObject updateBlockState(Block block, IRubyObject self) { // SSS FIXME: Why is self null in non-binding-eval contexts? if (self == null || block.getEvalType() == EvalType.BINDING_EVAL) { // Update self to the binding's self self = useBindingSelf(block.getBinding()); } // Clear block's eval type block.setEvalType(EvalType.NONE); // Return self in case it has been updated return self; }
@Override protected IRubyObject callDirect(ThreadContext context, Block block, IRubyObject[] args, Block blockArg) { InterpreterContext ic = ensureInstrsReady(); // so we get debugging output return Interpreter.INTERPRET_BLOCK(context, block, null, ic, args, block.getBinding().getMethod(), blockArg); }
private static DynamicScope getNewBlockScope(Block block, boolean pushNewDynScope, boolean reuseParentDynScope) { DynamicScope newScope = block.getBinding().getDynamicScope(); if (pushNewDynScope) return block.allocScope(newScope); // Reuse! We can avoid the push only if surrounding vars aren't referenced! if (reuseParentDynScope) return newScope; // No change return null; }