コード例 #1
0
def test_eq():
    sig1 = Signature("a", 0)
    assert sig1.eq(sig1)
    sig2 = Signature("a", 0)
    assert sig1.eq(sig2)

    sig3 = Signature("a", 1)
    assert not sig1.eq(sig3)

    sig4 = Signature("b", 0)
    assert not sig1.eq(sig4)
コード例 #2
0
    def build(term_name, args=None, signature=None, heap=None, cache=True):
        if args is None:
            args = []
        if heap is not None:
            # perform variable shunting:
            # remove variables that are not needed because they are bound
            # already and cannot be backtracked
            for i in range(len(args)):
                arg = args[i]
                if (isinstance(arg, Var) and arg.getbinding() is not None and
                        arg.created_after_choice_point is heap):
                    args[i] = arg.getbinding()
        if len(args) == 0:
            if cache:
                return Atom.newatom(term_name, signature)
            return Atom(term_name, signature)
        else:
            if signature is None:
                if cache:
                    signature = Signature.getsignature(term_name, len(args))
                else:
                    signature = Signature(term_name, len(args))
            else:
                assert signature.numargs == len(args)
            assert isinstance(signature, Signature)

            cls = Callable._find_specialized_class(term_name, len(args))
            if cls is not None:
                return cls(term_name, args, signature)
            cls = Callable._find_specialized_class('Term', len(args))
            if cls is not None:
                return cls(term_name, args, signature)
            return Term(term_name, args, signature)
コード例 #3
0
def test_module_exports():
    e = get_engine("""
    :- module(m, [g/2]).
    g(a, b).
    f(c, d, e).
    """)
    exports = e.modulewrapper.modules["m"].exports
    assert len(exports) == 1 and exports[0].eq(Signature("g", 2))
コード例 #4
0
 def __init__(self, name, signature=None):
     if signature is None:
         signature = Signature(name, 0)
     Callable.__init__(self)
     self._signature = signature
コード例 #5
0
ファイル: test_function.py プロジェクト: sebdumancic/pyrolog
 def signature(self):
     return Signature(self.name(), 123)