Пример #1
0
def impl_statistics(engine, heap, stat_name, value):
    t = []
    if stat_name == 'runtime':
        t = engine.clocks.get_cputime()
    if stat_name == 'walltime':
        t = engine.clocks.get_walltime()
    l = [term.Number(x) for x in t]
    helper.wrap_list(l).unify(value, heap)
Пример #2
0
def impl_statistics(engine, heap, stat_name, value):
    t = []
    if stat_name == 'runtime':
        t = engine.clocks.get_cputime()
    if stat_name == 'walltime':
        t = engine.clocks.get_walltime()
    l = [term.Number(x) for x in t]
    helper.wrap_list(l).unify(value, heap)
Пример #3
0
def impl_univ(engine, heap, first, second):
    if not isinstance(first, term.Var):
        if helper.is_term(first):
            assert isinstance(first, term.Callable)
            sig = first.signature().atom_signature
            l = [term.Callable.build(first.name(), signature=sig)] + first.arguments()
        else:
            l = [first]
        u1 = helper.wrap_list(l)
        if not isinstance(second, term.Var):
            u1.unify(second, heap)
        else:
            u1.unify(second, heap)
    else:
        if isinstance(second, term.Var):
            error.throw_instantiation_error()
        else:
            l = helper.unwrap_list(second)
            head = l[0].dereference(heap)
            if not isinstance(head, term.Atom):
                error.throw_type_error("atom", head)
            l2 = [None] * (len(l) - 1)
            for i in range(len(l2)):
                l2[i] = l[i + 1]
            name = jit.hint(head.signature(), promote=True).name
            term.Callable.build(name, l2).unify(first, heap)
Пример #4
0
def num_to_list(num):
    from prolog.interpreter.helper import wrap_list
    s = ""
    if isinstance(num, term.Number):
        s = str(num.num)
    elif isinstance(num, term.Float):
        s = str(num.floatval)
    elif isinstance(num, term.BigInt):
        s = num.value.str()
    else:
        error.throw_type_error("number", num)
    return wrap_list([Callable.build(c) for c in s])
Пример #5
0
def impl_copy_term_3(engine, heap, prolog_term, copy, goals):
    from prolog.interpreter.memo import CopyMemo
    gs = []
    memo = CopyMemo()
    X = heap.newvar()
    impl_term_attvars(engine, heap, prolog_term, X)
    attvars = unwrap_list(X.dereference(heap))
    for attvar in attvars:
        V = heap.newvar()
        memo.set(attvar, V)
        assert isinstance(attvar, AttVar)
        for module, index in attvar.attmap.indexes.iteritems():
            val = attvar.value_list[index]
            put_attr = Callable.build("put_attr", [V, Callable.build(module), val])
            gs.append(put_attr)
    prolog_term.copy(heap, memo).unify(copy, heap)
    goals.unify(wrap_list(gs), heap)
Пример #6
0
 def fail(self, heap):
     heap = heap.revert_upto(self.undoheap)
     self.bag.unify(helper.wrap_list(self.collector.result), heap)
     return self.nextcont, self.orig_fcont, heap
Пример #7
0
 def fail(self, heap):
     heap = heap.revert_upto(self.undoheap)
     self.bag.unify(helper.wrap_list(self.collector.result), heap)
     return self.nextcont, self.orig_fcont, heap
Пример #8
0
def atom_to_cons(atom):
    charlist = [term.Callable.build(c) for c in atom.name()]
    return helper.wrap_list(charlist)