Пример #1
0
  private DispatchNode doDynamicObject(
      VirtualFrame frame,
      DispatchNode first,
      Object receiverObject,
      Object methodName,
      Object[] argumentsObjects) {
    final DynamicObject callerClass;

    if (ignoreVisibility) {
      callerClass = null;
    } else if (getDispatchAction() == DispatchAction.RESPOND_TO_METHOD) {
      final Frame callerFrame =
          getContext()
              .getCallStack()
              .getCallerFrameIgnoringSend()
              .getFrame(FrameInstance.FrameAccess.READ_ONLY, true);
      callerClass = coreLibrary().getMetaClass(RubyArguments.getSelf(callerFrame.getArguments()));
    } else {
      callerClass = coreLibrary().getMetaClass(RubyArguments.getSelf(frame));
    }

    final InternalMethod method =
        lookup(callerClass, receiverObject, toString(methodName), ignoreVisibility);

    if (method == null) {
      return createMethodMissingNode(first, methodName, receiverObject);
    }

    final DynamicObject receiverMetaClass = coreLibrary().getMetaClass(receiverObject);
    if (RubyGuards.isRubySymbol(receiverObject)) {
      return new CachedBoxedSymbolDispatchNode(
          getContext(), methodName, first, method, getDispatchAction());
    } else if (Layouts.CLASS.getIsSingleton(receiverMetaClass)) {
      return new CachedSingletonDispatchNode(
          getContext(),
          methodName,
          first,
          ((DynamicObject) receiverObject),
          receiverMetaClass,
          method,
          getDispatchAction());
    } else {
      return new CachedBoxedDispatchNode(
          getContext(),
          methodName,
          first,
          ((DynamicObject) receiverObject).getShape(),
          receiverMetaClass,
          method,
          getDispatchAction());
    }
  }
Пример #2
0
 /**
  * The foreign receiver in the frame.
  *
  * @param frame the frame that was called via {@link #execute(com.oracle.truffle.api.nodes.Node,
  *     com.oracle.truffle.api.frame.VirtualFrame, com.oracle.truffle.api.interop.TruffleObject,
  *     java.lang.Object...) }
  * @return the receiver used when invoking the frame
  */
 public static TruffleObject getReceiver(Frame frame) {
   return (TruffleObject) frame.getArguments()[ForeignAccessArguments.RECEIVER_INDEX];
 }
Пример #3
0
 /**
  * Read only access to foreign call arguments inside of a frame.
  *
  * @param frame the frame that was called via {@link #execute(com.oracle.truffle.api.nodes.Node,
  *     com.oracle.truffle.api.frame.VirtualFrame, com.oracle.truffle.api.interop.TruffleObject,
  *     java.lang.Object...) }
  * @return read-only list of parameters passed to the frame
  */
 public static List<Object> getArguments(Frame frame) {
   final Object[] arr = frame.getArguments();
   return ReadOnlyArrayList.asList(arr, 1, arr.length);
 }