本文整理了Java中org.jruby.runtime.Block.getBinding()
方法的一些代码示例,展示了Block.getBinding()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Block.getBinding()
方法的具体详情如下:
包路径:org.jruby.runtime.Block
类名称:Block
方法名:getBinding
暂无
代码示例来源:origin: bazelbuild/bazel
@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();
}
代码示例来源:origin: bazelbuild/bazel
@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();
}
代码示例来源:origin: bazelbuild/bazel
@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();
}
代码示例来源:origin: bazelbuild/bazel
@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();
}
代码示例来源:origin: org.jruby/jruby-complete
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;
}
代码示例来源:origin: org.jruby/jruby-core
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;
}
代码示例来源:origin: org.jruby/jruby-complete
public Block cloneBlockForEval(IRubyObject self, EvalType evalType) {
Block block = cloneBlock();
block.getBinding().setSelf(self);
block.getBinding().getFrame().setSelf(self);
block.setEvalType(evalType);
return block;
}
代码示例来源:origin: org.jruby/jruby-complete
public Block deepCloneBlockForEval(IRubyObject self, EvalType evalType) {
Block block = cloneBlockAndBinding();
block.getBinding().setSelf(self);
block.getBinding().getFrame().setSelf(self);
block.setEvalType(evalType);
return block;
}
代码示例来源:origin: org.jruby/jruby-complete
@Override
protected IRubyObject yieldDirect(ThreadContext context, Block block, IRubyObject[] args, IRubyObject self) {
InterpreterContext ic = ensureInstrsReady(); // so we get debugging output
return Interpreter.INTERPRET_BLOCK(context, block, self, ic, args, block.getBinding().getMethod(), Block.NULL_BLOCK);
}
代码示例来源:origin: org.jruby/jruby-complete
private void yieldRefineBlock(ThreadContext context, RubyModule refinement, Block block) {
block.setEvalType(EvalType.MODULE_EVAL);
block.getBinding().setSelf(refinement);
block.yieldSpecific(context);
}
代码示例来源:origin: org.jruby/jruby-complete
@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);
}
代码示例来源:origin: org.jruby/jruby-core
private void yieldRefineBlock(ThreadContext context, RubyModule refinement, Block block) {
block.setEvalType(EvalType.MODULE_EVAL);
block.getBinding().setSelf(refinement);
block.yieldSpecific(context);
}
代码示例来源:origin: org.jruby/jruby-core
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);
}
代码示例来源:origin: org.jruby/jruby-complete
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);
}
代码示例来源:origin: org.jruby/jruby-core
@Override
protected IRubyObject yieldDirect(ThreadContext context, Block block, IRubyObject[] args, IRubyObject self) {
InterpreterContext ic = ensureInstrsReady(); // so we get debugging output
return Interpreter.INTERPRET_BLOCK(context, block, self, ic, args, block.getBinding().getMethod(), Block.NULL_BLOCK);
}
代码示例来源:origin: org.jruby/jruby-complete
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);
}
代码示例来源:origin: org.jruby/jruby-complete
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;
}
代码示例来源:origin: org.jruby/jruby-core
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;
}
代码示例来源:origin: org.jruby/jruby-complete
@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;
}
代码示例来源:origin: headius/jo
public IRubyObject call() throws Exception {
ThreadContext context = runtime.getCurrentContext();
try {
return body.call(context);
} catch (RaiseException re) {
RubyKernel.puts(context, body.getBinding().getSelf(), new IRubyObject[] {
RubyString.newString(runtime, "joroutine terminated with error: " + re.getMessage())});
RubyKernel.puts(context, body.getBinding().getSelf(), new IRubyObject[] {re.getException().backtrace()});
throw re;
}
}
内容来源于网络,如有侵权,请联系作者删除!