Search in sources :

Example 6 with BinderFactory

use of suite.lp.doer.BinderFactory 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

BinderFactory (suite.lp.doer.BinderFactory)6 Bind_ (suite.lp.doer.BinderFactory.Bind_)6 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Iterator (java.util.Iterator)4 List (java.util.List)4 Map (java.util.Map)4 Suite (suite.Suite)4 Mutable (suite.adt.Mutable)4 ListMultimap (suite.adt.map.ListMultimap)4 Pair (suite.adt.pair.Pair)4 IList (suite.immutable.IList)4 ProverConfig (suite.lp.Configuration.ProverConfig)4 CompileExpressionImpl (suite.lp.compile.impl.CompileExpressionImpl)4 Binder (suite.lp.doer.Binder)4 BindEnv (suite.lp.doer.BinderFactory.BindEnv)4 Cloner (suite.lp.doer.Cloner)4 Clone_ (suite.lp.doer.ClonerFactory.Clone_)4 Evaluate_ (suite.lp.doer.EvaluatorFactory.Evaluate_)4 Generalizer (suite.lp.doer.Generalizer)4