def impl_if(engine, heap, rule, if_clause, then_clause, scont, fcont, fcont_after_condition=None): if fcont_after_condition is None: fcont_after_condition = fcont scont = continuation.BodyContinuation(engine, rule, scont, then_clause) scont = IfScopeNotifier(engine, scont, fcont, fcont_after_condition) newscont = continuation.BodyContinuation(engine, rule, scont, if_clause) return newscont, fcont, heap
def impl_findall(engine, heap, rule, template, goal, bag, scont, fcont): newheap = heap.branch() collector = FindallContinuation(engine, template, heap, scont) newscont = continuation.BodyContinuation(engine, rule, collector, goal) fcont = DoneWithFindallContinuation(engine, scont, fcont, heap, collector, bag) return newscont, fcont, newheap
def impl_catch(engine, heap, rule, goal, catcher, recover, scont, fcont): scont = continuation.CatchingDelimiter(engine, rule, scont, fcont, catcher, recover, heap) scont = continuation.CutScopeNotifier(engine, scont, fcont) scont = continuation.BodyContinuation(engine, rule, scont, goal) #continuation.view(scont, fcont, heap) return scont, fcont, heap.branch()
def impl_and(engine, heap, rule, call1, call2, scont, fcont, sister_rule = None): if not isinstance(call2, term.Var) and not isinstance(call2, term.Callable): return error.throw_type_error('callable', call2) scont = continuation.BodyContinuation(engine, rule, scont, call2) scont.parent_rule = rule scont.from_and = True return engine.call(call1, rule, scont, fcont, heap, 0, rule, sister_rule)
def continue_arg(Choice, engine, scont, fcont, heap, varnum, num, temarg, vararg, rule): if num < temarg.argument_count() - 1: fcont = Choice(engine, scont, fcont, heap, varnum, num + 1, temarg, vararg, rule) heap = heap.branch() scont = continuation.BodyContinuation( engine, rule, scont, term.Callable.build("=", [vararg, temarg.argument_at(num)])) varnum.unify(term.Number(num + 1), heap) return scont, fcont, heap
def impl_or(engine, heap, rule, call1, call2, scont, fcont): # sucks a bit to have to special-case A -> B ; C here :-( if call1.signature().eq(ifsig): assert helper.is_term(call1) return if_then_else(engine, heap, rule, scont, fcont, call1.argument_at(0), call1.argument_at(1), call2) else: fcont = OrContinuation(engine, rule, scont, fcont, heap, call2) newscont = continuation.BodyContinuation(engine, rule, scont, call1) return newscont, fcont, heap.branch()
def fail(self, heap): heap = heap.revert_upto(self.undoheap, discard_choicepoint=True) scont = continuation.BodyContinuation(self.engine, self.rule, self.nextcont, self.altcall) return scont, self.orig_fcont, heap
def impl_and(engine, heap, rule, call1, call2, scont, fcont): if not isinstance(call2, term.Var) and not isinstance( call2, term.Callable): return error.throw_type_error('callable', call2) scont = continuation.BodyContinuation(engine, rule, scont, call2) return engine.call(call1, rule, scont, fcont, heap)