[pypy-svn] r18679 - in pypy/dist/pypy/rpython/l3interp: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Sun Oct 16 13:10:09 CEST 2005
Author: cfbolz
Date: Sun Oct 16 13:10:07 2005
New Revision: 18679
Modified:
pypy/dist/pypy/rpython/l3interp/l3interp.py
pypy/dist/pypy/rpython/l3interp/model.py
pypy/dist/pypy/rpython/l3interp/test/test_l3interp.py
Log:
(pedronis, cfbolz):
added call_graph_int + test
Modified: pypy/dist/pypy/rpython/l3interp/l3interp.py
==============================================================================
--- pypy/dist/pypy/rpython/l3interp/l3interp.py (original)
+++ pypy/dist/pypy/rpython/l3interp/l3interp.py Sun Oct 16 13:10:07 2005
@@ -6,6 +6,8 @@
pass
class LLInterpreter(object):
+ def __init__(self, globals):
+ self.globals = globals
def eval_graph_int(self, graph, args):
frame = LLFrame(graph, self)
returnlink = frame.eval(args)
@@ -20,13 +22,14 @@
def eval(self, int_values):
link = self.graph.startlink
self.copy_startlink_vars(link, int_values)
- while type(link) is model.Link:
+ while not link.stop_graph_evaluation:
link = self.eval_block(link.target)
self.copy_link_vars(link)
return link
def eval_block(self, block):
for op in block.operations:
+# print op.opimpl, op.result, op.args, self.int_vars
op.opimpl(self, op.result, op.args)
exitswitch = block.exitswitch
if exitswitch >= 0:
@@ -35,6 +38,7 @@
return block.exits[0]
def copy_startlink_vars(self, link, int_values):
+# print "copy_startlink_vars", int_values, link.move_int_registers
if link.move_int_registers is None:
return
for i in range(0, len(link.move_int_registers), 2):
@@ -43,6 +47,7 @@
self.set_int(target, int_values[source])
def copy_link_vars(self, link):
+# print "copy_link_vars", link.move_int_registers, self.int_vars
if link.move_int_registers is None:
return
for i in range(0, len(link.move_int_registers), 2):
@@ -67,3 +72,9 @@
def op_int_is_true(self, result, args):
int1 = self.get_int(args[0])
self.set_int(result, bool(int1))
+
+ def op_call_graph_int(self, result, args):
+ graph = self.interp.globals.graphs[args[0]]
+ concrete_args = [self.get_int(arg) for arg in args[1:]]
+ r = self.interp.eval_graph_int(graph, concrete_args)
+ self.set_int(result, r)
Modified: pypy/dist/pypy/rpython/l3interp/model.py
==============================================================================
--- pypy/dist/pypy/rpython/l3interp/model.py (original)
+++ pypy/dist/pypy/rpython/l3interp/model.py Sun Oct 16 13:10:07 2005
@@ -95,6 +95,7 @@
self.result = result # resulting variable
class Link(object):
+ stop_graph_evaluation = False
def __init__(self, target, exitcase=None):
self.target = target # target is a Block
self.exitcase = exitcase # NULL for non-exceptional case
@@ -102,6 +103,7 @@
self.move_int_registers = None
class ReturnLink(Link):
+ stop_graph_evaluation = True
def __init__(self, return_val=0, exitcase=None):
Link.__init__(self, None, exitcase)
if return_val != 0:
Modified: pypy/dist/pypy/rpython/l3interp/test/test_l3interp.py
==============================================================================
--- pypy/dist/pypy/rpython/l3interp/test/test_l3interp.py (original)
+++ pypy/dist/pypy/rpython/l3interp/test/test_l3interp.py Sun Oct 16 13:10:07 2005
@@ -25,7 +25,7 @@
graph.set_constants_int([3, 4])
g = model.Globals()
g.graphs = [graph]
- interp = l3interp.LLInterpreter()
+ interp = l3interp.LLInterpreter(g)
return interp.eval_graph_int(graph, [])
def test_very_simple():
@@ -50,7 +50,7 @@
graph.set_constants_int([4])
g = model.Globals()
g.graphs = [graph]
- interp = l3interp.LLInterpreter()
+ interp = l3interp.LLInterpreter(g)
return interp.eval_graph_int(graph, [number])
def test_simple():
@@ -78,7 +78,7 @@
graph.set_constants_int([1, 2])
g = model.Globals()
g.graphs = [graph]
- interp = l3interp.LLInterpreter()
+ interp = l3interp.LLInterpreter(g)
return interp.eval_graph_int(graph, [number])
def test_branch():
@@ -92,3 +92,46 @@
assert fn(4) == 2
assert fn(0) == 1
+#----------------------------------------------------------------------
+
+def eval_call(number):
+ #XXX uh: this isn't funny anymore
+ #def g(x):
+ # return x + 1
+ #def f(x):
+ # return g(x) + 2
+ op_g = model.Operation(l3interp.LLFrame.op_int_add, 1, [0, -1])
+ op_f = model.Operation(l3interp.LLFrame.op_int_add, 2, [1, -1])
+ call_op = model.Operation(l3interp.LLFrame.op_call_graph_int, 1, [0, 0])
+ returnlink_g = model.ReturnLink(1)
+ returnlink_f = model.ReturnLink(2)
+ block_g = model.Block(model.ONE_EXIT, [returnlink_g])
+ block_g.operations.append(op_g)
+ startlink_g = model.StartLink(target=block_g)
+ startlink_g.move_int_registers = [0, 0]
+ graph_g = model.Graph("g", startlink_g)
+ graph_g.set_constants_int([1])
+
+ block_f = model.Block(model.ONE_EXIT, [returnlink_f])
+ block_f.operations.extend([call_op, op_f])
+ startlink_f = model.StartLink(target=block_f)
+ startlink_f.move_int_registers = [0, 0]
+ graph_f = model.Graph("f", startlink_f)
+ graph_f.set_constants_int([2])
+ g = model.Globals()
+ g.graphs = [graph_g, graph_f]
+ interp = l3interp.LLInterpreter(g)
+ return interp.eval_graph_int(graph_f, [number])
+
+def test_call():
+ result = eval_call(4)
+ assert result == 7
+ result = eval_call(0)
+ assert result == 3
+
+def test_call_translated():
+ fn = translate(eval_call, [int])
+ assert fn(4) == 7
+ assert fn(0) == 3
+
+
More information about the Pypy-commit
mailing list