@Override public RubySymbol execute(VirtualFrame frame) { notDesignedForCompilation(); final Object receiverObject = receiver.execute(frame); final RubyMethod methodObject = (RubyMethod) method.execute(frame); RubyModule module; if (receiverObject instanceof RubyModule) { module = (RubyModule) receiverObject; } else { module = ((RubyBasicObject) receiverObject).getSingletonClass(this); } final RubyMethod methodWithDeclaringModule = methodObject.withDeclaringModule(module); if (moduleFunctionFlag(frame)) { module.addMethod(this, methodWithDeclaringModule.withVisibility(Visibility.PRIVATE)); module .getSingletonClass(this) .addMethod(this, methodWithDeclaringModule.withVisibility(Visibility.PUBLIC)); } else { module.addMethod(this, methodWithDeclaringModule); } return getContext().newSymbol(method.getName()); }
@Override public Object dispatch(VirtualFrame frame, RubyProc block, Object[] argumentsObjects) { final RubyMethod method = block.getMethod(); return callNode.call( frame, method.getCallTarget(), RubyArguments.pack( method.getDeclarationFrame(), block.getSelfCapturedInScope(), block.getBlockCapturedInScope(), argumentsObjects)); }
public CachedBoxedSymbolDispatchNode( RubyContext context, Object cachedName, DispatchNode next, Object value, RubyMethod method) { super(context, cachedName, next); unmodifiedAssumption = context.getCoreLibrary().getSymbolClass().getUnmodifiedAssumption(); this.value = value; this.method = method; if (method != null) { callNode = Truffle.getRuntime().createDirectCallNode(method.getCallTarget()); } }
@Specialization(guards = "guardName") public Object dispatch( VirtualFrame frame, RubyNilClass methodReceiverObject, LexicalScope lexicalScope, RubySymbol receiverObject, Object methodName, Object blockObject, Object argumentsObjects, Dispatch.DispatchAction dispatchAction) { CompilerAsserts.compilationConstant(dispatchAction); // Check the class has not been modified try { unmodifiedAssumption.check(); } catch (InvalidAssumptionException e) { return resetAndDispatch( frame, methodReceiverObject, lexicalScope, receiverObject, methodName, CompilerDirectives.unsafeCast(blockObject, RubyProc.class, true, false), argumentsObjects, dispatchAction, "class modified"); } if (dispatchAction == Dispatch.DispatchAction.CALL_METHOD) { return callNode.call( frame, RubyArguments.pack( method, method.getDeclarationFrame(), receiverObject, CompilerDirectives.unsafeCast(blockObject, RubyProc.class, true, false), CompilerDirectives.unsafeCast(argumentsObjects, Object[].class, true))); } else if (dispatchAction == Dispatch.DispatchAction.RESPOND_TO_METHOD) { return true; } else if (dispatchAction == Dispatch.DispatchAction.READ_CONSTANT) { return value; } else { throw new UnsupportedOperationException(); } }