[pypy-svn] r18342 - in pypy/dist/pypy/translator/c: . src test
cfbolz at codespeak.net
cfbolz at codespeak.net
Mon Oct 10 16:45:45 CEST 2005
Author: cfbolz
Date: Mon Oct 10 16:45:40 2005
New Revision: 18342
Added:
pypy/dist/pypy/translator/c/src/address.h
pypy/dist/pypy/translator/c/test/test_lladdresses.py
Modified:
pypy/dist/pypy/translator/c/primitive.py
pypy/dist/pypy/translator/c/src/g_include.h
Log:
implement easy operations for addresses in genc
Modified: pypy/dist/pypy/translator/c/primitive.py
==============================================================================
--- pypy/dist/pypy/translator/c/primitive.py (original)
+++ pypy/dist/pypy/translator/c/primitive.py Mon Oct 10 16:45:40 2005
@@ -1,5 +1,6 @@
import sys
from pypy.rpython.lltype import *
+from pypy.rpython.memory.lladdress import Address, NULL
# ____________________________________________________________
#
@@ -43,7 +44,11 @@
def name_unichar(value):
assert type(value) is unicode and len(value) == 1
return '%d' % ord(value)
-
+
+def name_address(value):
+ assert value == NULL
+ return 'NULL'
+
PrimitiveName = {
Signed: name_signed,
@@ -53,6 +58,7 @@
UniChar: name_unichar,
Bool: name_bool,
Void: name_void,
+ Address: name_address,
}
PrimitiveType = {
@@ -63,6 +69,7 @@
UniChar: 'unsigned int @',
Bool: 'char @',
Void: 'void @',
+ Address: 'void* @',
}
PrimitiveErrorValue = {
@@ -73,4 +80,5 @@
UniChar: '((unsigned) -1)',
Bool: '((char) -1)',
Void: '/* error */',
+ Address: 'NULL',
}
Added: pypy/dist/pypy/translator/c/src/address.h
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/c/src/address.h Mon Oct 10 16:45:40 2005
@@ -0,0 +1,18 @@
+/************************************************************/
+/*** C header subsection: operations between addresses ***/
+
+/*** unary operations ***/
+
+/*** binary operations ***/
+
+#define OP_ADR_DELTA(x,y,r,err) r = ((x) - (y))
+#define OP_ADR_SUB(x,y,r,err) r = ((x) - (y))
+#define OP_ADR_ADD(x,y,r,err) r = ((x) + (y))
+
+#define OP_ADR_EQ(x,y,r,err) r = ((x) == (y))
+#define OP_ADR_NE(x,y,r,err) r = ((x) != (y))
+#define OP_ADR_LE(x,y,r,err) r = ((x) <= (y))
+#define OP_ADR_GT(x,y,r,err) r = ((x) > (y))
+#define OP_ADR_LT(x,y,r,err) r = ((x) < (y))
+#define OP_ADR_GE(x,y,r,err) r = ((x) >= (y))
+
Modified: pypy/dist/pypy/translator/c/src/g_include.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/g_include.h (original)
+++ pypy/dist/pypy/translator/c/src/g_include.h Mon Oct 10 16:45:40 2005
@@ -28,6 +28,7 @@
#include "src/unichar.h"
#include "src/float.h"
#include "src/pyobj.h"
+#include "src/address.h"
/*** modules ***/
#ifdef HAVE_RTYPER /* only if we have an RTyper */
Added: pypy/dist/pypy/translator/c/test/test_lladdresses.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/c/test/test_lladdresses.py Mon Oct 10 16:45:40 2005
@@ -0,0 +1,7 @@
+from pypy.rpython.memory import lladdress
+from pypy.translator.c.test.test_genc import compile
+
+def test_null():
+ def f():
+ return lladdress.NULL - lladdress.NULL
+ fc = compile(f, [])
More information about the Pypy-commit
mailing list