示例#1
0
文件: P6num.java 项目: gerdr/nqp
 public SixModelObject type_object_for(ThreadContext tc, SixModelObject HOW) {
   STable st = new STable(this, HOW);
   SixModelObject obj = new TypeObject();
   obj.st = st;
   st.WHAT = obj;
   return st.WHAT;
 }
示例#2
0
文件: P6num.java 项目: gerdr/nqp
 public void serialize_inlined(
     ThreadContext tc, STable st, SerializationWriter writer, String prefix, SixModelObject obj) {
   try {
     writer.writeNum((double) obj.getClass().getField(prefix).get(obj));
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
示例#3
0
  /* Explodes any flattening parts. Creates and puts in place a new callsite
   * and enlarged-as-needed argument arrays.
   */
  public CallSiteDescriptor explodeFlattening(CallFrame cf, Object[] oldArgs) {
    ArrayList<Byte> newFlags = new ArrayList<Byte>();
    ArrayList<Object> newArgs = new ArrayList<Object>();
    ArrayList<String> newNames = new ArrayList<String>();
    int oldArgsIdx = 0;
    int oldNameIdx = 0;

    for (byte af : argFlags) {
      switch (af) {
        case ARG_OBJ | ARG_FLAT:
          SixModelObject flatArray = (SixModelObject) oldArgs[oldArgsIdx++];
          int prim = flatArray.st.REPR.get_value_storage_spec(cf.tc, flatArray.st).boxed_primitive;
          long elems = flatArray.elems(cf.tc);
          for (long i = 0; i < elems; i++) {
            if (prim == StorageSpec.BP_NONE) {
              newArgs.add(flatArray.at_pos_boxed(cf.tc, i));
              newFlags.add(ARG_OBJ);
            } else {
              flatArray.at_pos_native(cf.tc, i);
              switch (prim) {
                case StorageSpec.BP_INT:
                  newArgs.add(cf.tc.native_i);
                  newFlags.add(ARG_INT);
                  break;
                case StorageSpec.BP_NUM:
                  newArgs.add(cf.tc.native_n);
                  newFlags.add(ARG_NUM);
                  break;
                case StorageSpec.BP_STR:
                  newArgs.add(cf.tc.native_s);
                  newFlags.add(ARG_STR);
                  break;
                default:
                  throw ExceptionHandling.dieInternal(cf.tc, "Unknown boxed primitive");
              }
            }
          }
          break;
        case ARG_OBJ | ARG_FLAT | ARG_NAMED:
          SixModelObject flatHash = (SixModelObject) oldArgs[oldArgsIdx++];
          if (flatHash instanceof VMHashInstance) {
            HashMap<String, SixModelObject> storage = ((VMHashInstance) flatHash).storage;
            for (String key : storage.keySet()) {
              newNames.add(key);
              newArgs.add(storage.get(key));
              newFlags.add((byte) (ARG_OBJ | ARG_NAMED));
            }
          } else {
            throw ExceptionHandling.dieInternal(
                cf.tc,
                "Flattening named argument must have VMHash REPR instead of "
                    + flatHash.st.REPR.name);
          }
          break;
        case ARG_OBJ | ARG_NAMED:
        case ARG_INT | ARG_NAMED:
        case ARG_NUM | ARG_NAMED:
        case ARG_STR | ARG_NAMED:
          newArgs.add(oldArgs[oldArgsIdx++]);
          newNames.add(names[oldNameIdx++]);
          newFlags.add(af);
          break;
        default:
          newArgs.add(oldArgs[oldArgsIdx++]);
          newFlags.add(af);
      }
    }

    byte[] newFlagsArr = new byte[newFlags.size()];
    for (int i = 0; i < newFlagsArr.length; i++) newFlagsArr[i] = newFlags.get(i);
    String[] newNamesArr = new String[newNames.size()];
    for (int i = 0; i < newNamesArr.length; i++) newNamesArr[i] = newNames.get(i);
    CallSiteDescriptor exploded = new CallSiteDescriptor(newFlagsArr, newNamesArr);

    Object[] args = new Object[newArgs.size()];
    for (int i = 0; i < newArgs.size(); i++) args[i] = newArgs.get(i);
    cf.tc.flatArgs = args;

    return exploded;
  }