def impl_or(engine, call1, call2, continuation): oldstate = engine.heap.branch() try: return engine.call(call1, continuation) except error.UnificationFailed: engine.heap.revert(oldstate) return engine.call(call2, continuation, choice_point=False)
def impl_or(engine, call1, call2, continuation): oldstate = engine.heap.branch() try: return engine.call(call1, continuation) except error.UnificationFailed: engine.heap.revert(oldstate) return engine.call(call2, continuation, choice_point=False)
def impl_not(engine, call): try: try: engine.call(call) except error.CutException, e: engine.continue_after_cut(e.continuation) except error.UnificationFailed: return None raise error.UnificationFailed()
def impl_if(engine, if_clause, then_clause, continuation): oldstate = engine.heap.branch() try: engine.call(if_clause) except error.UnificationFailed: engine.heap.revert(oldstate) raise return engine.call(helper.ensure_callable(then_clause), continuation, choice_point=False)
def impl_not(engine, call): try: try: engine.call(call) except error.CutException, e: engine.continue_after_cut(e.continuation) except error.UnificationFailed: return None raise error.UnificationFailed()
def impl_if(engine, if_clause, then_clause, continuation): oldstate = engine.heap.branch() try: engine.call(if_clause) except error.UnificationFailed: engine.heap.revert(oldstate) raise return engine.call(helper.ensure_callable(then_clause), continuation, choice_point=False)
def impl_findall(engine, template, goal, bag): oldstate = engine.heap.branch() collector = FindallContinuation(template) try: engine.call(goal, collector) except error.UnificationFailed: engine.heap.revert(oldstate) result = term.Atom.newatom("[]") for i in range(len(collector.found) - 1, -1, -1): copy = collector.found[i] d = {} copy = copy.copy(engine.heap, d) result = term.Term(".", [copy, result]) bag.unify(result, engine.heap)
def impl_and(engine, call1, call2, continuation): if not isinstance(call2, term.Var) and not isinstance( call2, term.Callable): error.throw_type_error('callable', call2) and_continuation = AndContinuation(call2, continuation) return engine.call(call1, and_continuation, choice_point=False)
def _call(self, engine): next_call = self.next_call.dereference(engine.heap) next_call = helper.ensure_callable(next_call) return engine.call(next_call, self.continuation, choice_point=False)
def impl_call(engine, call, continuation): try: return engine.call(call, continuation) except error.CutException, e: return e.continuation.call(engine, choice_point=False)
def impl_once(engine, clause, continuation): engine.call(clause) return continuation.call(engine, choice_point=False)
def impl_and(engine, call1, call2, continuation): if not isinstance(call2, term.Var) and not isinstance(call2, term.Callable): error.throw_type_error('callable', call2) and_continuation = AndContinuation(call2, continuation) return engine.call(call1, and_continuation, choice_point=False)
def _call(self, engine): next_call = self.next_call.dereference(engine.heap) next_call = helper.ensure_callable(next_call) return engine.call(next_call, self.continuation, choice_point=False)