[pypy-svn] r13967 - pypy/dist/pypy/translator/c

tismer at codespeak.net tismer at codespeak.net
Sun Jun 26 16:53:05 CEST 2005


Author: tismer
Date: Sun Jun 26 16:53:04 2005
New Revision: 13967

Added:
   pypy/dist/pypy/translator/c/mkuint.py   (contents, props changed)
Modified:
   pypy/dist/pypy/translator/c/int_include.h
Log:
implemented all uint operations by the little mkuint.py script.
no testing provided at all.
If there are operations which need to be implemented
differently, please implement them directly after
the int implementation and re-run the script.


Modified: pypy/dist/pypy/translator/c/int_include.h
==============================================================================
--- pypy/dist/pypy/translator/c/int_include.h	(original)
+++ pypy/dist/pypy/translator/c/int_include.h	Sun Jun 26 16:53:04 2005
@@ -18,11 +18,13 @@
 	else FAIL_OVF(err, "integer negate")
 
 #define OP_INT_ABS(x,r,err)    r = (x) >= 0 ? x : -(x);
+#define OP_UINT_ABS(x,r,err)   r = (x);
 
 #define OP_INT_ABS_OVF(x,r,err) \
 	OP_INT_ABS(x,r,err) \
 	if ((x) >= 0 || (x) != -(x)); \
 	else FAIL_OVF(err, "integer absolute")
+#define OP_UINT_ABS_OVF(x,r,err)   r = (x);
 
 /***  binary operations ***/
 
@@ -113,7 +115,7 @@
 #define OP_INT_FLOORDIV_ZER(x,y,r,err) \
 	if ((y)) { OP_INT_FLOORDIV(x,y,r,err) } \
 	else FAIL_ZER(err, "integer division")
-		
+
 #define OP_INT_FLOORDIV_OVF_ZER(x,y,r,err) \
 	if ((y)) { OP_INT_FLOORDIV_OVF(x,y,r,err) } \
 	else FAIL_ZER(err, "integer division")
@@ -130,7 +132,7 @@
 #define OP_INT_MOD_ZER(x,y,r,err) \
 	if ((y)) { OP_INT_MOD(x,y,r,err) } \
 	else FAIL_ZER(err, "integer modulo")
-		
+
 #define OP_INT_MOD_OVF_ZER(x,y,r,err) \
 	if ((y)) { OP_INT_MOD_OVF(x,y,r,err) } \
 	else FAIL_ZER(err, "integer modulo")
@@ -216,3 +218,44 @@
 		*p_rem = xmody;
 	return xdivy;
 }
+/* no editing below this point */
+/* following lines are generated by mkuint.py */
+
+#define OP_UINT_IS_TRUE OP_INT_IS_TRUE
+#define OP_UINT_INVERT OP_INT_INVERT
+#define OP_UINT_POS OP_INT_POS
+#define OP_UINT_NEG OP_INT_NEG
+#define OP_UINT_NEG_OVF OP_INT_NEG_OVF
+/* skipping OP_UINT_ABS */
+/* skipping OP_UINT_ABS_OVF */
+#define OP_UINT_EQ OP_INT_EQ
+#define OP_UINT_NE OP_INT_NE
+#define OP_UINT_LE OP_INT_LE
+#define OP_UINT_GT OP_INT_GT
+#define OP_UINT_LT OP_INT_LT
+#define OP_UINT_GE OP_INT_GE
+#define OP_UINT_CMP OP_INT_CMP
+#define OP_UINT_ADD OP_INT_ADD
+#define OP_UINT_ADD_OVF OP_INT_ADD_OVF
+#define OP_UINT_SUB OP_INT_SUB
+#define OP_UINT_SUB_OVF OP_INT_SUB_OVF
+#define OP_UINT_MUL OP_INT_MUL
+#define OP_UINT_MUL_OVF OP_INT_MUL_OVF
+#define OP_UINT_MUL_OVF OP_INT_MUL_OVF
+#define OP_UINT_RSHIFT OP_INT_RSHIFT
+#define OP_UINT_RSHIFT_VAL OP_INT_RSHIFT_VAL
+#define OP_UINT_LSHIFT OP_INT_LSHIFT
+#define OP_UINT_LSHIFT_VAL OP_INT_LSHIFT_VAL
+#define OP_UINT_LSHIFT_OVF OP_INT_LSHIFT_OVF
+#define OP_UINT_LSHIFT_OVF_VAL OP_INT_LSHIFT_OVF_VAL
+#define OP_UINT_FLOORDIV OP_INT_FLOORDIV
+#define OP_UINT_FLOORDIV_OVF OP_INT_FLOORDIV_OVF
+#define OP_UINT_FLOORDIV_ZER OP_INT_FLOORDIV_ZER
+#define OP_UINT_FLOORDIV_OVF_ZER OP_INT_FLOORDIV_OVF_ZER
+#define OP_UINT_MOD OP_INT_MOD
+#define OP_UINT_MOD_OVF OP_INT_MOD_OVF
+#define OP_UINT_MOD_ZER OP_INT_MOD_ZER
+#define OP_UINT_MOD_OVF_ZER OP_INT_MOD_OVF_ZER
+#define OP_UINT_AND OP_INT_AND
+#define OP_UINT_OR OP_INT_OR
+#define OP_UINT_XOR OP_INT_XOR

Added: pypy/dist/pypy/translator/c/mkuint.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/c/mkuint.py	Sun Jun 26 16:53:04 2005
@@ -0,0 +1,36 @@
+# auto-generating the unsigned part of int_include.h
+
+"""
+usage:
+run this script in int_include.h's folder.
+
+Rule:
+all #define OP_INT_ macros are repeated for uint,
+except:
+if an int macro is immediately followed by an uint
+version, this takes precedence.
+"""
+
+fname = 'int_include.h'
+
+srclines = []
+lines = []
+
+stopline = '/* no editing below this point */'
+
+for srcline in file(fname):
+    srcline = srcline.rstrip()
+    line = srcline.lstrip()
+    if line.startswith('#define OP_INT_'):
+        macroname = line.split('(')[0].split()[1]
+        newname = 'OP_UINT_' + macroname[7:]
+        lines.append('#define %s %s' % (newname, macroname))
+    elif line.startswith('#define OP_UINT_'):
+        # comment the last one out
+        lines.append('/* skipping %s */' % lines.pop().split()[1])
+    elif line == stopline:
+        break
+    srclines.append(srcline)
+
+print >> file(fname, 'w'), '\n'.join(srclines + [stopline,
+            '/* following lines are generated by mkuint.py */', ''] + lines)



More information about the Pypy-commit mailing list