[pypy-svn] r12760 - in pypy/dist/pypy: annotation annotation/test rpython rpython/test translator/c translator/c/test translator/genc translator/genc/test
arigo at codespeak.net
arigo at codespeak.net
Tue May 24 12:00:24 CEST 2005
Author: arigo
Date: Tue May 24 12:00:23 2005
New Revision: 12760
Added:
pypy/dist/pypy/rpython/lltype.py
- copied, changed from r12755, pypy/dist/pypy/rpython/lltypes.py
pypy/dist/pypy/rpython/rtyper.py
- copied, changed from r12755, pypy/dist/pypy/rpython/typer.py
pypy/dist/pypy/rpython/test/test_lltype.py
- copied, changed from r12755, pypy/dist/pypy/rpython/test/test_lltypes.py
pypy/dist/pypy/rpython/test/test_rtyper.py
- copied, changed from r12755, pypy/dist/pypy/rpython/test/test_typer.py
Removed:
pypy/dist/pypy/rpython/lltypes.py
pypy/dist/pypy/rpython/test/test_lltypes.py
pypy/dist/pypy/rpython/test/test_typer.py
pypy/dist/pypy/rpython/typer.py
Modified:
pypy/dist/pypy/annotation/binaryop.py
pypy/dist/pypy/annotation/bookkeeper.py
pypy/dist/pypy/annotation/builtin.py
pypy/dist/pypy/annotation/model.py
pypy/dist/pypy/annotation/test/test_model.py
pypy/dist/pypy/annotation/unaryop.py
pypy/dist/pypy/rpython/rlist.py
pypy/dist/pypy/rpython/test/test_llann.py
pypy/dist/pypy/rpython/test/test_rlist.py
pypy/dist/pypy/translator/c/database.py
pypy/dist/pypy/translator/c/funcgen.py
pypy/dist/pypy/translator/c/node.py
pypy/dist/pypy/translator/c/primitive.py
pypy/dist/pypy/translator/c/pyobj.py
pypy/dist/pypy/translator/c/support.py
pypy/dist/pypy/translator/c/test/test_database.py
pypy/dist/pypy/translator/genc/ctyper.py
pypy/dist/pypy/translator/genc/lltype.py
pypy/dist/pypy/translator/genc/test/test_lltyped.py
Log:
Renamed files in rpython:
- typer.py ---> rtyper.py
- lltypes.py ---> lltype.py
Lots of fixes to the import statements in the rest of the code.
Modified: pypy/dist/pypy/annotation/binaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/binaryop.py (original)
+++ pypy/dist/pypy/annotation/binaryop.py Tue May 24 12:00:23 2005
@@ -477,7 +477,6 @@
return pair(s, pbc).union()
# annotation of low-level types
-from pypy.rpython import lltypes
from pypy.annotation.model import SomePtr, ll_to_annotation
class __extend__(pairtype(SomePtr, SomePtr)):
Modified: pypy/dist/pypy/annotation/bookkeeper.py
==============================================================================
--- pypy/dist/pypy/annotation/bookkeeper.py (original)
+++ pypy/dist/pypy/annotation/bookkeeper.py Tue May 24 12:00:23 2005
@@ -16,7 +16,6 @@
from pypy.interpreter.pycode import cpython_code_signature
from pypy.interpreter.argument import ArgErr
from pypy.rpython.rarithmetic import r_uint
-from pypy.rpython import lltypes
from pypy.tool.unionfind import UnionFind
import inspect, new
@@ -224,8 +223,6 @@
def valueoftype(self, t):
"""The most precise SomeValue instance that contains all
objects of type t."""
- if isinstance(t, lltypes.LowLevelType):
- return ll_to_annotation(t._example())
assert isinstance(t, (type, ClassType))
if t is bool:
return SomeBool()
Modified: pypy/dist/pypy/annotation/builtin.py
==============================================================================
--- pypy/dist/pypy/annotation/builtin.py (original)
+++ pypy/dist/pypy/annotation/builtin.py Tue May 24 12:00:23 2005
@@ -247,15 +247,15 @@
# annotation of low-level types
from pypy.annotation.model import SomePtr
-from pypy.rpython import lltypes
+from pypy.rpython import lltype
def malloc(T, n=None):
assert n is None or n.knowntype == int
assert T.is_constant()
if n is not None:
n = 1
- p = lltypes.malloc(T.const, n)
- r = SomePtr(lltypes.typeOf(p))
+ p = lltype.malloc(T.const, n)
+ r = SomePtr(lltype.typeOf(p))
#print "MALLOC", r
return r
@@ -263,7 +263,7 @@
#print "CAST", s_p
assert isinstance(s_p, SomePtr), "casting of non-pointer: %r" % s_p
assert PtrT.is_constant()
- return SomePtr(ll_ptrtype=lltypes.typeOf(lltypes.cast_flags(PtrT.const, s_p.ll_ptrtype._example())))
+ return SomePtr(ll_ptrtype=lltype.typeOf(lltype.cast_flags(PtrT.const, s_p.ll_ptrtype._example())))
def cast_parent(PtrT, s_p):
assert isinstance(s_p, SomePtr), "casting of non-pointer: %r" % s_p
@@ -272,9 +272,9 @@
parent_p = PtrT._example()
candidate_p = s_p.ll_ptrtype._example()
parent_p._setfirst(candidate_p)
- return SomePtr(ll_ptrtype=lltypes.typeOf(lltypes.cast_parent(PtrT, candidate_p)))
+ return SomePtr(ll_ptrtype=lltype.typeOf(lltype.cast_parent(PtrT, candidate_p)))
-BUILTIN_ANALYZERS[lltypes.malloc] = malloc
-BUILTIN_ANALYZERS[lltypes.cast_flags] = cast_flags
-BUILTIN_ANALYZERS[lltypes.cast_parent] = cast_parent
+BUILTIN_ANALYZERS[lltype.malloc] = malloc
+BUILTIN_ANALYZERS[lltype.cast_flags] = cast_flags
+BUILTIN_ANALYZERS[lltype.cast_parent] = cast_parent
Modified: pypy/dist/pypy/annotation/model.py
==============================================================================
--- pypy/dist/pypy/annotation/model.py (original)
+++ pypy/dist/pypy/annotation/model.py Tue May 24 12:00:23 2005
@@ -320,14 +320,14 @@
self.ll_ptrtype = ll_ptrtype
-from pypy.rpython import lltypes
+from pypy.rpython import lltype
annotation_to_ll_map = [
- (SomeBool(), lltypes.Bool),
- (SomeInteger(), lltypes.Signed),
- (SomeInteger(nonneg=True, unsigned=True), lltypes.Unsigned),
- (SomeChar(), lltypes.Char),
- (SomePBC({None: True}), lltypes.Void),
+ (SomeBool(), lltype.Bool),
+ (SomeInteger(), lltype.Signed),
+ (SomeInteger(nonneg=True, unsigned=True), lltype.Unsigned),
+ (SomeChar(), lltype.Char),
+ (SomePBC({None: True}), lltype.Void),
]
def annotation_to_lltype(s_val, info=None):
@@ -348,7 +348,7 @@
def ll_to_annotation(v):
if v is None:
raise ValueError, "cannot retrieve Void low-level type value"
- typ = lltypes.typeOf(v)
+ typ = lltype.typeOf(v)
s = ll_to_annotation_map.get(typ)
if s is None:
return SomePtr(typ)
Modified: pypy/dist/pypy/annotation/test/test_model.py
==============================================================================
--- pypy/dist/pypy/annotation/test/test_model.py (original)
+++ pypy/dist/pypy/annotation/test/test_model.py Tue May 24 12:00:23 2005
@@ -103,21 +103,21 @@
assert s1 != s2
def test_ll_to_annotation():
- s_z = ll_to_annotation(lltypes.Signed._defl())
+ s_z = ll_to_annotation(lltype.Signed._defl())
s_s = SomeInteger()
s_u = SomeInteger(nonneg=True, unsigned=True)
assert s_z.contains(s_s)
assert not s_z.contains(s_u)
- s_uz = ll_to_annotation(lltypes.Unsigned._defl())
+ s_uz = ll_to_annotation(lltype.Unsigned._defl())
assert s_uz.contains(s_u)
- assert ll_to_annotation(lltypes.Bool._defl()).contains(SomeBool())
- assert ll_to_annotation(lltypes.Char._defl()).contains(SomeChar())
- S = lltypes.GcStruct('s')
- A = lltypes.GcArray()
- s_p = ll_to_annotation(lltypes.malloc(S))
- assert isinstance(s_p, SomePtr) and s_p.ll_ptrtype == lltypes.GcPtr(S)
- s_p = ll_to_annotation(lltypes.malloc(A, 0))
- assert isinstance(s_p, SomePtr) and s_p.ll_ptrtype == lltypes.GcPtr(A)
+ assert ll_to_annotation(lltype.Bool._defl()).contains(SomeBool())
+ assert ll_to_annotation(lltype.Char._defl()).contains(SomeChar())
+ S = lltype.GcStruct('s')
+ A = lltype.GcArray()
+ s_p = ll_to_annotation(lltype.malloc(S))
+ assert isinstance(s_p, SomePtr) and s_p.ll_ptrtype == lltype.GcPtr(S)
+ s_p = ll_to_annotation(lltype.malloc(A, 0))
+ assert isinstance(s_p, SomePtr) and s_p.ll_ptrtype == lltype.GcPtr(A)
def test_annotation_to_lltype():
from pypy.rpython.rarithmetic import r_uint
@@ -128,25 +128,25 @@
s_u = SomeInteger(nonneg=True, unsigned=True);
s_u1 = SomeInteger(nonneg=True, unsigned=True);
s_u1.const = r_uint(1)
- assert annotation_to_lltype(s_i) == lltypes.Signed
- assert annotation_to_lltype(s_pos) == lltypes.Signed
- assert annotation_to_lltype(s_1) == lltypes.Signed
- assert annotation_to_lltype(s_m1) == lltypes.Signed
- assert annotation_to_lltype(s_u) == lltypes.Unsigned
- assert annotation_to_lltype(s_u1) == lltypes.Unsigned
- assert annotation_to_lltype(SomeBool()) == lltypes.Bool
- assert annotation_to_lltype(SomeChar()) == lltypes.Char
- PS = lltypes.GcPtr(lltypes.GcStruct('s'))
+ assert annotation_to_lltype(s_i) == lltype.Signed
+ assert annotation_to_lltype(s_pos) == lltype.Signed
+ assert annotation_to_lltype(s_1) == lltype.Signed
+ assert annotation_to_lltype(s_m1) == lltype.Signed
+ assert annotation_to_lltype(s_u) == lltype.Unsigned
+ assert annotation_to_lltype(s_u1) == lltype.Unsigned
+ assert annotation_to_lltype(SomeBool()) == lltype.Bool
+ assert annotation_to_lltype(SomeChar()) == lltype.Char
+ PS = lltype.GcPtr(lltype.GcStruct('s'))
s_p = SomePtr(ll_ptrtype=PS)
assert annotation_to_lltype(s_p) == PS
py.test.raises(ValueError, "annotation_to_lltype(si0)")
def test_ll_union():
- PS1 = lltypes.GcPtr(lltypes.GcStruct('s'))
- PS2 = lltypes.GcPtr(lltypes.GcStruct('s'))
- PS3 = lltypes.GcPtr(lltypes.GcStruct('s3'))
- PA1 = lltypes.GcPtr(lltypes.GcArray())
- PA2 = lltypes.GcPtr(lltypes.GcArray())
+ PS1 = lltype.GcPtr(lltype.GcStruct('s'))
+ PS2 = lltype.GcPtr(lltype.GcStruct('s'))
+ PS3 = lltype.GcPtr(lltype.GcStruct('s3'))
+ PA1 = lltype.GcPtr(lltype.GcArray())
+ PA2 = lltype.GcPtr(lltype.GcArray())
assert unionof(SomePtr(PS1),SomePtr(PS1)) == SomePtr(PS1)
assert unionof(SomePtr(PS1),SomePtr(PS2)) == SomePtr(PS2)
Modified: pypy/dist/pypy/annotation/unaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/unaryop.py (original)
+++ pypy/dist/pypy/annotation/unaryop.py Tue May 24 12:00:23 2005
@@ -435,7 +435,6 @@
pass
# annotation of low-level types
-from pypy.rpython import lltypes
from pypy.annotation.model import SomePtr, ll_to_annotation, annotation_to_lltype
class __extend__(SomePtr):
Copied: pypy/dist/pypy/rpython/lltype.py (from r12755, pypy/dist/pypy/rpython/lltypes.py)
==============================================================================
--- pypy/dist/pypy/rpython/lltypes.py (original)
+++ pypy/dist/pypy/rpython/lltype.py Tue May 24 12:00:23 2005
@@ -190,7 +190,7 @@
class _PtrType(LowLevelType):
def __init__(self, TO, **flags):
if not isinstance(TO, ContainerType):
- raise TypeError, ("can only point to a Struct or an Array or a FuncType, "
+ raise TypeError, ("can only point to a Container type, "
"not to %s" % (TO,))
if 'gc' in flags:
if not isinstance(TO, GC_CONTAINER):
@@ -571,13 +571,13 @@
raise TypeError, "malloc for Structs and Arrays only"
return _ptr(GcPtr(T), o)
-def function(TYPE, name, **attrs):
+def functionptr(TYPE, name, **attrs):
if not isinstance(TYPE, FuncType):
raise TypeError, "function() for FuncTypes only"
o = _func(TYPE, _name=name, **attrs)
return _ptr(NonGcPtr(TYPE), o)
-def pyobject(obj, **flags):
+def pyobjectptr(obj, **flags):
T = _PtrType(PyObject, **flags)
o = _pyobject(obj)
return _ptr(T, o)
Deleted: /pypy/dist/pypy/rpython/lltypes.py
==============================================================================
--- /pypy/dist/pypy/rpython/lltypes.py Tue May 24 12:00:23 2005
+++ (empty file)
@@ -1,583 +0,0 @@
-import weakref
-import py
-from pypy.rpython.rarithmetic import r_uint
-from pypy.tool.uid import Hashable
-
-class frozendict(dict):
-
- def __hash__(self):
- items = self.items()
- items.sort()
- return hash(tuple(items))
-
-
-class LowLevelType(object):
- def __eq__(self, other):
- return self.__class__ is other.__class__ and self.__dict__ == other.__dict__
- def __ne__(self, other):
- return not (self == other)
-
- def __hash__(self):
- items = self.__dict__.items()
- items.sort()
- return hash((self.__class__,) + tuple(items))
-
- def __repr__(self):
- return '<%s>' % (self,)
-
- def __str__(self):
- return self.__class__.__name__
-
- def _defl(self, parent=None, parentindex=None):
- raise NotImplementedError
-
- def _freeze_(self):
- return True
-
- def _inline_is_varsize(self, last):
- return False
-
-
-class ContainerType(LowLevelType):
- def _inline_is_varsize(self, last):
- raise TypeError, "%r cannot be inlined in structure" % self
-
-
-class Struct(ContainerType):
- def __init__(self, name, *fields):
- self._name = name
- flds = {}
- names = []
- self._arrayfld = None
- for name, typ in fields:
- if name.startswith('_'):
- raise NameError, ("%s: field name %r should not start with "
- "an underscore" % (self._name, name,))
- names.append(name)
- if name in flds:
- raise TypeError("%s: repeated field name" % self._name)
- flds[name] = typ
- if isinstance(typ, GC_CONTAINER):
- if name == fields[0][0] and isinstance(self, GC_CONTAINER):
- pass # can inline a GC_CONTAINER as 1st field of GcStruct
- else:
- raise TypeError("%s: cannot inline GC container %r" % (
- self._name, typ))
-
- # look if we have an inlined variable-sized array as the last field
- if fields:
- for name, typ in fields[:-1]:
- typ._inline_is_varsize(False)
- first = False
- name, typ = fields[-1]
- if typ._inline_is_varsize(True):
- self._arrayfld = name
- self._flds = frozendict(flds)
- self._names = tuple(names)
-
- def _inline_is_varsize(self, last):
- if self._arrayfld:
- raise TypeError("cannot inline a var-sized struct "
- "inside another struct")
- return False
-
- def __getattr__(self, name):
- try:
- return self._flds[name]
- except KeyError:
- raise AttributeError, 'struct %s has no field %r' % (self._name,
- name)
-
- def _str_fields(self):
- return ', '.join(['%s: %s' % (name, self._flds[name])
- for name in self._names])
-
- def __str__(self):
- return "%s %s { %s }" % (self.__class__.__name__,
- self._name, self._str_fields())
-
- def _defl(self, parent=None, parentindex=None):
- return _struct(self, parent=parent, parentindex=parentindex)
-
- def _container_example(self):
- if self._arrayfld is None:
- n = None
- else:
- n = 1
- return _struct(self, n)
-
-class GcStruct(Struct):
- pass
-
-class Array(ContainerType):
- def __init__(self, *fields):
- self.OF = Struct("<arrayitem>", *fields)
- if self.OF._arrayfld is not None:
- raise TypeError("array cannot contain an inlined array")
-
- def _inline_is_varsize(self, last):
- if not last:
- raise TypeError("array field must be last")
- return True
-
- def __str__(self):
- return "%s of { %s }" % (self.__class__.__name__,
- self.OF._str_fields(),)
-
- def _container_example(self):
- return _array(self, 1)
-
-class GcArray(Array):
- def _inline_is_varsize(self, last):
- raise TypeError("cannot inline a GC array inside a structure")
-
-class FuncType(ContainerType):
- def __init__(self, args, result):
- for arg in args:
- if isinstance(arg, ContainerType):
- raise TypeError, "function arguments can only be primitives or pointers"
- self.ARGS = tuple(args)
- if isinstance(result, ContainerType):
- raise TypeError, "function result can only be primitive or pointer"
- self.RESULT = result
-
- def __str__(self):
- args = ', '.join(map(str, self.ARGS))
- return "Func ( %s ) -> %s" % (args, self.RESULT)
-
- def _container_example(self):
- def ex(*args):
- return self.RESULT._example()
- return _func(self, _callable=ex)
-
-class PyObjectType(ContainerType):
- def __str__(self):
- return "PyObject"
-PyObject = PyObjectType()
-
-class ForwardReference(ContainerType):
- def become(self, realcontainertype):
- if not isinstance(realcontainertype, GC_CONTAINER):
- raise TypeError("ForwardReference can only be to GcStruct or "
- "GcArray, not %r" % (realcontainertype,))
- self.__class__ = realcontainertype.__class__
- self.__dict__ = realcontainertype.__dict__
-
-GC_CONTAINER = (GcStruct, GcArray, PyObjectType, ForwardReference)
-
-
-class Primitive(LowLevelType):
- def __init__(self, name, default):
- self._name = name
- self._default = default
-
- def __str__(self):
- return self._name
-
- def _defl(self, parent=None, parentindex=None):
- return self._default
-
- _example = _defl
-
-
-Signed = Primitive("Signed", 0)
-Unsigned = Primitive("Unsigned", r_uint(0))
-Char = Primitive("Char", '\x00')
-Bool = Primitive("Bool", False)
-Void = Primitive("Void", None)
-
-
-class _PtrType(LowLevelType):
- def __init__(self, TO, **flags):
- if not isinstance(TO, ContainerType):
- raise TypeError, ("can only point to a Struct or an Array or a FuncType, "
- "not to %s" % (TO,))
- if 'gc' in flags:
- if not isinstance(TO, GC_CONTAINER):
- raise TypeError, ("GcPtr can only point to GcStruct, GcArray or"
- " PyObject, not to %s" % (TO,))
- self.TO = TO
- self.flags = frozendict(flags)
-
- def _str_flags(self):
- flags = self.flags.keys()
- flags.sort()
- result = []
- for flag in flags:
- if self.flags[flag] is not True:
- flag = '%s=%r' % (flag, self.flags[flag])
- result.append(flag)
- return ', '.join(result)
-
- def __str__(self):
- return 'ptr(%s) to %s' % (self._str_flags(), self.TO)
-
- def _defl(self, parent=None, parentindex=None):
- return _ptr(self, None)
-
- def _example(self):
- o = self.TO._container_example()
- return _ptr(self, o)
-
- def withflags(self, **flags):
- newflags = self.flags.copy()
- newflags.update(flags)
- return _PtrType(self.TO, **newflags)
-
-def GcPtr(TO, **flags):
- return _PtrType(TO, gc=True, **flags)
-
-def NonGcPtr(TO, **flags):
- return _PtrType(TO, **flags)
-
-
-# ____________________________________________________________
-
-
-def typeOf(val):
- if isinstance(val, bool):
- return Bool
- if isinstance(val, r_uint):
- return Unsigned
- if isinstance(val, int):
- return Signed
- if isinstance(val, str):
- assert len(val) == 1
- return Char
- if val is None:
- return Void # maybe
- return val._TYPE
-
-class InvalidCast(TypeError):
- pass
-
-def cast_flags(PTRTYPE, ptr):
- if not isinstance(ptr, _ptr) or not isinstance(PTRTYPE, _PtrType):
- raise TypeError, "can only cast pointers to other pointers"
- CURTYPE = ptr._TYPE
- if CURTYPE.TO != PTRTYPE.TO:
- raise TypeError, "cast_flags only between pointers to the same type"
- # allowed direct casts (for others, you need several casts):
- # * adding one flag
- curflags = CURTYPE.flags
- newflags = PTRTYPE.flags
- if len(curflags) + 1 == len(newflags):
- for key in curflags:
- if key not in newflags or curflags[key] != newflags[key]:
- raise InvalidCast(CURTYPE, PTRTYPE)
- # * removing one flag
- elif len(curflags) - 1 == len(newflags):
- for key in newflags:
- if key not in curflags or curflags[key] != newflags[key]:
- raise InvalidCast(CURTYPE, PTRTYPE)
- # end
- else:
- raise InvalidCast(CURTYPE, PTRTYPE)
- return _ptr(PTRTYPE, ptr._obj)
-
-def cast_parent(PTRTYPE, ptr):
- if not isinstance(ptr, _ptr) or not isinstance(PTRTYPE, _PtrType):
- raise TypeError, "can only cast pointers to other pointers"
- CURTYPE = ptr._TYPE
- if CURTYPE.flags != PTRTYPE.flags:
- raise TypeError("cast_parent() cannot change the flags (%s) to (%s)"
- % (CURTYPE._str_flags(), PTRTYPE._str_flags()))
- # * converting from TO-structure to a parent TO-structure whose first
- # field is the original structure
- if (not isinstance(CURTYPE.TO, Struct) or
- not isinstance(PTRTYPE.TO, Struct) or
- len(PTRTYPE.TO._names) == 0 or
- PTRTYPE.TO._flds[PTRTYPE.TO._names[0]] != CURTYPE.TO):
- raise InvalidCast(CURTYPE, PTRTYPE)
- ptr._check()
- parent = ptr._obj._wrparent()
- PARENTTYPE = ptr._obj._wrparent_type
- if getattr(parent, PARENTTYPE._names[0]) is not ptr._obj:
- raise InvalidCast(CURTYPE, PTRTYPE)
- return _ptr(PTRTYPE, parent)
-
-
-def _TmpPtr(TO):
- return _PtrType(TO, _tmp=True)
-
-def _expose(val, can_have_gc=False):
- """XXX A nice docstring here"""
- T = typeOf(val)
- if isinstance(T, ContainerType):
- assert not isinstance(T, FuncType), "functions cannot be substructures"
- if can_have_gc and isinstance(T, GcStruct):
- val = _ptr(GcPtr(T), val)
- else:
- val = _ptr(_TmpPtr(T), val)
- return val
-
-def parentlink(container):
- parent = container._parentstructure()
- if parent is not None:
- return parent, container._wrparent_index
-## if isinstance(parent, _struct):
-## for name in parent._TYPE._names:
-## if getattr(parent, name) is container:
-## return parent, name
-## raise RuntimeError("lost ourselves")
-## if isinstance(parent, _array):
-## raise TypeError("cannot fish a pointer to an array item or an "
-## "inlined substructure of it")
-## raise AssertionError("don't know about %r" % (parent,))
- else:
- return None, None
-
-
-class _ptr(object):
-
- def __init__(self, TYPE, pointing_to):
- self.__dict__['_TYPE'] = TYPE
- self.__dict__['_T'] = TYPE.TO
- self.__dict__['_obj'] = pointing_to
-
- def __eq__(self, other):
- if not isinstance(other, _ptr):
- raise TypeError("comparing pointer with %r object" % (
- type(other).__name__,))
- if self._TYPE != other._TYPE:
- raise TypeError("comparing %r and %r" % (self._TYPE, other._TYPE))
- return self._obj is other._obj
-
- def __ne__(self, other):
- return not (self == other)
-
- def __nonzero__(self):
- return self._obj is not None
-
- def _check(self):
- if self._obj is None:
- raise RuntimeError("dereferencing 'NULL' pointer to %r" % (self._T,))
- self._obj._check()
-
- def __getattr__(self, field_name): # ! can only return basic or ptr !
- if isinstance(self._T, Struct):
- if field_name in self._T._flds:
- self._check()
- o = getattr(self._obj, field_name)
- can_have_gc = (field_name == self._T._names[0] and
- 'gc' in self._TYPE.flags)
- return _expose(o, can_have_gc)
- raise AttributeError("%r instance has no field %r" % (self._T,
- field_name))
-
- def _setfirst(self, p):
- if isinstance(self._T, Struct) and self._T._names:
- if not isinstance(p, _ptr) or not isinstance(p._obj, _struct):
- raise InvalidCast(typeOf(p), typeOf(self))
- field_name = self._T._names[0]
- T1 = self._T._flds[field_name]
- T2 = typeOf(p._obj)
- if T1 != T2:
- raise InvalidCast(typeOf(p), typeOf(self))
- self._check()
- setattr(self._obj, field_name, p._obj)
- p._obj._wrparent = weakref.ref(self._obj)
- p._obj._wrparent_type = typeOf(self._obj)
- return
- raise TypeError("%r instance has no first field" % (self._T,))
-
- def __setattr__(self, field_name, val):
- if isinstance(self._T, Struct):
- if field_name in self._T._flds:
- T1 = self._T._flds[field_name]
- T2 = typeOf(val)
- if T1 != T2:
- raise TypeError("%r instance field %r:\n"
- "expects %r\n"
- " got %r" % (self._T, field_name, T1, T2))
- self._check()
- setattr(self._obj, field_name, val)
- return
- raise AttributeError("%r instance has no field %r" % (self._T,
- field_name))
-
- def __getitem__(self, i): # ! can only return basic or ptr !
- if isinstance(self._T, Array):
- self._check()
- if not (0 <= i < len(self._obj.items)):
- raise IndexError("array index out of bounds")
- o = self._obj.items[i]
- return _expose(o)
- raise TypeError("%r instance is not an array" % (self._T,))
-
- def __setitem__(self, i, val): # ! not allowed !
- if isinstance(self._T, Array):
- raise TypeError("cannot directly assign to array items")
- raise TypeError("%r instance is not an array" % (self._T,))
-
- def __len__(self):
- if isinstance(self._T, Array):
- self._check()
- return len(self._obj.items)
- raise TypeError("%r instance is not an array" % (self._T,))
-
- def __repr__(self):
- return '<%s>' % (self,)
-
- def __str__(self):
- return '%s to %s' % (self._TYPE.__class__.__name__.lower(), self._obj)
-
- def __call__(self, *args):
- if isinstance(self._T, FuncType):
- self._check()
- if len(args) != len(self._T.ARGS):
- raise TypeError,"calling %r with wrong argument number: %r" % (self._T, args)
- for a, ARG in zip(args, self._T.ARGS):
- if typeOf(a) != ARG:
- raise TypeError,"calling %r with wrong argument types: %r" % (self._T, args)
- return self._obj._callable(*args)
- raise TypeError("%r instance is not a function" % (self._T,))
-
-
-class _struct(object):
- _wrparent = None
-
- def __init__(self, TYPE, n=None, parent=None, parentindex=None):
- self._TYPE = TYPE
- if n is not None and TYPE._arrayfld is None:
- raise TypeError("%r is not variable-sized" % (TYPE,))
- if n is None and TYPE._arrayfld is not None:
- raise TypeError("%r is variable-sized" % (TYPE,))
- for fld, typ in TYPE._flds.items():
- if isinstance(typ, Struct):
- value = _struct(typ, parent=self, parentindex=fld)
- elif fld == TYPE._arrayfld:
- value = _array(typ, n, parent=self, parentindex=fld)
- else:
- value = typ._defl()
- setattr(self, fld, value)
- if parent is not None:
- self._wrparent_type = typeOf(parent)
- self._wrparent = weakref.ref(parent)
- self._wrparent_index = parentindex
-
- def _parentstructure(self):
- if self._wrparent is not None:
- parent = self._wrparent()
- if parent is None:
- raise RuntimeError("accessing substructure %r,\n"
- "but already garbage collected parent %r"
- % (self, self._wrparent_type))
- return parent
- return None
-
- def _check(self):
- parent = self._parentstructure()
- if parent is not None:
- parent._check()
-
- def __repr__(self):
- return '<%s>' % (self,)
-
- def _str_fields(self):
- fields = []
- for name in self._TYPE._names:
- T = self._TYPE._flds[name]
- if isinstance(T, Primitive):
- reprvalue = repr(getattr(self, name))
- else:
- reprvalue = '...'
- fields.append('%s=%s' % (name, reprvalue))
- return ', '.join(fields)
-
- def __str__(self):
- return 'struct %s { %s }' % (self._TYPE._name, self._str_fields())
-
-class _array(object):
- _wrparent = None
-
- def __init__(self, TYPE, n, parent=None, parentindex=None):
- if not isinstance(n, int):
- raise TypeError, "array length must be an int"
- if n < 0:
- raise ValueError, "negative array length"
- self._TYPE = TYPE
- self.items = [TYPE.OF._defl(parent=self, parentindex=j)
- for j in range(n)]
- if parent is not None:
- self._wrparent_type = typeOf(parent)
- self._wrparent = weakref.ref(parent)
- self._wrparent_index = parentindex
-
- def _parentstructure(self):
- if self._wrparent is not None:
- parent = self._wrparent()
- if parent is None:
- raise RuntimeError("accessing subarray %r,\n"
- "but already garbage collected parent %r"
- % (self, self._wrparent_type))
- return parent
- return None
-
- def _check(self):
- parent = self._parentstructure()
- if parent is not None:
- parent._check()
-
- def __repr__(self):
- return '<%s>' % (self,)
-
- def __str__(self):
- return 'array [ %s ]' % (', '.join(['{%s}' % item._str_fields()
- for item in self.items]),)
-
-class _func(object):
- def __init__(self, TYPE, **attrs):
- self._TYPE = TYPE
- self._name = "?"
- self._callable = None
- self.__dict__.update(attrs)
-
- def _parentstructure(self):
- return None
-
- def _check(self):
- if self._callable is None:
- raise RuntimeError,"calling undefined function"
-
- def __repr__(self):
- return '<%s>' % (self,)
-
- def __str__(self):
- return "func %s" % self._name
-
-class _pyobject(Hashable):
- _TYPE = PyObject
-
- def _parentstructure(self):
- return None
-
- def _check(self):
- pass
-
- def __repr__(self):
- return '<%s>' % (self,)
-
- def __str__(self):
- return "pyobject %s" % (super(_pyobject, self).__str__(),)
-
-
-def malloc(T, n=None):
- if isinstance(T, Struct):
- o = _struct(T, n)
- elif isinstance(T, Array):
- o = _array(T, n)
- else:
- raise TypeError, "malloc for Structs and Arrays only"
- return _ptr(GcPtr(T), o)
-
-def function(TYPE, name, **attrs):
- if not isinstance(TYPE, FuncType):
- raise TypeError, "function() for FuncTypes only"
- o = _func(TYPE, _name=name, **attrs)
- return _ptr(NonGcPtr(TYPE), o)
-
-def pyobject(obj, **flags):
- T = _PtrType(PyObject, **flags)
- o = _pyobject(obj)
- return _ptr(T, o)
Modified: pypy/dist/pypy/rpython/rlist.py
==============================================================================
--- pypy/dist/pypy/rpython/rlist.py (original)
+++ pypy/dist/pypy/rpython/rlist.py Tue May 24 12:00:23 2005
@@ -1,6 +1,6 @@
import py
from pypy.annotation.model import *
-from pypy.rpython.lltypes import *
+from pypy.rpython.lltype import *
from pypy.tool.sourcetools import compile_template
Copied: pypy/dist/pypy/rpython/rtyper.py (from r12755, pypy/dist/pypy/rpython/typer.py)
==============================================================================
--- pypy/dist/pypy/rpython/typer.py (original)
+++ pypy/dist/pypy/rpython/rtyper.py Tue May 24 12:00:23 2005
@@ -1,5 +1,5 @@
import types
-from pypy.rpython.lltypes import *
+from pypy.rpython.lltype import *
from pypy.annotation.model import *
from pypy.objspace.flow.model import Variable, Constant, SpaceOperation
from pypy.translator.typer import Specializer, flatten_ops, TyperError
@@ -203,8 +203,10 @@
try:
functyp = python_function.TYPE
except AttributeError:
+ inputargs_s = [ll_to_annotation(t._example())
+ for t in argtypes]
s_returnvalue = self.annotator.build_types(python_function,
- argtypes)
+ inputargs_s)
inferred_type = annotation_to_lltype(s_returnvalue,
info=python_function)
if inferred_type != restype:
Modified: pypy/dist/pypy/rpython/test/test_llann.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_llann.py (original)
+++ pypy/dist/pypy/rpython/test/test_llann.py Tue May 24 12:00:23 2005
@@ -1,4 +1,4 @@
-from pypy.rpython.lltypes import *
+from pypy.rpython.lltype import *
from pypy.annotation import model as annmodel
@@ -94,6 +94,6 @@
def llf(p):
return p(0)
a = self.RPythonAnnotator()
- s = a.build_types(llf, [PF])
+ s = a.build_types(llf, [annmodel.SomePtr(PF)])
assert s.knowntype == int
Copied: pypy/dist/pypy/rpython/test/test_lltype.py (from r12755, pypy/dist/pypy/rpython/test/test_lltypes.py)
==============================================================================
--- pypy/dist/pypy/rpython/test/test_lltypes.py (original)
+++ pypy/dist/pypy/rpython/test/test_lltype.py Tue May 24 12:00:23 2005
@@ -1,5 +1,5 @@
-from pypy.rpython.lltypes import *
-from pypy.rpython.lltypes import _TmpPtr
+from pypy.rpython.lltype import *
+from pypy.rpython.lltype import _TmpPtr
def test_basics():
S0 = GcStruct("s0", ('a', Signed), ('b', Signed))
Deleted: /pypy/dist/pypy/rpython/test/test_lltypes.py
==============================================================================
--- /pypy/dist/pypy/rpython/test/test_lltypes.py Tue May 24 12:00:23 2005
+++ (empty file)
@@ -1,259 +0,0 @@
-from pypy.rpython.lltypes import *
-from pypy.rpython.lltypes import _TmpPtr
-
-def test_basics():
- S0 = GcStruct("s0", ('a', Signed), ('b', Signed))
- assert S0.a == Signed
- assert S0.b == Signed
- s0 = malloc(S0)
- print s0
- assert typeOf(s0) == GcPtr(S0)
- assert s0.a == 0
- assert s0.b == 0
- assert typeOf(s0.a) == Signed
- s0.a = 1
- s0.b = s0.a
- assert s0.a == 1
- assert s0.b == 1
- # simple array
- Ar = GcArray(('v', Signed))
- x = malloc(Ar,0)
- print x
- assert len(x) == 0
- x = malloc(Ar,3)
- print x
- assert typeOf(x) == GcPtr(Ar)
- assert typeOf(x[0]) == _TmpPtr(Ar.OF)
- assert typeOf(x[0].v) == Signed
- assert x[0].v == 0
- x[0].v = 1
- x[1].v = 2
- x[2].v = 3
- assert [x[z].v for z in range(3)] == [1, 2, 3]
- #
- def define_list(T):
- List_typ = GcStruct("list",
- ("items", GcPtr(GcArray(('item',T)))))
- def newlist():
- l = malloc(List_typ)
- items = malloc(List_typ.items.TO, 0)
- l.items = items
- return l
-
- def append(l, newitem):
- length = len(l.items)
- newitems = malloc(List_typ.items.TO, length+1)
- i = 0
- while i<length:
- newitems[i].item = l.items[i].item
- i += 1
- newitems[length].item = newitem
- l.items = newitems
-
- def item(l, i):
- return l.items[i].item
-
- return List_typ, newlist, append, item
-
- List_typ, inewlist, iappend, iitem = define_list(Signed)
-
- l = inewlist()
- assert typeOf(l) == GcPtr(List_typ)
- iappend(l, 2)
- iappend(l, 3)
- assert len(l.items) == 2
- assert iitem(l, 0) == 2
- assert iitem(l, 1) == 3
-
- IWrap = GcStruct("iwrap", ('v', Signed))
- List_typ, iwnewlist, iwappend, iwitem = define_list(GcPtr(IWrap))
-
- l = iwnewlist()
- assert typeOf(l) == GcPtr(List_typ)
- iw2 = malloc(IWrap)
- iw3 = malloc(IWrap)
- iw2.v = 2
- iw3.v = 3
- assert iw3.v == 3
- iwappend(l, iw2)
- iwappend(l, iw3)
- assert len(l.items) == 2
- assert iwitem(l, 0).v == 2
- assert iwitem(l, 1).v == 3
-
- # not allowed
- S = Struct("s", ('v', Signed))
- List_typ, iwnewlistzzz, iwappendzzz, iwitemzzz = define_list(S) # works but
- l = iwnewlistzzz()
- S1 = GcStruct("strange", ('s', S))
- py.test.raises(TypeError, "iwappendzzz(l, malloc(S1).s)")
-
-def test_varsizestruct():
- S1 = GcStruct("s1", ('a', Signed), ('rest', Array(('v', Signed))))
- py.test.raises(TypeError, "malloc(S1)")
- s1 = malloc(S1, 4)
- assert s1.a == 0
- assert typeOf(s1.rest) == _TmpPtr(S1.rest)
- assert len(s1.rest) == 4
- assert typeOf(s1.rest[0]) == _TmpPtr(S1.rest.OF)
- assert typeOf(s1.rest[0].v) == Signed
- assert s1.rest[0].v == 0
- py.test.raises(IndexError, "s1.rest[4]")
- py.test.raises(IndexError, "s1.rest[-1]")
-
- s1.a = 17
- s1.rest[3].v = 5
- assert s1.a == 17
- assert s1.rest[3].v == 5
-
- py.test.raises(TypeError, "Struct('invalid', ('rest', Array(('v', Signed))), ('a', Signed))")
- py.test.raises(TypeError, "Struct('invalid', ('rest', GcArray(('v', Signed))), ('a', Signed))")
- py.test.raises(TypeError, "Struct('invalid', ('x', Struct('s1', ('a', Signed), ('rest', Array(('v', Signed))))))")
- py.test.raises(TypeError, "Struct('invalid', ('x', S1))")
-
-def test_substructure_ptr():
- S2 = Struct("s2", ('a', Signed))
- S1 = GcStruct("s1", ('sub1', S2), ('sub2', S2))
- p1 = malloc(S1)
- assert typeOf(p1.sub1) == _TmpPtr(S2)
- assert typeOf(p1.sub2) == _TmpPtr(S2)
-
-def test_gc_substructure_ptr():
- S1 = GcStruct("s2", ('a', Signed))
- S2 = Struct("s3", ('a', Signed))
- S0 = GcStruct("s1", ('sub1', S1), ('sub2', S2))
- p1 = malloc(S0)
- assert typeOf(p1.sub1) == GcPtr(S1)
- assert typeOf(p1.sub2) == _TmpPtr(S2)
-
-def test_tagged_pointer():
- S1 = GcStruct("s1", ('a', Signed), ('b', Unsigned))
- PList = [
- GcPtr(S1),
- NonGcPtr(S1),
- GcPtr(S1, mytag=True),
- NonGcPtr(S1, mytag=True),
- GcPtr(S1, myothertag=True),
- ]
- for P1 in PList:
- for P2 in PList:
- assert (P1 == P2) == (P1 is P2)
- assert PList[2] == GcPtr(S1, mytag=True)
-
-def test_cast_flags():
- S1 = GcStruct("s1", ('a', Signed), ('b', Unsigned))
- p1 = malloc(S1)
- p2 = cast_flags(NonGcPtr(S1), p1)
- assert typeOf(p2) == NonGcPtr(S1)
- p3 = cast_flags(GcPtr(S1), p2)
- assert typeOf(p3) == GcPtr(S1)
- assert p1 == p3
- py.test.raises(TypeError, "p1 == p2")
- py.test.raises(TypeError, "p2 == p3")
-
- PT = GcPtr(S1, mytag=True)
- p2 = cast_flags(PT, p1)
- assert typeOf(p2) == PT
- p3 = cast_flags(GcPtr(S1), p2)
- assert typeOf(p3) == GcPtr(S1)
- assert p1 == p3
- py.test.raises(TypeError, "p1 == p2")
- py.test.raises(TypeError, "p2 == p3")
-
-def test_cast_parent():
- S2 = Struct("s2", ('a', Signed))
- S1 = GcStruct("s1", ('sub1', S2), ('sub2', S2))
- p1 = malloc(S1)
- p2 = p1.sub1
- assert typeOf(p2) == _TmpPtr(S2)
- p3 = cast_flags(NonGcPtr(S2), p2)
- assert typeOf(p3) == NonGcPtr(S2)
- p4 = cast_parent(NonGcPtr(S1), p3)
- assert typeOf(p4) == NonGcPtr(S1)
- p5 = cast_flags(GcPtr(S1), p4)
- assert typeOf(p5) == GcPtr(S1)
- assert p5 == p1
- py.test.raises(TypeError, "cast_parent(GcPtr(S1), p1.sub1)")
- py.test.raises(TypeError, "cast_parent(GcPtr(S1), p1.sub2)")
- py.test.raises(TypeError, "cast_parent(_TmpPtr(S1), p1.sub2)")
- py.test.raises(TypeError, "cast_parent(NonGcPtr(S2), p3)")
- SUnrelated = Struct("unrelated")
- py.test.raises(TypeError, "cast_parent(NonGcPtr(SUnrelated), p3)")
-
-def test_best_effort_gced_parent_detection():
- S2 = Struct("s2", ('a', Signed))
- S1 = GcStruct("s1", ('sub1', S2), ('sub2', S2), ('tail', Array(('e', Signed))))
- p1 = malloc(S1, 1)
- p2 = p1.sub2
- assert p2.a == 0
- p3 = p1.tail
- p3[0].e = 1
- assert p3[0].e == 1
- del p1
- import gc
- gc.collect()
- py.test.raises(RuntimeError, "p2.a")
- py.test.raises(RuntimeError, "p3[0]")
-
-def test_best_effort_gced_parent_for_arrays():
- A1 = GcArray(('v', Signed))
- p1 = malloc(A1, 10)
- p1[5].v=3
- assert p1[0].v == 0
- assert p1[9].v == 0
- assert p1[5].v == 3
- p1_5 = p1[5]
- del p1
- import gc
- gc.collect()
- py.test.raises(RuntimeError, "p1_5.v")
-
-def test_examples():
- A1 = GcArray(('v', Signed))
- S = GcStruct("s", ('v', Signed))
- St = GcStruct("st", ('v', Signed),('trail', Array(('v', Signed))))
-
- PA1 = GcPtr(A1)
- PS = GcPtr(S)
- PSt = GcPtr(St)
-
- ex_pa1 = PA1._example()
- ex_ps = PS._example()
- ex_pst = PSt._example()
-
- assert typeOf(ex_pa1) == PA1
- assert typeOf(ex_ps) == PS
- assert typeOf(ex_pst) == PSt
-
- assert ex_pa1[0].v == 0
- assert ex_ps.v == 0
- assert ex_pst.v == 0
- assert ex_pst.trail[0].v == 0
-
-def test_functions():
- F = FuncType((Signed,), Signed)
- py.test.raises(TypeError, "Struct('x', ('x', F))")
-
- PF = NonGcPtr(F)
- pf = PF._example()
- assert pf(0) == 0
- py.test.raises(TypeError, pf, 0, 0)
- py.test.raises(TypeError, pf, 'a')
-
-def test_inconsistent_gc_containers():
- A = GcArray(('y', Signed))
- S = GcStruct('b', ('y', Signed))
- py.test.raises(TypeError, "GcPtr(Struct('a', ('x', Signed)))")
- py.test.raises(TypeError, "Struct('a', ('x', S))")
- py.test.raises(TypeError, "GcStruct('a', ('x', Signed), ('y', S))")
- py.test.raises(TypeError, "Array(('x', S))")
- py.test.raises(TypeError, "GcArray(('x', S))")
- py.test.raises(TypeError, "Struct('a', ('x', A))")
- py.test.raises(TypeError, "GcStruct('a', ('x', A))")
-
-def test_forward_reference():
- F = ForwardReference()
- S = GcStruct('abc', ('x', GcPtr(F)))
- F.become(S)
- assert S.x == GcPtr(S)
- py.test.raises(TypeError, "ForwardReference().become(Struct('abc'))")
Modified: pypy/dist/pypy/rpython/test/test_rlist.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rlist.py (original)
+++ pypy/dist/pypy/rpython/test/test_rlist.py Tue May 24 12:00:23 2005
@@ -1,6 +1,6 @@
from pypy.translator.translator import Translator
-from pypy.rpython.lltypes import *
-from pypy.rpython.typer import RPythonTyper
+from pypy.rpython.lltype import *
+from pypy.rpython.rtyper import RPythonTyper
def test_simple():
Copied: pypy/dist/pypy/rpython/test/test_rtyper.py (from r12755, pypy/dist/pypy/rpython/test/test_typer.py)
==============================================================================
--- pypy/dist/pypy/rpython/test/test_typer.py (original)
+++ pypy/dist/pypy/rpython/test/test_rtyper.py Tue May 24 12:00:23 2005
@@ -1,6 +1,6 @@
from pypy.translator.translator import Translator
-from pypy.rpython.lltypes import *
-from pypy.rpython.typer import RPythonTyper
+from pypy.rpython.lltype import *
+from pypy.rpython.rtyper import RPythonTyper
def test_simple():
Deleted: /pypy/dist/pypy/rpython/test/test_typer.py
==============================================================================
--- /pypy/dist/pypy/rpython/test/test_typer.py Tue May 24 12:00:23 2005
+++ (empty file)
@@ -1,15 +0,0 @@
-from pypy.translator.translator import Translator
-from pypy.rpython.lltypes import *
-from pypy.rpython.typer import RPythonTyper
-
-
-def test_simple():
- def dummyfn(x):
- return x+1
-
- t = Translator(dummyfn)
- t.annotate([int])
- typer = RPythonTyper(t.annotator)
- typer.specialize()
- #t.view()
- assert "did not crash"
Deleted: /pypy/dist/pypy/rpython/typer.py
==============================================================================
--- /pypy/dist/pypy/rpython/typer.py Tue May 24 12:00:23 2005
+++ (empty file)
@@ -1,229 +0,0 @@
-import types
-from pypy.rpython.lltypes import *
-from pypy.annotation.model import *
-from pypy.objspace.flow.model import Variable, Constant, SpaceOperation
-from pypy.translator.typer import Specializer, flatten_ops, TyperError
-from pypy.rpython.rlist import ListType, substitute_newlist
-
-
-PyObjPtr = GcPtr(PyObject)
-
-class Retry(Exception):
- """Raised by substitute_*() after they have inserted new patterns
- in the typer's registry. This asks the typer to try again from
- scratch to specialize the current operation."""
-
-
-class RPythonTyper(Specializer):
- Retry = Retry
-
- def __init__(self, annotator):
- # initialization
- Specializer.__init__(self, annotator, defaultconcretetype=PyObjPtr,
- typematches = [], specializationtable = [],
- )
- self.registry = {}
- self.typecache = {}
- SINT = SomeInteger()
- self['add', SINT, SINT] = 'int_add', Signed, Signed, Signed
- #self['add', UINT, UINT] = 'int_add', Unsigned, Unsigned, Unsigned
-
- s_malloc = annotator.bookkeeper.immutablevalue(malloc)
- self['simple_call', s_malloc, ...] = substitute_malloc
-
- # ____________________ lists ____________________
- self['newlist', ...] = substitute_newlist
-
- # ____________________ conversions ____________________
- self.concreteconversions = {
- (Signed, PyObjPtr): ('int2obj', Signed, PyObjPtr),
- (PyObjPtr, Signed): ('obj2int', PyObjPtr, Signed),
- }
-
- def __setitem__(self, pattern, substitution):
- patternlist = self.registry.setdefault(pattern[0], [])
- # items inserted last have higher priority
- patternlist.insert(0, (pattern[1:], substitution))
-
- def registermethod(self, pattern, substitution):
- # method calls are decomposed in two operations that must be
- # handled separately:
- #
- # v1 = getattr(self, 'method_name') --> v1 = cast_flags(self)
- # v2 = simple_call(v1, ...) --> v2 = simple_call(meth, v1, ...)
- #
- # where 'v1' becomes a pointer with the (method='method_name') flag.
- # It points to 'self', but the flag modifies its meaning to
- # "pointer to the method 'method_name' of self" instead of just
- # "pointer to self".
- #
- method_name = pattern[0]
- s_self = pattern[1]
- method = substitution[0]
- SELFPTR = substitution[1]
- METHODPTR = SELFPTR.withflags(method=method_name)
- s_method_name = self.annotator.bookkeeper.immutablevalue(method_name)
-
- self['getattr', s_self, s_method_name] = (
- 'cast_flags', SELFPTR, None, METHODPTR)
-
- s_method = s_self.find_method(method_name)
- self[('simple_call', s_method) + pattern[2:]] = (
- method, SELFPTR) + substitution[2:]
-
- def maketype(self, cls, s_annotation):
- try:
- return self.typecache[cls, s_annotation]
- except KeyError:
- newtype = cls(s_annotation)
- self.typecache[cls, s_annotation] = newtype
- newtype.define(self)
- return newtype
-
- def annotation2concretetype(self, s_value):
- try:
- return annotation_to_lltype(s_value)
- except ValueError:
- if isinstance(s_value, SomeList):
- return self.maketype(ListType, s_value).LISTPTR
- return PyObjPtr
-
- def convertvar(self, v, concretetype):
- """Get the operation(s) needed to convert 'v' to the given type."""
- ops = []
- v_concretetype = getattr(v, 'concretetype', PyObjPtr)
- if isinstance(v, Constant):
- # we should never modify a Constant in-place
- v = Constant(v.value)
- v.concretetype = concretetype
-
- elif v_concretetype != concretetype:
- try:
- subst = self.concreteconversions[v_concretetype, concretetype]
- except KeyError:
- raise TyperError("cannot convert from %r\n"
- "to %r" % (v_concretetype, concretetype))
- vresult = Variable()
- op = SpaceOperation('?', [v], vresult)
- flatten_ops(self.substitute_op(op, subst), ops)
- v = vresult
-
- return v, ops
-
- def specialized_op(self, op, bindings):
- assert len(op.args) == len(bindings)
-
- # first check for direct low-level operations on pointers
- if op.args and isinstance(bindings[0], SomePtr):
- PTR = bindings[0].ll_ptrtype
-
- if op.opname == 'getitem':
- s_result = self.annotator.binding(op.result)
- T = annotation_to_lltype(s_result, 'getitem')
- return self.typed_op(op, [PTR, Signed], T,
- newopname='getarrayitem')
-
- if op.opname == 'len':
- return self.typed_op(op, [PTR], Signed,
- newopname='getarraysize')
-
- if op.opname == 'getattr':
- assert isinstance(op.args[1], Constant)
- s_result = self.annotator.binding(op.result)
- FIELD_TYPE = PTR.TO._flds[op.args[1].value]
- T = annotation_to_lltype(s_result, 'getattr')
- if isinstance(FIELD_TYPE, ContainerType):
- newopname = 'getsubstruct'
- else:
- newopname = 'getfield'
- return self.typed_op(op, [PTR, Void], T, newopname=newopname)
-
- if op.opname == 'setattr':
- assert isinstance(op.args[1], Constant)
- FIELD_TYPE = PTR.TO._flds[op.args[1].value]
- assert not isinstance(FIELD_TYPE, ContainerType)
- return self.typed_op(op, [PTR, Void, FIELD_TYPE], Void,
- newopname='setfield')
-
- if op.opname == 'eq':
- return self.typed_op(op, [PTR, PTR], Bool,
- newopname='ptr_eq')
- if op.opname == 'ne':
- return self.typed_op(op, [PTR, PTR], Bool,
- newopname='ptr_ne')
-
- # generic specialization based on the registration table
- patternlist = self.registry.get(op.opname, [])
- for pattern, substitution in patternlist:
- if pattern and pattern[-1] is Ellipsis:
- pattern = pattern[:-1]
- if len(pattern) > len(op.args):
- continue
- elif len(pattern) != len(op.args):
- continue
- for s_match, s_value in zip(pattern, bindings):
- if not s_match.contains(s_value):
- break
- else:
- # match!
- try:
- return self.substitute_op(op, substitution)
- except Retry:
- return self.specialized_op(op, bindings)
-
- # specialization not found
- argtypes = [self.defaultconcretetype] * len(op.args)
- return self.typed_op(op, argtypes, self.defaultconcretetype)
-
- def substitute_op(self, op, substitution):
- if isinstance(substitution, tuple):
- newopname = substitution[0]
- argtypes = substitution[1:-1]
- resulttype = substitution[-1]
- assert len(argtypes) == len(op.args)
- # None in the substitution list means "remove this argument"
- while None in argtypes:
- argtypes = list(argtypes)
- i = argtypes.index(None)
- del argtypes[i]
- args = list(op.args)
- del args[i]
- op = SpaceOperation(op.opname, args, op.result)
- return self.typed_op(op, argtypes, resulttype,
- newopname = newopname)
- else:
- assert callable(substitution), "type error in the registry tables"
- return substitution(self, op)
-
- def typed_op(self, op, argtypes, restype, newopname=None):
- if isinstance(newopname, types.FunctionType):
- python_function = newopname
- newargs = [Constant(python_function)] + op.args
- op = SpaceOperation('simple_call', newargs, op.result)
- try:
- functyp = python_function.TYPE
- except AttributeError:
- s_returnvalue = self.annotator.build_types(python_function,
- argtypes)
- inferred_type = annotation_to_lltype(s_returnvalue,
- info=python_function)
- if inferred_type != restype:
- raise TyperError("%r return type mismatch:\n"
- "declared %r\n"
- "inferred %r" % (python_function,
- inferred_type, restype))
- functyp = NonGcPtr(FuncType(argtypes, restype))
- python_function.TYPE = functyp
- argtypes = [functyp] + list(argtypes)
- newopname = None
- return Specializer.typed_op(self, op, argtypes, restype, newopname)
-
-
-def substitute_malloc(typer, op):
- s_result = typer.annotator.binding(op.result)
- T = annotation_to_lltype(s_result, 'malloc')
- if len(op.args) == 2:
- substitution = 'malloc', None, Void, T
- else:
- substitution = 'malloc_varsize', None, Void, Signed, T
- return typer.substitute_op(op, substitution)
Modified: pypy/dist/pypy/translator/c/database.py
==============================================================================
--- pypy/dist/pypy/translator/c/database.py (original)
+++ pypy/dist/pypy/translator/c/database.py Tue May 24 12:00:23 2005
@@ -1,7 +1,6 @@
-from pypy.rpython.lltypes import Primitive, _PtrType, typeOf
-from pypy.rpython.lltypes import Struct, Array, FuncType, PyObject, Void
-from pypy.rpython.lltypes import ContainerType
-from pypy.rpython.typer import PyObjPtr
+from pypy.rpython.lltype import Primitive, _PtrType, typeOf
+from pypy.rpython.lltype import Struct, Array, FuncType, PyObject, Void
+from pypy.rpython.lltype import ContainerType
from pypy.objspace.flow.model import Constant
from pypy.translator.c.primitive import PrimitiveName, PrimitiveType
from pypy.translator.c.primitive import PrimitiveErrorValue
Modified: pypy/dist/pypy/translator/c/funcgen.py
==============================================================================
--- pypy/dist/pypy/translator/c/funcgen.py (original)
+++ pypy/dist/pypy/translator/c/funcgen.py Tue May 24 12:00:23 2005
@@ -4,7 +4,7 @@
from pypy.translator.c.support import llvalue_from_constant
from pypy.objspace.flow.model import Variable, Constant, Block
from pypy.objspace.flow.model import traverse, uniqueitems
-from pypy.rpython.lltypes import GcPtr, NonGcPtr, PyObject
+from pypy.rpython.lltype import GcPtr, NonGcPtr, PyObject
PyObjGcPtr = GcPtr(PyObject)
Modified: pypy/dist/pypy/translator/c/node.py
==============================================================================
--- pypy/dist/pypy/translator/c/node.py (original)
+++ pypy/dist/pypy/translator/c/node.py Tue May 24 12:00:23 2005
@@ -1,7 +1,7 @@
from __future__ import generators
-from pypy.rpython.lltypes import Struct, Array, FuncType, PyObjectType, typeOf
-from pypy.rpython.lltypes import GcStruct, GcArray, GC_CONTAINER, ContainerType
-from pypy.rpython.lltypes import parentlink
+from pypy.rpython.lltype import Struct, Array, FuncType, PyObjectType, typeOf
+from pypy.rpython.lltype import GcStruct, GcArray, GC_CONTAINER, ContainerType
+from pypy.rpython.lltype import parentlink
from pypy.translator.c.funcgen import FunctionCodeGenerator
from pypy.translator.c.support import cdecl, somelettersfrom
Modified: pypy/dist/pypy/translator/c/primitive.py
==============================================================================
--- pypy/dist/pypy/translator/c/primitive.py (original)
+++ pypy/dist/pypy/translator/c/primitive.py Tue May 24 12:00:23 2005
@@ -1,4 +1,4 @@
-from pypy.rpython.lltypes import *
+from pypy.rpython.lltype import *
# ____________________________________________________________
#
Modified: pypy/dist/pypy/translator/c/pyobj.py
==============================================================================
--- pypy/dist/pypy/translator/c/pyobj.py (original)
+++ pypy/dist/pypy/translator/c/pyobj.py Tue May 24 12:00:23 2005
@@ -6,7 +6,7 @@
from pypy.translator.gensupp import builtin_base, NameManager
from pypy.rpython.rarithmetic import r_int, r_uint
-from pypy.rpython.lltypes import pyobject
+from pypy.rpython.lltype import pyobjectptr
# XXX maybe this can be done more elegantly:
# needed to convince should_translate_attr
@@ -41,7 +41,7 @@
stackentry = obj
self.debugstack = (self.debugstack, stackentry)
try:
- return self.getvalue(pyobject(obj))
+ return self.getvalue(pyobjectptr(obj))
finally:
self.debugstack, x = self.debugstack
assert x is stackentry
Modified: pypy/dist/pypy/translator/c/support.py
==============================================================================
--- pypy/dist/pypy/translator/c/support.py (original)
+++ pypy/dist/pypy/translator/c/support.py Tue May 24 12:00:23 2005
@@ -1,4 +1,4 @@
-from pypy.rpython import lltypes
+from pypy.rpython import lltype
from pypy.translator.gensupp import NameManager
class ErrorValue:
@@ -34,9 +34,9 @@
try:
T = c.concretetype
except AttributeError:
- return lltypes.pyobject(c.value)
+ return lltype.pyobjectptr(c.value)
else:
- assert lltypes.typeOf(c.value) == T
+ assert lltype.typeOf(c.value) == T
return c.value
Modified: pypy/dist/pypy/translator/c/test/test_database.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_database.py (original)
+++ pypy/dist/pypy/translator/c/test/test_database.py Tue May 24 12:00:23 2005
@@ -1,10 +1,9 @@
import autopath, sys
-from pypy.rpython.lltypes import *
+from pypy.rpython.lltype import *
from pypy.translator.translator import Translator
from pypy.translator.c.database import LowLevelDatabase
from pypy.objspace.flow.model import Constant, Variable, SpaceOperation
from pypy.objspace.flow.model import Block, Link, FunctionGraph
-from pypy.rpython.lltypes import Struct, Array, malloc
def dump_on_stdout(database):
@@ -130,7 +129,7 @@
# -------------------- end --------------------
F = FuncType([Signed], Signed)
- f = function(F, "f", graph=graph)
+ f = functionptr(F, "f", graph=graph)
db = LowLevelDatabase()
db.get(f)
db.complete()
@@ -151,7 +150,7 @@
graph = t.getflowgraph()
F = FuncType([GcPtr(PyObject)], GcPtr(PyObject))
- f = function(F, "f", graph=graph)
+ f = functionptr(F, "f", graph=graph)
db = LowLevelDatabase()
db.get(f)
db.complete()
Modified: pypy/dist/pypy/translator/genc/ctyper.py
==============================================================================
--- pypy/dist/pypy/translator/genc/ctyper.py (original)
+++ pypy/dist/pypy/translator/genc/ctyper.py Tue May 24 12:00:23 2005
@@ -16,7 +16,7 @@
from pypy.translator.genc.classtype import CClassPtrType
from pypy.translator.genc.instancetype import CInstanceType
from pypy.translator.genc.lltype import CPtrType, CLiteralTypeName
-from pypy.rpython import lltypes
+from pypy.rpython import lltype
import types
from pypy.interpreter.pycode import CO_VARARGS
@@ -131,7 +131,7 @@
if op.opname == 'simple_call' and isinstance(op.args[0], Constant):
# XXX move me elsewhere
func = op.args[0].value
- if func is lltypes.malloc:
+ if func is lltype.malloc:
s_result = self.annotator.binding(op.result)
ctliteral = self.annotator.translator.getconcretetype(
CLiteralTypeName)
@@ -142,12 +142,12 @@
[ctliteral], self.annotation2concretetype(s_result))
]
else:
- if isinstance(ct, lltypes.Struct):
+ if isinstance(ct, lltype.Struct):
assert ct._arrayfld is not None
sizefield = ct._arrayfld + '.size'
varstruct = ct._flds[ct._arrayfld].OF
else:
- assert isinstance(ct, lltypes.Array)
+ assert isinstance(ct, lltype.Array)
sizefield = 'size'
varstruct = ct.OF
Modified: pypy/dist/pypy/translator/genc/lltype.py
==============================================================================
--- pypy/dist/pypy/translator/genc/lltype.py (original)
+++ pypy/dist/pypy/translator/genc/lltype.py Tue May 24 12:00:23 2005
@@ -2,7 +2,7 @@
from pypy.translator.genc.basetype import CType
from pypy.translator.gensupp import C_IDENTIFIER
from pypy.objspace.flow.model import SpaceOperation, Constant, Variable
-from pypy.rpython import lltypes
+from pypy.rpython import lltype
class CLiteral(CType): # HACK! TEMPORARY
@@ -12,7 +12,7 @@
class CLiteralTypeName(CType): # HACK! TEMPORARY
def nameof(self, obj, debug=None):
- assert isinstance(obj, lltypes.LowLevelType)
+ assert isinstance(obj, lltype.LowLevelType)
ct = ll2concretetype(self.translator, obj)
return ct.typename
@@ -69,7 +69,7 @@
cliteral = typer.annotator.translator.getconcretetype(CLiteral)
s_result = typer.annotator.binding(op.result)
ctresult = typer.annotation2concretetype(s_result)
- if isinstance(attrtype, lltypes.ContainerType):
+ if isinstance(attrtype, lltype.ContainerType):
yield typer.typed_op(op, [self, cliteral], ctresult,
newopname='getsubstruct')
else:
@@ -87,7 +87,7 @@
attrname = v_attrname.value
attrtype = self.lltype.TO._flds[attrname]
cliteral = typer.annotator.translator.getconcretetype(CLiteral)
- if isinstance(attrtype, lltypes.ContainerType):
+ if isinstance(attrtype, lltype.ContainerType):
raise AssertionError("cannot setattr to a substructure")
ctinput = ll2concretetype(typer.annotator.translator, attrtype)
yield typer.typed_op(op, [self, cliteral, ctinput], typer.TNone,
@@ -190,11 +190,11 @@
from pypy.translator.genc import inttype, nonetype
primitivetypemap = {
- lltypes.Signed: inttype.CIntType,
- lltypes.Unsigned: inttype.CUnsignedType,
- #lltypes.Char: ...
- lltypes.Bool: inttype.CIntType,
- lltypes.Void: nonetype.CNoneType,
+ lltype.Signed: inttype.CIntType,
+ lltype.Unsigned: inttype.CUnsignedType,
+ #lltype.Char: ...
+ lltype.Bool: inttype.CIntType,
+ lltype.Void: nonetype.CNoneType,
}
def get_primitive_type(translator, lltype):
@@ -202,12 +202,12 @@
return translator.getconcretetype(cls)
ll2concretetypemap = {
- lltypes.Struct: CStructType,
- lltypes.GcStruct: CStructType,
- lltypes.Array: CArrayType,
- lltypes.GcArray: CArrayType,
- lltypes._PtrType: CPtrType,
- lltypes.Primitive: get_primitive_type,
+ lltype.Struct: CStructType,
+ lltype.GcStruct: CStructType,
+ lltype.Array: CArrayType,
+ lltype.GcArray: CArrayType,
+ lltype._PtrType: CPtrType,
+ lltype.Primitive: get_primitive_type,
}
def ll2concretetype(translator, lltype):
Modified: pypy/dist/pypy/translator/genc/test/test_lltyped.py
==============================================================================
--- pypy/dist/pypy/translator/genc/test/test_lltyped.py (original)
+++ pypy/dist/pypy/translator/genc/test/test_lltyped.py Tue May 24 12:00:23 2005
@@ -1,4 +1,4 @@
-from pypy.rpython.lltypes import *
+from pypy.rpython.lltype import *
from pypy.translator.tool.buildpyxmodule import skip_missing_compiler
from pypy.translator.translator import Translator
from pypy.translator.genc.ctyper import GenCSpecializer
More information about the Pypy-commit
mailing list