@Override public IRubyObject call( ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) { if (IRRuntimeHelpers.isDebug()) doDebug(); DynamicMethodBox box = this.box; if (box.callCount >= 0) tryJit(context, box); DynamicMethod jittedMethod = box.actualMethod; if (jittedMethod != null) { return jittedMethod.call(context, self, clazz, name, arg0, arg1, arg2, block); } else { return INTERPRET_METHOD( context, ensureInstrsReady(), getImplementationClass().getMethodLocation(), self, name, arg0, arg1, arg2, block); } }
protected Object interpretSuper( ThreadContext context, IRubyObject self, IRubyObject[] args, Block block) { // SSS FIXME: We should check in the current module (for instance methods) or the current // module's meta class (for class methods) // // RubyModule currM = context.getCurrentScope().getStaticScope().getModule(); // RubyModule klazz = (isInstanceMethodSuper) ? currM : currM.getMetaClass(); // // The question is how do we know what this 'super' ought to do? // For 'super' that occurs in a method scope, this is easy to figure out. // But, what about 'super' that occurs in block scope? How do we figure that out? RubyModule klazz = context.getFrameKlazz(); // SSS FIXME: Even though we may know the method name in some instances, // we are not making use of it here. String methodName = context.getCurrentFrame().getName(); // methAddr.getName(); checkSuperDisabledOrOutOfMethod(context, klazz, methodName); RubyClass superClass = RuntimeHelpers.findImplementerIfNecessary(self.getMetaClass(), klazz).getSuperClass(); DynamicMethod method = superClass != null ? superClass.searchMethod(methodName) : UndefinedMethod.INSTANCE; Object rVal = method.isUndefined() ? RuntimeHelpers.callMethodMissing( context, self, method.getVisibility(), methodName, CallType.SUPER, args, block) : method.call(context, self, superClass, methodName, args, block); return hasUnusedResult() ? null : rVal; }
@Override public Object interpret( ThreadContext context, DynamicScope currDynScope, IRubyObject self, Object[] temp, Block aBlock) { // FIXME: Receiver is not being used...should we be retrieving it? IRubyObject receiver = (IRubyObject) getReceiver().retrieve(context, self, currDynScope, temp); IRubyObject[] args = prepareArguments(context, self, getCallArgs(), currDynScope, temp); Block block = prepareBlock(context, self, currDynScope, temp); RubyModule klazz = context.getFrameKlazz(); // SSS FIXME: Even though we may know the method name in some instances, // we are not making use of it here. It is cleaner in the sense of not // relying on implicit information whose data flow doesn't show up in the IR. String methodName = context.getCurrentFrame().getName(); // methAddr.getName(); checkSuperDisabledOrOutOfMethod(context, klazz, methodName); RubyClass superClass = RuntimeHelpers.findImplementerIfNecessary(self.getMetaClass(), klazz).getSuperClass(); DynamicMethod method = superClass != null ? superClass.searchMethod(methodName) : UndefinedMethod.INSTANCE; Object rVal = method.isUndefined() ? RuntimeHelpers.callMethodMissing( context, self, method.getVisibility(), methodName, CallType.SUPER, args, block) : method.call(context, self, superClass, methodName, args, block); return hasUnusedResult() ? null : rVal; }
private static IRubyObject callConversionMethod( ThreadContext context, DynamicMethod method, IRubyObject converter, String methodName, IRubyObject value) { if (method.getArity().required() == 2) { return method.call( context, converter, converter.getMetaClass(), methodName, value, context.runtime.getNil()); } else { return method.call(context, converter, converter.getMetaClass(), methodName, value); } }
public IRubyObject invoke( ThreadContext context, IRubyObject caller, IRubyObject self, IRubyObject[] args, Block block) throws Throwable { RubyClass selfClass = pollAndGetClass(context, self); SwitchPoint switchPoint = (SwitchPoint) selfClass.getInvalidator().getData(); CacheEntry entry = selfClass.searchWithCache(methodName); DynamicMethod method = entry.method; if (methodMissing(entry, caller)) { return callMethodMissing(entry, callType, context, self, methodName, args, block); } MethodHandle mh = getHandle(selfClass, this, method); updateInvocationTarget(mh, self, selfClass, entry, switchPoint); return method.call(context, self, selfClass, methodName, args, block); }
private IRubyObject invokeRuby( final DynamicMethod method, final JavaProxyMethod proxyMethod, final RubyClass metaClass, final String name, final Object[] nargs) { final IRubyObject[] newArgs = new IRubyObject[nargs.length]; for (int i = nargs.length; --i >= 0; ) { newArgs[i] = JavaUtil.convertJavaToUsableRubyObject(runtime, nargs[i]); } final int arity = method.getArity().getValue(); if (arity < 0 || arity == newArgs.length) { final ThreadContext context = runtime.getCurrentContext(); return method.call(context, self, metaClass, name, newArgs); } if (proxyMethod.hasSuperImplementation()) { final ThreadContext context = runtime.getCurrentContext(); final RubyClass superClass = metaClass.getSuperClass(); return Helpers.invokeAs(context, superClass, self, name, newArgs, Block.NULL_BLOCK); } throw runtime.newArgumentError(newArgs.length, arity); }