Search in sources :

Example 11 with Prototype

use of suite.lp.kb.Prototype in project suite by stupidsing.

the class SewingProverImpl method compileCpsCallPredicate.

private Cps compileCpsCallPredicate(BinderFactory bf, Node node, Cps cpsx) {
    Prototype prototype = Prototype.of(node);
    if (rules.containsKey(prototype)) {
        Clone_ f = bf.cloner(node);
        Cps cps;
        if (isHasCutByPrototype.get(prototype)) {
            Mutable<Trampoline> mtr = getTrampolineByPrototype(prototype);
            Trampoline rem = rt -> {
                rt.cont(cpsx);
                return fail;
            };
            cps = rt -> {
                IList<Trampoline> rems = rt.rems;
                rt.rems = IList.cons(fail, IList.end());
                new Runtime(rt, rt_ -> {
                    rt_.query = f.apply(rt.env);
                    rt_.rems = rems;
                    rt_.pushRem(rem);
                    return mtr.get();
                }).trampoline();
                return null;
            };
        } else {
            Mutable<Cps> mcps = getCpsByPrototype(prototype);
            cps = rt -> {
                Cps cps0 = rt.cps;
                rt.cps = rt_ -> {
                    rt.cps = cps0;
                    return cpsx;
                };
                rt.query = f.apply(rt.env);
                return mcps.get();
            };
        }
        return cps;
    } else
        return Fail.t("cannot find predicate " + prototype);
}
Also used : Prover(suite.lp.doer.Prover) BindEnv(suite.lp.doer.BinderFactory.BindEnv) BuiltinPredicate(suite.lp.predicate.PredicateUtil.BuiltinPredicate) LogUtil(suite.os.LogUtil) Mutable(suite.adt.Mutable) BinderFactory(suite.lp.doer.BinderFactory) Node(suite.node.Node) ProverConstant(suite.lp.doer.ProverConstant) VariableMapper(suite.lp.sewing.VariableMapper) Suspend(suite.node.Suspend) Map(java.util.Map) Prototype(suite.lp.kb.Prototype) RuleSet(suite.lp.kb.RuleSet) Generalizer(suite.lp.doer.Generalizer) Bind_(suite.lp.doer.BinderFactory.Bind_) Cloner(suite.lp.doer.Cloner) Object_(suite.util.Object_) SystemPredicates(suite.lp.predicate.SystemPredicates) Tree(suite.node.Tree) Pair(suite.adt.pair.Pair) Friends.max(suite.util.Friends.max) List(java.util.List) Clone_(suite.lp.doer.ClonerFactory.Clone_) ListMultimap(suite.adt.map.ListMultimap) As(suite.streamlet.As) Int(suite.node.Int) TreeUtil(suite.node.util.TreeUtil) ProverConfig(suite.lp.Configuration.ProverConfig) Read(suite.streamlet.Read) Rule(suite.lp.kb.Rule) HashMap(java.util.HashMap) IList(suite.immutable.IList) ArrayList(java.util.ArrayList) Data(suite.node.Data) Formatter(suite.node.io.Formatter) String_(suite.util.String_) Rethrow(suite.util.Rethrow) Binder(suite.lp.doer.Binder) Tuple(suite.node.Tuple) Reference(suite.node.Reference) Suite(suite.Suite) SuiteException(suite.node.util.SuiteException) Iterator(java.util.Iterator) CompileExpressionImpl(suite.lp.compile.impl.CompileExpressionImpl) Source(suite.util.FunUtil.Source) TermOp(suite.node.io.TermOp) List_(suite.util.List_) Evaluate_(suite.lp.doer.EvaluatorFactory.Evaluate_) Rewrite(suite.node.util.Rewrite) Streamlet(suite.streamlet.Streamlet) Atom(suite.node.Atom) Sink(suite.util.FunUtil.Sink) ProverFactory(suite.lp.doer.ProverFactory) Env(suite.lp.sewing.Env) Fail(suite.util.Fail) Prototype(suite.lp.kb.Prototype) Clone_(suite.lp.doer.ClonerFactory.Clone_)

Aggregations

Prototype (suite.lp.kb.Prototype)11 Node (suite.node.Node)10 Atom (suite.node.Atom)7 Generalizer (suite.lp.doer.Generalizer)6 Reference (suite.node.Reference)6 Tree (suite.node.Tree)6 TermOp (suite.node.io.TermOp)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Suite (suite.Suite)5 Pair (suite.adt.pair.Pair)5 Binder (suite.lp.doer.Binder)5 Rule (suite.lp.kb.Rule)5 Read (suite.streamlet.Read)5 Fail (suite.util.Fail)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Prover (suite.lp.doer.Prover)4 RuleSet (suite.lp.kb.RuleSet)4 Iterator (java.util.Iterator)3