use of suite.node.Int in project suite by stupidsing.
the class Amd64Parse method parseOpMem.
private Operand parseOpMem(Node[] m, int size) {
OpMem opMem = amd64.new OpMem();
opMem.size = size;
opMem.indexReg = -1;
opMem.baseReg = -1;
opMem.dispSize = 0;
for (Node component : scan(m[0], ".0 + .1")) if ((m = Suite.pattern(".0 * .1").match(component)) != null)
if (opMem.indexReg < 0) {
opMem.indexReg = amd64.regByName.get(m[0]).reg;
opMem.scale = ((Int) m[1]).number;
} else
Fail.t("bad operand");
else if (component instanceof Int)
if (opMem.dispSize == 0) {
opMem.disp = ((Int) component).number;
opMem.dispSize = 4;
} else
Fail.t("bad operand");
else if (opMem.baseReg < 0)
opMem.baseReg = amd64.regByName.get(component).reg;
else
Fail.t("bad operand");
return opMem;
}
use of suite.node.Int in project suite by stupidsing.
the class Amd64Parse method parseOperand.
public Operand parseOperand(Node node) {
Operand operand;
Node[] m;
if ((operand = amd64.registerByName.get(node)) != null)
return operand;
else if ((m = Suite.pattern("BYTE `.0`").match(node)) != null)
return parseOpMem(m, 1);
else if ((m = Suite.pattern("WORD `.0`").match(node)) != null)
return parseOpMem(m, 2);
else if ((m = Suite.pattern("DWORD `.0`").match(node)) != null)
return parseOpMem(m, 4);
else if ((m = Suite.pattern("`.0`").match(node)) != null)
return parseOpMem(m, 4);
else if (node instanceof Int) {
OpImm opImm = amd64.new OpImm();
opImm.imm = ((Int) node).number;
opImm.size = 4;
return opImm;
} else
return Fail.t("bad operand");
}
use of suite.node.Int in project suite by stupidsing.
the class SewingBinderImpl method binder.
public Bind_ binder(Node node) {
return new //
SwitchNode<Bind_>(//
node).applyIf(Atom.class, n -> {
return compileBindAtom(n);
}).applyIf(Int.class, n -> {
return compileBindInt(n);
}).applyIf(Reference.class, n -> {
int index = mapper().computeIndex(n);
return (be, n_) -> Binder.bind(n_, be.env.get(index), be.trail);
}).applyIf(Str.class, n -> {
return compileBindStr(n);
}).applyTree((operator, l, r) -> {
Clone_ f = cloner(node);
Bind_ c0 = binder(l);
Bind_ c1 = binder(r);
return (be, n) -> {
Node n_ = n.finalNode();
Tree t;
if (n_ instanceof Reference)
if (isBindTrees) {
be.trail.addBind((Reference) n_, f.apply(be.env));
return true;
} else
return false;
else
return //
(t = Tree.decompose(n_, operator)) != null && //
c0.test(be, t.getLeft()) && c1.test(be, t.getRight());
};
}).applyIf(Tuple.class, tuple -> {
Clone_ f = cloner(node);
Bind_[] cs = Read.from(tuple.nodes).map(this::binder).toArray(Bind_.class);
int length = cs.length;
return (be, n) -> {
Node n_ = n.finalNode();
if (n_ instanceof Tuple) {
Node[] nodes = ((Tuple) n_).nodes;
if (nodes.length == length) {
for (int i = 0; i < length; i++) if (!cs[i].test(be, nodes[i]))
return false;
return true;
} else
return false;
} else if (n_ instanceof Reference)
if (isBindTrees) {
be.trail.addBind((Reference) n_, f.apply(be.env));
return true;
} else
return false;
else
return false;
};
}).applyIf(Node.class, n -> {
Clone_ f = cloner(node);
return (be, n_) -> Binder.bind(n_, f.apply(be.env), be.trail);
}).result();
}
use of suite.node.Int in project suite by stupidsing.
the class Polynomial method format.
public Node format(Poly<N> poly) {
Express ex = new Express();
OpGroup add = ex.add;
OpGroup mul = ex.mul;
Int_Obj<Node> powerFun = p -> {
Node power = mul.identity();
for (int i = 0; i < p; i++) power = mul.apply(x, power);
return power;
};
Node sum = format_.apply(n0);
for (IntObjPair<N> pair : poly.streamlet().sortByKey(Integer::compare)) {
int p = pair.t0;
Node power = p < 0 ? mul.inverse(powerFun.apply(-p)) : powerFun.apply(p);
sum = add.apply(mul.apply(format_.apply(pair.t1), power), sum);
}
return sum;
}
use of suite.node.Int in project suite by stupidsing.
the class Grapher method save.
public void save(DataOutputStream dos) throws IOException {
int size = gns.size();
dos.writeInt(size);
dos.writeInt(id);
for (int index = 0; index < size; index++) {
GN gn = gns.get(index);
ReadType type = gn.type;
List<IntIntPair> children = gn.children;
dos.writeByte(type.value);
if (type == ReadType.TERM)
new //
SwitchNode<Node>(//
gn.terminal).doIf(Atom.class, n -> {
dos.writeByte((byte) 'a');
dos.writeUTF(n.name);
}).doIf(Int.class, n -> {
dos.writeByte((byte) 'i');
dos.writeInt(n.number);
}).doIf(Reference.class, n -> {
dos.writeByte((byte) 'r');
}).doIf(Str.class, n -> {
dos.writeByte((byte) 's');
dos.writeUTF(n.value);
}).nonNullResult();
else if (type == ReadType.TREE) {
dos.writeUTF(gn.op.getName());
dos.writeInt(children.get(0).t1 - index);
dos.writeInt(children.get(1).t1 - index);
} else if (type == ReadType.DICT || type == ReadType.TUPLE) {
dos.writeInt(children.size());
for (IntIntPair child : children) {
if (type == ReadType.DICT)
dos.writeInt(child.t0 - index);
dos.writeInt(child.t1 - index);
}
}
}
}
Aggregations