示例#1
0
  private DispatchNode doUnboxedObject(
      VirtualFrame frame, DispatchNode first, Object receiverObject, Object methodName) {
    final DynamicObject callerClass;

    if (ignoreVisibility) {
      callerClass = null;
    } else {
      callerClass = coreLibrary().getMetaClass(RubyArguments.getSelf(frame));
    }

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

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

    if (receiverObject instanceof Boolean) {
      final Assumption falseUnmodifiedAssumption =
          Layouts.MODULE.getFields(coreLibrary().getFalseClass()).getUnmodifiedAssumption();
      final InternalMethod falseMethod =
          lookup(callerClass, false, methodNameString, ignoreVisibility);

      final Assumption trueUnmodifiedAssumption =
          Layouts.MODULE.getFields(coreLibrary().getTrueClass()).getUnmodifiedAssumption();
      final InternalMethod trueMethod =
          lookup(callerClass, true, methodNameString, ignoreVisibility);
      assert falseMethod != null || trueMethod != null;

      return new CachedBooleanDispatchNode(
          getContext(),
          methodName,
          first,
          falseUnmodifiedAssumption,
          falseMethod,
          trueUnmodifiedAssumption,
          trueMethod,
          getDispatchAction());
    } else {
      return new CachedUnboxedDispatchNode(
          getContext(),
          methodName,
          first,
          receiverObject.getClass(),
          Layouts.MODULE
              .getFields(coreLibrary().getLogicalClass(receiverObject))
              .getUnmodifiedAssumption(),
          method,
          getDispatchAction());
    }
  }
示例#2
0
 @TruffleBoundary
 private InternalMethod prepareLexicalScope(DynamicObject module, InternalMethod definition) {
   lexicalScope.unsafeSetLiveModule(module);
   Layouts.MODULE.getFields(lexicalScope.getParent().getLiveModule()).addLexicalDependent(module);
   return definition.withDeclaringModule(module);
 }