Search in sources :

Example 16 with Int

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;
}
Also used : Node(suite.node.Node) OpMem(suite.assembler.Amd64.OpMem) Int(suite.node.Int)

Example 17 with Int

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");
}
Also used : OpImm(suite.assembler.Amd64.OpImm) Operand(suite.assembler.Amd64.Operand) Node(suite.node.Node) Int(suite.node.Int)

Example 18 with Int

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();
}
Also used : Reference(suite.node.Reference) Read(suite.streamlet.Read) Atom(suite.node.Atom) Binder(suite.lp.doer.Binder) SwitchNode(suite.node.io.SwitchNode) Int(suite.node.Int) Tuple(suite.node.Tuple) BinderFactory(suite.lp.doer.BinderFactory) Str(suite.node.Str) Tree(suite.node.Tree) Node(suite.node.Node) Reference(suite.node.Reference) SwitchNode(suite.node.io.SwitchNode) Node(suite.node.Node) Tree(suite.node.Tree) SwitchNode(suite.node.io.SwitchNode) Atom(suite.node.Atom) Tuple(suite.node.Tuple)

Example 19 with Int

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;
}
Also used : Ring(suite.math.sym.Sym.Ring) Predicate(java.util.function.Predicate) Pattern(suite.BindArrayUtil.Pattern) IntObjStreamlet(suite.primitive.streamlet.IntObjStreamlet) OpGroup(suite.math.sym.Express.OpGroup) IntObjMap(suite.primitive.adt.map.IntObjMap) Fun(suite.util.FunUtil.Fun) Node(suite.node.Node) Opt(suite.adt.Opt) Iterate(suite.util.FunUtil.Iterate) Int_Obj(suite.primitive.IntPrimitives.Int_Obj) Fun2(suite.util.FunUtil2.Fun2) Obj_Int(suite.primitive.IntPrimitives.Obj_Int) IntObjPair(suite.primitive.adt.pair.IntObjPair) Fixie(suite.adt.pair.Fixie) Fixie3(suite.adt.pair.Fixie_.Fixie3) As(suite.streamlet.As) SwitchNode(suite.node.io.SwitchNode) Int(suite.node.Int) OpGroup(suite.math.sym.Express.OpGroup) Node(suite.node.Node) SwitchNode(suite.node.io.SwitchNode)

Example 20 with Int

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);
            }
        }
    }
}
Also used : DataInputStream(java.io.DataInputStream) Read(suite.streamlet.Read) HashMap(java.util.HashMap) Deque(java.util.Deque) ArrayList(java.util.ArrayList) Node(suite.node.Node) HashSet(java.util.HashSet) ProverConstant(suite.lp.doer.ProverConstant) DataOutputStream(java.io.DataOutputStream) Map(java.util.Map) IdentityKey(suite.adt.IdentityKey) Binder(suite.lp.doer.Binder) Tuple(suite.node.Tuple) Dict(suite.node.Dict) Reference(suite.node.Reference) Trail(suite.lp.Trail) IntIntPair(suite.primitive.adt.pair.IntIntPair) Set(java.util.Set) IOException(java.io.IOException) NodeRead(suite.node.io.Rewrite_.NodeRead) NodeHead(suite.node.io.Rewrite_.NodeHead) IntObjMap(suite.primitive.adt.map.IntObjMap) Tree(suite.node.Tree) Objects(java.util.Objects) Pair(suite.adt.pair.Pair) List(java.util.List) Atom(suite.node.Atom) Entry(java.util.Map.Entry) As(suite.streamlet.As) ArrayDeque(java.util.ArrayDeque) Int(suite.node.Int) Fail(suite.util.Fail) Str(suite.node.Str) ReadType(suite.node.io.Rewrite_.ReadType) ReadType(suite.node.io.Rewrite_.ReadType) Reference(suite.node.Reference) Atom(suite.node.Atom) IntIntPair(suite.primitive.adt.pair.IntIntPair)

Aggregations

Int (suite.node.Int)24 Node (suite.node.Node)22 Reference (suite.node.Reference)16 Tree (suite.node.Tree)16 Atom (suite.node.Atom)12 Pair (suite.adt.pair.Pair)10 ArrayList (java.util.ArrayList)9 Map (java.util.Map)8 Str (suite.node.Str)8 Tuple (suite.node.Tuple)8 List (java.util.List)7 Binder (suite.lp.doer.Binder)7 Read (suite.streamlet.Read)7 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)6 Set (java.util.Set)6 Dict (suite.node.Dict)6 Fail (suite.util.Fail)6 ArrayDeque (java.util.ArrayDeque)5 Entry (java.util.Map.Entry)5