@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);
   }
 }
示例#2
0
  public static void main(String[] args) {

    final JFrame frame = new JFrame();
    frame.setBounds(100, 100, 1200, 800);
    frame.setLayout(null);
    final VirtualFrame subFrame = new VirtualFrame(20, 20, 1160, 740);
    subFrame.setTitle("Scrolling test");
    frame.add(subFrame);
    frame.setVisible(true);

    final TextScroller scroller =
        new TextScroller(25, VirtualFrame.DEFAULT_BAR_THICKNESS + 25, 400, 650);
    subFrame.add(scroller);
    scroller.addLabel("A________________", "Arial", 1, 25);
    scroller.addLabel("B________________", "Arial", 1, 15);
    scroller.addLabel("C________________", "Arial", 1, 20);
    scroller.addLabel("D________________", "Arial", 1, 25);
    scroller.addLabel("E________________", "Arial", 1, 15);
    scroller.addLabel("F________________", "Arial", 1, 20);
    scroller.addLabel("G________________", "Arial", 1, 25);
    scroller.addLabel("H________________", "Arial", 1, 15);
    scroller.addLabel("I________________", "Arial", 1, 20);
    scroller.addLabel("J________________", "Arial", 1, 25);
    scroller.addLabel("K________________", "Arial", 1, 15);
    scroller.addLabel("L________________", "Arial", 1, 20);
    scroller.addLabel("M________________", "Arial", 1, 25);
    scroller.addLabel("N________________", "Arial", 1, 15);
    scroller.addLabel("O________________", "Arial", 1, 20);
    scroller.addLabel("P________________", "Arial", 1, 25);
    scroller.addLabel("Q________________", "Arial", 1, 15);
    scroller.addLabel("R________________", "Arial", 1, 20);
    scroller.addLabel("S________________", "Arial", 1, 25);
    scroller.addLabel("T________________", "Arial", 1, 15);
    scroller.addLabel("U________________", "Arial", 1, 20);
    scroller.addLabel("V________________", "Arial", 1, 25);
    scroller.addLabel("W________________", "Arial", 1, 15);
    scroller.addLabel("X________________", "Arial", 1, 20);
    scroller.addLabel("Y________________", "Arial", 1, 25);
    scroller.addLabel("Z________________", "Arial", 1, 15);
    scroller.addLabel("AA_______________", "Arial", 1, 25);
    scroller.addLabel("BB_______________", "Arial", 1, 15);
    scroller.addLabel("CC_______________", "Arial", 1, 20);
    scroller.addLabel("DD_______________", "Arial", 1, 25);
    scroller.addLabel("EE_______________", "Arial", 1, 15);
    scroller.addLabel("FF_______________", "Arial", 1, 20);
    scroller.addLabel("GG_______________", "Arial", 1, 25);
    scroller.addLabel("HH_______________", "Arial", 1, 15);
    scroller.addLabel("II_______________", "Arial", 1, 20);
    scroller.initialize();
  }
示例#3
0
  private boolean moduleFunctionFlag(VirtualFrame frame) {
    final FrameSlot moduleFunctionFlagSlot =
        frame.getFrameDescriptor().findFrameSlot(RubyModule.MODULE_FUNCTION_FLAG_FRAME_SLOT_ID);

    if (moduleFunctionFlagSlot == null) {
      return false;
    } else {
      Object moduleFunctionObject;

      try {
        moduleFunctionObject = frame.getObject(moduleFunctionFlagSlot);
      } catch (FrameSlotTypeException e) {
        throw new RuntimeException(e);
      }

      return (moduleFunctionObject instanceof Boolean) && (boolean) moduleFunctionObject;
    }
  }
示例#4
0
文件: HashNodes.java 项目: phs/jruby
    @Specialization
    public Object construct(VirtualFrame frame, RubyHash hash, Object index) {
      final Object value = hash.get(index);

      if (value == null) {
        if (hash.defaultBlock == null) {
          return NilPlaceholder.INSTANCE;
        } else {
          return hash.defaultBlock.call(frame.pack(), hash, index);
        }
      } else {
        return value;
      }
    }
示例#5
0
  @Override
  public boolean doesRespondTo(VirtualFrame frame, RubyBasicObject receiverObject) {
    // TODO(CS): copy-and-paste of the above - needs to be factored out

    MethodCacheEntry entry = lookupInCache(receiverObject.getLookupNode());

    if (entry == null) {
      CompilerDirectives.transferToInterpreterAndInvalidate();

      final RubyBasicObject boxedCallingSelf =
          getContext().getCoreLibrary().box(RubyArguments.getSelf(frame.getArguments()));

      try {
        entry = new MethodCacheEntry(lookup(boxedCallingSelf, receiverObject, name), false);
      } catch (UseMethodMissingException e) {
        try {
          entry =
              new MethodCacheEntry(
                  lookup(boxedCallingSelf, receiverObject, "method_missing"), true);
        } catch (UseMethodMissingException e2) {
          throw new RaiseException(
              getContext()
                  .getCoreLibrary()
                  .runtimeError(receiverObject.toString() + " didn't have a #method_missing"));
        }
      }

      if (entry.isMethodMissing()) {
        hasAnyMethodsMissing = true;
      }

      cache.put(receiverObject.getLookupNode(), entry);

      if (cache.size() > RubyContext.GENERAL_DISPATCH_SIZE_WARNING_THRESHOLD) {
        getContext()
            .getRuntime()
            .getWarnings()
            .warn(
                IRubyWarnings.ID.TRUFFLE,
                getEncapsulatingSourceSection().getSource().getName(),
                getEncapsulatingSourceSection().getStartLine(),
                "general call node cache has " + cache.size() + " entries");
      }
    }

    return !entry.isMethodMissing();
  }
示例#6
0
  @Override
  public Object execute(VirtualFrame frame) {
    final RubyArguments rubyArguments = frame.getArguments(RubyArguments.class);

    final Object[] arguments = rubyArguments.getArguments();

    final RubyClass arrayClass = getContext().getCoreLibrary().getArrayClass();

    if (arguments.length <= index) {
      return new RubyArray(arrayClass);
    } else if (index == 0) {
      return new RubyArray(arrayClass, new ObjectArrayStore(arguments));
    } else {
      return new RubyArray(
          arrayClass, new ObjectArrayStore(Arrays.copyOfRange(arguments, index, arguments.length)));
    }
  }
示例#7
0
  @Override
  public Object dispatch(
      VirtualFrame frame,
      RubyBasicObject receiverObject,
      RubyProc blockObject,
      Object[] argumentsObjects) {
    MethodCacheEntry entry = lookupInCache(receiverObject.getLookupNode());

    if (entry == null) {
      CompilerDirectives.transferToInterpreterAndInvalidate();

      final RubyBasicObject boxedCallingSelf =
          getContext().getCoreLibrary().box(RubyArguments.getSelf(frame.getArguments()));

      try {
        entry = new MethodCacheEntry(lookup(boxedCallingSelf, receiverObject, name), false);
      } catch (UseMethodMissingException e) {
        try {
          entry =
              new MethodCacheEntry(
                  lookup(boxedCallingSelf, receiverObject, "method_missing"), true);
        } catch (UseMethodMissingException e2) {
          throw new RaiseException(
              getContext()
                  .getCoreLibrary()
                  .runtimeError(receiverObject.toString() + " didn't have a #method_missing"));
        }
      }

      if (entry.isMethodMissing()) {
        hasAnyMethodsMissing = true;
      }

      cache.put(receiverObject.getLookupNode(), entry);

      if (cache.size() > RubyContext.GENERAL_DISPATCH_SIZE_WARNING_THRESHOLD) {
        getContext()
            .getRuntime()
            .getWarnings()
            .warn(
                IRubyWarnings.ID.TRUFFLE,
                getEncapsulatingSourceSection().getSource().getName(),
                getEncapsulatingSourceSection().getStartLine(),
                "general call node cache has " + cache.size() + " entries");
      }
    }

    final Object[] argumentsToUse;

    if (hasAnyMethodsMissing && entry.isMethodMissing()) {
      final Object[] modifiedArgumentsObjects = new Object[1 + argumentsObjects.length];
      modifiedArgumentsObjects[0] = getContext().newSymbol(name);
      System.arraycopy(argumentsObjects, 0, modifiedArgumentsObjects, 1, argumentsObjects.length);
      argumentsToUse = modifiedArgumentsObjects;
    } else {
      argumentsToUse = argumentsObjects;
    }

    return callNode.call(
        frame,
        entry.getMethod().getCallTarget(),
        RubyArguments.pack(
            entry.getMethod().getDeclarationFrame(), receiverObject, blockObject, argumentsToUse));
  }
示例#8
0
 int execute(VirtualFrame frame) {
   return frame.getArguments(TestArguments.class).values[index];
 }