[pypy-svn] r12929 - in pypy/dist/pypy: annotation rpython
arigo at codespeak.net
arigo at codespeak.net
Tue May 31 15:58:17 CEST 2005
Author: arigo
Date: Tue May 31 15:58:16 2005
New Revision: 12929
Modified:
pypy/dist/pypy/annotation/builtin.py
pypy/dist/pypy/rpython/rbuiltin.py
pypy/dist/pypy/rpython/robject.py
pypy/dist/pypy/rpython/rptr.py
Log:
Support the nullptr() and nullgcptr() functions in the annotator and typer.
Some improved conversions.
Modified: pypy/dist/pypy/annotation/builtin.py
==============================================================================
--- pypy/dist/pypy/annotation/builtin.py (original)
+++ pypy/dist/pypy/annotation/builtin.py Tue May 31 15:58:16 2005
@@ -296,8 +296,23 @@
lltype = annotation_to_lltype(s_val, info="in typeOf(): ")
return immutablevalue(lltype)
+def nullptr(T):
+ assert T.is_constant()
+ p = lltype.nullptr(T.const)
+ r = SomePtr(lltype.typeOf(p))
+ r.const = p
+ return r
+
+def nullgcptr(T):
+ assert T.is_constant()
+ p = lltype.nullgcptr(T.const)
+ r = SomePtr(lltype.typeOf(p))
+ r.const = p
+ return r
+
BUILTIN_ANALYZERS[lltype.malloc] = malloc
BUILTIN_ANALYZERS[lltype.cast_flags] = cast_flags
BUILTIN_ANALYZERS[lltype.cast_parent] = cast_parent
BUILTIN_ANALYZERS[lltype.typeOf] = typeOf
-
+BUILTIN_ANALYZERS[lltype.nullptr] = nullptr
+BUILTIN_ANALYZERS[lltype.nullgcptr] = nullgcptr
Modified: pypy/dist/pypy/rpython/rbuiltin.py
==============================================================================
--- pypy/dist/pypy/rpython/rbuiltin.py (original)
+++ pypy/dist/pypy/rpython/rbuiltin.py Tue May 31 15:58:16 2005
@@ -1,6 +1,7 @@
from pypy.annotation.pairtype import pair, pairtype
from pypy.annotation.model import SomeBuiltin, SomeObject, SomeString
-from pypy.rpython.lltype import malloc, typeOf, Void, Signed
+from pypy.rpython.lltype import malloc, typeOf, nullptr, nullgcptr
+from pypy.rpython.lltype import Void, Signed
from pypy.rpython.rtyper import TyperError
@@ -81,9 +82,11 @@
return hop.genop('malloc_varsize', vlist,
resulttype = hop.s_result.lowleveltype())
-def rtype_typeOf(hop):
+def rtype_const_result(hop):
return hop.inputconst(Void, hop.s_result.const)
BUILTIN_TYPER[malloc] = rtype_malloc
-BUILTIN_TYPER[typeOf] = rtype_typeOf
+BUILTIN_TYPER[typeOf] = rtype_const_result
+BUILTIN_TYPER[nullptr] = rtype_const_result
+BUILTIN_TYPER[nullgcptr] = rtype_const_result
Modified: pypy/dist/pypy/rpython/robject.py
==============================================================================
--- pypy/dist/pypy/rpython/robject.py (original)
+++ pypy/dist/pypy/rpython/robject.py Tue May 31 15:58:16 2005
@@ -2,7 +2,7 @@
from pypy.annotation.model import SomeObject, annotation_to_lltype
from pypy.annotation import model as annmodel
from pypy.rpython.lltype import PyObject, GcPtr, Void, Bool
-from pypy.rpython.rtyper import TyperError
+from pypy.rpython.rtyper import TyperError, inputconst
PyObjPtr = GcPtr(PyObject)
@@ -62,5 +62,8 @@
TO = s_to.lowleveltype()
if PyObjPtr == FROM == TO:
return v
+ elif FROM == Void and s_from.is_constant() and s_to.contains(s_from):
+ # convert from a constant to a non-constant
+ return inputconst(TO, s_from.const)
else:
return NotImplemented
Modified: pypy/dist/pypy/rpython/rptr.py
==============================================================================
--- pypy/dist/pypy/rpython/rptr.py (original)
+++ pypy/dist/pypy/rpython/rptr.py Tue May 31 15:58:16 2005
@@ -6,7 +6,10 @@
class __extend__(SomePtr):
def lowleveltype(s_ptr):
- return s_ptr.ll_ptrtype
+ if s_ptr.is_constant(): # constant NULL
+ return Void
+ else:
+ return s_ptr.ll_ptrtype
def rtype_getattr(s_ptr, hop):
attr = hop.args_s[1].const
More information about the Pypy-commit
mailing list