コード例 #1
0
ファイル: TypeApp.java プロジェクト: brbaker/mesh
  /** internal reality checks on param/arg kinds */
  private boolean checkKindAgreement(final Type abs, final Type argDeref) {
    final Kind absKind = abs.getKind();

    if (!(absKind instanceof ArrowKind)) {
      Session.error(
          loc,
          "internal error: abs {0} has non-lambda kind {1} in type app {2}",
          abs.dump(),
          absKind.dump(),
          dump());

      return false;
    }

    final Kind paramKind = ((ArrowKind) absKind).getParamKind();
    final Kind argKind = argDeref.getKind();

    if (!paramKind.equals(argKind)) {
      Session.error(
          loc,
          "internal error: param kind {0} incompatible with arg kind {1} in type app {2}",
          paramKind.dump(),
          argKind.dump(),
          dump());

      return false;
    }

    return true;
  }
コード例 #2
0
ファイル: TypeApp.java プロジェクト: brbaker/mesh
  public Type eval() {
    if (reduced != null) return reduced;

    if (inEval) return this;

    final Type baseEval = base.deref().eval();
    final Type argEval = arg.deref().eval();

    if (!(baseEval instanceof TypeCons))
      // error has been raised
      return this;

    final TypeCons cons = (TypeCons) baseEval;

    final Type body = cons.getBody();
    if (body == null) return reduced(baseEval, argEval);

    // check base abs param kind against arg kind
    if (!checkKindAgreement(cons, argEval))
      // error has been raised
      return this;

    // evaluate by building param->arg subst map and
    // applying it to body term

    final SubstMap argMap = new SubstMap();

    final Collection<TypeParam> params = body.getParams().values();

    if (params.size() == 1) {
      final TypeParam param = params.iterator().next();
      assert param.getTypeScope() == body : "nope";

      argMap.put(param, argEval);
    } else {
      if (!(argEval instanceof TypeTuple)) assert false;

      final Iterator<Type> argList = ((TypeTuple) argEval).getMembers().iterator();

      for (final TypeParam param : params) {
        assert param.getTypeScope() == body : "nope";
        argMap.put(param, argList.next());
      }
    }

    final Type bodySubst = new TypeApplier(body, argMap).apply();

    // evaluate body with args substituted for params
    inEval = true;
    reduced = bodySubst.eval();
    inEval = false;

    if (Session.isDebug())
      Session.debug(
          body.getLoc(), "eval {0}({1}) => {2}", body.dump(), argMap.dump(), reduced.dump());

    return reduced;
  }
コード例 #3
0
ファイル: _accept.java プロジェクト: brbaker/mesh
  public static Tuple invoke(final Object arg0, final Lambda handler) {
    final java.net.ServerSocket serverSocket = (java.net.ServerSocket) arg0;

    try {
      final Socket requestSocket = serverSocket.accept();

      final InputStream is = requestSocket.getInputStream();
      final DataOutputStream os = new DataOutputStream(requestSocket.getOutputStream());

      final StringBuilder sb = new StringBuilder();
      final Reader reader = new InputStreamReader(is);
      final int BUFSIZE = 8192;
      final char chars[] = new char[BUFSIZE];
      int bytesRead;
      do {
        bytesRead = reader.read(chars, 0, BUFSIZE);
        if (bytesRead > 0) sb.append(chars, 0, bytesRead);
      } while (bytesRead == BUFSIZE && (chars[BUFSIZE - 1] != '\n' || chars[BUFSIZE - 2] != '\n'));

      final String in = sb.toString();

      if (Session.isDebug()) Session.debug("read {0}", in);

      final String out = (String) handler.apply(in);

      os.writeUTF(out);
      os.flush();

      is.close();
      os.close();
      requestSocket.close();

    } catch (IOException e) {
      if (!e.getMessage().toLowerCase().equals("socket closed")) System.out.println(e);
    }

    return Tuple.UNIT;
  }
コード例 #4
0
ファイル: TypeParam.java プロジェクト: bhosmer/mesh
 public SubstMap subsume(final Loc loc, final Type other, final TypeEnv env) {
   Session.error(loc, "internal error: TypeParam.subsume()");
   return null;
 }