[pypy-svn] r17109 - in pypy/dist/pypy/rpython: . memory/test

cfbolz at codespeak.net cfbolz at codespeak.net
Wed Aug 31 00:43:13 CEST 2005


Author: cfbolz
Date: Wed Aug 31 00:43:08 2005
New Revision: 17109

Modified:
   pypy/dist/pypy/rpython/llinterp.py
   pypy/dist/pypy/rpython/memory/test/test_address.py
Log:
some additions to the llinterpreter needed to interpret GCs:
   - replacement of prints with the correct usage of log
   - implementation of raw_memcopy + test
   - set the gc=None so that the create_gc thing can already use the
     llinterpreter for setup work
   - print_traceback had to be changed because the flowgraphs of the GC's
     functions are not in llinterpreter.flowgraphs


Modified: pypy/dist/pypy/rpython/llinterp.py
==============================================================================
--- pypy/dist/pypy/rpython/llinterp.py	(original)
+++ pypy/dist/pypy/rpython/llinterp.py	Wed Aug 31 00:43:08 2005
@@ -19,21 +19,23 @@
     """ low level interpreter working with concrete values. """
 
     def __init__(self, flowgraphs, typer, lltype=lltype):
-        if hasattr(lltype, "prepare_graphs_and_create_gc"):
-            self.gc = lltype.prepare_graphs_and_create_gc(self, flowgraphs)
-        else:
-            self.gc = None
         self.flowgraphs = flowgraphs
         self.bindings = {}
         self.typer = typer
         self.llt = lltype  #module that contains the used lltype classes
         self.active_frame = None
+        # XXX hack hack hack: set gc to None because
+        # prepare_graphs_and_create_gc might already use the llinterpreter!
+        self.gc = None
+        if hasattr(lltype, "prepare_graphs_and_create_gc"):
+            self.gc = lltype.prepare_graphs_and_create_gc(self, flowgraphs)
 
     def getgraph(self, func):
         return self.flowgraphs[func]
 
-    def eval_function(self, func, args=()):
-        graph = self.getgraph(func)
+    def eval_function(self, func, args=(), graph=None):
+        if graph is None:
+            graph = self.getgraph(func)
         llframe = LLFrame(graph, args, self)
         try:
             return llframe.eval()
@@ -51,7 +53,12 @@
         frames.reverse()
         for frame in frames:
             print frame.graph.name,
-            print self.typer.annotator.annotated[frame.curr_block].__module__
+            try:
+                print self.typer.annotator.annotated[frame.curr_block].__module__
+            except KeyError:
+                # if the graph is from the GC it was not produced by the same
+                # translator :-(
+                print "<unknown module>"
             for i, operation in enumerate(frame.curr_block.operations):
                 if i == frame.curr_operation_index:
                     print "E  ",
@@ -60,11 +67,11 @@
                 print operation
 
     def find_roots(self):
-        print "find_roots"
+        log.find_roots("starting")
         frame = self.active_frame
         roots = []
         while frame is not None:
-            print frame.graph.name
+            log.find_roots("graph", frame.graph.name)
             frame.find_roots(roots)
             frame = frame.f_back
         return roots
@@ -228,7 +235,7 @@
             self.make_llexception(e)
 
     def find_roots(self, roots):
-        print "find_roots in LLFrame", roots, self.curr_block.inputargs
+        log.find_roots(self.curr_block.inputargs)
         for arg in self.curr_block.inputargs:
             if (isinstance(arg, Variable) and
                 isinstance(self.getval(arg), self.llt._ptr)):
@@ -469,6 +476,11 @@
         assert self.llt.typeOf(addr) == lladdress.Address
         lladdress.raw_free(addr)
 
+    def op_raw_memcopy(self, fromaddr, toaddr, size):
+        assert self.llt.typeOf(fromaddr) == lladdress.Address
+        assert self.llt.typeOf(toaddr) == lladdress.Address
+        lladdress.raw_memcopy(fromaddr, toaddr, size)
+
     def op_raw_load(self, addr, typ, offset):
         assert isinstance(addr, lladdress.address)
         value = getattr(addr, str(typ).lower())[offset]

Modified: pypy/dist/pypy/rpython/memory/test/test_address.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/test/test_address.py	(original)
+++ pypy/dist/pypy/rpython/memory/test/test_address.py	Wed Aug 31 00:43:08 2005
@@ -260,6 +260,20 @@
         res = interpret(f, [0])
         assert res
 
+    def test_raw_memcopy(self):
+        def f():
+            addr = raw_malloc(100)
+            addr.signed[0] = 12
+            (addr + 10).signed[0] = 42
+            (addr + 20).char[0] = "a"
+            addr1 = raw_malloc(100)
+            raw_memcopy(addr, addr1, 100)
+            result = addr1.signed[0] == 12
+            result = result and (addr1 + 10).signed[0] == 42
+            result = result and (addr1 + 20).char[0] == "a"
+            return result
+        res = interpret(f, [])
+        assert res
 
 class TestAddressSimulation(object):
     def test_null_is_singleton(self):



More information about the Pypy-commit mailing list