Package org.eclipse.imp.pdb.facts

Examples of org.eclipse.imp.pdb.facts.IMapWriter


          int dn = ((IInteger) w[0]).intValue(), nm = ((IInteger) w[1])
              .intValue();
          b[i] = vf.rational(dn, nm);
        } else if (found.getFieldType(i).isMap()) {
          IValue[] g = toArray(v);
          IMapWriter w = vf.mapWriter();
          for (int j = 0; j < g.length; j++) {
            w.put(((IList) g[j]).get(0), ((IList) g[j]).get(1));
          }
          b[i] = w.done();
        } else if (found.getFieldType(i).isList())
          b[i] = computed[i];
        else
          break;
      } else if (computed[i].getType().isString()) {
View Full Code Here


    }
    if (funname.equals("#set")) {
      return a.length == 0 ? vf.set(tf.valueType()) : vf.set(a);
    }
    if (funname.equals("#map")) {
      IMapWriter w = vf.mapWriter();
      for (int i = 0; i < a.length; i++) {
        w.put(((ITuple) a[i]).get(0), ((ITuple) a[i]).get(1));
      }
      return w.done();
    }
    if (funname.equals("#datetime"))
      return dateTime(((IString) a[0]).getValue());

    Type computed = tf.tupleType(b);
View Full Code Here

      ISetWriter w = vf.setWriter(expected.getElementType());
      w.insert(terms);
      return w.done();
    } else if(base.isMap()){
      //Type tt = expected.getElementType();
      IMapWriter w = vf.mapWriter(expected); //tt.getFieldType(0), tt.getFieldType(1));
      for (int i = terms.length - 1; i >= 0; i--) {
        w.put(((ITuple) terms[i]).get(0), ((ITuple)terms[i]).get(1));
      }
      return w.done();
    }
    throw new FactParseError("Unexpected type " + expected,
        reader.getPosition());
  }
View Full Code Here

    IValue[] args = new IValue[argValues.length + 1];
    int i = 0;
    for(IValue argValue : argValues) {
      args[i++] = argValue;
    }
    IMapWriter kwargs = rvm.vf.mapWriter();
    if(keyArgValues != null) {
      for(Entry<String, IValue> entry : keyArgValues.entrySet()) {
        kwargs.put(rvm.vf.string(entry.getKey()), keyArgValues.get(entry.getValue()));
      }
    }
    args[i] = kwargs.done();
    IValue rval = rvm.executeFunction(this, args);
    return ResultFactory.makeResult(rval.getType(), rval, rvm.getEvaluatorContext())// TODO: remove CTX
  }
View Full Code Here

  @SuppressWarnings("deprecation")
  @Override
  public IValue visitMap(Type type) throws IOException {
    // [ [k, v], ... ]
    IMapWriter w = vf.mapWriter(keyType(type), valueType(type));
    List l = (List)stack.peek();
    for (Object e: l) {
      List pair = (List)e;
      stack.push(pair.get(0));
      IValue k = read(keyType(type));
      stack.pop();
      stack.push(pair.get(1));
      IValue v = read(valueType(type));
      stack.pop();
      w.put(k, v);
    }
    return w.done();
  }
View Full Code Here

        while (entries.hasNext()) {
          Entry<IValue, IValue> ent = entries.next();
          newEntries.put(ent.getKey().accept(this), ent.getValue().accept(this));
        }

        IMapWriter writer = vf.mapWriter(calcLub(newEntries.keySet()), calcLub(newEntries.values()));
        writer.putAll(newEntries);
        return writer.done();
      }

      @Override
      public IValue visitConstructor(IConstructor o)
          throws RuntimeException {
View Full Code Here

            stack.pop();
            return vf.constructor(JSON_ivalue, v);
          }
        }
      }
      IMapWriter w = vf.mapWriter();
      for (Object k: map.keySet()) {
        w.put(vf.string((String) k), convertToIValue(map.get(k)))
      }
      return vf.constructor(JSON_object, w.done());
    }
    if (obj instanceof List) {
      IListWriter w = vf.listWriter();
      for (Object k: (List)obj) {
        w.append(convertToIValue(k))
      }
      return vf.constructor(JSON_array, w.done());
    }
    if (obj instanceof Double) {
      return vf.constructor(JSON_null);
     
    }
View Full Code Here

            throw RuntimeExceptionFactory.io(values.string(e.getMessage()), null, null);
        }
      }
    }

    IMapWriter mw = values.mapWriter(strType, types.relType(strType, strType));

    for (Map.Entry<java.lang.String, ISetWriter> entry : table.entrySet()) {
      mw.insert(values.tuple(values.string(entry.getKey()), entry.getValue().done()));
    }
    return mw.done();
  }
View Full Code Here

          throw RuntimeExceptionFactory.io(values.string(e.getMessage()), ctx.getCurrentAST(), ctx.getStackTrace());
        }
      }
    }
   
    IMapWriter mr = values.mapWriter();
   
    for (Map.Entry<java.lang.String, Type> entry : table.entrySet()) {
      Type t = entry.getValue();
      mr.put(values.string(entry.getKey()),
             ((IConstructor) new TypeReifier(values).typeToValue(types.relType(t.getFieldType(0), t.getFieldType(1)), ctx).getValue()))
    }
    return mr.done();
  }
View Full Code Here

        // interesting operation, sets the image of all keys to one default
        if (!repl.getType().isSubtypeOf(type.getValueType())) {
          throw new UnexpectedType(type.getValueType(), repl.getType(), ctx.getCurrentAST());
        }

        IMapWriter w = getValueFactory().mapWriter();

        for (IValue key : value) {
          w.put(key, repl.getValue());
        }

        return makeResult(type, w.done(), ctx);
      }
    }
   
    throw new UndeclaredFieldException(type, name);
  }
View Full Code Here

TOP

Related Classes of org.eclipse.imp.pdb.facts.IMapWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.