Beispiel #1
0
  public Operand[] cloneCallArgs(InlinerInfo ii) {
    int i = 0;
    Operand[] clonedArgs = new Operand[arguments.length];

    for (Operand a : arguments) {
      clonedArgs[i++] = a.cloneForInlining(ii);
    }

    return clonedArgs;
  }
Beispiel #2
0
  @Override
  public Object interpret(
      ThreadContext context,
      DynamicScope currDynScope,
      IRubyObject self,
      Object[] temp,
      Block block) {
    String newNameString = newName.retrieve(context, self, currDynScope, temp).toString();
    String oldNameString = oldName.retrieve(context, self, currDynScope, temp).toString();

    context.runtime.getGlobalVariables().alias(newNameString, oldNameString);
    return null;
  }
Beispiel #3
0
  protected Block prepareBlock(
      ThreadContext context, IRubyObject self, DynamicScope currDynScope, Object[] temp) {
    if (closure == null) return Block.NULL_BLOCK;

    Object value = closure.retrieve(context, self, currDynScope, temp);

    Block block;
    if (value instanceof Block) {
      block = (Block) value;
    } else if (value instanceof RubyProc) {
      block = ((RubyProc) value).getBlock();
    } else if (value instanceof RubyMethod) {
      block = ((RubyProc) ((RubyMethod) value).to_proc(context, null)).getBlock();
    } else if ((value instanceof IRubyObject) && ((IRubyObject) value).isNil()) {
      block = Block.NULL_BLOCK;
    } else if (value instanceof IRubyObject) {
      block =
          ((RubyProc)
                  TypeConverter.convertToType(
                      (IRubyObject) value, context.getRuntime().getProc(), "to_proc", true))
              .getBlock();
    } else {
      throw new RuntimeException(
          "Unhandled case in CallInstr:prepareBlock.  Got block arg: " + value);
    }

    // ENEBO: This came from duplicated logic from SuperInstr....
    // Blocks passed in through calls are always normal blocks, no matter where they came from
    block.type = Block.Type.NORMAL;

    return block;
  }
 private Object cache(
     ThreadContext context,
     DynamicScope currDynScope,
     IRubyObject self,
     Object[] temp,
     Ruby runtime,
     Object constant) {
   StaticScope staticScope =
       (StaticScope) definingScope.retrieve(context, self, currDynScope, temp);
   RubyModule object = runtime.getObject();
   // SSS FIXME: IRManager objects dont have a static-scope yet, so this hack of looking up the
   // module right away
   // This IR needs fixing!
   constant =
       (staticScope == null)
           ? object.getConstant(constName)
           : staticScope.getConstantInner(runtime, constName, object);
   if (constant == null) {
     constant = UndefinedValue.UNDEFINED;
   } else {
     // recache
     generation = runtime.getConstantInvalidator().getData();
     cachedConstant = constant;
   }
   return constant;
 }
  @Override
  public Object interpret(
      ThreadContext context,
      DynamicScope currDynScope,
      IRubyObject self,
      Object[] temp,
      Block block) {
    // SSS FIXME: This is ugly and needs fixing.  Is there another way of capturing this info?
    RubyModule containerModule =
        (candidateScope == null) ? null : candidateScope.getStaticScope().getModule();
    if (containerModule == null)
      containerModule = ASTInterpreter.getClassVariableBase(context, context.getRuntime());
    if (containerModule == null && object != null) {
      IRubyObject arg = (IRubyObject) object.retrieve(context, self, currDynScope, temp);
      // SSS: What is the right thing to do here?
      containerModule =
          arg
              .getMetaClass(); // (arg instanceof RubyClass) ? ((RubyClass)arg).getRealClass() :
                               // arg.getType();
    }

    if (containerModule == null)
      throw context.getRuntime().newTypeError("no class/module to define class variable");

    return containerModule;
  }
 @Override
 public Instr cloneForInlining(InlinerInfo ii) {
   return new GetClassVarContainerModuleInstr(
       ii.getRenamedVariable(result),
       candidateScope,
       object == null ? null : object.cloneForInlining(ii));
 }
 @Override
 public Instr cloneForInlining(InlinerInfo ii) {
   return new InheritanceSearchConstInstr(
       ii.getRenamedVariable(result),
       currentModule.cloneForInlining(ii),
       constName,
       noPrivateConsts);
 }
Beispiel #8
0
  @Override
  public void simplifyOperands(Map<Operand, Operand> valueMap, boolean force) {
    // FIXME: receiver should never be null (checkArity seems to be one culprit)
    if (receiver != null) receiver = receiver.getSimplifiedOperand(valueMap, force);
    methAddr = (MethAddr) methAddr.getSimplifiedOperand(valueMap, force);
    for (int i = 0; i < arguments.length; i++) {
      arguments[i] = arguments[i].getSimplifiedOperand(valueMap, force);
    }

    // Recompute containsSplat flag
    containsSplat = containsSplat(arguments);

    if (closure != null) closure = closure.getSimplifiedOperand(valueMap, force);
    flagsComputed = false; // Forces recomputation of flags

    // recompute whenever instr operands change! (can this really change though?)
    callSite = getCallSiteFor(callType, methAddr);
  }
Beispiel #9
0
  public Block prepareBlock(
      ThreadContext context,
      IRubyObject self,
      StaticScope currScope,
      DynamicScope currDynScope,
      Object[] temp) {
    if (closure == null) return Block.NULL_BLOCK;

    return IRRuntimeHelpers.getBlockFromObject(
        context, closure.retrieve(context, self, currScope, currDynScope, temp));
  }
Beispiel #10
0
  @Override
  public Object interpret(
      ThreadContext context,
      DynamicScope dynamicScope,
      IRubyObject self,
      Object[] temp,
      Block block) {
    IRubyObject object = (IRubyObject) receiver.retrieve(context, self, dynamicScope, temp);
    IRubyObject[] values = prepareArguments(context, self, arguments, dynamicScope, temp);
    Block preparedBlock = prepareBlock(context, self, dynamicScope, temp);

    return callSite.call(context, self, object, values, preparedBlock);
  }
Beispiel #11
0
  protected IRubyObject[] prepareArgumentsComplex(
      ThreadContext context,
      IRubyObject self,
      Operand[] args,
      StaticScope currScope,
      DynamicScope currDynScope,
      Object[] temp) {
    // SSS: For regular calls, IR builder never introduces splats except as the first argument
    // But when zsuper is converted to SuperInstr with known args, splats can appear anywhere
    // in the list.  So, this looping handles both these scenarios, although if we wanted to
    // optimize for CallInstr which has splats only in the first position, we could do that.
    List<IRubyObject> argList = new ArrayList<IRubyObject>();
    for (Operand arg : args) {
      IRubyObject rArg = (IRubyObject) arg.retrieve(context, self, currScope, currDynScope, temp);
      if (arg instanceof Splat) {
        argList.addAll(Arrays.asList(((RubyArray) rArg).toJavaArray()));
      } else {
        argList.add(rArg);
      }
    }

    return argList.toArray(new IRubyObject[argList.size()]);
  }
  @Override
  public Object interpret(
      ThreadContext context,
      StaticScope currScope,
      DynamicScope currDynScope,
      IRubyObject self,
      Object[] temp) {
    Ruby runtime = context.runtime;
    Object cmVal = currentModule.retrieve(context, self, currScope, currDynScope, temp);
    RubyModule module;
    if (cmVal instanceof RubyModule) {
      module = (RubyModule) cmVal;
    } else {
      throw runtime.newTypeError(cmVal + " is not a type/class");
    }
    Object constant = cachedConstant; // Store to temp so it does null out on us mid-stream
    if (!isCached(runtime, module, constant)) constant = cache(runtime, module);

    return constant;
  }
Beispiel #13
0
 private static Object retrieveOp(
     Operand r,
     ThreadContext context,
     IRubyObject self,
     DynamicScope currDynScope,
     Object[] temp) {
   Object res;
   if (r instanceof Self) {
     return self;
   } else if (r instanceof TemporaryVariable) {
     res = temp[((TemporaryVariable) r).offset];
     return res == null ? context.nil : res;
   } else if (r instanceof LocalVariable) {
     LocalVariable lv = (LocalVariable) r;
     res = currDynScope.getValue(lv.getLocation(), lv.getScopeDepth());
     return res == null ? context.nil : res;
   } else {
     return r.retrieve(context, self, currDynScope, temp);
   }
 }
  private Object cache(
      ThreadContext context,
      StaticScope currScope,
      DynamicScope currDynScope,
      IRubyObject self,
      Object[] temp) {
    StaticScope staticScope =
        (StaticScope) definingScope.retrieve(context, self, currScope, currDynScope, temp);

    IRubyObject constant = staticScope.getConstantInner(constName);

    if (constant == null) {
      constant = UndefinedValue.UNDEFINED;
    } else {
      // recache
      Invalidator invalidator = context.runtime.getConstantInvalidator(constName);
      cache = new ConstantCache(constant, invalidator.getData(), invalidator);
    }

    return constant;
  }
 @Override
 public void simplifyOperands(Map<Operand, Operand> valueMap, boolean force) {
   currentModule = currentModule.getSimplifiedOperand(valueMap, force);
 }
Beispiel #16
0
 // FIXME: Potentially some of these values should not need to have their type prefixed.
 public void encode(Operand operand) {
   encoder.encode(operand.getOperandType().getCoded());
   operand.visit(this);
 }
 @Override
 public void simplifyOperands(Map<Operand, Operand> valueMap, boolean force) {
   definingScope = definingScope.getSimplifiedOperand(valueMap, force);
 }
Beispiel #18
0
 @Override
 public Instr cloneForInlining(InlinerInfo ii) {
   return new GVarAliasInstr(newName.cloneForInlining(ii), oldName.cloneForInlining(ii));
 }
Beispiel #19
0
 @Override
 public void simplifyOperands(Map<Operand, Operand> valueMap, boolean force) {
   oldName = oldName.getSimplifiedOperand(valueMap, force);
   newName = newName.getSimplifiedOperand(valueMap, force);
 }
 @Override
 public Instr clone(CloneInfo ii) {
   return new LexicalSearchConstInstr(
       ii.getRenamedVariable(result), definingScope.cloneForInlining(ii), constName);
 }
 @Override
 public void simplifyOperands(Map<Operand, Operand> valueMap, boolean force) {
   if (object != null) object = object.getSimplifiedOperand(valueMap, force);
 }