@Override
  public Object execute(VirtualFrame frame) {
    if (optimizedProfile.profile(RubyArguments.isKwOptimized(frame.getArguments()))) {
      Object kwarg =
          argumentValueProfile.profile(
              RubyArguments.getOptimizedKeywordArgument(frame.getArguments(), kwIndex));

      if (defaultProfile.profile(
          kwarg instanceof OptionalKeywordArgMissingNode.OptionalKeywordArgMissing)) {
        return defaultValue.execute(frame);
      } else {
        return kwarg;
      }
    } else {
      final RubyHash hash = RubyArguments.getUserKeywordsHash(frame.getArguments(), minimum);

      if (defaultProfile.profile(hash == null)) {
        return defaultValue.execute(frame);
      }

      Object value = lookupKeywordInHash(hash);

      if (defaultProfile.profile(value == null)) {
        return defaultValue.execute(frame);
      }

      return value;
    }
  }
Beispiel #2
0
  @Override
  public Object execute(VirtualFrame frame) {
    // TODO(cs): can module ever not evaluate to a RubyModule?

    final RubyModule moduleObject = (RubyModule) module.execute(frame);

    final Object rhsValue = rhs.execute(frame);

    assert rhsValue != null;
    assert !(rhsValue instanceof String);

    moduleObject.setModuleConstant(name, rhsValue);

    return rhsValue;
  }
Beispiel #3
0
  @Override
  public DynamicObject execute(VirtualFrame frame) {
    CompilerDirectives.transferToInterpreter();

    final Object receiverObject = receiver.execute(frame);

    final InternalMethod methodObject = (InternalMethod) methodNode.execute(frame);

    final DynamicObject module = (DynamicObject) receiverObject;
    assert RubyGuards.isRubyModule(module);

    final Visibility visibility = getVisibility(frame, methodObject.getName());
    final InternalMethod method =
        methodObject.withDeclaringModule(module).withVisibility(visibility);

    if (method.getVisibility() == Visibility.MODULE_FUNCTION) {
      Layouts.MODULE.getFields(module).addMethod(this, method.withVisibility(Visibility.PRIVATE));
      Layouts.MODULE
          .getFields(singletonClassNode.executeSingletonClass(module))
          .addMethod(this, method.withVisibility(Visibility.PUBLIC));
    } else {
      Layouts.MODULE.getFields(module).addMethod(this, method);
    }

    return getSymbol(method.getName());
  }
Beispiel #4
0
  @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());
  }
Beispiel #5
0
 @Override
 public Object execute(VirtualFrame frame) {
   if (CompilerDirectives.injectBranchProbability(
       getBranchProbability(), condition.executeBoolean(frame))) {
     if (CompilerDirectives.inInterpreter()) {
       thenCount++;
     }
     thenProfile.enter();
     return thenBody.execute(frame);
   } else {
     if (CompilerDirectives.inInterpreter()) {
       elseCount++;
     }
     elseProfile.enter();
     return elseBody.execute(frame);
   }
 }
Beispiel #6
0
 @Override
 public Object execute(VirtualFrame frame) {
   try {
     return tryPart.execute(frame);
   } finally {
     ensurePart.executeVoid(frame);
   }
 }
  @ExplodeLoop
  @Override
  public final Object execute(VirtualFrame frame) {
    final Object self = RubyArguments.getSelf(frame.getArguments());

    // Execute the arguments

    final Object[] argumentsObjects = new Object[arguments.length];

    CompilerAsserts.compilationConstant(arguments.length);
    for (int i = 0; i < arguments.length; i++) {
      argumentsObjects[i] = arguments[i].execute(frame);
    }

    // Execute the block

    RubyProc blockObject;

    if (block != null) {
      final Object blockTempObject = block.execute(frame);

      if (blockTempObject instanceof RubyNilClass) {
        blockObject = null;
      } else {
        blockObject = (RubyProc) blockTempObject;
      }
    } else {
      blockObject = null;
    }

    // Check we have a method and the module is unmodified

    if (!guard(frame, self)) {
      CompilerDirectives.transferToInterpreterAndInvalidate();
      lookup(frame);
    }

    // Call the method

    if (isSplatted) {
      // TODO(CS): need something better to splat the arguments array
      notDesignedForCompilation();
      final RubyArray argumentsArray = (RubyArray) argumentsObjects[0];
      return callNode.call(
          frame,
          RubyArguments.pack(
              superMethod,
              superMethod.getDeclarationFrame(),
              self,
              blockObject,
              argumentsArray.slowToArray()));
    } else {
      return callNode.call(
          frame,
          RubyArguments.pack(
              superMethod, superMethod.getDeclarationFrame(), self, blockObject, argumentsObjects));
    }
  }
Beispiel #8
0
  // TODO CS 20-Aug-15 this needs to go
  public static boolean verySlowIsFrozen(RubyContext context, Object object) {
    final RubyNode node =
        IsFrozenNodeGen.create(context, null, new LiteralNode(context, null, object));
    new Node() {
      @Child RubyNode child = node;
    }.adoptChildren();

    return (boolean) node.execute(null);
  }
 @Override
 public Object execute(VirtualFrame frame) {
   if (RubyArguments.getUserArgumentsCount(frame.getArguments()) < minimum) {
     defaultValueProfile.enter();
     return defaultValue.execute(frame);
   } else {
     return RubyArguments.getUserArgument(frame.getArguments(), index);
   }
 }
Beispiel #10
0
  @Override
  public Object execute(VirtualFrame frame) {
    try {
      return body.execute(frame);
    } catch (BreakException e) {
      breakProfile.enter();

      if (matchingBreakProfile.profile(e.getBreakID() == breakID)) {
        return e.getResult();
      } else {
        throw e;
      }
    }
  }
Beispiel #11
0
  @Override
  public RubyBasicObject executeRubyBasicObject(VirtualFrame frame) {
    final Object object = child.execute(frame);

    RubyBasicObject boxedObject;

    if (object instanceof RubyBasicObject) {
      boxedObject = (RubyBasicObject) object;
    } else {
      boxBranch.enter();
      boxedObject = getContext().getCoreLibrary().box(object);
    }

    return boxedObject;
  }
Beispiel #12
0
  @Override
  public Object execute(VirtualFrame frame) {
    CompilerDirectives.transferToInterpreter();

    // TODO(CS): cast
    final DynamicObject module = (DynamicObject) definingModule.execute(frame);

    lexicalScope.setLiveModule(module);
    Layouts.MODULE.getFields(lexicalScope.getParent().getLiveModule()).addLexicalDependent(module);

    final InternalMethod definition =
        definitionMethod.executeMethod(frame).withDeclaringModule(module);
    return callModuleDefinitionNode.call(
        frame,
        definition.getCallTarget(),
        RubyArguments.pack(
            definition, null, null, module, null, DeclarationContext.MODULE, new Object[] {}));
  }
  @Override
  public Object execute(VirtualFrame frame) {
    try {
      assert assertArgumentsShouldBeVisible(frame);

      final Object result = child.execute(frame);

      assert shouldObjectBeVisible(result)
          : "result@" + getEncapsulatingSourceSection().getShortDescription();

      return result;
    } catch (StackOverflowError error) {
      // TODO: we might want to do sth smarter here to avoid consuming frames when we are almost out
      // of it.
      CompilerDirectives.transferToInterpreter();
      throw new RaiseException(translate(error));
    } catch (TruffleFatalException | ThreadExitException exception) {
      throw exception;
    } catch (ControlFlowException exception) {
      controlProfile.enter();
      throw exception;
    } catch (RaiseException exception) {
      rethrowProfile.enter();
      throw exception;
    } catch (MainExitException exception) {
      CompilerDirectives.transferToInterpreter();
      throw exception;
    } catch (ArithmeticException exception) {
      CompilerDirectives.transferToInterpreter();
      throw new RaiseException(translate(exception));
    } catch (UnsupportedSpecializationException exception) {
      CompilerDirectives.transferToInterpreter();
      throw new RaiseException(translate(exception));
    } catch (org.jruby.exceptions.RaiseException e) {
      CompilerDirectives.transferToInterpreter();
      throw new RaiseException(getContext().toTruffle(e.getException(), this));
    } catch (Throwable exception) {
      CompilerDirectives.transferToInterpreter();
      throw new RaiseException(translate(exception));
    }
  }
Beispiel #14
0
  @Override
  public Object execute(VirtualFrame frame) {
    while (true) {
      try {
        final Object result = tryPart.execute(frame);
        elsePart.executeVoid(frame);
        return result;
      } catch (ControlFlowException exception) {
        controlFlowProfile.enter();

        throw exception;
      } catch (RuntimeException exception) {
        CompilerDirectives.transferToInterpreter();

        try {
          return handleException(frame, exception);
        } catch (RetryException e) {
          continue;
        }
      }
    }
  }
Beispiel #15
0
 public void executeVoid(VirtualFrame frame) {
   execute(frame);
 }
Beispiel #16
0
 @Override
 public Object execute(VirtualFrame frame) {
   return child.execute(frame);
 }