use of catdata.fql.decl.SigExp in project fql by CategoricalData.
the class TransChecker method visit.
@SuppressWarnings("unused")
@Override
public Pair<String, String> visit(FQLProgram env, Const e) {
InstExp src = env.insts.get(e.src);
if (src == null) {
throw new RuntimeException("Missing instance " + e.src);
}
InstExp dst = env.insts.get(e.dst);
if (dst == null) {
throw new RuntimeException("Missing instance " + e.src);
}
if (!(src instanceof InstExp.Const)) {
throw new RuntimeException(e.src + " is not a constant.");
}
if (!(dst instanceof InstExp.Const)) {
throw new RuntimeException(e.dst + " is not a constant.");
}
InstExp.Const src0 = (InstExp.Const) src;
InstExp.Const dst0 = (InstExp.Const) dst;
SigExp srct = src0.type(env);
SigExp dstt = dst0.type(env);
if (!srct.equals(dstt)) {
throw new RuntimeException("Instances not of same type on " + e + " are " + srct + " and " + dstt);
}
Signature sig = srct.toSig(env);
List<Pair<String, List<Pair<Object, Object>>>> bbb = e.objs;
try {
new Transform(new Instance(sig, src0.data), new Instance(sig, dst0.data), bbb);
} catch (FQLException fe) {
fe.printStackTrace();
throw new RuntimeException(fe.getLocalizedMessage());
}
return new Pair<>(e.src, e.dst);
}
use of catdata.fql.decl.SigExp in project fql by CategoricalData.
the class FQLParser method toSchema.
@SuppressWarnings({ "rawtypes", "unchecked" })
private static SigExp toSchema(Object o) {
try {
Tuple3<?, ?, ?> t = (Tuple3<?, ?, ?>) o;
Token z = (Token) t.b;
String y = z.toString();
switch(y) {
case "+":
return new SigExp.Plus(toSchema(t.a), toSchema(t.c));
case "*":
return new SigExp.Times(toSchema(t.a), toSchema(t.c));
case "^":
return new SigExp.Exp(toSchema(t.a), toSchema(t.c));
case "union":
return new Union(toSchema(t.a), toSchema(t.c));
default:
break;
}
} catch (RuntimeException cce) {
}
try {
org.jparsec.functors.Pair p = (org.jparsec.functors.Pair) o;
if (p.a.toString().equals("unit")) {
return new SigExp.One(new HashSet<>((Collection<String>) p.b));
} else if (p.a.toString().equals("opposite")) {
return new SigExp.Opposite(toSchema(p.b));
}
} catch (RuntimeException cce) {
}
try {
if (o.toString().equals("void")) {
return new SigExp.Zero();
} else if (o.toString().equals("?")) {
return new Unknown("?" + unknown_idx++);
}
throw new RuntimeException();
} catch (RuntimeException cce) {
}
try {
return toSchemaConst(o);
} catch (RuntimeException cce) {
}
return new SigExp.Var(o.toString());
}
use of catdata.fql.decl.SigExp in project fql by CategoricalData.
the class TransChecker method visit.
@Override
public Pair<String, String> visit(FQLProgram env, TT e) {
InstExp x = env.insts.get(e.obj);
if (x == null) {
throw new RuntimeException("Missing " + e.obj + " in " + e);
}
if (!(x instanceof One)) {
throw new RuntimeException(e.obj + " is not a unit: " + x);
}
// InstExp.One y = (InstExp.One) x;
InstExp z = env.insts.get(e.tgt);
if (z == null) {
throw new RuntimeException("Missing " + e.tgt + " in " + e);
}
SigExp xt = x.type(env);
SigExp yt = z.type(env);
if (!xt.equals(yt)) {
throw new RuntimeException("Instances have different types in " + e + ": " + xt + " and " + yt);
}
return new Pair<>(e.tgt, e.obj);
}
use of catdata.fql.decl.SigExp in project fql by CategoricalData.
the class TransChecker method visit.
@Override
public Pair<String, String> visit(FQLProgram env, External e) {
InstExp src = env.insts.get(e.src);
if (src == null) {
throw new RuntimeException("Missing instance " + e.src);
}
InstExp dst = env.insts.get(e.dst);
if (dst == null) {
throw new RuntimeException("Missing instance " + e.src);
}
if (!(src instanceof InstExp.External)) {
throw new RuntimeException(e.src + " is not external.");
}
if (!(dst instanceof InstExp.External)) {
throw new RuntimeException(e.dst + " is not external.");
}
InstExp.External src0 = (InstExp.External) src;
InstExp.External dst0 = (InstExp.External) dst;
SigExp srct = src0.type(env);
SigExp dstt = dst0.type(env);
if (!srct.equals(dstt)) {
throw new RuntimeException("Instances not of same type on " + e + " are " + srct + " and " + dstt);
}
return new Pair<>(e.src, e.dst);
}
use of catdata.fql.decl.SigExp in project fql by CategoricalData.
the class TransChecker method visit.
@Override
public Pair<String, String> visit(FQLProgram env, FF e) {
InstExp x = env.insts.get(e.obj);
if (x == null) {
throw new RuntimeException("Missing " + e.obj + " in " + e);
}
if (!(x instanceof Zero)) {
throw new RuntimeException(e.obj + " is not void: " + x);
}
// InstExp.One y = (InstExp.One) x;
InstExp z = env.insts.get(e.tgt);
if (z == null) {
throw new RuntimeException("Missing " + e.tgt + " in " + e);
}
SigExp xt = x.type(env);
SigExp yt = z.type(env);
if (!xt.equals(yt)) {
throw new RuntimeException("Instances have different types in " + e + ": " + xt + " and " + yt);
}
return new Pair<>(e.obj, e.tgt);
}
Aggregations