Commits

David Schneider  committed 8b872da

Replace calls to Atom.newatom with factory method calls

  • Participants
  • Parent commits 59ebd04
  • Branches continuation-based

Comments (0)

Files changed (10)

File prolog/builtin/allsolution.py

         heap.revert_and_discard(oldstate)
     else:
         assert 0, "unreachable"
-    result = term.Atom.newatom("[]")
+    result = term.Callable.build("[]")
     for i in range(len(collector.found) - 1, -1, -1):
         copy = collector.found[i]
         d = {}

File prolog/builtin/control.py

     newscont = continuation.BodyContinuation(engine, notscont, call)
     return newscont, notfcont, heap.branch()
 
-CUTATOM = term.Atom.newatom("!")
+CUTATOM = term.Callable.build("!")
 
 @expose_builtin("->", unwrap_spec=["callable", "raw"],
                 handles_continuation=True)

File prolog/builtin/parseraccess.py

             for op in ops:
                 try:
                     precedence.unify(term.Number(prec), heap)
-                    typ.unify(term.Atom.newatom(form), heap)
+                    typ.unify(term.Callable.build(form), heap)
                     name.unify(term.Atom(op), heap)
                     return continuation.call(engine, choice_point=True)
                 except error.UnificationFailed:

File prolog/interpreter/continuation.py

 #        return self.throw(term, scont, fcont, heap)
 #
 #    def throw_existence_error(self, object_type, obj, scont, fcont, heap):
-#        term = Callable.build("existence_error", [Atom.newatom(object_type), obj])
+#        term = Callable.build("existence_error", [Callable.build(object_type), obj])
 #        return self.throw_system_error(term, scont, fcont, heap)
 #
 #    def throw_instantiation_error(self, scont, fcont, heap):
-#        term = Atom.newatom("instantiation_error")
+#        term = Callable.build("instantiation_error")
 #        return self.throw_system_error(term, scont, fcont, heap)
 #
 #    def throw_type_error(self, valid_type, obj, scont, fcont, heap):
 #        # atom, atomic, byte, callable, character
 #        # evaluable, in_byte, in_character, integer, list
 #        # number, predicate_indicator, variable
-#        term = Callable.build("type_error", [Atom.newatom(valid_type), obj])
+#        term = Callable.build("type_error", [Callable.build(valid_type), obj])
 #        return self.throw_system_error(term, scont, fcont, heap)
 #
 #    def throw_domain_error(self, valid_domain, obj, scont, fcont, heap):
 #        # operator_specifier, prolog_flag, read_option, source_sink,
 #        # stream, stream_option, stream_or_alias, stream_position,
 #        # stream_property, write_option
-#        term = Callable.build("domain_error", [Atom.newatom(valid_domain), obj])
+#        term = Callable.build("domain_error", [Callable.build(valid_domain), obj])
 #        return self.throw_system_error(term, scont, fcont, heap)
 #
 #    def throw_permission_error(self, operation, permission_type, obj, scont, fcont, heap):
 #        # valid permission_types are:
 #        # binary_stream, flag, operator, past_end_of_stream, private_procedure,
 #        # static_procedure, source_sink, stream, text_stream. 
-#        term = Callable.build("permission_error", [term.Atom.newatom(operation),
-#                                         term.Atom.newatom(permission_type),
+#        term = Callable.build("permission_error", [term.Callable.build(operation),
+#                                         term.Callable.build(permission_type),
 #                                         obj])
 #        return self.throw_system_error(term, scont, fcont, heap)
 

File prolog/interpreter/error.py

 
 def throw_existence_error(object_type, obj):
     from prolog.interpreter import term
-    t = term.Callable.build("existence_error", [term.Atom.newatom(object_type), obj])
+    t = term.Callable.build("existence_error", [term.Callable.build(object_type), obj])
     raise wrap_error(t)
 
 def throw_instantiation_error():
     from prolog.interpreter import term
-    raise wrap_error(term.Atom.newatom("instantiation_error"))
+    raise wrap_error(term.Callable.build("instantiation_error"))
 
 def throw_type_error(valid_type, obj):
     from prolog.interpreter import term
     # number, predicate_indicator, variable
     from prolog.interpreter import term
     raise wrap_error(
-        term.Callable.build("type_error", [term.Atom.newatom(valid_type), obj]))
+        term.Callable.build("type_error", [term.Callable.build(valid_type), obj]))
 
 def throw_domain_error(valid_domain, obj):
     from prolog.interpreter import term
     # stream, stream_option, stream_or_alias, stream_position,
     # stream_property, write_option
     raise wrap_error(
-        term.Callable.build("domain_error", [term.Atom.newatom(valid_domain), obj]))
+        term.Callable.build("domain_error", [term.Callable.build(valid_domain), obj]))
 
 def throw_permission_error(operation, permission_type, obj):
     from prolog.interpreter import term
     # binary_stream, flag, operator, past_end_of_stream, private_procedure,
     # static_procedure, source_sink, stream, text_stream. 
     raise wrap_error(
-        term.Callable.build("permission_error", [term.Atom.newatom(operation),
-                                       term.Atom.newatom(permission_type),
+        term.Callable.build("permission_error", [term.Callable.build(operation),
+                                       term.Callable.build(permission_type),
                                        obj]))

File prolog/interpreter/helper.py

 from prolog.interpreter import term
 from prolog.interpreter import error
 
-emptylist = term.Atom.newatom("[]")
+emptylist = term.Callable.build("[]")
 
 def wrap_list(python_list):
     curr = emptylist

File prolog/interpreter/parsing.py

         return node
 
     def general_symbol_visit(self, node):
-        from prolog.interpreter.term import Atom
+        from prolog.interpreter.term import Callable
         if node.additional_info.startswith("'"):
             end = len(node.additional_info) - 1
             assert end >= 0
             name = unescape(node.additional_info[1:end])
         else:
             name = node.additional_info
-        return Atom.newatom(name)
+        return Callable.build(name)
 
     def visit_VAR(self, node):
         from prolog.interpreter.term import Var

File prolog/interpreter/term.py

             return self
 
     def get_prolog_signature(self):
-        return Term("/", [Atom.newatom(self.name()),
+        return Term("/", [Callable.build(self.name()),
                                                 Number(self.argument_count())])
     
     def contains_var(self, var, heap):

File prolog/interpreter/test/test_continuation.py

             all.append(query.getvalue(heap))
             raise error.UnificationFailed
     e = Engine()
-    e.add_rule(Callable.build("f", [Atom.newatom("x")]), True)
-    e.add_rule(Callable.build("f", [Atom.newatom("y")]), True)
-    e.add_rule(Callable.build("g", [Atom.newatom("a")]), True)
-    e.add_rule(Callable.build("g", [Atom.newatom("b")]), True)
+    e.add_rule(Callable.build("f", [Callable.build("x")]), True)
+    e.add_rule(Callable.build("f", [Callable.build("y")]), True)
+    e.add_rule(Callable.build("g", [Callable.build("a")]), True)
+    e.add_rule(Callable.build("g", [Callable.build("b")]), True)
             
     query = Callable.build(",", [Callable.build("f", [Var()]), Callable.build("g", [Var()])])
     py.test.raises(error.UnificationFailed,

File prolog/interpreter/test/test_unification.py

 from prolog.interpreter.continuation import Heap, Engine
 
 def test_atom():
-    a = Atom.newatom("hallo")
-    b = Atom.newatom("hallo")
+    a = Callable.build("hallo")
+    b = Callable.build("hallo")
     # does not raise
     a.unify(b, None)
-    py.test.raises(UnificationFailed, "a.unify(Atom.newatom('xxx'), None)")
+    py.test.raises(UnificationFailed, "a.unify(Callable.build('xxx'), None)")
 
 def test_var():
     b = Var()
     heap = Heap()
-    b.unify(Atom.newatom("hallo"), heap)
+    b.unify(Callable.build("hallo"), heap)
     assert b.getvalue(heap).name()== "hallo"
     a = Var()
     b = Var()
     a.unify(b, heap)
-    a.unify(Atom.newatom("hallo"), heap)
+    a.unify(Callable.build("hallo"), heap)
     assert a.getvalue(heap).name()== "hallo"
     assert b.getvalue(heap).name()== "hallo"
 
     b = Var()
     heap = Heap()
     b.unify(b, heap)
-    b.unify(Atom.newatom("hallo"), heap)
-    py.test.raises(UnificationFailed, b.unify, Atom.newatom("bye"), heap)
+    b.unify(Callable.build("hallo"), heap)
+    py.test.raises(UnificationFailed, b.unify, Callable.build("bye"), heap)
 
 def test_recursive():
     b = Var()
 def test_term():
     X = Var()
     Y = Var()
-    t1 = Callable.build("f", [Atom.newatom("hallo"), X])
-    t2 = Callable.build("f", [Y, Atom.newatom("HALLO")])
+    t1 = Callable.build("f", [Callable.build("hallo"), X])
+    t2 = Callable.build("f", [Y, Callable.build("HALLO")])
     heap = Heap()
     print t1, t2
     t1.unify(t2, heap)