@JRubyMethod(module = true, name = "compile_ir", required = 1, optional = 3) public static IRubyObject compile_ir(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) { // def compile_ir(content = nil, filename = DEFAULT_FILENAME, extra_position_info = false, &block) return Java.wrapJavaObject(context.runtime, compileIR(context, args, block)); }
@JRubyMethod(name = "security_restricted=", module = true) public static IRubyObject set_security_restricted(IRubyObject recv, IRubyObject arg) { Ruby.setSecurityRestricted(arg.isTrue()); return is_security_restricted(recv); }
@JRubyMethod(module = true, name = "parse", alias = "ast_for", required = 1, optional = 3) public static IRubyObject parse(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) { // def parse(content = nil, filename = DEFAULT_FILENAME, extra_position_info = false, lineno = 0, &block) return Java.wrapJavaObject(context.runtime, parseImpl(context, args, block)); }
@JRubyMethod(module = true) public static IRubyObject subclasses(ThreadContext context, IRubyObject recv, IRubyObject arg) { return subclasses(context, recv, arg instanceof RubyClass ? (RubyClass) arg : arg.getMetaClass(), false); }
/** * Run the provided (required) block with the "global runtime" set to the current runtime, * for libraries that expect to operate against the global runtime. */ @JRubyMethod(module = true) public static IRubyObject with_current_runtime_as_global(ThreadContext context, IRubyObject recv, Block block) { final Ruby current = context.runtime; final Ruby global = Ruby.getGlobalRuntime(); try { if (current != global) { current.useAsGlobalRuntime(); } return block.yield(context, runtime(context, recv)); // previously yield (without an argument) } finally { if (Ruby.getGlobalRuntime() != global) { global.useAsGlobalRuntime(); } } }
@JRubyMethod(module = true) public static IRubyObject subclasses(ThreadContext context, IRubyObject recv, IRubyObject arg) { return subclasses(context, recv, arg instanceof RubyClass ? (RubyClass) arg : arg.getMetaClass(), false); }
/** * Run the provided (required) block with the "global runtime" set to the current runtime, * for libraries that expect to operate against the global runtime. */ @JRubyMethod(module = true) public static IRubyObject with_current_runtime_as_global(ThreadContext context, IRubyObject recv, Block block) { final Ruby current = context.runtime; final Ruby global = Ruby.getGlobalRuntime(); try { if (current != global) { current.useAsGlobalRuntime(); } return block.yield(context, runtime(context, recv)); // previously yield (without an argument) } finally { if (Ruby.getGlobalRuntime() != global) { global.useAsGlobalRuntime(); } } }
@JRubyMethod(module = true, name = "parse", alias = "ast_for", required = 1, optional = 3) public static IRubyObject parse(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) { // def parse(content = nil, filename = DEFAULT_FILENAME, extra_position_info = false, lineno = 0, &block) return Java.wrapJavaObject(context.runtime, parseImpl(context, args, block)); }
@JRubyMethod(module = true, name = "compile_ir", required = 1, optional = 3) public static IRubyObject compile_ir(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) { // def compile_ir(content = nil, filename = DEFAULT_FILENAME, extra_position_info = false, &block) return Java.wrapJavaObject(context.runtime, compileIR(context, args, block)); }
@JRubyMethod(module = true) public static IRubyObject subclasses(ThreadContext context, IRubyObject recv, IRubyObject arg, IRubyObject opts) { boolean recurseAll = false; opts = ArgsUtil.getOptionsArg(context.runtime, opts); if (opts != context.nil) { IRubyObject all = ((RubyHash) opts).fastARef(context.runtime.newSymbol("all")); if (all != null) recurseAll = all.isTrue(); } return subclasses(context, recv, arg instanceof RubyClass ? (RubyClass) arg : arg.getMetaClass(), recurseAll); }
@JRubyMethod(name = "security_restricted=", module = true) public static IRubyObject set_security_restricted(IRubyObject recv, IRubyObject arg) { Ruby.setSecurityRestricted(arg.isTrue()); return is_security_restricted(recv); }
private static IRScriptBody compileIR(ThreadContext context, IRubyObject[] args, Block block) { RootNode node = (RootNode) parseImpl(context, args, block); IRManager manager = new IRManager(context.runtime, context.runtime.getInstanceConfig()); manager.setDryRun(true); IRScriptBody scope = (IRScriptBody) IRBuilder.buildRoot(manager, node).getScope(); scope.setScriptDynamicScope(node.getScope()); return scope; }
@JRubyMethod(module = true, name = "compile", required = 1, optional = 3) public static IRubyObject compile(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) { // def compile(content = nil, filename = DEFAULT_FILENAME, extra_position_info = false, &block) final Ruby runtime = context.runtime; final RubyString content = args[0].convertToString(); args[0] = content; final RubyString filename = args.length > 1 ? args[1].convertToString() : RubyString.newEmptyString(runtime); IRScriptBody scope = compileIR(context, args, block); JVMVisitor visitor = new JVMVisitor(runtime); JVMVisitorMethodContext methodContext = new JVMVisitorMethodContext(); byte[] bytes = visitor.compileToBytecode(scope, methodContext); scope.getStaticScope().setModule( runtime.getTopSelf().getMetaClass() ); RubyClass CompiledScript = (RubyClass) runtime.getModule("JRuby").getConstantAt("CompiledScript"); // JRuby::CompiledScript#initialize(filename, class_name, content, bytes) return CompiledScript.newInstance(context, new IRubyObject[] { filename, scope.getName(), content, Java.getInstance(runtime, bytes) }, Block.NULL_BLOCK); }
@JRubyMethod(module = true) public static IRubyObject subclasses(ThreadContext context, IRubyObject recv, IRubyObject arg, IRubyObject opts) { boolean recurseAll = false; opts = ArgsUtil.getOptionsArg(context.runtime, opts); if (opts != context.nil) { IRubyObject all = ((RubyHash) opts).fastARef(context.runtime.newSymbol("all")); if (all != null) recurseAll = all.isTrue(); } return subclasses(context, recv, arg instanceof RubyClass ? (RubyClass) arg : arg.getMetaClass(), recurseAll); }
private static IRScriptBody compileIR(ThreadContext context, IRubyObject[] args, Block block) { RootNode node = (RootNode) parseImpl(context, args, block); IRManager manager = new IRManager(context.runtime, context.runtime.getInstanceConfig()); manager.setDryRun(true); IRScriptBody scope = (IRScriptBody) IRBuilder.buildRoot(manager, node).getScope(); scope.setScriptDynamicScope(node.getScope()); return scope; }
@JRubyMethod(module = true, name = "compile", required = 1, optional = 3) public static IRubyObject compile(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) { // def compile(content = nil, filename = DEFAULT_FILENAME, extra_position_info = false, &block) final Ruby runtime = context.runtime; final RubyString content = args[0].convertToString(); args[0] = content; final RubyString filename = args.length > 1 ? args[1].convertToString() : RubyString.newEmptyString(runtime); IRScriptBody scope = compileIR(context, args, block); JVMVisitor visitor = new JVMVisitor(runtime); JVMVisitorMethodContext methodContext = new JVMVisitorMethodContext(); byte[] bytes = visitor.compileToBytecode(scope, methodContext); scope.getStaticScope().setModule( runtime.getTopSelf().getMetaClass() ); RubyClass CompiledScript = (RubyClass) runtime.getModule("JRuby").getConstantAt("CompiledScript"); // JRuby::CompiledScript#initialize(filename, class_name, content, bytes) return CompiledScript.newInstance(context, new IRubyObject[] { filename, scope.getName(), content, Java.getInstance(runtime, bytes) }, Block.NULL_BLOCK); }