Ejemplo n.º 1
0
 @Override
 public Instr cloneForInlining(InlinerInfo ii) {
   Operand receiver = getReceiver();
   if (this.implMethod == JRubyImplementationMethod.CHECK_ARITY) {
     Operand[] args = getCallArgs();
     int required = ((Fixnum) args[0]).value.intValue();
     int opt = ((Fixnum) args[1]).value.intValue();
     int rest = ((Fixnum) args[2]).value.intValue();
     int numArgs = ii.getArgsCount();
     if ((numArgs < required) || ((rest == -1) && (numArgs > (required + opt)))) {
       // Argument error! Throw it at runtime
       return new JRubyImplCallInstr(
           null,
           JRubyImplementationMethod.RAISE_ARGUMENT_ERROR,
           null,
           new Operand[] {args[0], args[1], args[2], new Fixnum((long) numArgs)});
     } else {
       return null;
     }
   } else {
     return new JRubyImplCallInstr(
         result == null ? null : ii.getRenamedVariable(result),
         this.implMethod,
         receiver == null ? null : receiver.cloneForInlining(ii),
         cloneCallArgs(ii),
         closure == null ? null : closure.cloneForInlining(ii));
   }
 }
 @Override
 public Object call(ThreadContext context, IRubyObject self, IRubyObject receiver, Object[] temp) {
   IRubyObject value1 = (IRubyObject) arg1.retrieve(context, self, temp);
   IRubyObject value2 = (IRubyObject) arg2.retrieve(context, self, temp);
   IRubyObject value3 = (IRubyObject) arg3.retrieve(context, self, temp);
   IRubyObject value4 = (IRubyObject) arg4.retrieve(context, self, temp);
   return callSite.call(context, self, receiver, value1, value2, value3, value4);
 }
Ejemplo n.º 3
0
 @Override
 public Instr cloneForInlining(InlinerInfo ii) {
   return new ToAryInstr(
       (Variable) result.cloneForInlining(ii),
       array.cloneForInlining(ii),
       (BooleanLiteral) dontToAryArrays.cloneForInlining(ii));
 }
Ejemplo n.º 4
0
 @Override
 public Instr cloneForInlinedScope(InlinerInfo ii) {
   return new ModuleVersionGuardInstr(
       module,
       expectedVersion,
       candidateObj.cloneForInlining(ii),
       ii.getRenamedLabel(failurePathLabel));
 }
Ejemplo n.º 5
0
  @Override
  public Operand simplifyAndGetResult(Map<Operand, Operand> valueMap) {
    simplifyOperands(valueMap, false);
    if (!value.isConstant()) return null;

    return value == Nil.NIL || value == BooleanLiteral.FALSE
        ? BooleanLiteral.FALSE
        : BooleanLiteral.TRUE;
  }
Ejemplo n.º 6
0
 @Override
 public Object interpret(
     ThreadContext context,
     IRubyObject self,
     IRubyObject[] args,
     Block block,
     Object exception,
     Object[] temp) {
   result.store(context, self, temp, methodHandle.retrieve(context, self, temp));
   return null;
 }
Ejemplo n.º 7
0
  @Override
  public Object interpret(
      ThreadContext context,
      IRubyObject self,
      IRubyObject[] args,
      Block block,
      Object exception,
      Object[] temp) {
    IRubyObject receiver = (IRubyObject) arg1.retrieve(context, self, temp);
    IRubyObject value = (IRubyObject) arg2.retrieve(context, self, temp);

    if (value == UndefinedValue.UNDEFINED) {
      result.store(context, self, temp, receiver);
    } else if (receiver instanceof RubyArray) {
      RubyArray testVals = (RubyArray) receiver;
      for (int i = 0, n = testVals.getLength(); i < n; i++) {
        IRubyObject excType = (IRubyObject) testVals.eltInternal(i);
        if (!(excType instanceof RubyModule)) {
          throw context
              .getRuntime()
              .newTypeError("class or module required for rescue clause. Found: " + excType);
        }
        IRubyObject eqqVal = excType.callMethod(context, "===", value);
        if (eqqVal.isTrue()) {
          result.store(context, self, temp, eqqVal);
          return null;
        }
      }
      result.store(context, self, temp, context.getRuntime().newBoolean(false));
    } else {
      if (!(receiver instanceof RubyModule)) {
        throw context
            .getRuntime()
            .newTypeError("class or module required for rescue clause. Found: " + receiver);
      }
      result.store(context, self, temp, receiver.callMethod(context, "===", value));
    }

    return null;
  }
Ejemplo n.º 8
0
  @Override
  public Object interpret(
      ThreadContext context,
      DynamicScope currDynScope,
      IRubyObject self,
      Object[] temp,
      Block block) {
    Object receiver = array.retrieve(context, self, currDynScope, temp);

    // Don't call to_ary if we we have an array already and we are asked not to run to_ary on arrays
    if (dontToAryArrays.isTrue() && receiver instanceof RubyArray) {
      return receiver;
    } else {
      return RuntimeHelpers.aryToAry((IRubyObject) receiver);
    }
  }
Ejemplo n.º 9
0
 @Override
 public Object interpret(
     ThreadContext context,
     IRubyObject self,
     IRubyObject[] args,
     Block block,
     Object exception,
     Object[] temp) {
   // ENEBO: This seems like a lot of extra work...
   result.store(
       context,
       self,
       temp,
       context
           .getRuntime()
           .newBoolean(((IRubyObject) value.retrieve(context, self, temp)).isTrue()));
   return null;
 }
Ejemplo n.º 10
0
 @Override
 public void simplifyOperands(Map<Operand, Operand> valueMap, boolean force) {
   candidateObj = candidateObj.getSimplifiedOperand(valueMap, force);
 }
Ejemplo n.º 11
0
 public Instr cloneForInlining(InlinerInfo ii) {
   return new RescueEQQInstr(
       ii.getRenamedVariable(result), arg1.cloneForInlining(ii), arg2.cloneForInlining(ii));
 }
Ejemplo n.º 12
0
 @Override
 public void simplifyOperands(Map<Operand, Operand> valueMap, boolean force) {
   arg1 = arg1.getSimplifiedOperand(valueMap, force);
   arg2 = arg2.getSimplifiedOperand(valueMap, force);
 }
Ejemplo n.º 13
0
  public void setConstantValue(String constRef, Operand val) {
    if (val.isConstant()) _constMap.put(constRef, val);

    if (this instanceof IR_Module)
      ((IR_Module) this).getRootMethod().addInstr(new PUT_CONST_Instr(this, constRef, val));
  }
Ejemplo n.º 14
0
 @Override
 public Operand simplifyAndGetResult(Map<Operand, Operand> valueMap) {
   simplifyOperands(valueMap);
   Operand val = argument.getValue(valueMap);
   return val.fetchCompileTimeArrayElement(index, all);
 }
Ejemplo n.º 15
0
 @Override
 public Instr cloneForInlining(InlinerInfo ii) {
   return new IsTrueInstr(ii.getRenamedVariable(result), value.cloneForInlining(ii));
 }
Ejemplo n.º 16
0
 @Override
 public void simplifyOperands(Map<Operand, Operand> valueMap, boolean force) {
   value = value.getSimplifiedOperand(valueMap, force);
 }
Ejemplo n.º 17
0
 public Instr cloneForInlining(InlinerInfo ii) {
   return new MethodLookupInstr(
       ii.getRenamedVariable(result), (MethodHandle) methodHandle.cloneForInlining(ii));
 }
Ejemplo n.º 18
0
 public boolean versionMatches(
     ThreadContext context, DynamicScope currDynScope, IRubyObject self, Object[] temp) {
   IRubyObject receiver = (IRubyObject) candidateObj.retrieve(context, self, currDynScope, temp);
   // if (module.getGeneration() != expectedVersion) ... replace this instr with a direct jump
   return (receiver.getMetaClass().getGeneration() == expectedVersion);
 }
Ejemplo n.º 19
0
 @Override
 public Operand simplifyAndGetResult(IRScope scope, Map<Operand, Operand> valueMap) {
   simplifyOperands(valueMap, false);
   return dontToAryArrays.isTrue() && (array.getValue(valueMap) instanceof Array) ? array : null;
 }