[pypy-svn] r22006 - in pypy/dist/pypy/translator/c: . src test
ericvrp at codespeak.net
ericvrp at codespeak.net
Thu Jan 12 10:31:21 CET 2006
Author: ericvrp
Date: Thu Jan 12 10:31:20 2006
New Revision: 22006
Modified:
pypy/dist/pypy/translator/c/funcgen.py
pypy/dist/pypy/translator/c/src/address.h
pypy/dist/pypy/translator/c/test/test_lladdresses.py
Log:
Added genc support of stack flavored_malloc
Modified: pypy/dist/pypy/translator/c/funcgen.py
==============================================================================
--- pypy/dist/pypy/translator/c/funcgen.py (original)
+++ pypy/dist/pypy/translator/c/funcgen.py Thu Jan 12 10:31:20 2006
@@ -568,6 +568,8 @@
flavor = op.args[0].value
if flavor == "raw":
return "OP_RAW_MALLOC(%s, %s, %s);" % (esize, eresult, err)
+ elif flavor == "stack":
+ return "OP_STACK_MALLOC(%s, %s, %s);" % (esize, eresult, err)
else:
raise NotImplementedError
Modified: pypy/dist/pypy/translator/c/src/address.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/address.h (original)
+++ pypy/dist/pypy/translator/c/src/address.h Thu Jan 12 10:31:20 2006
@@ -20,5 +20,9 @@
r = (void*) malloc(size); \
if (r == NULL) FAIL_EXCEPTION(err, PyExc_MemoryError, "out of memory");\
+#define OP_STACK_MALLOC(size,r,err) \
+ r = (void*) alloca(size); \
+ if (r == NULL) FAIL_EXCEPTION(err, PyExc_MemoryError, "out of memory");\
+
#define OP_RAW_FREE(x,r,err) free(x);
#define OP_RAW_MEMCOPY(x,y,size,r,err) memcpy(y,x,size);
Modified: pypy/dist/pypy/translator/c/test/test_lladdresses.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_lladdresses.py (original)
+++ pypy/dist/pypy/translator/c/test/test_lladdresses.py Thu Jan 12 10:31:20 2006
@@ -88,7 +88,7 @@
res = fc()
assert res == int('011100' * 2, 2)
-def test_flavored_malloc():
+def test_flavored_malloc_raw():
class A(object):
_alloc_flavor_ = "raw"
def __init__(self, val):
@@ -100,3 +100,15 @@
return result
fn = compile(f, [int])
assert fn(1) == 2
+
+def test_flavored_malloc_stack():
+ class A(object):
+ _alloc_flavor_ = "stack"
+ def __init__(self, val):
+ self.val = val
+ def f(x):
+ a = A(x + 1)
+ result = a.val
+ return result
+ fn = compile(f, [int])
+ assert fn(1) == 2
More information about the Pypy-commit
mailing list