[pypy-svn] r44157 - in pypy/branch/prolog-bytecode/pypy/lang/prolog: builtin interpreter interpreter/test
cfbolz at codespeak.net
cfbolz at codespeak.net
Mon Jun 11 20:57:09 CEST 2007
Author: cfbolz
Date: Mon Jun 11 20:57:08 2007
New Revision: 44157
Modified:
pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/allsolution.py
pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/arithmeticbuiltin.py
pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/atomconstruction.py
pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/control.py
pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/database.py
pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/exception.py
pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/parseraccess.py
pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/register.py
pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/termconstruction.py
pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/unify.py
pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py
pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py
pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/helper.py
pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interactive.py
pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py
pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/portal.py
pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/term.py
pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_arithmetic.py
pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_builtin.py
pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_engine.py
pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_interpreter.py
pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_jit.py
pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_parsing.py
pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_unification.py
pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/tool.py
pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/translatedmain.py
Log:
rename "heap" to "trail", which is a way better description now.
Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/allsolution.py
==============================================================================
--- pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/allsolution.py (original)
+++ pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/allsolution.py Mon Jun 11 20:57:08 2007
@@ -11,22 +11,22 @@
self.template = template
def _call(self, engine):
- clone = self.template.getvalue(engine.heap)
+ clone = self.template.getvalue(engine.trail)
self.found.append(clone)
raise error.UnificationFailed()
def impl_findall(engine, template, goal, bag):
- oldstate = engine.heap.branch()
+ oldstate = engine.trail.branch()
collector = FindallContinuation(template)
try:
engine.call(goal, collector)
except error.UnificationFailed:
- engine.heap.revert(oldstate)
+ engine.trail.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)
+ copy = copy.copy(engine.trail, d)
result = term.Term(".", [copy, result])
- bag.unify(result, engine.heap)
+ bag.unify(result, engine.trail)
expose_builtin(impl_findall, "findall", unwrap_spec=['raw', 'callable', 'raw'])
Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/arithmeticbuiltin.py
==============================================================================
--- pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/arithmeticbuiltin.py (original)
+++ pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/arithmeticbuiltin.py Mon Jun 11 20:57:08 2007
@@ -9,13 +9,13 @@
def impl_between(engine, lower, upper, varorint, continuation):
if isinstance(varorint, term.Var):
for i in range(lower, upper):
- oldstate = engine.heap.branch()
+ oldstate = engine.trail.branch()
try:
- varorint.unify(term.Number(i), engine.heap)
+ varorint.unify(term.Number(i), engine.trail)
return continuation.call(engine, choice_point=True)
except error.UnificationFailed:
- engine.heap.revert(oldstate)
- varorint.unify(term.Number(upper), engine.heap)
+ engine.trail.revert(oldstate)
+ varorint.unify(term.Number(upper), engine.trail)
return continuation.call(engine, choice_point=False)
else:
integer = helper.unwrap_int(varorint)
@@ -26,7 +26,7 @@
handles_continuation=True)
def impl_is(engine, var, num):
- var.unify(num, engine.heap)
+ var.unify(num, engine.trail)
impl_is._look_inside_me_ = True
expose_builtin(impl_is, "is", unwrap_spec=["raw", "arithmetic"])
Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/atomconstruction.py
==============================================================================
--- pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/atomconstruction.py (original)
+++ pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/atomconstruction.py Mon Jun 11 20:57:08 2007
@@ -11,13 +11,13 @@
# nondeterministic splitting of result
r = helper.convert_to_str(result)
for i in range(len(r) + 1):
- oldstate = engine.heap.branch()
+ oldstate = engine.trail.branch()
try:
- a1.unify(term.Atom(r[:i]), engine.heap)
- a2.unify(term.Atom(r[i:]), engine.heap)
+ a1.unify(term.Atom(r[:i]), engine.trail)
+ a2.unify(term.Atom(r[i:]), engine.trail)
return continuation.call(engine, choice_point=True)
except error.UnificationFailed:
- engine.heap.revert(oldstate)
+ engine.trail.revert(oldstate)
raise error.UnificationFailed()
else:
s2 = helper.convert_to_str(a2)
@@ -25,7 +25,7 @@
if r.endswith(s2):
stop = len(r) - len(s2)
assert stop > 0
- a1.unify(term.Atom(r[:stop]), engine.heap)
+ a1.unify(term.Atom(r[:stop]), engine.trail)
else:
raise error.UnificationFailed()
else:
@@ -33,12 +33,12 @@
if isinstance(a2, term.Var):
r = helper.convert_to_str(result)
if r.startswith(s1):
- a2.unify(term.Atom(r[len(s1):]), engine.heap)
+ a2.unify(term.Atom(r[len(s1):]), engine.trail)
else:
raise error.UnificationFailed()
else:
s2 = helper.convert_to_str(a2)
- result.unify(term.Atom(s1 + s2), engine.heap)
+ result.unify(term.Atom(s1 + s2), engine.trail)
return continuation.call(engine, choice_point=False)
expose_builtin(impl_atom_concat, "atom_concat",
unwrap_spec=["obj", "obj", "obj"],
@@ -47,7 +47,7 @@
def impl_atom_length(engine, s, length):
if not (isinstance(length, term.Var) or isinstance(length, term.Number)):
error.throw_type_error("integer", length)
- term.Number(len(s)).unify(length, engine.heap)
+ term.Number(len(s)).unify(length, engine.trail)
expose_builtin(impl_atom_length, "atom_length", unwrap_spec = ["atom", "obj"])
def impl_sub_atom(engine, s, before, length, after, sub, continuation):
@@ -70,7 +70,7 @@
if startbefore < 0:
startbefore = 0
stopbefore = len(s) + 1
- oldstate = engine.heap.branch()
+ oldstate = engine.trail.branch()
if not isinstance(sub, term.Var):
s1 = helper.unwrap_atom(sub)
if len(s1) >= stoplength or len(s1) < startlength:
@@ -83,12 +83,12 @@
if b < 0:
break
start = b + 1
- before.unify(term.Number(b), engine.heap)
- after.unify(term.Number(len(s) - len(s1) - b), engine.heap)
- length.unify(term.Number(len(s1)), engine.heap)
+ before.unify(term.Number(b), engine.trail)
+ after.unify(term.Number(len(s) - len(s1) - b), engine.trail)
+ length.unify(term.Number(len(s1)), engine.trail)
return continuation.call(engine, choice_point=True)
except:
- engine.heap.revert(oldstate)
+ engine.trail.revert(oldstate)
raise
except error.UnificationFailed:
pass
@@ -100,13 +100,13 @@
continue
try:
try:
- before.unify(term.Number(b), engine.heap)
- after.unify(term.Number(len(s) - l - b), engine.heap)
- length.unify(term.Number(l), engine.heap)
- sub.unify(term.Atom(s[b:b + l]), engine.heap)
+ before.unify(term.Number(b), engine.trail)
+ after.unify(term.Number(len(s) - l - b), engine.trail)
+ length.unify(term.Number(l), engine.trail)
+ sub.unify(term.Atom(s[b:b + l]), engine.trail)
return continuation.call(engine, choice_point=True)
except:
- engine.heap.revert(oldstate)
+ engine.trail.revert(oldstate)
raise
except error.UnificationFailed:
pass
@@ -119,14 +119,14 @@
continue
try:
try:
- before.unify(term.Number(b), engine.heap)
- after.unify(term.Number(a), engine.heap)
- length.unify(term.Number(l), engine.heap)
- sub.unify(term.Atom(s[b:b + l]), engine.heap)
+ before.unify(term.Number(b), engine.trail)
+ after.unify(term.Number(a), engine.trail)
+ length.unify(term.Number(l), engine.trail)
+ sub.unify(term.Atom(s[b:b + l]), engine.trail)
return continuation.call(engine, choice_point=True)
return None
except:
- engine.heap.revert(oldstate)
+ engine.trail.revert(oldstate)
raise
except error.UnificationFailed:
pass
Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/control.py
==============================================================================
--- pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/control.py (original)
+++ pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/control.py Mon Jun 11 20:57:08 2007
@@ -33,7 +33,7 @@
self.continuation = continuation
def _call(self, engine):
- next_call = self.next_call.dereference(engine.heap)
+ next_call = self.next_call.dereference(engine.trail)
next_call = helper.ensure_callable(next_call)
return engine.call(next_call, self.continuation, choice_point=False)
@@ -46,11 +46,11 @@
handles_continuation=True)
def impl_or(engine, call1, call2, continuation):
- oldstate = engine.heap.branch()
+ oldstate = engine.trail.branch()
try:
return engine.call(call1, continuation)
except error.UnificationFailed:
- engine.heap.revert(oldstate)
+ engine.trail.revert(oldstate)
return engine.call(call2, continuation, choice_point=False)
expose_builtin(impl_or, ";", unwrap_spec=["callable", "callable"],
@@ -68,11 +68,11 @@
expose_builtin(impl_not, ["not", "\\+"], unwrap_spec=["callable"])
def impl_if(engine, if_clause, then_clause, continuation):
- oldstate = engine.heap.branch()
+ oldstate = engine.trail.branch()
try:
engine.call(if_clause)
except error.UnificationFailed:
- engine.heap.revert(oldstate)
+ engine.trail.revert(oldstate)
raise
return engine.call(helper.ensure_callable(then_clause), continuation,
choice_point=False)
Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/database.py
==============================================================================
--- pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/database.py (original)
+++ pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/database.py Mon Jun 11 20:57:08 2007
@@ -19,11 +19,11 @@
expose_builtin(impl_abolish, "abolish", unwrap_spec=["obj"])
def impl_assert(engine, rule):
- engine.add_rule(rule.getvalue(engine.heap))
+ engine.add_rule(rule.getvalue(engine.trail))
expose_builtin(impl_assert, ["assert", "assertz"], unwrap_spec=["callable"])
def impl_asserta(engine, rule):
- engine.add_rule(rule.getvalue(engine.heap), end=False)
+ engine.add_rule(rule.getvalue(engine.trail), end=False)
expose_builtin(impl_asserta, "asserta", unwrap_spec=["callable"])
@@ -46,16 +46,16 @@
rulechain = function.rulechain
while rulechain:
rule = rulechain.rule
- oldstate = engine.heap.branch()
+ oldstate = engine.trail.branch()
try:
memo = {}
- rulehead = rule.head.copy(engine.heap, memo)
- rulehead.unify(head, engine.heap)
+ rulehead = rule.head.copy(engine.trail, memo)
+ rulehead.unify(head, engine.trail)
if body is not None:
- rulebody = rule.body.copy(engine.heap, memo)
- rulebody.unify(body, engine.heap)
+ rulebody = rule.body.copy(engine.trail, memo)
+ rulebody.unify(body, engine.trail)
except error.UnificationFailed:
- engine.heap.revert(oldstate)
+ engine.trail.revert(oldstate)
else:
if function.rulechain is rulechain:
if rulechain.next is None:
Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/exception.py
==============================================================================
--- pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/exception.py (original)
+++ pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/exception.py Mon Jun 11 20:57:08 2007
@@ -8,23 +8,23 @@
def impl_catch(engine, goal, catcher, recover, continuation):
catching_continuation = enginemod.LimitedScopeContinuation(continuation)
- old_state = engine.heap.branch()
+ old_state = engine.trail.branch()
try:
return engine.call(goal, catching_continuation)
except error.CatchableError, e:
if not catching_continuation.scope_active:
raise
- exc_term = e.term.getvalue(engine.heap)
- engine.heap.revert(old_state)
+ exc_term = e.term.getvalue(engine.trail)
+ engine.trail.revert(old_state)
d = {}
- exc_term = exc_term.copy(engine.heap, d)
+ exc_term = exc_term.copy(engine.trail, d)
try:
impl_ground(engine, exc_term)
except error.UnificationFailed:
raise error.UncatchableError(
"not implemented: catching of non-ground terms")
try:
- catcher.unify(exc_term, engine.heap)
+ catcher.unify(exc_term, engine.trail)
except error.UnificationFailed:
if isinstance(e, error.UserError):
raise error.UserError(exc_term)
Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/parseraccess.py
==============================================================================
--- pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/parseraccess.py (original)
+++ pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/parseraccess.py Mon Jun 11 20:57:08 2007
@@ -9,14 +9,14 @@
for prec, allops in engine.getoperations():
for form, ops in allops:
for op in ops:
- oldstate = engine.heap.branch()
+ oldstate = engine.trail.branch()
try:
- precedence.unify(term.Number(prec), engine.heap)
- typ.unify(term.Atom.newatom(form), engine.heap)
- name.unify(term.Atom(op), engine.heap)
+ precedence.unify(term.Number(prec), engine.trail)
+ typ.unify(term.Atom.newatom(form), engine.trail)
+ name.unify(term.Atom(op), engine.trail)
return continuation.call(engine, choice_point=True)
except error.UnificationFailed:
- engine.heap.revert(oldstate)
+ engine.trail.revert(oldstate)
raise error.UnificationFailed()
expose_builtin(impl_current_op, "current_op", unwrap_spec=["obj", "obj", "obj"],
handles_continuation=True)
Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/register.py
==============================================================================
--- pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/register.py (original)
+++ pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/register.py Mon Jun 11 20:57:08 2007
@@ -44,10 +44,10 @@
varname = "var%s" % (i, )
subargs.append(varname)
if spec in ("obj", "callable", "int", "atom", "arithmetic"):
- code.append(" %s = %s.dereference(engine.heap)" %
+ code.append(" %s = %s.dereference(engine.trail)" %
(varname, rawarg))
elif spec in ("concrete", "list"):
- code.append(" %s = %s.getvalue(engine.heap)" %
+ code.append(" %s = %s.getvalue(engine.trail)" %
(varname, rawarg))
if spec in ("int", "atom", "arithmetic", "list"):
code.append(
Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/termconstruction.py
==============================================================================
--- pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/termconstruction.py (original)
+++ pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/termconstruction.py Mon Jun 11 20:57:08 2007
@@ -7,11 +7,11 @@
def impl_functor(engine, t, functor, arity):
if helper.is_atomic(t):
- functor.unify(t, engine.heap)
- arity.unify(term.Number(0), engine.heap)
+ functor.unify(t, engine.trail)
+ arity.unify(term.Number(0), engine.trail)
elif isinstance(t, term.Term):
- functor.unify(term.Atom(t.name), engine.heap)
- arity.unify(term.Number(len(t.args)), engine.heap)
+ functor.unify(term.Atom(t.name), engine.trail)
+ arity.unify(term.Number(len(t.args)), engine.trail)
elif isinstance(t, term.Var):
if isinstance(functor, term.Var):
error.throw_instantiation_error()
@@ -21,12 +21,12 @@
else:
functor = helper.ensure_atomic(functor)
if a == 0:
- t.unify(helper.ensure_atomic(functor), engine.heap)
+ t.unify(helper.ensure_atomic(functor), engine.trail)
else:
name = helper.unwrap_atom(functor)
t.unify(
term.Term(name, [term.Var() for i in range(a)]),
- engine.heap)
+ engine.trail)
expose_builtin(impl_functor, "functor", unwrap_spec=["obj", "obj", "obj"])
def impl_arg(engine, first, second, third, continuation):
@@ -39,13 +39,13 @@
if isinstance(first, term.Var):
for i in range(len(second.args)):
arg = second.args[i]
- oldstate = engine.heap.branch()
+ oldstate = engine.trail.branch()
try:
- third.unify(arg, engine.heap)
- first.unify(term.Number(i + 1), engine.heap)
+ third.unify(arg, engine.trail)
+ first.unify(term.Number(i + 1), engine.trail)
return continuation.call(engine, choice_point=True)
except error.UnificationFailed:
- engine.heap.revert(oldstate)
+ engine.trail.revert(oldstate)
raise error.UnificationFailed()
elif isinstance(first, term.Number):
num = first.num
@@ -56,7 +56,7 @@
if num > len(second.args):
raise error.UnificationFailed()
arg = second.args[num - 1]
- third.unify(arg, engine.heap)
+ third.unify(arg, engine.trail)
else:
error.throw_type_error("integer", first)
return continuation.call(engine, choice_point=False)
@@ -71,9 +71,9 @@
l = [first]
u1 = helper.wrap_list(l)
if not isinstance(second, term.Var):
- u1.unify(second, engine.heap)
+ u1.unify(second, engine.trail)
else:
- u1.unify(second, engine.heap)
+ u1.unify(second, engine.trail)
else:
if isinstance(second, term.Var):
error.throw_instantiation_error()
@@ -82,13 +82,13 @@
head = l[0]
if not isinstance(head, term.Atom):
error.throw_type_error("atom", head)
- term.Term(head.name, l[1:]).unify(first, engine.heap)
+ term.Term(head.name, l[1:]).unify(first, engine.trail)
expose_builtin(impl_univ, "=..", unwrap_spec=["obj", "obj"])
def impl_copy_term(engine, interm, outterm):
d = {}
- copy = interm.copy(engine.heap, d)
- outterm.unify(copy, engine.heap)
+ copy = interm.copy(engine.trail, d)
+ outterm.unify(copy, engine.trail)
expose_builtin(impl_copy_term, "copy_term", unwrap_spec=["obj", "obj"])
Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/unify.py
==============================================================================
--- pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/unify.py (original)
+++ pypy/branch/prolog-bytecode/pypy/lang/prolog/builtin/unify.py Mon Jun 11 20:57:08 2007
@@ -8,21 +8,21 @@
# comparison and unification of terms
def impl_unify(engine, obj1, obj2):
- obj1.unify(obj2, engine.heap)
+ obj1.unify(obj2, engine.trail)
expose_builtin(impl_unify, "=", unwrap_spec=["raw", "raw"])
def impl_unify_with_occurs_check(engine, obj1, obj2):
- obj1.unify(obj2, engine.heap, occurs_check=True)
+ obj1.unify(obj2, engine.trail, occurs_check=True)
expose_builtin(impl_unify_with_occurs_check, "unify_with_occurs_check",
unwrap_spec=["raw", "raw"])
def impl_does_not_unify(engine, obj1, obj2):
try:
- branch = engine.heap.branch()
+ branch = engine.trail.branch()
try:
- obj1.unify(obj2, engine.heap)
+ obj1.unify(obj2, engine.trail)
finally:
- engine.heap.revert(branch)
+ engine.trail.revert(branch)
except error.UnificationFailed:
return
raise error.UnificationFailed()
@@ -37,7 +37,7 @@
("ge", "@>=", "!= -1")]:
exec py.code.Source("""
def impl_standard_comparison_%s(engine, obj1, obj2):
- c = term.cmp_standard_order(obj1, obj2, engine.heap)
+ c = term.cmp_standard_order(obj1, obj2, engine.trail)
if not c %s:
raise error.UnificationFailed()""" % (ext, python)).compile()
expose_builtin(globals()["impl_standard_comparison_%s" % (ext, )], prolog,
Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py
==============================================================================
--- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py (original)
+++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/compiler.py Mon Jun 11 20:57:08 2007
@@ -81,7 +81,7 @@
def compile_body(self, body):
from pypy.lang.prolog.builtin import builtins_list, builtins_index
- body = body.dereference(self.engine.heap)
+ body = body.dereference(self.engine.trail)
if isinstance(body, Var):
self.can_contain_cut = True
self.compile_termbuilding(body)
Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py
==============================================================================
--- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py (original)
+++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/engine.py Mon Jun 11 20:57:08 2007
@@ -39,7 +39,7 @@
def __str__(self):
return "TrailChunk(%s, %s)" % (self.last, self.trail)
-class Heap(object):
+class Trail(object):
_virtualizable_ = True
def __init__(self):
self.current_chunk = TrailChunk()
@@ -124,7 +124,7 @@
class Engine(object):
def __init__(self):
- self.heap = Heap()
+ self.trail = Trail()
self.signature2function = {}
self.parser = None
self.operations = None
Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/helper.py
==============================================================================
--- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/helper.py (original)
+++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/helper.py Mon Jun 11 20:57:08 2007
@@ -30,7 +30,7 @@
def is_ground(obj, engine):
stack = [obj]
while stack:
- obj = stack.pop().dereference(engine.heap)
+ obj = stack.pop().dereference(engine.trail)
if isinstance(obj, term.Var):
return False
if isinstance(obj, term.Term):
Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interactive.py
==============================================================================
--- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interactive.py (original)
+++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interactive.py Mon Jun 11 20:57:08 2007
@@ -59,11 +59,11 @@
f = TermFormatter(engine, quoted=True, max_depth=10)
vars = var_to_pos.items()
vars.sort()
- heap = engine.heap
+ trail = engine.trail
for var, real_var in vars:
if var.startswith("_"):
continue
- val = real_var.getvalue(heap)
+ val = real_var.getvalue(trail)
write("%s = %s\n" % (var, f.format(val)))
class PrologConsole(code.InteractiveConsole):
Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py
==============================================================================
--- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py (original)
+++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/interpreter.py Mon Jun 11 20:57:08 2007
@@ -52,11 +52,11 @@
class Frame(object):
- def __init__(self, engine, code, localvarcache=None, heap=None):
+ def __init__(self, engine, code, localvarcache=None, trail=None):
self.engine = engine
- if heap is None:
- heap = engine.heap
- self.heap = heap
+ if trail is None:
+ trail = engine.trail
+ self.trail = trail
self.code = code
if localvarcache is None:
localvarcache = [None] * code.maxlocalvar
@@ -78,7 +78,7 @@
hint(i, concrete=True)
arg = stack[startfrom + i]
hint(arg.__class__, promote=True)
- result[i].unify(arg, self.heap)
+ result[i].unify(arg, self.trail)
i += 1
self.result = None
@@ -101,12 +101,12 @@
return self._run(codeobject, head, pc, continuation)
if not we_are_jitted():
assert codeobject is not None
- return run_jit(self.localvarcache, self.engine, self.heap,
+ return run_jit(self.localvarcache, self.engine, self.trail,
codeobject, head, pc, continuation)
return self.opaque_run(codeobject, head, pc, continuation)
def opaque_run(self, codeobject, head, pc, continuation):
- return run_jit(self.localvarcache, self.engine, self.heap,
+ return run_jit(self.localvarcache, self.engine, self.trail,
codeobject, head, pc, continuation)
opaque_run._look_inside_me = False
@@ -195,7 +195,7 @@
def ACTIVATE_LOCAL(self, stack, number):
var = self.localvarcache[number]
assert type(var) is LocalVar
- self.localvarcache[number] = result = var.dereference(self.heap)
+ self.localvarcache[number] = result = var.dereference(self.trail)
var.active = True
def MAKETERM(self, stack, number):
@@ -247,7 +247,7 @@
self.localvarcache[number] = None
def UNIFY(self, stack):
- stack.pop().unify(stack.pop(), self.heap)
+ stack.pop().unify(stack.pop(), self.trail)
def user_call(self, function, args, continuation):
rulechain = function.rulechain
@@ -255,7 +255,7 @@
if rulechain is None:
error.throw_existence_error(
"procedure", function.prolog_signature)
- oldstate = self.heap.branch()
+ oldstate = self.trail.branch()
while rulechain is not None:
rule = rulechain.rule
choice_point = rulechain.next is not None
@@ -267,7 +267,7 @@
result = frame.run_directly(continuation)
return result
except error.UnificationFailed:
- self.heap.revert(oldstate)
+ self.trail.revert(oldstate)
except error.CutException, e:
if continuation.scope_active:
return self.engine.continue_after_cut(e.continuation,
@@ -279,12 +279,12 @@
result = frame.run_directly(continuation, choice_point)
return result
except error.UnificationFailed:
- self.heap.revert(oldstate)
+ self.trail.revert(oldstate)
if not choice_point:
raise
rulechain = rulechain.next
-def run_jit(original_localvarcache, engine, heap, codeobject,
+def run_jit(original_localvarcache, engine, trail, codeobject,
head, pc, continuation):
hint(None, global_merge_point=True)
hint(codeobject, concrete=True)
@@ -296,7 +296,7 @@
else:
bytecode = codeobject.opcode
pc = hint(pc, promote=True)
- self = jit_enter_function(engine, heap, codeobject, original_localvarcache)
+ self = jit_enter_function(engine, trail, codeobject, original_localvarcache)
original_self = self
original_code = codeobject
@@ -335,7 +335,7 @@
original_localvarcache)
return continuation
-def jit_enter_function(engine, heap, code, concrete_localvarcache):
+def jit_enter_function(engine, trail, code, concrete_localvarcache):
# complete funnyness
localvarcache = [None] * code.maxlocalvar
i = code.maxlocalvar
@@ -348,7 +348,7 @@
localvarcache[i] = obj
self = Frame(engine, code, localvarcache)
self.localvarcache = localvarcache
- self.heap = heap
+ self.trail = trail
return self
def jit_leave_function(code, localvarcache, original_localvarcache):
Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/portal.py
==============================================================================
--- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/portal.py (original)
+++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/portal.py Mon Jun 11 20:57:08 2007
@@ -42,13 +42,13 @@
for cls in [term.Callable, term.Atom, term.Term]:
self.seegraph(cls.get_prolog_signature)
self.seegraph(PORTAL)
- self.seegraph(engine.Heap.newvar)
+ self.seegraph(engine.Trail.newvar)
self.seegraph(engine.TrailChunk.__init__)
self.seegraph(interpreter.Rule.make_frame)
self.seegraph(interpreter.jit_enter_function)
self.seegraph(interpreter.jit_leave_function)
for method in "branch revert newvar add_trail".split():
- self.seegraph(getattr(engine.Heap, method))
+ self.seegraph(getattr(engine.Trail, method))
for method in ("unify_head run_directly run user_call "
"dispatch_bytecode getcode "
"__init__ _run").split():
Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/term.py
==============================================================================
--- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/term.py (original)
+++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/term.py Mon Jun 11 20:57:08 2007
@@ -23,24 +23,24 @@
raise NotImplementedError("abstract base class")
return self
- def getvalue(self, heap):
+ def getvalue(self, trail):
return self
- def dereference(self, heap):
+ def dereference(self, trail):
raise NotImplementedError("abstract base class")
- def copy(self, heap, memo):
+ def copy(self, trail, memo):
raise NotImplementedError("abstract base class")
@specialize.arg(3)
- def unify(self, other, heap, occurs_check=False):
+ def unify(self, other, trail, occurs_check=False):
raise NotImplementedError("abstract base class")
@specialize.arg(3)
- def _unify(self, other, heap, occurs_check=False):
+ def _unify(self, other, trail, occurs_check=False):
raise NotImplementedError("abstract base class")
- def contains_var(self, var, heap):
+ def contains_var(self, var, trail):
return False
def __eq__(self, other):
@@ -65,59 +65,59 @@
self.binding = None
@specialize.arg(3)
- def unify(self, other, heap, occurs_check=False):
- return self.dereference(heap)._unify(other, heap, occurs_check)
+ def unify(self, other, trail, occurs_check=False):
+ return self.dereference(trail)._unify(other, trail, occurs_check)
@specialize.arg(3)
- def _unify(self, other, heap, occurs_check=False):
- other = other.dereference(heap)
+ def _unify(self, other, trail, occurs_check=False):
+ other = other.dereference(trail)
if isinstance(other, Var) and other is self:
pass
- elif occurs_check and other.contains_var(self, heap):
+ elif occurs_check and other.contains_var(self, trail):
raise UnificationFailed()
else:
- self.setvalue(other, heap)
+ self.setvalue(other, trail)
- def dereference(self, heap):
+ def dereference(self, trail):
next = self.binding
if next is None:
return self
if isinstance(next, Var):
if _is_early_constant(next):
- result = next.dereference(heap)
+ result = next.dereference(trail)
else:
- result = next.opaque_dereference(heap)
- self.setvalue(result, heap)
+ result = next.opaque_dereference(trail)
+ self.setvalue(result, trail)
return result
return next
- def opaque_dereference(self, heap):
- return self.dereference(heap)
+ def opaque_dereference(self, trail):
+ return self.dereference(trail)
- def getvalue(self, heap):
- res = self.dereference(heap)
+ def getvalue(self, trail):
+ res = self.dereference(trail)
if not isinstance(res, Var):
- return res.getvalue(heap)
+ return res.getvalue(trail)
return res
- def setvalue(self, value, heap):
+ def setvalue(self, value, trail):
if value is not self.binding:
- heap.add_trail(self)
+ trail.add_trail(self)
self.binding = value
- def copy(self, heap, memo):
+ def copy(self, trail, memo):
try:
return memo[self]
except KeyError:
- newvar = memo[self] = heap.newvar()
+ newvar = memo[self] = trail.newvar()
return newvar
- def contains_var(self, var, heap):
- self = self.dereference(heap)
+ def contains_var(self, var, trail):
+ self = self.dereference(trail)
if self is var:
return True
if not isinstance(self, Var):
- return self.contains_var(var, heap)
+ return self.contains_var(var, trail)
return False
def __repr__(self):
@@ -129,7 +129,7 @@
return self is other
def eval_arithmetic(self, engine):
- self = self.dereference(engine.heap)
+ self = self.dereference(engine.trail)
if isinstance(self, Var):
error.throw_instantiation_error()
return self.eval_arithmetic(engine)
@@ -142,34 +142,34 @@
self.binding = None
self.active = False
- def setvalue(self, value, heap):
+ def setvalue(self, value, trail):
if self.active:
- heap.add_trail(self)
+ trail.add_trail(self)
self.binding = value
class NonVar(PrologObject):
__slots__ = ()
- def dereference(self, heap):
+ def dereference(self, trail):
return self
@specialize.arg(3)
- def unify(self, other, heap, occurs_check=False):
- return self._unify(other, heap, occurs_check)
+ def unify(self, other, trail, occurs_check=False):
+ return self._unify(other, trail, occurs_check)
@specialize.arg(3)
- def basic_unify(self, other, heap, occurs_check=False):
+ def basic_unify(self, other, trail, occurs_check=False):
raise NotImplementedError("abstract base class")
@specialize.arg(3)
- def _unify(self, other, heap, occurs_check=False):
- other = other.dereference(heap)
+ def _unify(self, other, trail, occurs_check=False):
+ other = other.dereference(trail)
if isinstance(other, Var):
- other._unify(self, heap, occurs_check)
+ other._unify(self, trail, occurs_check)
else:
- self.basic_unify(other, heap, occurs_check)
+ self.basic_unify(other, trail, occurs_check)
class Callable(NonVar):
@@ -198,13 +198,13 @@
return "Atom(%r)" % (self.name,)
@specialize.arg(3)
- def basic_unify(self, other, heap, occurs_check=False):
+ def basic_unify(self, other, trail, occurs_check=False):
if isinstance(other, Atom) and (self is other or
other.name == self.name):
return
raise UnificationFailed
- def copy(self, heap, memo):
+ def copy(self, trail, memo):
return self
def get_prolog_signature(self):
@@ -235,12 +235,12 @@
self.num = num
@specialize.arg(3)
- def basic_unify(self, other, heap, occurs_check=False):
+ def basic_unify(self, other, trail, occurs_check=False):
if isinstance(other, Number) and other.num == self.num:
return
raise UnificationFailed
- def copy(self, heap, memo):
+ def copy(self, trail, memo):
return self
def __str__(self):
@@ -261,13 +261,13 @@
self.floatval = floatval
@specialize.arg(3)
- def basic_unify(self, other, heap, occurs_check=False):
+ def basic_unify(self, other, trail, occurs_check=False):
if isinstance(other, Float) and other.floatval == self.floatval:
return
raise UnificationFailed
basic_unify._look_inside_me_ = False
- def copy(self, heap, memo):
+ def copy(self, trail, memo):
return self
def __str__(self):
@@ -291,19 +291,19 @@
pass
@specialize.arg(3)
- def basic_unify(self, other, heap, occurs_check=False):
+ def basic_unify(self, other, trail, occurs_check=False):
if self is other:
return
raise UnificationFailed
- def copy(self, heap, memo):
+ def copy(self, trail, memo):
return self
# helper functions for various Term methods
-def _getvalue(obj, heap):
- return obj.getvalue(heap)
+def _getvalue(obj, trail):
+ return obj.getvalue(trail)
class Term(Callable):
STANDARD_ORDER = 3
@@ -323,28 +323,28 @@
return "%s(%s)" % (self.name, ", ".join([str(a) for a in self.args]))
@specialize.arg(3)
- def basic_unify(self, other, heap, occurs_check=False):
+ def basic_unify(self, other, trail, occurs_check=False):
if (isinstance(other, Term) and
self.name == other.name and
len(self.args) == len(other.args)):
i = 0
while i < len(self.args):
- self.args[i].unify(other.args[i], heap, occurs_check)
+ self.args[i].unify(other.args[i], trail, occurs_check)
i += 1
else:
raise UnificationFailed
- def copy(self, heap, memo):
+ def copy(self, trail, memo):
newargs = []
i = 0
while i < len(self.args):
- arg = self.args[i].copy(heap, memo)
+ arg = self.args[i].copy(trail, memo)
newargs.append(arg)
i += 1
return Term(self.name, newargs, self.signature)
- def getvalue(self, heap):
- return self._copy_term(_getvalue, heap)
+ def getvalue(self, trail):
+ return self._copy_term(_getvalue, trail)
def _copy_term(self, copy_individual, *extraargs):
args = [None] * len(self.args)
@@ -363,9 +363,9 @@
def get_prolog_signature(self):
return Term("/", [Atom.newatom(self.name), Number(len(self.args))])
- def contains_var(self, var, heap):
+ def contains_var(self, var, trail):
for arg in self.args:
- if arg.contains_var(var, heap):
+ if arg.contains_var(var, trail):
return True
return False
@@ -393,7 +393,7 @@
return -1
return 1
-def cmp_standard_order(obj1, obj2, heap):
+def cmp_standard_order(obj1, obj2, trail):
c = rcmp(obj1.STANDARD_ORDER, obj2.STANDARD_ORDER)
if c != 0:
return c
@@ -412,9 +412,9 @@
if c != 0:
return c
for i in range(len(obj1.args)):
- a1 = obj1.args[i].dereference(heap)
- a2 = obj2.args[i].dereference(heap)
- c = cmp_standard_order(a1, a2, heap)
+ a1 = obj1.args[i].dereference(trail)
+ a2 = obj2.args[i].dereference(trail)
+ c = cmp_standard_order(a1, a2, trail)
if c != 0:
return c
return 0
Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_arithmetic.py
==============================================================================
--- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_arithmetic.py (original)
+++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_arithmetic.py Mon Jun 11 20:57:08 2007
@@ -2,7 +2,7 @@
from pypy.lang.prolog.interpreter.parsing import parse_file, TermBuilder
from pypy.lang.prolog.interpreter.parsing import parse_query_term, get_engine
from pypy.lang.prolog.interpreter.error import UnificationFailed, CutException
-from pypy.lang.prolog.interpreter.engine import Heap, Engine
+from pypy.lang.prolog.interpreter.engine import Trail, Engine
from pypy.lang.prolog.interpreter import error
from pypy.lang.prolog.interpreter.test.tool import collect_all, assert_false, assert_true
Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_builtin.py
==============================================================================
--- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_builtin.py (original)
+++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_builtin.py Mon Jun 11 20:57:08 2007
@@ -2,7 +2,7 @@
from pypy.lang.prolog.interpreter.parsing import parse_file, TermBuilder
from pypy.lang.prolog.interpreter.parsing import parse_query_term, get_engine
from pypy.lang.prolog.interpreter.error import UnificationFailed
-from pypy.lang.prolog.interpreter.engine import Heap, Engine
+from pypy.lang.prolog.interpreter.engine import Trail, Engine
from pypy.lang.prolog.interpreter import error
from pypy.lang.prolog.interpreter.test.tool import collect_all, assert_false, assert_true
from pypy.lang.prolog.interpreter.test.tool import prolog_raises
Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_engine.py
==============================================================================
--- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_engine.py (original)
+++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_engine.py Mon Jun 11 20:57:08 2007
@@ -12,7 +12,7 @@
""")
t, vars = get_query_and_vars("f(X).")
e.run(t)
- assert vars['X'].dereference(e.heap).name == "a"
+ assert vars['X'].dereference(e.trail).name == "a"
def test_and():
e = get_engine("""
@@ -24,7 +24,7 @@
e.run(parse_query_term("f(a, c)."))
t, vars = get_query_and_vars("f(X, c).")
e.run(t)
- assert vars['X'].dereference(e.heap).name == "a"
+ assert vars['X'].dereference(e.trail).name == "a"
def test_and_long():
e = get_engine("""
@@ -56,7 +56,7 @@
e.run(parse_query_term("num(succ(0))."))
t, vars = get_query_and_vars("num(X).")
e.run(t)
- assert vars['X'].dereference(e.heap).num == 0
+ assert vars['X'].dereference(e.trail).num == 0
e.run(parse_query_term("add(0, 0, 0)."))
py.test.raises(UnificationFailed, e.run, parse_query_term("""
add(0, 0, succ(0))."""))
@@ -93,7 +93,7 @@
""")
t, vars = get_query_and_vars("f(a, b, Z).")
e.run(t)
- assert vars['Z'].dereference(e.heap).name == "a"
+ assert vars['Z'].dereference(e.trail).name == "a"
f = collect_all(e, "X = 1; X = 2.")
assert len(f) == 2
Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_interpreter.py
==============================================================================
--- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_interpreter.py (original)
+++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_interpreter.py Mon Jun 11 20:57:08 2007
@@ -8,7 +8,7 @@
r = Rule(head, body, e)
query = get_query_and_vars("f(a).")[0]
frame = r.make_frame(query.args)
- assert frame.localvarcache[0].dereference(e.heap).name == "a"
+ assert frame.localvarcache[0].dereference(e.trail).name == "a"
cont = object()
c2 = frame.run(frame.code, False, 0, cont)
assert cont is c2
@@ -18,7 +18,7 @@
cont = object()
c2 = frame.run(frame.code, False, 0, cont)
assert cont is c2
- assert vars['X'].dereference(e.heap).name == 'a'
+ assert vars['X'].dereference(e.trail).name == 'a'
def test_build_term():
e = get_engine("")
@@ -28,5 +28,5 @@
frame = Frame(e, r.code)
frame.run(frame.code, True, 0, None)
frame.run(frame.code, False, 0, None)
- assert frame.result[0].dereference(e.heap).name == "a"
- assert frame.result[1].dereference(e.heap).name == "b"
+ assert frame.result[0].dereference(e.trail).name == "a"
+ assert frame.result[1].dereference(e.trail).name == "b"
Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_jit.py
==============================================================================
--- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_jit.py (original)
+++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_jit.py Mon Jun 11 20:57:08 2007
@@ -87,7 +87,7 @@
t, vars = get_query_and_vars("a([a, b, c], [d, f, g], X).")
def main(n):
- e.heap = engine.Heap()
+ e.heap = engine.Trail()
if n == 0:
e.call(t)
@@ -144,7 +144,7 @@
num = term.Number(50)
def main(n):
- e.heap = engine.Heap()
+ e.heap = engine.Trail()
if n == 0:
e.call(term.Term("f", [num]))
return True
Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_parsing.py
==============================================================================
--- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_parsing.py (original)
+++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_parsing.py Mon Jun 11 20:57:08 2007
@@ -38,8 +38,8 @@
term, vars = get_query_and_vars(
"""add_numeral(succ(succ(null)), succ(succ(null)), X).""")
e.run(term)
- var = vars['X'].getvalue(e.heap)
- var.unify(four, e.heap)
+ var = vars['X'].getvalue(e.trail)
+ var.unify(four, e.trail)
term = parse_query_term(
"""greater_than(succ(succ(succ(null))), succ(succ(null))).""")
e.run(term)
Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_unification.py
==============================================================================
--- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_unification.py (original)
+++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/test_unification.py Mon Jun 11 20:57:08 2007
@@ -1,7 +1,7 @@
import py
from pypy.lang.prolog.interpreter.error import UnificationFailed
from pypy.lang.prolog.interpreter.term import Atom, Var, Number, Term, BlackBox
-from pypy.lang.prolog.interpreter.engine import Heap, Engine
+from pypy.lang.prolog.interpreter.engine import Trail, Engine
def test_atom():
a = Atom.newatom("hallo")
@@ -12,45 +12,45 @@
def test_var():
b = Var()
- heap = Heap()
- b.unify(Atom.newatom("hallo"), heap)
- assert b.getvalue(heap).name == "hallo"
+ trail = Trail()
+ b.unify(Atom.newatom("hallo"), trail)
+ assert b.getvalue(trail).name == "hallo"
a = Var()
b = Var()
- a.unify(b, heap)
- a.unify(Atom.newatom("hallo"), heap)
- assert a.getvalue(heap).name == "hallo"
- assert b.getvalue(heap).name == "hallo"
+ a.unify(b, trail)
+ a.unify(Atom.newatom("hallo"), trail)
+ assert a.getvalue(trail).name == "hallo"
+ assert b.getvalue(trail).name == "hallo"
def test_unify_var():
b = Var()
- heap = Heap()
- b.unify(b, heap)
- b.unify(Atom.newatom("hallo"), heap)
- py.test.raises(UnificationFailed, b.unify, Atom.newatom("bye"), heap)
+ trail = Trail()
+ b.unify(b, trail)
+ b.unify(Atom.newatom("hallo"), trail)
+ py.test.raises(UnificationFailed, b.unify, Atom.newatom("bye"), trail)
def test_recursive():
b = Var()
- heap = Heap()
- b.unify(Term("hallo", [b]), heap)
+ trail = Trail()
+ b.unify(Term("hallo", [b]), trail)
def test_term():
X = Var()
Y = Var()
t1 = Term("f", [Atom.newatom("hallo"), X])
t2 = Term("f", [Y, Atom.newatom("HALLO")])
- heap = Heap()
+ trail = Trail()
print t1, t2
- t1.unify(t2, heap)
- assert X.getvalue(heap).name == "HALLO"
- assert Y.getvalue(heap).name == "hallo"
+ t1.unify(t2, trail)
+ assert X.getvalue(trail).name == "HALLO"
+ assert Y.getvalue(trail).name == "hallo"
def test_blackbox():
bl1 = BlackBox()
bl2 = BlackBox()
- heap = Heap()
- bl1.unify(bl1, heap)
- py.test.raises(UnificationFailed, bl1.unify, bl2, heap)
+ trail = Trail()
+ bl1.unify(bl1, trail)
+ py.test.raises(UnificationFailed, bl1.unify, bl2, trail)
def test_run():
e = Engine()
@@ -60,9 +60,9 @@
e.add_rule(Term("f", [X, X]))
e.add_rule(Term(":-", [Term("f", [X, Y]),
Term("f", [Y, X])]))
- X = e.heap.newvar()
+ X = e.trail.newvar()
e.run(Term("f", [Atom.newatom("b"), X]))
- assert X.dereference(e.heap).name == "b"
+ assert X.dereference(e.trail).name == "b"
e.run(Term("f", [Atom.newatom("b"), Atom.newatom("a")]))
e.run(Term("f", [Atom.newatom("c"), Atom.newatom("c")]))
Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/tool.py
==============================================================================
--- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/tool.py (original)
+++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/test/tool.py Mon Jun 11 20:57:08 2007
@@ -1,7 +1,7 @@
import py
from pypy.lang.prolog.interpreter.error import UnificationFailed, FunctionNotFound
from pypy.lang.prolog.interpreter.parsing import parse_query_term, get_engine
-from pypy.lang.prolog.interpreter.engine import Continuation, Heap, Engine
+from pypy.lang.prolog.interpreter.engine import Continuation, Trail, Engine
def assert_true(query, e=None):
if e is None:
@@ -9,7 +9,7 @@
terms, vars = e.parse(query)
term, = terms
e.run(term)
- return dict([(name, var.dereference(e.heap))
+ return dict([(name, var.dereference(e.trail))
for name, var in vars.iteritems()])
def assert_false(query, e=None):
if e is None:
@@ -27,7 +27,7 @@
self.vars = vars
def _call(self, engine):
- self.heaps.append(dict([(name, var.dereference(engine.heap))
+ self.heaps.append(dict([(name, var.dereference(engine.trail))
for name, var in self.vars.iteritems()]))
print "restarting computation"
raise UnificationFailed
Modified: pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/translatedmain.py
==============================================================================
--- pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/translatedmain.py (original)
+++ pypy/branch/prolog-bytecode/pypy/lang/prolog/interpreter/translatedmain.py Mon Jun 11 20:57:08 2007
@@ -44,7 +44,7 @@
for var, real_var in var_to_pos.iteritems():
if var.startswith("_"):
continue
- val = f.format(real_var.getvalue(engine.heap))
+ val = f.format(real_var.getvalue(engine.trail))
write("%s = %s\n" % (var, val))
def getch():
More information about the pypy-svn
mailing list