private Object lookupRestKeywordArgumentHash(VirtualFrame frame) {
    final Object hash = readUserKeywordsHashNode.execute(frame);

    if (noHash.profile(hash == null)) {
      return Layouts.HASH.createHash(
          coreLibrary().getHashFactory(), null, 0, null, null, null, null, false);
    }

    CompilerDirectives.bailout("Ruby keyword arguments aren't optimized");

    final DynamicObject hashObject = (DynamicObject) hash;

    final List<Map.Entry<Object, Object>> entries = new ArrayList<>();

    outer:
    for (Map.Entry<Object, Object> keyValue : HashOperations.iterableKeyValues(hashObject)) {
      if (!RubyGuards.isRubySymbol(keyValue.getKey())) {
        continue;
      }

      for (String excludedKeyword : excludedKeywords) {
        if (excludedKeyword.equals(keyValue.getKey().toString())) {
          continue outer;
        }
      }

      entries.add(keyValue);
    }

    return BucketsStrategy.create(
        getContext(), entries, Layouts.HASH.getCompareByIdentity(hashObject));
  }
Example #2
0
 private Object timeToUnit(long time, DynamicObject unit) {
   assert RubyGuards.isRubySymbol(unit);
   if (unit == nanosecondSymbol) {
     return time;
   } else if (unit == floatSecondSymbol) {
     return time / 1e9;
   } else {
     throw new UnsupportedOperationException(Layouts.SYMBOL.getString(unit));
   }
 }
Example #3
0
 private String toString(Object methodName) {
   if (methodName instanceof String) {
     return (String) methodName;
   } else if (RubyGuards.isRubyString(methodName)) {
     return methodName.toString();
   } else if (RubyGuards.isRubySymbol(methodName)) {
     return Layouts.SYMBOL.getString((DynamicObject) methodName);
   } else {
     throw new UnsupportedOperationException();
   }
 }
Example #4
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());
    }
  }