[pypy-svn] r10276 - pypy/dist/pypy/translator/genc

arigo at codespeak.net arigo at codespeak.net
Sun Apr 3 23:04:31 CEST 2005


Author: arigo
Date: Sun Apr  3 23:04:30 2005
New Revision: 10276

Modified:
   pypy/dist/pypy/translator/genc/ctyper.py
   pypy/dist/pypy/translator/genc/g_int.h
   pypy/dist/pypy/translator/genc/t_int.py
Log:
Support the None type (for now, stored as an int, until we find a better way
to represent it as no variable at all).



Modified: pypy/dist/pypy/translator/genc/ctyper.py
==============================================================================
--- pypy/dist/pypy/translator/genc/ctyper.py	(original)
+++ pypy/dist/pypy/translator/genc/ctyper.py	Sun Apr  3 23:04:30 2005
@@ -5,15 +5,19 @@
 from pypy.translator.typer import Specializer, TypeMatch
 from pypy.annotation.model import SomeInteger, SomePBC
 from pypy.translator.genc.t_pyobj import CType_PyObject
-from pypy.translator.genc.t_int import CType_Int
+from pypy.translator.genc.t_int import CType_Int, CType_None
 from pypy.translator.genc.t_func import CType_FuncPtr
 import types
 from pypy.interpreter.pycode import CO_VARARGS
 
 class GenCSpecializer(Specializer):
 
-    TInt = TypeMatch(SomeInteger(), CType_Int)
-    typematches = [TInt]   # in more-specific-first, more-general-last order
+    TInt  = TypeMatch(SomeInteger(), CType_Int)
+    TNone = TypeMatch(SomePBC({None: True}), CType_None)
+
+    # in more-specific-first, more-general-last order
+    typematches = [TNone, TInt]
+
     defaulttypecls = CType_PyObject
 
     specializationtable = [

Modified: pypy/dist/pypy/translator/genc/g_int.h
==============================================================================
--- pypy/dist/pypy/translator/genc/g_int.h	(original)
+++ pypy/dist/pypy/translator/genc/g_int.h	Sun Apr  3 23:04:30 2005
@@ -7,6 +7,9 @@
 #define OP_OBJ2INT(o,r,err)   if ((r=PyInt_AsLong(o))==-1 && PyErr_Occurred()) \
 							  FAIL(err)
 
+#define OP_NONE2OBJ(n,r,err)  r = Py_None; Py_INCREF(r);
+#define OP_OBJ2NONE(o,n,err)  assert(o == Py_None); n = 0;
+
 #define OP_INT_IS_TRUE(x,r,err)   r = (x != 0);
 
 #define OP_INT_ADD(x,y,r,err)     r = x + y;

Modified: pypy/dist/pypy/translator/genc/t_int.py
==============================================================================
--- pypy/dist/pypy/translator/genc/t_int.py	(original)
+++ pypy/dist/pypy/translator/genc/t_int.py	Sun Apr  3 23:04:30 2005
@@ -11,3 +11,17 @@
 
     def nameof(self, v, debug=None):
         return '%d' % v
+
+
+class CType_None:
+    ctypetemplate    = 'int %s'
+    convert_to_obj   = 'none2obj'
+    convert_from_obj = 'obj2none'
+    error_return     = '-1'
+
+    def __init__(self, genc):
+        pass
+
+    def nameof(self, v, debug=None):
+        assert v is None
+        return '0'



More information about the Pypy-commit mailing list