[pypy-svn] r21863 - in pypy/dist/pypy/translator/llvm: . test

ericvrp at codespeak.net ericvrp at codespeak.net
Tue Jan 10 09:12:33 CET 2006


Author: ericvrp
Date: Tue Jan 10 09:12:32 2006
New Revision: 21863

Modified:
   pypy/dist/pypy/translator/llvm/opwriter.py
   pypy/dist/pypy/translator/llvm/test/test_lladdresses.py
Log:
WIP: flavored_malloc support


Modified: pypy/dist/pypy/translator/llvm/opwriter.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/opwriter.py	(original)
+++ pypy/dist/pypy/translator/llvm/opwriter.py	Tue Jan 10 09:12:32 2006
@@ -254,7 +254,8 @@
     def direct_call(self, opr):
         self.codewriter.call(opr.retref, opr.rettype, opr.argrefs[0],
                              opr.argtypes[1:], opr.argrefs[1:])
-
+    # the following works since the extra arguments that indirect_call has
+    # is of type Void, which is removed by direct_call
     indirect_call = direct_call
 
     def malloc(self, opr):
@@ -276,6 +277,29 @@
                              self.db.repr_constructor(arg_type),
                              opr.argtypes[1:], opr.argrefs[1:])
 
+    def flavored_malloc(self, opr):
+        #TYPE = self.lltypemap(opr.op.result).TO
+        #typename = self.db.gettype(TYPE)
+        #eresult = self.expr(opr.op.result)
+        #esize = 'sizeof(%s)' % cdecl(typename, '')
+        flavor = opr.op.args[0].value
+        if flavor == "raw": 
+            self.codewriter.call(opr.retref, opr.rettype, "%raw_malloc",
+                                 opr.argtypes[1:], opr.argrefs[1:]) 
+            #return "OP_RAW_MALLOC(%s, %s);" % (esize, eresult) 
+        else:
+            raise NotImplementedError
+
+    def flavored_free(self, opr):
+        flavor = opr.op.args[0].value
+        if flavor == "raw":
+            self.codewriter.call(opr.retref, opr.rettype, "%raw_free",
+                                 opr.argtypes[1:], opr.argrefs[1:])
+            #return "OP_RAW_FREE(%s, %s)" % (self.expr(opr.op.args[1]),
+            #                                self.expr(opr.op.result))
+        else:
+            raise NotImplementedError
+
     def _getindexhelper(self, name, struct):
         assert name in list(struct._names)
 

Modified: pypy/dist/pypy/translator/llvm/test/test_lladdresses.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/test/test_lladdresses.py	(original)
+++ pypy/dist/pypy/translator/llvm/test/test_lladdresses.py	Tue Jan 10 09:12:32 2006
@@ -1,6 +1,7 @@
 from pypy.rpython.memory.lladdress import *
 from pypy.annotation.model import SomeAddress, SomeChar
 from pypy.translator.llvm.test.runtest import compile_function as compile
+from pypy.rpython.objectmodel import free_non_gc_object                                              
 import py
 
 def test_null():
@@ -101,3 +102,17 @@
     fc = compile(f, [])
     res = fc()
     assert res == int('011100' * 2, 2)
+
+def test_flavored_malloc():
+    py.test.skip("not supported yet")
+    class A(object):
+        _alloc_flavor_ = "raw"
+        def __init__(self, val):
+            self.val = val
+    def f(x):
+        a = A(x + 1)
+        result = a.val
+        free_non_gc_object(a)
+        return result
+    fn = compile(f, [int])
+    assert fn(1) == 2 



More information about the Pypy-commit mailing list