[pypy-svn] r32883 - in pypy/dist/pypy/rpython/memory/gctransform2: . test
mwh at codespeak.net
mwh at codespeak.net
Wed Oct 4 19:25:07 CEST 2006
Author: mwh
Date: Wed Oct 4 19:25:02 2006
New Revision: 32883
Added:
pypy/dist/pypy/rpython/memory/gctransform2/stacklessframework.py (contents, props changed)
pypy/dist/pypy/rpython/memory/gctransform2/test/test_stacklessframework.py (contents, props changed)
Log:
add the stacklessframework to gctransform2
Added: pypy/dist/pypy/rpython/memory/gctransform2/stacklessframework.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/rpython/memory/gctransform2/stacklessframework.py Wed Oct 4 19:25:02 2006
@@ -0,0 +1,89 @@
+from pypy.rpython.memory.gctransform2.transform import \
+ MinimalGCTransformer, var_ispyobj
+from pypy.rpython.memory.gctransform2.framework import \
+ FrameworkGCTransformer
+from pypy.rpython.lltypesystem import lltype, llmemory
+
+class StacklessFrameworkMinimalGCTransformer(MinimalGCTransformer):
+ def gct_flavored_malloc(self, hop):
+ flavor = hop.spaceop.args[0].value
+ if flavor == 'gc_nocollect':
+ return self.parenttransformer.gct_flavored_malloc(hop)
+ else:
+ self.default(hop)
+ gct_flavored_malloc_varsize = gct_flavored_malloc
+
+
+class StacklessFrameworkGCTransformer(FrameworkGCTransformer):
+ use_stackless = True
+ extra_static_slots = 1 # for the stack_capture()'d frame
+ MinimalGCTransformer = StacklessFrameworkMinimalGCTransformer
+
+ def __init__(self, translator):
+ FrameworkGCTransformer.__init__(self, translator)
+ # and now, fun fun fun, we need to inline malloc_fixedsize
+ # manually into all 'malloc' operation users, because inlining
+ # it after it has been stackless transformed is both a Very
+ # Bad Idea and forbidden by the fact that stackless transform
+ # makes it self-recursive! Argh.
+## self.replace_and_inline_malloc_already_now()
+ # nothing left to inline during code generation
+ self.inline = False
+
+## def replace_and_inline_malloc_already_now(self):
+## for graph in self.translator.graphs:
+## any_malloc = False
+## for block in graph.iterblocks():
+## if block.operations:
+## newops = []
+## for op in block.operations:
+## if op.opname.startswith('malloc'):
+## any_malloc = True
+## ops = self.replace_malloc(op, [], block)
+## if isinstance(ops, tuple):
+## ops = ops[0]
+## newops.extend(ops)
+## else:
+## newops.append(op)
+## block.operations = newops
+## if any_malloc:
+## self.inline_helpers(graph)
+
+ def build_stack_root_iterator(self):
+ from pypy.rpython.rstack import stack_capture
+ sizeofaddr = llmemory.sizeof(llmemory.Address)
+ gcdata = self.gcdata
+
+ class StackRootIterator:
+ _alloc_flavor_ = 'raw'
+
+ def setup_root_stack():
+ pass
+ setup_root_stack = staticmethod(setup_root_stack)
+
+ push_root = None
+ pop_root = None
+
+ def __init__(self):
+ frame = llmemory.cast_ptr_to_adr(stack_capture())
+ self.static_current = gcdata.static_root_start
+ index = len(gcdata.static_roots)
+ self.static_roots_index = index
+ gcdata.static_roots[index-1] = frame
+
+ def pop(self):
+ while self.static_current != gcdata.static_root_end:
+ result = self.static_current
+ self.static_current += sizeofaddr
+ if result.address[0].address[0] != llmemory.NULL:
+ return result.address[0]
+ i = self.static_roots_index
+ if i > 0:
+ i -= 1
+ self.static_roots_index = i
+ p = lltype.direct_arrayitems(gcdata.static_roots)
+ p = lltype.direct_ptradd(p, i)
+ return llmemory.cast_ptr_to_adr(p)
+ return llmemory.NULL
+
+ return StackRootIterator
Added: pypy/dist/pypy/rpython/memory/gctransform2/test/test_stacklessframework.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/rpython/memory/gctransform2/test/test_stacklessframework.py Wed Oct 4 19:25:02 2006
@@ -0,0 +1,46 @@
+from pypy.rpython.memory.gctransform2.test.test_transform import rtype
+from pypy.rpython.memory.gctransform2.stacklessframework import \
+ StacklessFrameworkGCTransformer
+from pypy.rpython.lltypesystem import lltype
+from pypy.translator.c.gc import StacklessFrameworkGcPolicy
+from pypy.translator.translator import TranslationContext, graphof
+from pypy import conftest
+
+import py
+
+class StacklessFrameworkGcPolicy2(StacklessFrameworkGcPolicy):
+ transformerclass = StacklessFrameworkGCTransformer
+
+def test_stackless_simple():
+ def g(x):
+ return x + 1
+ class A(object):
+ pass
+ def entrypoint(argv):
+ a = A()
+ a.b = g(1)
+ return a.b
+
+ from pypy.rpython.llinterp import LLInterpreter
+ from pypy.translator.c.genc import CStandaloneBuilder
+ from pypy.translator.c import gc
+ from pypy.annotation.listdef import s_list_of_strings
+
+ t = rtype(entrypoint, [s_list_of_strings])
+ cbuild = CStandaloneBuilder(t, entrypoint, StacklessFrameworkGcPolicy2)
+ db = cbuild.generate_graphs_for_llinterp()
+ entrypointptr = cbuild.getentrypointptr()
+ entrygraph = entrypointptr._obj.graph
+
+ r_list_of_strings = t.rtyper.getrepr(s_list_of_strings)
+ ll_argv = r_list_of_strings.convert_const([])
+
+ llinterp = LLInterpreter(t.rtyper)
+
+ # FIIIIISH
+ setupgraph = db.gctransformer.frameworkgc_setup_ptr.value._obj.graph
+ llinterp.eval_graph(setupgraph, [])
+
+ res = llinterp.eval_graph(entrygraph, [ll_argv])
+
+ assert res == 2
More information about the Pypy-commit
mailing list