예제 #1
0
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)
예제 #2
0
파일: control.py 프로젝트: griels/pypy-sc
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)
예제 #3
0
파일: control.py 프로젝트: griels/pypy-sc
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()
예제 #4
0
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)
예제 #5
0
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()
예제 #6
0
파일: control.py 프로젝트: griels/pypy-sc
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)
예제 #7
0
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)
예제 #8
0
파일: control.py 프로젝트: griels/pypy-sc
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)
예제 #9
0
파일: control.py 프로젝트: griels/pypy-sc
 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)
예제 #10
0
파일: metacall.py 프로젝트: griels/pypy-sc
def impl_call(engine, call, continuation):
    try:
        return engine.call(call, continuation)
    except error.CutException, e:
        return e.continuation.call(engine, choice_point=False)
예제 #11
0
파일: metacall.py 프로젝트: griels/pypy-sc
def impl_once(engine, clause, continuation):
    engine.call(clause)
    return continuation.call(engine, choice_point=False)
예제 #12
0
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)
예제 #13
0
 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)