@Deprecated public static RubySymbol addInstanceMethod(RubyModule containingClass, String name, DynamicMethod method, Visibility visibility, ThreadContext context, Ruby runtime) { return addInstanceMethod(containingClass, runtime.fastNewSymbol(name), method, visibility, context, runtime); }
@Deprecated public static RubySymbol addInstanceMethod(RubyModule containingClass, String name, DynamicMethod method, Visibility visibility, ThreadContext context, Ruby runtime) { return addInstanceMethod(containingClass, runtime.fastNewSymbol(name), method, visibility, context, runtime); }
public static IRubyObject def(ThreadContext context, IRubyObject self, Object scriptObject, String rubyName, String javaName, StaticScope scope, int arity, String filename, int line, CallConfiguration callConfig, String parameterDesc) { Class compiledClass = scriptObject.getClass(); Ruby runtime = context.runtime; RubyModule containingClass = context.getRubyClass(); Visibility visibility = context.getCurrentVisibility(); performNormalMethodChecks(containingClass, runtime, rubyName); MethodFactory factory = MethodFactory.createFactory(compiledClass.getClassLoader()); DynamicMethod method = constructNormalMethod( factory, javaName, rubyName, containingClass, new SimpleSourcePosition(filename, line), arity, scope, visibility, scriptObject, callConfig, parameterDesc); addInstanceMethod(containingClass, rubyName, method, visibility,context, runtime); return runtime.getNil(); }
public static IRubyObject def(ThreadContext context, IRubyObject self, Object scriptObject, String rubyName, String javaName, StaticScope scope, int arity, String filename, int line, CallConfiguration callConfig, String parameterDesc) { Class compiledClass = scriptObject.getClass(); Ruby runtime = context.runtime; RubyModule containingClass = context.getRubyClass(); Visibility visibility = context.getCurrentVisibility(); performNormalMethodChecks(containingClass, runtime, rubyName); MethodFactory factory = MethodFactory.createFactory(compiledClass.getClassLoader()); DynamicMethod method = constructNormalMethod( factory, javaName, rubyName, containingClass, new SimpleSourcePosition(filename, line), arity, scope, visibility, scriptObject, callConfig, parameterDesc); addInstanceMethod(containingClass, rubyName, method, visibility,context, runtime); return runtime.getNil(); }
@JIT public static void defCompiledInstanceMethod(ThreadContext context, MethodHandle handle, IRScope method, DynamicScope currDynScope, IRubyObject self) { Ruby runtime = context.runtime; RubySymbol methodName = method.getName(); RubyModule clazz = findInstanceMethodContainer(context, currDynScope, self); Visibility currVisibility = context.getCurrentVisibility(); Visibility newVisibility = Helpers.performNormalMethodChecksAndDetermineVisibility(runtime, clazz, methodName, currVisibility); DynamicMethod newMethod = new CompiledIRMethod(handle, method, newVisibility, clazz); // FIXME: needs checkID and proper encoding to force hard symbol Helpers.addInstanceMethod(clazz, methodName, newMethod, currVisibility, context, runtime); }
@JIT public static void defCompiledInstanceMethod(ThreadContext context, MethodHandle variable, MethodHandle specific, int specificArity, IRScope method, DynamicScope currDynScope, IRubyObject self) { Ruby runtime = context.runtime; RubySymbol methodName = method.getName(); RubyModule clazz = findInstanceMethodContainer(context, currDynScope, self); Visibility currVisibility = context.getCurrentVisibility(); Visibility newVisibility = Helpers.performNormalMethodChecksAndDetermineVisibility(runtime, clazz, methodName, currVisibility); DynamicMethod newMethod = new CompiledIRMethod(variable, specific, specificArity, method, newVisibility, clazz); // FIXME: needs checkID and proper encoding to force hard symbol Helpers.addInstanceMethod(clazz, methodName, newMethod, currVisibility, context, runtime); }
@JIT public static void defCompiledInstanceMethod(ThreadContext context, MethodHandle handle, IRScope method, DynamicScope currDynScope, IRubyObject self) { Ruby runtime = context.runtime; RubySymbol methodName = method.getName(); RubyModule clazz = findInstanceMethodContainer(context, currDynScope, self); Visibility currVisibility = context.getCurrentVisibility(); Visibility newVisibility = Helpers.performNormalMethodChecksAndDetermineVisibility(runtime, clazz, methodName, currVisibility); DynamicMethod newMethod = new CompiledIRMethod(handle, method, newVisibility, clazz); // FIXME: needs checkID and proper encoding to force hard symbol Helpers.addInstanceMethod(clazz, methodName, newMethod, currVisibility, context, runtime); }
@JIT public static void defCompiledInstanceMethod(ThreadContext context, MethodHandle variable, MethodHandle specific, int specificArity, IRScope method, DynamicScope currDynScope, IRubyObject self) { Ruby runtime = context.runtime; RubySymbol methodName = method.getName(); RubyModule clazz = findInstanceMethodContainer(context, currDynScope, self); Visibility currVisibility = context.getCurrentVisibility(); Visibility newVisibility = Helpers.performNormalMethodChecksAndDetermineVisibility(runtime, clazz, methodName, currVisibility); DynamicMethod newMethod = new CompiledIRMethod(variable, specific, specificArity, method, newVisibility, clazz); // FIXME: needs checkID and proper encoding to force hard symbol Helpers.addInstanceMethod(clazz, methodName, newMethod, currVisibility, context, runtime); }
public IRubyObject defineMethodFromBlock(ThreadContext context, IRubyObject arg0, Block block, Visibility visibility) { final Ruby runtime = context.runtime; RubySymbol name = TypeConverter.checkID(arg0); DynamicMethod newMethod; if (!block.isGiven()) { throw runtime.newArgumentError("tried to create Proc object without a block"); } // If we know it comes from IR we can convert this directly to a method and // avoid overhead of invoking it as a block if (block.getBody() instanceof IRBlockBody && runtime.getInstanceConfig().getCompileMode().shouldJIT()) { // FIXME: Once Interp and Mixed Methods are one class we can fix this to work in interp mode too. IRBlockBody body = (IRBlockBody) block.getBody(); IRClosure closure = body.getScope(); // Ask closure to give us a method equivalent. IRMethod method = closure.convertToMethod(name); if (method != null) { newMethod = new DefineMethodMethod(method, visibility, this, context.getFrameBlock()); Helpers.addInstanceMethod(this, name, newMethod, visibility, context, runtime); return name; } } newMethod = createProcMethod(runtime, name.idString(), visibility, block); Helpers.addInstanceMethod(this, name, newMethod, visibility, context, runtime); return name; }
@Interp public static void defInterpretedInstanceMethod(ThreadContext context, IRScope method, DynamicScope currDynScope, IRubyObject self) { Ruby runtime = context.runtime; RubySymbol methodName = method.getName(); RubyModule rubyClass = findInstanceMethodContainer(context, currDynScope, self); Visibility currVisibility = context.getCurrentVisibility(); Visibility newVisibility = Helpers.performNormalMethodChecksAndDetermineVisibility(runtime, rubyClass, methodName, currVisibility); DynamicMethod newMethod; if (runtime.getInstanceConfig().getCompileMode() == RubyInstanceConfig.CompileMode.OFF) { newMethod = new InterpretedIRMethod(method, newVisibility, rubyClass); } else { newMethod = new MixedModeIRMethod(method, newVisibility, rubyClass); } Helpers.addInstanceMethod(rubyClass, methodName, newMethod, currVisibility, context, runtime); }
public IRubyObject defineMethodFromBlock(ThreadContext context, IRubyObject arg0, Block block, Visibility visibility) { final Ruby runtime = context.runtime; RubySymbol name = TypeConverter.checkID(arg0); DynamicMethod newMethod; if (!block.isGiven()) { throw runtime.newArgumentError("tried to create Proc object without a block"); } // If we know it comes from IR we can convert this directly to a method and // avoid overhead of invoking it as a block if (block.getBody() instanceof IRBlockBody && runtime.getInstanceConfig().getCompileMode().shouldJIT()) { // FIXME: Once Interp and Mixed Methods are one class we can fix this to work in interp mode too. IRBlockBody body = (IRBlockBody) block.getBody(); IRClosure closure = body.getScope(); // Ask closure to give us a method equivalent. IRMethod method = closure.convertToMethod(name); if (method != null) { newMethod = new DefineMethodMethod(method, visibility, this, context.getFrameBlock()); Helpers.addInstanceMethod(this, name, newMethod, visibility, context, runtime); return name; } } newMethod = createProcMethod(runtime, name.idString(), visibility, block); Helpers.addInstanceMethod(this, name, newMethod, visibility, context, runtime); return name; }
@Interp public static void defInterpretedInstanceMethod(ThreadContext context, IRScope method, DynamicScope currDynScope, IRubyObject self) { Ruby runtime = context.runtime; RubySymbol methodName = method.getName(); RubyModule rubyClass = findInstanceMethodContainer(context, currDynScope, self); Visibility currVisibility = context.getCurrentVisibility(); Visibility newVisibility = Helpers.performNormalMethodChecksAndDetermineVisibility(runtime, rubyClass, methodName, currVisibility); DynamicMethod newMethod; if (runtime.getInstanceConfig().getCompileMode() == RubyInstanceConfig.CompileMode.OFF) { newMethod = new InterpretedIRMethod(method, newVisibility, rubyClass); } else { newMethod = new MixedModeIRMethod(method, newVisibility, rubyClass); } Helpers.addInstanceMethod(rubyClass, methodName, newMethod, currVisibility, context, runtime); }
@JRubyMethod(name = "define_method", visibility = PRIVATE, reads = VISIBILITY) public IRubyObject define_method(ThreadContext context, IRubyObject arg0, Block block) { Ruby runtime = context.runtime; String name = TypeConverter.convertToIdentifier(arg0); DynamicMethod newMethod = null; Visibility visibility = PUBLIC; // We need our identifier to be retrievable and creatable as a symbol. This side-effect // populates this name into our symbol table so it will exist later if needed. The // reason for this hack/side-effect is that symbols store their values as raw bytes. We lose encoding // info so we need to make an entry so any accesses with raw bytes later gets proper symbol. RubySymbol.newSymbol(runtime, arg0); if (!block.isGiven()) { throw getRuntime().newArgumentError("tried to create Proc object without a block"); } block = block.cloneBlockAndFrame(); RubyProc proc = runtime.newProc(Block.Type.LAMBDA, block); // a normal block passed to define_method changes to do arity checking; make it a lambda proc.getBlock().type = Block.Type.LAMBDA; newMethod = createProcMethod(name, visibility, proc); Helpers.addInstanceMethod(this, name, newMethod, visibility, context, runtime); return proc; }
@JRubyMethod(name = "define_method", visibility = PRIVATE, reads = VISIBILITY) public IRubyObject define_method(ThreadContext context, IRubyObject arg0, Block block) { Ruby runtime = context.runtime; String name = TypeConverter.convertToIdentifier(arg0); DynamicMethod newMethod = null; Visibility visibility = PUBLIC; // We need our identifier to be retrievable and creatable as a symbol. This side-effect // populates this name into our symbol table so it will exist later if needed. The // reason for this hack/side-effect is that symbols store their values as raw bytes. We lose encoding // info so we need to make an entry so any accesses with raw bytes later gets proper symbol. RubySymbol.newSymbol(runtime, arg0); if (!block.isGiven()) { throw getRuntime().newArgumentError("tried to create Proc object without a block"); } block = block.cloneBlockAndFrame(); RubyProc proc = runtime.newProc(Block.Type.LAMBDA, block); // a normal block passed to define_method changes to do arity checking; make it a lambda proc.getBlock().type = Block.Type.LAMBDA; newMethod = createProcMethod(name, visibility, proc); Helpers.addInstanceMethod(this, name, newMethod, visibility, context, runtime); return proc; }
public IRubyObject defineMethodFromCallable(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Visibility visibility) { final Ruby runtime = context.runtime; RubySymbol name = TypeConverter.checkID(arg0); DynamicMethod newMethod; if (runtime.getProc().isInstance(arg1)) { // double-testing args.length here, but it avoids duplicating the proc-setup code in two places RubyProc proc = (RubyProc)arg1; newMethod = createProcMethod(runtime, name.idString(), visibility, proc.getBlock()); } else if (arg1 instanceof AbstractRubyMethod) { AbstractRubyMethod method = (AbstractRubyMethod)arg1; checkValidBindTargetFrom(context, (RubyModule) method.owner(context)); newMethod = method.getMethod().dup(); newMethod.setImplementationClass(this); newMethod.setVisibility(visibility); } else { throw runtime.newTypeError("wrong argument type " + arg1.getType().getName() + " (expected Proc/Method)"); } Helpers.addInstanceMethod(this, name, newMethod, visibility, context, runtime); return name; }
public IRubyObject defineMethodFromCallable(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Visibility visibility) { final Ruby runtime = context.runtime; RubySymbol name = TypeConverter.checkID(arg0); DynamicMethod newMethod; if (runtime.getProc().isInstance(arg1)) { // double-testing args.length here, but it avoids duplicating the proc-setup code in two places RubyProc proc = (RubyProc)arg1; newMethod = createProcMethod(runtime, name.idString(), visibility, proc.getBlock()); } else if (arg1 instanceof AbstractRubyMethod) { AbstractRubyMethod method = (AbstractRubyMethod)arg1; checkValidBindTargetFrom(context, (RubyModule) method.owner(context)); newMethod = method.getMethod().dup(); newMethod.setImplementationClass(this); newMethod.setVisibility(visibility); } else { throw runtime.newTypeError("wrong argument type " + arg1.getType().getName() + " (expected Proc/Method)"); } Helpers.addInstanceMethod(this, name, newMethod, visibility, context, runtime); return name; }
Helpers.addInstanceMethod(this, name, newMethod, visibility, context, runtime);
Helpers.addInstanceMethod(this, name, newMethod, visibility, context, runtime);