@JRubyMethod(meta = true) public static IRubyObject list(ThreadContext context, IRubyObject recv) { Ruby runtime = recv.getRuntime(); RubyHash names; synchronized (recv) { names = (RubyHash) recv.getInternalVariables().getInternalVariable("signal_list"); if (names == null) { names = RubyHash.newHash(runtime); for (Map.Entry<String, Integer> sig : RubySignal.list().entrySet()) { names.op_aset(context, runtime.freezeAndDedupString(runtime.newString(sig.getKey())), runtime.newFixnum(sig.getValue())); } names.op_aset(context, runtime.freezeAndDedupString(runtime.newString("EXIT")), runtime.newFixnum(0)); recv.getInternalVariables().setInternalVariable("signal_list", names); } else { names.dup(context); } } return names; }
private static RubyString str(final ThreadContext context, final IRubyObject self) { final IRubyObject str = (IRubyObject) self.getInternalVariables().getInternalVariable("str"); return /* str == null ? string(context, self) : */ str.convertToString(); }
@JRubyMethod(compat = CompatVersion.RUBY1_9) public static IRubyObject chunk(ThreadContext context, IRubyObject self, final IRubyObject initialState, final Block block) { if(!block.isGiven()) { throw context.runtime.newArgumentError("no block given"); } IRubyObject enumerator = context.runtime.getEnumerator().allocate(); enumerator.getInternalVariables().setInternalVariable("chunk_enumerable", self); enumerator.getInternalVariables().setInternalVariable("chunk_categorize", RubyProc.newProc(context.runtime, block, block.type)); enumerator.getInternalVariables().setInternalVariable("chunk_initial_state", initialState); Helpers.invoke(context, enumerator, "initialize", CallBlock.newCallClosure(self, context.runtime.getEnumerable(), Arity.ONE_ARGUMENT, new ChunkedBlockCallback(context.runtime, enumerator), context)); return enumerator; }
private static RubyString str(final ThreadContext context, final IRubyObject self) { final IRubyObject str = (IRubyObject) self.getInternalVariables().getInternalVariable("str"); return /* str == null ? string(context, self) : */ str.convertToString(); }
private void raiseAnonymous() { // TODO: MRI calls Timeout::Error.catch here with the body of the timeout; we use __identifier__. IRubyObject anonException = getDefaultException(timeout).newInstance(timeout.getRuntime().getCurrentContext(), message, Block.NULL_BLOCK); anonException.getInternalVariables().setInternalVariable("__identifier__", id); currentThread.raise(anonException); }
@JRubyMethod(meta = true) public static IRubyObject list(ThreadContext context, IRubyObject recv) { Ruby runtime = recv.getRuntime(); RubyHash names; synchronized (recv) { names = (RubyHash) recv.getInternalVariables().getInternalVariable("signal_list"); if (names == null) { names = RubyHash.newHash(runtime); for (Map.Entry<String, Integer> sig : RubySignal.list().entrySet()) { names.op_aset(context, runtime.freezeAndDedupString(runtime.newString(sig.getKey())), runtime.newFixnum(sig.getValue())); } names.op_aset(context, runtime.freezeAndDedupString(runtime.newString("EXIT")), runtime.newFixnum(0)); recv.getInternalVariables().setInternalVariable("signal_list", names); } else { names.dup(context); } } return names; }
@JRubyMethod(visibility = PRIVATE) public static IRubyObject private_iv_get(ThreadContext context, IRubyObject self, IRubyObject target, IRubyObject prop) { IRubyObject obj = (IRubyObject)target.getInternalVariables().getInternalVariable(prop.asJavaString()); if (obj == null) obj = context.nil; return obj; } }
@JRubyMethod(compat = CompatVersion.RUBY1_9) public static IRubyObject chunk(ThreadContext context, IRubyObject self, final IRubyObject initialState, final Block block) { if(!block.isGiven()) { throw context.runtime.newArgumentError("no block given"); } IRubyObject enumerator = context.runtime.getEnumerator().allocate(); enumerator.getInternalVariables().setInternalVariable("chunk_enumerable", self); enumerator.getInternalVariables().setInternalVariable("chunk_categorize", RubyProc.newProc(context.runtime, block, block.type)); enumerator.getInternalVariables().setInternalVariable("chunk_initial_state", initialState); Helpers.invoke(context, enumerator, "initialize", CallBlock.newCallClosure(self, context.runtime.getEnumerable(), Arity.ONE_ARGUMENT, new ChunkedBlockCallback(context.runtime, enumerator), context)); return enumerator; }
Boolean blocking = (Boolean)recv.getInternalVariables().getInternalVariable("group_blocking"); if (blocking != null && blocking) { throw runtime.newRuntimeError("parallel group iteration"); recv.getInternalVariables().setInternalVariable("group_blocking", true); recv.getInternalVariables().setInternalVariable("group_blocking", false);
@JRubyMethod(visibility = PRIVATE) public static IRubyObject private_iv_get(ThreadContext context, IRubyObject self, IRubyObject target, IRubyObject prop) { IRubyObject obj = (IRubyObject)target.getInternalVariables().getInternalVariable(prop.asJavaString()); if (obj == null) obj = context.nil; return obj; } }
private void raiseAnonymous() { // TODO: MRI calls Timeout::Error.catch here with the body of the timeout; we use __identifier__. IRubyObject anonException = getDefaultException(timeout).newInstance(timeout.getRuntime().getCurrentContext(), message, Block.NULL_BLOCK); anonException.getInternalVariables().setInternalVariable("__identifier__", id); currentThread.raise(anonException); }
Boolean blocking = (Boolean)recv.getInternalVariables().getInternalVariable("group_blocking"); if (blocking != null && blocking) { throw runtime.newRuntimeError("parallel group iteration"); recv.getInternalVariables().setInternalVariable("group_blocking", true); recv.getInternalVariables().setInternalVariable("group_blocking", false);
public IRubyObject call(ThreadContext context, IRubyObject[] args, Block block) { InternalVariables variables = enumerator.getInternalVariables(); final IRubyObject enumerable = (IRubyObject) variables.getInternalVariable("chunk_enumerable"); final RubyProc categorize = (RubyProc) variables.getInternalVariable("chunk_categorize"); final IRubyObject yielder = packEnumValues(context, args); final ChunkArg arg = new ChunkArg(context);
public void run() { if (latch.compareAndSet(false, true)) { if (currentThread.alive_p().isTrue()) { RubyClass anonException = (RubyClass)runtime.getClassFromPath("Timeout::AnonymousException"); IRubyObject anonExceptionObj = anonException.newInstance(runtime.getCurrentContext(), runtime.newString("execution expired"), Block.NULL_BLOCK); anonExceptionObj.getInternalVariables().setInternalVariable("__identifier__", id); currentThread.internalRaise(new IRubyObject[] {anonExceptionObj}); } } } };
Boolean blocking = (Boolean)recv.getInternalVariables().getInternalVariable("group_blocking"); if (blocking != null && blocking) { throw runtime.newRuntimeError("parallel group iteration"); recv.getInternalVariables().setInternalVariable("group_blocking", true); recv.getInternalVariables().setInternalVariable("group_blocking", false);
public IRubyObject call(ThreadContext context, IRubyObject[] args, Block block) { InternalVariables variables = enumerator.getInternalVariables(); final IRubyObject enumerable = (IRubyObject) variables.getInternalVariable("chunk_enumerable"); final RubyProc categorize = (RubyProc) variables.getInternalVariable("chunk_categorize"); final IRubyObject yielder = packEnumValues(context, args); final ChunkArg arg = new ChunkArg(context);
public void run() { if (latch.compareAndSet(false, true)) { if (currentThread.alive_p().isTrue()) { RubyClass anonException = (RubyClass)runtime.getClassFromPath("Timeout::AnonymousException"); IRubyObject anonExceptionObj = anonException.newInstance(runtime.getCurrentContext(), runtime.newString("execution expired"), Block.NULL_BLOCK); anonExceptionObj.getInternalVariables().setInternalVariable("__identifier__", id); currentThread.internalRaise(new IRubyObject[] {anonExceptionObj}); } } } };
Boolean blocking = (Boolean)recv.getInternalVariables().getInternalVariable("group_blocking"); if (blocking != null && blocking) { throw runtime.newRuntimeError("parallel group iteration"); recv.getInternalVariables().setInternalVariable("group_blocking", true); recv.getInternalVariables().setInternalVariable("group_blocking", false);
@JRubyMethod(visibility = Visibility.PRIVATE) public static IRubyObject initialize(ThreadContext context, IRubyObject self, IRubyObject javaClassName, Block block) { Ruby runtime = context.runtime; self.getInstanceVariables().setInstanceVariable("@java_class", JavaClass.forNameVerbose(runtime, javaClassName.asJavaString())); self.getInstanceVariables().setInstanceVariable("@block", RubyProc.newProc(runtime, block, block.type)); self.getInternalVariables().getInternalVariable("@block"); return context.nil; }
@JRubyMethod public static IRubyObject chunk(ThreadContext context, IRubyObject self, final Block block) { final Ruby runtime = context.runtime; if(!block.isGiven()) { return enumeratorizeWithSize(context, self, "chunk", enumSizeFn(context, self)); } IRubyObject enumerator = context.runtime.getEnumerator().allocate(); enumerator.getInternalVariables().setInternalVariable("chunk_enumerable", self); enumerator.getInternalVariables().setInternalVariable("chunk_categorize", RubyProc.newProc(context.runtime, block, block.type)); Helpers.invoke(context, enumerator, "initialize", CallBlock.newCallClosure(self, context.runtime.getEnumerable(), Signature.ONE_ARGUMENT, new ChunkedBlockCallback(context.runtime, enumerator), context)); return enumerator; }