[pypy-svn] r12890 - in pypy/branch/pycompiler: annotation annotation/test documentation documentation/image interpreter lib module/unicodedata objspace/flow objspace/std rpython rpython/test tool translator translator/c translator/c/test translator/genc translator/genc/test translator/goal translator/llvm translator/llvm/test translator/pickle translator/pickle/attic translator/test

ludal at codespeak.net ludal at codespeak.net
Mon May 30 16:50:36 CEST 2005


Author: ludal
Date: Mon May 30 16:50:36 2005
New Revision: 12890

Added:
   pypy/branch/pycompiler/documentation/image/
      - copied from r12888, pypy/dist/pypy/documentation/image/
   pypy/branch/pycompiler/documentation/image/translation.sxd   (props changed)
      - copied unchanged from r12888, pypy/dist/pypy/documentation/image/translation.sxd
   pypy/branch/pycompiler/rpython/lltype.py   (props changed)
      - copied unchanged from r12888, pypy/dist/pypy/rpython/lltype.py
   pypy/branch/pycompiler/rpython/rbool.py
      - copied unchanged from r12888, pypy/dist/pypy/rpython/rbool.py
   pypy/branch/pycompiler/rpython/rbuiltin.py   (props changed)
      - copied unchanged from r12888, pypy/dist/pypy/rpython/rbuiltin.py
   pypy/branch/pycompiler/rpython/rfloat.py
      - copied unchanged from r12888, pypy/dist/pypy/rpython/rfloat.py
   pypy/branch/pycompiler/rpython/rint.py   (props changed)
      - copied unchanged from r12888, pypy/dist/pypy/rpython/rint.py
   pypy/branch/pycompiler/rpython/robject.py   (props changed)
      - copied unchanged from r12888, pypy/dist/pypy/rpython/robject.py
   pypy/branch/pycompiler/rpython/rpbc.py   (props changed)
      - copied unchanged from r12888, pypy/dist/pypy/rpython/rpbc.py
   pypy/branch/pycompiler/rpython/rptr.py   (props changed)
      - copied unchanged from r12888, pypy/dist/pypy/rpython/rptr.py
   pypy/branch/pycompiler/rpython/rtyper.py   (props changed)
      - copied unchanged from r12888, pypy/dist/pypy/rpython/rtyper.py
   pypy/branch/pycompiler/rpython/test/snippet.py
      - copied unchanged from r12888, pypy/dist/pypy/rpython/test/snippet.py
   pypy/branch/pycompiler/rpython/test/test_lltype.py   (props changed)
      - copied unchanged from r12888, pypy/dist/pypy/rpython/test/test_lltype.py
   pypy/branch/pycompiler/rpython/test/test_rbool.py
      - copied unchanged from r12888, pypy/dist/pypy/rpython/test/test_rbool.py
   pypy/branch/pycompiler/rpython/test/test_rfloat.py
      - copied unchanged from r12888, pypy/dist/pypy/rpython/test/test_rfloat.py
   pypy/branch/pycompiler/rpython/test/test_rint.py
      - copied unchanged from r12888, pypy/dist/pypy/rpython/test/test_rint.py
   pypy/branch/pycompiler/rpython/test/test_rtyper.py   (props changed)
      - copied unchanged from r12888, pypy/dist/pypy/rpython/test/test_rtyper.py
   pypy/branch/pycompiler/translator/c/genc.py   (props changed)
      - copied unchanged from r12888, pypy/dist/pypy/translator/c/genc.py
   pypy/branch/pycompiler/translator/c/int_include.h   (props changed)
      - copied unchanged from r12888, pypy/dist/pypy/translator/c/int_include.h
   pypy/branch/pycompiler/translator/c/ll_include.h
      - copied unchanged from r12888, pypy/dist/pypy/translator/c/ll_include.h
   pypy/branch/pycompiler/translator/c/test/test_genc.py   (props changed)
      - copied unchanged from r12888, pypy/dist/pypy/translator/c/test/test_genc.py
   pypy/branch/pycompiler/translator/c/wrapper.py   (props changed)
      - copied unchanged from r12888, pypy/dist/pypy/translator/c/wrapper.py
   pypy/branch/pycompiler/translator/llvm/reprmap.py
      - copied unchanged from r12888, pypy/dist/pypy/translator/llvm/reprmap.py
   pypy/branch/pycompiler/translator/pickle/
      - copied from r12888, pypy/dist/pypy/translator/pickle/
   pypy/branch/pycompiler/translator/pickle/__init__.py
      - copied unchanged from r12888, pypy/dist/pypy/translator/pickle/__init__.py
   pypy/branch/pycompiler/translator/pickle/attic/
      - copied from r12888, pypy/dist/pypy/translator/pickle/attic/
   pypy/branch/pycompiler/translator/pickle/attic/genpickle.py   (props changed)
      - copied unchanged from r12888, pypy/dist/pypy/translator/pickle/attic/genpickle.py
   pypy/branch/pycompiler/translator/pickle/genpickle.py
      - copied unchanged from r12888, pypy/dist/pypy/translator/pickle/genpickle.py
Removed:
   pypy/branch/pycompiler/rpython/lltypes.py
   pypy/branch/pycompiler/rpython/test/test_lltypes.py
   pypy/branch/pycompiler/rpython/test/test_typer.py
   pypy/branch/pycompiler/rpython/typer.py
Modified:
   pypy/branch/pycompiler/annotation/binaryop.py
   pypy/branch/pycompiler/annotation/bookkeeper.py
   pypy/branch/pycompiler/annotation/builtin.py
   pypy/branch/pycompiler/annotation/model.py
   pypy/branch/pycompiler/annotation/test/test_model.py
   pypy/branch/pycompiler/annotation/unaryop.py
   pypy/branch/pycompiler/documentation/_ref.txt
   pypy/branch/pycompiler/documentation/coding-guide.txt
   pypy/branch/pycompiler/documentation/objspace.txt
   pypy/branch/pycompiler/documentation/redirections
   pypy/branch/pycompiler/documentation/translation.txt
   pypy/branch/pycompiler/interpreter/compiler.py
   pypy/branch/pycompiler/lib/inprogress__codecs.py
   pypy/branch/pycompiler/lib/unicodecodec.py
   pypy/branch/pycompiler/module/unicodedata/CompositionExclusions-3.2.0.txt   (props changed)
   pypy/branch/pycompiler/module/unicodedata/CompositionExclusions-4.1.0.txt   (props changed)
   pypy/branch/pycompiler/module/unicodedata/UnicodeData-3.2.0.txt   (props changed)
   pypy/branch/pycompiler/module/unicodedata/UnicodeData-4.1.0.txt   (props changed)
   pypy/branch/pycompiler/objspace/flow/model.py
   pypy/branch/pycompiler/objspace/std/inttype.py
   pypy/branch/pycompiler/objspace/std/unicodetype.py
   pypy/branch/pycompiler/rpython/rlist.py
   pypy/branch/pycompiler/rpython/test/test_llann.py
   pypy/branch/pycompiler/rpython/test/test_rlist.py
   pypy/branch/pycompiler/tool/sourcetools.py
   pypy/branch/pycompiler/translator/annrpython.py
   pypy/branch/pycompiler/translator/c/database.py
   pypy/branch/pycompiler/translator/c/funcgen.py
   pypy/branch/pycompiler/translator/c/g_include.h
   pypy/branch/pycompiler/translator/c/g_module.h
   pypy/branch/pycompiler/translator/c/g_support.h
   pypy/branch/pycompiler/translator/c/node.py
   pypy/branch/pycompiler/translator/c/primitive.py
   pypy/branch/pycompiler/translator/c/pyobj.py
   pypy/branch/pycompiler/translator/c/support.py
   pypy/branch/pycompiler/translator/c/test/test_database.py
   pypy/branch/pycompiler/translator/genc/ctyper.py
   pypy/branch/pycompiler/translator/genc/lltype.py
   pypy/branch/pycompiler/translator/genc/test/test_lltyped.py
   pypy/branch/pycompiler/translator/goal/translate_pypy.py
   pypy/branch/pycompiler/translator/llvm/build_llvm_module.py
   pypy/branch/pycompiler/translator/llvm/classrepr.py
   pypy/branch/pycompiler/translator/llvm/funcrepr.py
   pypy/branch/pycompiler/translator/llvm/genllvm.py
   pypy/branch/pycompiler/translator/llvm/llvmbc.py
   pypy/branch/pycompiler/translator/llvm/pbcrepr.py
   pypy/branch/pycompiler/translator/llvm/representation.py
   pypy/branch/pycompiler/translator/llvm/test/test_class.py
   pypy/branch/pycompiler/translator/llvm/test/test_genllvm.py
   pypy/branch/pycompiler/translator/llvm/test/test_seq.py
   pypy/branch/pycompiler/translator/llvm/test/test_snippet.py
   pypy/branch/pycompiler/translator/llvm/typerepr.py
   pypy/branch/pycompiler/translator/test/test_annrpython.py
Log:
 * merge modifications from trunk: 12758:12888


Modified: pypy/branch/pycompiler/annotation/binaryop.py
==============================================================================
--- pypy/branch/pycompiler/annotation/binaryop.py	(original)
+++ pypy/branch/pycompiler/annotation/binaryop.py	Mon May 30 16:50:36 2005
@@ -84,7 +84,8 @@
     def inplace_floordiv((obj1, obj2)): return pair(obj1, obj2).floordiv()
     def inplace_div((obj1, obj2)):      return pair(obj1, obj2).div()
     def inplace_mod((obj1, obj2)):      return pair(obj1, obj2).mod()
-    def inplace_pow((obj1, obj2), obj3):return pair(obj1, obj2).pow(obj3)
+    def inplace_pow((obj1, obj2)):      return pair(obj1, obj2).pow(
+                                                      SomePBC({None: True}))
     def inplace_lshift((obj1, obj2)):   return pair(obj1, obj2).lshift()
     def inplace_rshift((obj1, obj2)):   return pair(obj1, obj2).rshift()
     def inplace_and((obj1, obj2)):      return pair(obj1, obj2).and_()
@@ -477,7 +478,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/branch/pycompiler/annotation/bookkeeper.py
==============================================================================
--- pypy/branch/pycompiler/annotation/bookkeeper.py	(original)
+++ pypy/branch/pycompiler/annotation/bookkeeper.py	Mon May 30 16:50:36 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()
@@ -411,10 +408,12 @@
         except KeyError:
             if isinstance(thing, FunctionType):
                 # XXX XXX XXX HAAAAAAAAAAAACK
-                # xxx we need a way to let know subsequent phases (the generator) about the specialized function
-                # the caller flowgraph as it is doesn't.
-                # This line just avoids that the flowgraph of the original function, which is what will be considered
-                # and compiled for now will be computed during generation itself
+                # xxx we need a way to let know subsequent phases (the
+                # generator) about the specialized function.
+                # The caller flowgraph, as it is, doesn't know.
+                # This line just avoids that the flowgraph of the original
+                # function (which is what will be considered and compiled for
+                # now) will be computed during generation itself.
                 self.annotator.translator.getflowgraph(thing)
                 #
                 thing = func_with_new_name(thing, name or thing.func_name)

Modified: pypy/branch/pycompiler/annotation/builtin.py
==============================================================================
--- pypy/branch/pycompiler/annotation/builtin.py	(original)
+++ pypy/branch/pycompiler/annotation/builtin.py	Mon May 30 16:50:36 2005
@@ -9,6 +9,7 @@
 from pypy.annotation.model import SomeList, SomeString, SomeTuple, SomeSlice
 from pypy.annotation.model import SomeUnicodeCodePoint
 from pypy.annotation.model import SomeFloat, unionof
+from pypy.annotation.model import annotation_to_lltype
 from pypy.annotation.bookkeeper import getbookkeeper
 from pypy.objspace.flow.model import Constant
 import pypy.rpython.rarithmetic
@@ -247,15 +248,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 +264,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 +273,14 @@
     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
+def typeOf(s_val):
+    lltype = annotation_to_lltype(s_val, info="in typeOf(): ")
+    return immutablevalue(lltype)
+
+BUILTIN_ANALYZERS[lltype.malloc] = malloc
+BUILTIN_ANALYZERS[lltype.cast_flags] = cast_flags
+BUILTIN_ANALYZERS[lltype.cast_parent] = cast_parent
+BUILTIN_ANALYZERS[lltype.typeOf] = typeOf
 

Modified: pypy/branch/pycompiler/annotation/model.py
==============================================================================
--- pypy/branch/pycompiler/annotation/model.py	(original)
+++ pypy/branch/pycompiler/annotation/model.py	Mon May 30 16:50:36 2005
@@ -303,9 +303,10 @@
 class SomeBuiltin(SomeObject):
     "Stands for a built-in function or method with special-cased analysis."
     knowntype = BuiltinFunctionType  # == BuiltinMethodType
-    def __init__(self, analyser, s_self=None):
+    def __init__(self, analyser, s_self=None, methodname=None):
         self.analyser = analyser
         self.s_self = s_self
+        self.methodname = methodname
 
 
 class SomeImpossibleValue(SomeObject):
@@ -320,14 +321,15 @@
         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),    
+    (SomeFloat(), lltype.Float),
+    (SomeChar(), lltype.Char),
+    (SomePBC({None: True}), lltype.Void),
 ]
 
 def annotation_to_lltype(s_val, info=None):
@@ -348,13 +350,16 @@
 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)
        else:
            return s
 
+def lltype_to_annotation(T):
+    return ll_to_annotation(T._example())
+
 
 # ____________________________________________________________
 

Modified: pypy/branch/pycompiler/annotation/test/test_model.py
==============================================================================
--- pypy/branch/pycompiler/annotation/test/test_model.py	(original)
+++ pypy/branch/pycompiler/annotation/test/test_model.py	Mon May 30 16:50:36 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/branch/pycompiler/annotation/unaryop.py
==============================================================================
--- pypy/branch/pycompiler/annotation/unaryop.py	(original)
+++ pypy/branch/pycompiler/annotation/unaryop.py	Mon May 30 16:50:36 2005
@@ -102,7 +102,7 @@
     def find_method(obj, name):
         "Look for a special-case implementation for the named method."
         analyser = getattr(obj.__class__, 'method_' + name)
-        return SomeBuiltin(analyser, obj)
+        return SomeBuiltin(analyser, obj, name)
 
     def getattr(obj, s_attr):
         # get a SomeBuiltin if the SomeObject has
@@ -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):
 

Modified: pypy/branch/pycompiler/documentation/_ref.txt
==============================================================================
--- pypy/branch/pycompiler/documentation/_ref.txt	(original)
+++ pypy/branch/pycompiler/documentation/_ref.txt	Mon May 30 16:50:36 2005
@@ -1,8 +1,8 @@
-.. _`issue40`: http://codespeak.net/issue/pypy-dev/issue40
 .. _`demo/`: http://codespeak.net/svn/pypy/dist/demo
 .. _`lib-python/`: http://codespeak.net/svn/pypy/dist/lib-python
 .. _`pypy/annotation`:
 .. _`annotation/`: http://codespeak.net/svn/pypy/dist/pypy/annotation
+.. _`annotation/binaryop.py`: http://codespeak.net/svn/pypy/dist/pypy/annotation/binaryop.py
 .. _`documentation/`: http://codespeak.net/svn/pypy/dist/pypy/documentation
 .. _`documentation/revreport/`: http://codespeak.net/svn/pypy/dist/pypy/documentation/revreport
 .. _`documentation/website/`: http://codespeak.net/svn/pypy/dist/pypy/documentation/website
@@ -26,9 +26,11 @@
 .. _`pypy/objspace/std`:
 .. _`objspace/std/`: http://codespeak.net/svn/pypy/dist/pypy/objspace/std
 .. _`objspace/thunk.py`: http://codespeak.net/svn/pypy/dist/pypy/objspace/thunk.py
-.. _`objspace/trace.py`:
-.. _`pypy/objspace/trace.py`: http://codespeak.net/svn/pypy/dist/pypy/objspace/trace.py
+.. _`pypy/objspace/trace.py`:
+.. _`objspace/trace.py`: http://codespeak.net/svn/pypy/dist/pypy/objspace/trace.py
 .. _`rpython/`: http://codespeak.net/svn/pypy/dist/pypy/rpython
+.. _`rpython/lltype.py`: http://codespeak.net/svn/pypy/dist/pypy/rpython/lltype.py
+.. _`rpython/rlist.py`: http://codespeak.net/svn/pypy/dist/pypy/rpython/rlist.py
 .. _`pypy/test_all.py`: http://codespeak.net/svn/pypy/dist/pypy/test_all.py
 .. _`tool/`: http://codespeak.net/svn/pypy/dist/pypy/tool
 .. _`tool/pytest/`: http://codespeak.net/svn/pypy/dist/pypy/tool/pytest

Modified: pypy/branch/pycompiler/documentation/coding-guide.txt
==============================================================================
--- pypy/branch/pycompiler/documentation/coding-guide.txt	(original)
+++ pypy/branch/pycompiler/documentation/coding-guide.txt	Mon May 30 16:50:36 2005
@@ -732,8 +732,8 @@
   includes w_self.  Don't use ``w_`` in application level
   python only code.
 
-Committing
-----------
+Committing & Branching to the repository
+-----------------------------------------------------
 
 - write good log messages because several people
   are reading the diffs. 
@@ -743,6 +743,19 @@
   that the property 'svn:eol-style' is set to native which 
   allows checkin/checkout in native line-ending format.
 
+- branching (aka "svn copy") of source code should usually
+  happen at ``svn/pypy/dist`` level in order to have a full
+  self-contained pypy checkout for each branch.   For branching
+  a ``try1`` branch you would for example do:: 
+
+    svn cp http://codespeak.net/svn/pypy/dist \
+           http://codespeak.net/svn/pypy/branch/try1 
+
+  This allows to checkout the ``try1`` branch and receive a 
+  self-contained working-copy for the branch.   Note that 
+  branching/copying is a cheap operation with subversion, as it 
+  takes constant time irrespective of the size of the tree. 
+
 - To learn more about how to use subversion read `this document`_.
 
 .. _`this document`: svn-help.html

Modified: pypy/branch/pycompiler/documentation/objspace.txt
==============================================================================
--- pypy/branch/pycompiler/documentation/objspace.txt	(original)
+++ pypy/branch/pycompiler/documentation/objspace.txt	Mon May 30 16:50:36 2005
@@ -269,7 +269,7 @@
     <pypy type 'int'>
 
 
->> _`flow object space`:
+.. _`flow object space`:
 
 The Flow Object Space
 =====================

Modified: pypy/branch/pycompiler/documentation/redirections
==============================================================================
--- pypy/branch/pycompiler/documentation/redirections	(original)
+++ pypy/branch/pycompiler/documentation/redirections	Mon May 30 16:50:36 2005
@@ -25,5 +25,7 @@
     'basicblock.asc'        : 'objspace.html#the-flow-model',
 
     'coding-style.html'     : 'coding-guide.html',
+
+    'controlflow.html'      : 'objspace.html#the-flow-model',
 }
 

Modified: pypy/branch/pycompiler/documentation/translation.txt
==============================================================================
--- pypy/branch/pycompiler/documentation/translation.txt	(original)
+++ pypy/branch/pycompiler/documentation/translation.txt	Mon May 30 16:50:36 2005
@@ -384,7 +384,7 @@
 +++++++++++++++++++++++++++++++++++++++
 
 Constants in the flowgraph are annotated with a corresponding
-``SomeXxx`` instance with 'const' attribute set to the their value.
+``SomeXxx`` instance with 'const' attribute set to their value.
 
 Constant instances of user-defined classes, callables (which include
 functions but also class types themself) and staticmethod are treated
@@ -465,35 +465,85 @@
 
     v3 = int_add(v1, v2)
 
-where -- in C notation -- all three variables v1, v2 and v3 are typed ``int``.  This is done by attaching an attribute ``concretetype`` to v1, v2 and v3 (which might be instances of Variable or possibly Constant).  In our model, this ``concretetype`` is ``pypy.rpython.lltypes.Signed``.  Of course, the purpose of replacing the operation called ``add`` with ``int_add`` is that code generators no longer have to worry about what kind of addition (or concatenation maybe?) it means.
+where -- in C notation -- all three variables v1, v2 and v3 are typed ``int``.  This is done by attaching an attribute ``concretetype`` to v1, v2 and v3 (which might be instances of Variable or possibly Constant).  In our model, this ``concretetype`` is ``pypy.rpython.lltype.Signed``.  Of course, the purpose of replacing the operation called ``add`` with ``int_add`` is that code generators no longer have to worry about what kind of addition (or concatenation maybe?) it means.
 
 
 The process in more details
 ---------------------------
 
-The RPython Typer does the following transformations for each block of all the annotated flow graphs (each block is processed independently, by assuming that the already-computed annotations are globally correct):
+The RPython Typer has a structure similar to that of the Annotator_: both consider each block of the flow graphs in turn, and perform some analysis on each operation.  In both cases the analysis of an operation depends on the annotations of its input arguments.  This is reflected in the usage of the same ``__extend__`` syntax in the source files (compare e.g. `annotation/binaryop.py`_ and `rpython/rlist.py`_).
 
-* We first replace all Variables that have constant annotations with real Constants in the flow graph.
+The analogy stops here, though: while it runs, the Annotator is in the middle of computing the annotations, so it might need to reflow and generalize until a fixpoint is reached.  The Typer, by contrast, works on the final annotations that the Annotator computed, without changing them, assuming that they are globally consistent.  There is no need to reflow: the Typer considers each block only once.  And unlike the Annotator, the Typer completely modifies the flow graph, by replacing each operation with some low-level operations.
 
-* For the time being, we assume that each SomeXxx annotation has a canonical low-level representation.  For example, all variables annotated with SomeInteger() will correspond to the ``Signed`` low-level type.  Each input argument of the block are tagged with the canonical low-level representation (this is done by attaching an attribute ``concretetype`` to each Variable).
-
-* Each operation, with its argument's annotation, is looked up in a table which specifies with which low-level operation(s) it should be substituted.  If needed, the arguments are first converted (with extra operations) from their current ``concretetype`` to the required low-level types.  For constant arguments, we just attach the ``concretetype`` to the Constant instance; as for Variables, this tells the code generator of which type the constant really is.  Finally, the substitution rules specify the ``concretetype`` of the result.  It is attached to the result Variable, and will be used further down the block to detect when conversions are needed.
-
-* When a block has been transformed in this way, all the links are considered; if the concrete types of the Variables that exit do not match the canonical low-level types expected by the target block, conversions are inserted -- they are put in a new block inserted along the link, as they are of no concern to the other exit links.
-
-This may look like flowing, similar to what the annotator does, but it is limited to a single block; for global coherency it trusts the more involved fixpoint-based algorithm run by the annotator.
+The main assumption of the RTyper, for the time being, is that each SomeXxx annotation has a canonical low-level representation.  For example, all variables annotated with SomeInteger() will correspond to the ``Signed`` low-level type.  The RTyper computes the canonical low-level type for each Variable based on its annotation, and stores it in the attribute ``concretetype``.  It also computes a ``concretetype`` for Constants, to match the way they are used in the low-level operations (for example, ``int_add(x, 1)`` requires a ``Constant(1)`` with ``concretetype=Signed``, but an untyped ``add(x, 1)`` works with a ``Constant(1)`` that must actually be a PyObject at run-time).
 
 
 Low-Level Types
 ---------------
 
-For now, the RPython Typer uses a standard low-level model which we believe can correspond rather directly to various target languages from C to LLVM to Java.  This model is implemented in the first part of `lltypes.py`_.
+The RPython Typer uses a standard low-level model which we believe can correspond rather directly to various target languages from C to LLVM to Java.  This model is implemented in the first part of `rpython/lltype.py`_.
 
-The second part of `lltypes.py`_ is a runnable implementation of these types, for testing purposes.  It allows us to write and test plain Python code using a malloc() function to obtain and manipulate structures and arrays.  This is useful for example to implement RPython types like 'list' with its operations and methods.
+The second part of `rpython/lltype.py`_ is a runnable implementation of these types, for testing purposes.  It allows us to write and test plain Python code using a malloc() function to obtain and manipulate structures and arrays.  This is useful for example to implement RPython types like 'list' with its operations and methods.
 
 The basic assumption is that Variables (i.e. local variables and function arguments and return value) all contain "simple" values: basically, just integers or pointers.  All the "container" data structures (struct and array) are allocated in the heap, and they are always manipulated via pointers.  (There is no equivalent to the C notion of local variable of a ``struct`` type.)
 
-.. _`lltypes.py`: http://codespeak.net/svn/pypy/dist/pypy/rpython/lltypes.py
+Here is a quick tour::
+
+    >>> from pypy.rpython.lltype import *
+
+(The module is called ``lltypes`` in PyPy release 0.6.)
+
+Here are a few primitive low-level types, and the typeOf() function to figure them out::
+
+    >>> Signed
+    <Signed>
+    >>> typeOf(5)
+    <Signed>
+    >>> typeOf(r_uint(12))
+    <Unsigned>
+    >>> typeOf('x')
+    <Char>
+
+Let's say that we want to build a type "point", which is a structure with two integer fields "x" and "y"::
+
+    >>> POINT = GcStruct('point', ('x', Signed), ('y', Signed))
+    >>> POINT
+    <GcStruct point { x: Signed, y: Signed }>
+
+The structure is a ``GcStruct``, which means a structure that can be allocated in the heap and eventually freed by some garbage collector.  (For platforms where we use reference counting, think about ``GcStruct`` as a struct with an additional reference counter field.) (NB. in PyPy release 0.6, GcStruct and GcArray don't exist; you must use Struct and Array instead.)
+
+Giving a name ('point') to the GcStruct is only for clarity: it is used in the representation.
+
+    >>> p = malloc(POINT)
+    >>> p
+    <_ptrtype to struct point { x=0, y=0 }>
+    >>> p.x = 5
+    >>> p.x
+    5
+    >>> p
+    <_ptrtype to struct point { x=5, y=0 }>
+
+``malloc()`` allocates a structure from the heap, initalizes it to 0 (currently), and returns a pointer to it.  The point of all this is to work with a very limited, easily controllable set of types, and define implementations of types like list in this elementary world.  The ``malloc()`` function is a kind of placeholder, which must eventually be provided by the code generator for the target platform; but as we have just seen its Python implementation in `rpython/lltype.py`_ works too, which is primarily useful for testing, interactive exploring, etc.
+
+The argument to ``malloc()`` is the structure type directly, but it returns a pointer to the structure, as ``typeOf()`` tells you::
+
+    >>> typeOf(p)
+    <ptr(gc) to GcStruct point { x: Signed, y: Signed }>
+
+For the purpose of creating structures with pointers to other structures, we can declare pointer types explicitely::
+
+    >>> typeOf(p) == GcPtr(POINT)
+    True
+    >>> BIZARRE = GcStruct('bizarre', ('p1', GcPtr(POINT)), ('p2', GcPtr(POINT)))
+    >>> b = malloc(BIZARRE)
+    >>> b.p1
+    <_ptrtype to None>
+    >>> b.p1 = b.p2 = p
+    >>> b.p1.y = 42
+    >>> b.p2.y
+    42
+
+The world of low-level types is more complicated than integers and GcStructs, though.  The next pages are a reference guide.
 
 
 Primitive Types
@@ -519,9 +569,10 @@
 Structure Types
 +++++++++++++++
 
-Structure types are built as instances of ``pypy.rpython.lltypes.Struct``::
+Structure types are built as instances of ``pypy.rpython.lltype.Struct``::
 
     MyStructType = Struct('somename',  ('field1', Type1), ('field2', Type2)...)
+    MyStructType = GcStruct('somename',  ('field1', Type1), ('field2', Type2)...)
 
 This declares a structure (or a Pascal ``record``) containing the specified named fields with the given types.  The field names cannot start with an underscore.  As noted above, you cannot directly manipulate structure objects, but only pointer to structures living in the heap.
 
@@ -529,18 +580,23 @@
 
 A structure can also contain an inlined array (see below), but only as its last field: in this case it is a "variable-sized" structure, whose memory layout starts with the non-variable fields and ends with a variable number of array items.  This number is determined when a structure is allocated in the heap.  Variable-sized structures cannot be inlined in other structures.
 
+GcStructs have a platform-specific GC header (e.g. a reference counter); only these can be malloc()ed.  Structs have no header, and are suitable for being embedded ("inlined") inside other structures.  As an exception, a GcStruct can be embedded as the first field of a GcStruct: the parent structure uses the same GC header as the substructure.
+
 
 Array Types
 +++++++++++
 
-An array type is built as an instance of ``pypy.rpython.lltypes.Array``::
+An array type is built as an instance of ``pypy.rpython.lltype.Array``::
 
     MyArrayType = Array(('field1', Type1), ('field2', Type2)...)
+    MyArrayType = GcArray(('field1', Type1), ('field2', Type2)...)
 
 The items of an array are always structures; the arguments to Array() give the fields of these structures (it can of course be a single field).  The allowed field types follow the same rules as for Struct(), but this particular structure cannot be variable-sized.
 
 For now, each array stores its length explicitely in a header.  An array can never be resized: it occupies a fixed amount of bytes determined when it is allocated.
 
+GcArrays can be malloc()ed (the length must be specified when malloc() is called, and arrays cannot be resized).  Plain Arrays cannot be malloc()ed but can be used as the last field of a structure, to make a variable-sized structure.  The whole structure can then be malloc()ed, and the length of the array is specified at this time.
+
 
 Pointer Types
 +++++++++++++
@@ -550,7 +606,7 @@
    GcPtr(T, **flags)
    NonGcPtr(T, **flags)
 
-The so-called GC pointers are the ones that hold a reference to the object they point to.  Typically, the malloc() operation allocates and returns a GcPtr to a new structure or array.  In a refcounting implementation, malloc() would allocate enough space for a reference counter before the actual structure, and initialize it to 1.  Actually, GC pointers can only point to a malloc()ed structure or array.  Non-GC pointers are used when you know that a pointer doesn't hold a (counted) reference to an object, usually because the object has no reference counter at all: for example, functions don't have one; more importantly, inlined substructures don't have one either.  For them, care must be taken to ensure that the bigger structure of which they are part of isn't freed while the NonGcPtr to the substructure is still in use.
+The so-called GC pointers are the ones that hold a reference to the object they point to.  Only GcStruct, GcArray and PyObject can have GcPtrs to them.  Typically, the malloc() operation allocates and returns a GcPtr to a new structure or array.  In a refcounting implementation, malloc() would allocate enough space for a reference counter before the actual structure, and initialize it to 1.  Actually, GC pointers can only point to a malloc()ed structure or array.  Non-GC pointers are used when you know that a pointer doesn't hold a (counted) reference to an object, usually because the object has no reference counter at all: for example, functions don't have one; more importantly, inlined substructures don't have one either.  For them, care must be taken to ensure that the bigger structure of which they are part of isn't freed while the NonGcPtr to the substructure is still in use.
 
 All pointer types can also have additional flags, whose meaning is unspecified at this level (apart from the flag ``gc=True`` which GcPtrs have and NonGcPtrs miss).  Types with different flags are incompatible, but the cast_flags() operation is provided to perform explicit casts.  The intention is for example to represent the high-level object "the method append() of this list" as the type ``GcPtr(ListType, method='append')`` -- i.e. a pointer to the list in question with an additional flag specifying that the pointer represents the method append() of that list, as opposed to the list itself.
 
@@ -578,7 +634,7 @@
 
 This list concatenation flow graph is then annotated as usual, with one difference: the annotator has to be taught about malloc() and the way the pointer thus obtained can be manipulated.  This generates a flow graph which is hopefully completely annotated with the SomePtr annotation.  Introduced just for this case, SomePtr maps directly to a low-level pointer type.  This is the only change needed to the Annotator to allow it to perform type inferrence of our very-low-level snippets of code.
 
-See for example http://codespeak.net/svn/pypy/dist/pypy/rpython/rlist.py.
+See for example `rpython/rlist.py`_.
 
 
 
@@ -858,15 +914,15 @@
       space.setitem(g3dict, gs_g, gfunc_g)
       return g3dict
 
-You see that actually a single function is produced: 'initapp2interpexec'. This is the
+You see that actually a single function is produced: ``initapp2interpexec``. This is the
 function that you will call with a space as argument. It defines a few functions and then
 does a number of initialization steps, builds the global objects the function need,
-and produces the interface function gfunc_g to be called from interpreter level.
+and produces the interface function ``gfunc_g`` to be called from interpreter level.
 
 The return value is ``g3dict``, which contains a module name and the function we asked for.
 
 Let's have a look at the body of this code: The first definition of ``g`` is just
-for the argument parsing and is used as ``f_g`` in the gateway.interp2app.
+for the argument parsing and is used as ``f_g`` in the ``gateway.interp2app``.
 We look at the second definition, ``fastf_g``, which does the actual
 computation. Comparing to the flowgraph from above_,
 you see a code block for every block in the graph.
@@ -913,9 +969,36 @@
 give a bit more speed. But this is a temporary format and will
 get optimized anyway when we produce the executable.
 
+Interplevel Snippets in the Sources
+-----------------------------------
+
+.. _`_exceptions.py`: http://codespeak.net/svn/pypy/dist/pypy/lib/_exceptions.py
+.. _`_classobj.py`: http://codespeak.net/svn/pypy/dist/pypy/lib/_classobj.py
+
+Code written in application space can consist of complete files
+to be translated (`_exceptions.py`_, `_classobj.py`_), or they
+can be tiny snippets scattered all over a source file, similar
+to our example from above.
+
+Translation of these snippets is done automatically and cached
+in pypy/_cache with the modulename and the md5 checksum appended
+to it as file name. If you have run your copy of pypy already,
+this folder should exist and have some generated files in it.
+These files consist of the generated code plus a little code
+that auto-destructs the cached file (plus .pyc/.pyo versions)
+if it is executed as __main__. On windows this means you can wipe
+a cached code snippet clear by double-clicking it. Note also that
+the auto-generated __init__.py file wipes the whole directory
+when executed.
+
+XXX this should go into some interpreter.doc, where gateway should be explained
+
 
 How it works
 ------------
 
 XXX to be added later
 
+
+
+.. include:: _ref.txt

Modified: pypy/branch/pycompiler/interpreter/compiler.py
==============================================================================
--- pypy/branch/pycompiler/interpreter/compiler.py	(original)
+++ pypy/branch/pycompiler/interpreter/compiler.py	Mon May 30 16:50:36 2005
@@ -246,7 +246,8 @@
     def compile_module(self, source, filename, mode ):
         pass
 
-    def compile_interactive
+    def compile_interactive(self):
+        pass
         
 
 Compiler = PythonCompiler

Modified: pypy/branch/pycompiler/lib/inprogress__codecs.py
==============================================================================
--- pypy/branch/pycompiler/lib/inprogress__codecs.py	(original)
+++ pypy/branch/pycompiler/lib/inprogress__codecs.py	Mon May 30 16:50:36 2005
@@ -34,8 +34,7 @@
 Copyright (c) Corporation for National Research Initiatives.
 
 """
-from unicodecodec_ import *
-
+from unicodecodec import *
 #/* --- Registry ----------------------------------------------------------- */
 codec_search_path = []
 codec_search_cache = {}
@@ -61,12 +60,24 @@
     
     result = codec_search_cache.get(encoding,None)
     if not result:
+        if len(codec_search_path) == 0:
+            import encodings
+            if len(codec_search_path) == 0:
+                raise LookupError("no codec search functions registered: can't find encoding")
+        if not isinstance(encoding,str):
+            raise TypeError("Encoding must be a string")
         for search in codec_search_path:
             result=search(encoding)
             if result :
-                codec_search_cache[encoding] = result 
-                break
+                if not( type(result) == tuple and len(result) == 4):
+                    raise TypeError("codec search functions must return 4-tuples")
+                else:
+                    codec_search_cache[encoding] = result 
+                    return result
+        if not result:
+            raise LookupError( "unknown encoding: %s" % encoding)
     return result
+    
 
 lookup = codec_lookup
 
@@ -80,11 +91,15 @@
     'xmlcharrefreplace' as well as any other name registered with
     codecs.register_error that can handle ValueErrors.
     """
-    
-    encoder = lookup(encoding)[0]
-    if encoder :
-        res = encoder(v,errors)
-    return res[0]
+    if isinstance(encoding,str):
+        encoder = lookup(encoding)[0]
+        if encoder and isinstance(errors,str):
+            res = encoder(v,errors)
+            return res[0]
+        else:
+            raise TypeError("Errors must be a string")
+    else:
+        raise TypeError("Encoding must be a string")
 
 def decode(obj,encoding='defaultencoding',errors='strict'):
     """decode(obj, [encoding[,errors]]) -> object
@@ -96,12 +111,17 @@
     as well as any other name registerd with codecs.register_error that is
     able to handle ValueErrors.
     """
-    decoder = lookup(encoding)[1]
-    if decoder:
-        res = decoder(obj,errors)
+    if isinstance(encoding,str):
+        decoder = lookup(encoding)[1]
+        if decoder and isinstance(errors,str):
+            res = decoder(v,errors)
+            if not isinstance(res,tuple) or len(res) != 2:
+                raise TypeError("encoder must return a tuple (object,integer)")
+            return res[0]
+        else:
+            raise TypeError("Errors must be a string")
     else:
-        raise LookupError("No such encoding")
-    return res[0]
+        raise TypeError("Encoding must be a string")
 
 def latin_1_encode( obj,errors='strict'):
     """None
@@ -132,7 +152,7 @@
     """None
     """
     res = PyUnicode_DecodeUTF8Stateful(data, len(data), errors, final)
-    res = ''.join(res)
+    res = u''.join(res)
     return res,len(res)
 
 def raw_unicode_escape_decode( data,errors='strict'):
@@ -145,7 +165,7 @@
 def utf_7_decode( data,errors='strict'):
     """None
     """
-    res = PyUnicode_DecodeUTF7(data,errors='strict')
+    res = PyUnicode_DecodeUTF7(data,len(data),errors='strict')
     res = ''.join(res)
     return res,len(res)
 
@@ -160,7 +180,7 @@
     """None
     """
     res = PyUnicode_DecodeLatin1(data,len(data),errors)
-    res = ''.join(res)
+    res = u''.join(res)
     return res, len(res)
 
 def utf_16_decode( data,errors='strict',final=None):
@@ -182,7 +202,7 @@
     """None
     """
     res = PyUnicode_DecodeASCII(data,len(data),errors)
-    res = ''.join(res)
+    res = u''.join(res)
     return res, len(res)
 
 def charmap_encode(obj,errors='strict',mapping='latin-1'):

Modified: pypy/branch/pycompiler/lib/unicodecodec.py
==============================================================================
--- pypy/branch/pycompiler/lib/unicodecodec.py	(original)
+++ pypy/branch/pycompiler/lib/unicodecodec.py	Mon May 30 16:50:36 2005
@@ -190,8 +190,8 @@
             i+=1
 
     if (inShift) :
-        outpos = p-PyUnicode_AS_UNICODE(unicode);
-        endinpos = size;
+        #XXX This aint right
+        endinpos = size
         raise UnicodeDecodeError, "unterminated shift sequence"
         
     return p
@@ -232,8 +232,8 @@
             else:
                 bitsleft += 16
                 charsleft += ch #((ord(charsleft) << 16) | ord(ch))
-                out, charsleft, bitsleft =  ENCODE(out, charsleft, bitsleft)
-
+                p, bitsleft =  ENCODE(charsleft, bitsleft)
+                out += p
 ##                /* If the next character is special then we dont' need to terminate
 ##                   the shift sequence. If the next character is not a BASE64 character
 ##                   or '-' then the shift sequence will be terminated implicitly and we
@@ -401,22 +401,22 @@
 
 #    /* ASCII is equivalent to the first 128 ordinals in Unicode. */
     if (size == 1 and ord(s) < 128) :
-        return PyUnicode_FromUnicode(unicode(s), 1)
+        return [unichr(ord(s))]
     if (size == 0):
-        return unicode('')
+        return [u''] #unicode('')
     p = []
     pos = 0
     while pos < len(s):
         c = s[pos]
         if ord(c) < 128:
-            p += c
+            p += unichr(ord(c))
             pos += 1
         else:
             
             res = unicode_call_errorhandler(
                     errors, "ascii", "ordinal not in range(128)",
                     s,  pos, pos+1)
-            p += res[0]
+            p += unicode(res[0])
             pos = res[1]
     return p
 
@@ -565,7 +565,7 @@
         
     p = []
     bom = sys.byteorder
-    if (byteorder == 0):
+    if (byteorder == 'native'):
         
         bom = sys.byteorder
         p += STORECHAR(0xFEFF,bom)
@@ -573,12 +573,12 @@
     if (size == 0):
         return ""
 
-    if (byteorder == -1):
+    if (byteorder == 'little' ):
         bom = 'little'
-    elif (byteorder == 1):
+    elif (byteorder == 'big'):
         bom = 'big'
 
-    
+
     for c in s:
         ch = ord(c)
         ch2 = 0
@@ -845,7 +845,7 @@
 
 def PyUnicode_EncodeUTF8(s,size,errors):
 
-    assert(s != None)
+    #assert(s != None)
     assert(size >= 0)
     p = []
     i = 0
@@ -892,12 +892,12 @@
 
 def PyUnicode_DecodeLatin1(s, size, errors):
     #/* Latin-1 is equivalent to the first 256 ordinals in Unicode. */
-    if (size == 1):
-        return [PyUnicode_FromUnicode(s, 1)]
+##    if (size == 1):
+##        return [PyUnicode_FromUnicode(s, 1)]
     pos = 0
     p = []
     while (pos < size):
-        p += s[pos]
+        p += unichr(ord(s[pos]))
         pos += 1
     return p
 
@@ -911,16 +911,13 @@
         encoding = "ascii"
     
     if (size == 0):
-        return ''
+        return ['']
     res = []
     pos=0
     while pos < len(p):
     #for ch in p:
         ch = p[pos]
-        try:
-            ord(ch)
-        except TypeError:
-            print "Typeerror",ch,type(ch)
+        
         if ord(ch) < limit:
             res += chr(ord(ch))
             pos += 1
@@ -933,6 +930,7 @@
             x = unicode_call_errorhandler(errors,encoding,reason,p,collstart,collend,False)
             res += str(x[0])
             pos = x[1]
+    
     return res
 
 def PyUnicode_EncodeLatin1(p,size,errors):
@@ -983,7 +981,7 @@
 
     if (size == 0):
         return u''
-
+    
     p = []
     pos = 0
     while (pos < size): 
@@ -1044,7 +1042,7 @@
     
           #  /* \UXXXXXXXX */
             elif ch == 'U':
-                digits = 8;
+                digits = 8
                 message = "truncated \\UXXXXXXXX escape";
                 x = hexescape(s,pos+1,digits,message,errors)
                 p += x[0]
@@ -1052,6 +1050,7 @@
 ##        /* \N{name} */
             elif ch == 'N':
                 message = "malformed \\N character escape"
+                pos += 1
                 try:
                     import unicodedata
                 except ImportError:
@@ -1068,8 +1067,9 @@
                         look += 1
                         try:
                             chr = unicodedata.lookup(s[pos:look])
+                            #x = hexescape(chr,pos+1,8,message,errors)
                         except KeyError:
-                            x=unicode_call_errorhandler(errors,"unicodeescape",message,s,pos-1,size)
+                            x=unicode_call_errorhandler(errors,"unicodeescape",message,s,pos-1,look)
                         else:
                             x = hexescape(s,pos+1,look-pos,message,errors)
                         p += x[0]
@@ -1115,15 +1115,13 @@
 
     
     rep = mapping[c]
-    if not rep:
-        raise UnicodeError
     if isinstance(rep,(int,long)):
         if rep<256:
             return chr(rep)
         else:
             raise TypeError
-    elif isinstance(rep,unicode):
-        raise TypeError
+##    elif isinstance(rep,unicode):
+##        raise TypeError
     else:
         return rep
 

Modified: pypy/branch/pycompiler/objspace/flow/model.py
==============================================================================
--- pypy/branch/pycompiler/objspace/flow/model.py	(original)
+++ pypy/branch/pycompiler/objspace/flow/model.py	Mon May 30 16:50:36 2005
@@ -367,7 +367,7 @@
                         if isinstance(v, Variable):
                             assert v in vars
                         else:
-                            assert v.value != last_exception
+                            assert v.value is not last_exception
                             #assert v.value != last_exc_value
                 exc_links = {}
                 if block.exitswitch is None:
@@ -402,7 +402,7 @@
                                 assert v != block.operations[-1].result
                         else:
                             if not exc_link:
-                                assert v.value != last_exception
+                                assert v.value is not last_exception
                                 #assert v.value != last_exc_value
                 vars_previous_blocks.update(vars)
 

Modified: pypy/branch/pycompiler/objspace/std/inttype.py
==============================================================================
--- pypy/branch/pycompiler/objspace/std/inttype.py	(original)
+++ pypy/branch/pycompiler/objspace/std/inttype.py	Mon May 30 16:50:36 2005
@@ -29,9 +29,10 @@
             except ParseStringOverflowError, e:
                  w_longval = retry_to_w_long(space, e.parser)                
         elif space.is_true(space.isinstance(w_value, space.w_unicode)):
+            from unicodeobject import unicode_to_decimal_w
+            string = unicode_to_decimal_w(space, w_value)
             try:
-                from unicodeobject import unicode_to_decimal_w
-                value = string_to_int(space, unicode_to_decimal_w(space, w_value))
+                value = string_to_int(space, string)
             except ParseStringError, e:
                 raise OperationError(space.w_ValueError,
                                      space.wrap(e.msg))

Modified: pypy/branch/pycompiler/objspace/std/unicodetype.py
==============================================================================
--- pypy/branch/pycompiler/objspace/std/unicodetype.py	(original)
+++ pypy/branch/pycompiler/objspace/std/unicodetype.py	Mon May 30 16:50:36 2005
@@ -53,7 +53,7 @@
         encoding = sys.getdefaultencoding()
     decoder = codecs.getdecoder(encoding)
     if errors is None:
-        retval, lenght = decoder(obj)
+        retval, length = decoder(obj)
     else:
         retval, length = decoder(obj, errors)
     if not isinstance(retval, unicode):

Deleted: /pypy/branch/pycompiler/rpython/lltypes.py
==============================================================================
--- /pypy/branch/pycompiler/rpython/lltypes.py	Mon May 30 16:50:36 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/branch/pycompiler/rpython/rlist.py
==============================================================================
--- pypy/branch/pycompiler/rpython/rlist.py	(original)
+++ pypy/branch/pycompiler/rpython/rlist.py	Mon May 30 16:50:36 2005
@@ -1,67 +1,97 @@
-import py
-from pypy.annotation.model import *
-from pypy.rpython.lltypes import *
-from pypy.tool.sourcetools import compile_template
-
-
-class ListType:
-
-    def __init__(self, s_list):
-        assert isinstance(s_list, SomeList)
-        self.s_list = s_list
-        self.s_item = s_list.listdef.listitem.s_value
-        self.LIST = ForwardReference()
-        self.LISTPTR = GcPtr(self.LIST)
-        #self.ITEM = ... see below
-
-    def define(self, typer):
-        self.ITEM = typer.annotation2concretetype(self.s_item)
-        LISTPTR = self.LISTPTR
-        LIST    = self.LIST
-        ITEM    = self.ITEM
-        LIST.become(GcStruct("list",
-                             ("items", GcPtr(GcArray(('item', ITEM))))))
-
-        def getitem(l, i):
-            return l.items[i].item
-
-        typer['getitem', self.s_list, SomeInteger()] = (
-               getitem,  LISTPTR,     Signed,       ITEM)
-
-        def append(l, newitem):
-            length = len(l.items)
-            newitems = malloc(LIST.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
-
-        typer.registermethod(('append', self.s_list, self.s_item),
-                             ( append,  LISTPTR,     ITEM,       Void))
-
-
-def substitute_newlist(typer, op):
-    # Make an implementation of newlist(x1,..,xn) which allocates
-    # a list with nbargs elements and initialize them.
-    s_result = typer.annotator.binding(op.result)
-    listtype = typer.maketype(ListType, s_result)
-    LIST = listtype.LIST
-    nbargs = len(op.args)
-
-    def template():
-        args = ', '.join(['arg%d' % i for i in range(nbargs)])
-        yield     'def newlist(%s):' % args
-        yield     '    l = malloc(LIST)'
-        yield     '    l.items = malloc(LIST.items.TO, %d)' % nbargs
-        for i in range(nbargs):
-            yield '    l.items[%d].item = arg%d' % (i, i)
-        yield     '    return l'
-
-    newlist = compile_template(template(), 'newlist')
-
-    pattern = ('newlist',) + (listtype.s_item,)*nbargs
-    substitution = (newlist,) + (listtype.ITEM,)*nbargs + (listtype.LISTPTR,)
-    typer[pattern] = substitution
-    raise typer.Retry       # the new pattern should match now
+from pypy.annotation.pairtype import pair, pairtype
+from pypy.annotation.model import SomeList, SomeInteger
+from pypy.rpython.lltype import *
+
+# ____________________________________________________________
+#
+#  Concrete implementation of RPython lists:
+#
+#    struct list {
+#        items_array *items;
+#    }
+#
+#    'items' points to a C-like array in memory preceded by a 'length' header,
+#    where each item contains a primitive value or pointer to the actual list
+#    item.
+
+class __extend__(SomeList):
+
+    def lowleveltype(s_list):
+        ITEM = s_list.get_s_items().lowleveltype()
+        LIST = GcStruct("list", ("items", GcPtr(GcArray(("item", ITEM)))))
+        return GcPtr(LIST)
+
+    def get_s_items(s_list):
+        return s_list.listdef.listitem.s_value
+
+    def rtype_len(s_lst, hop):
+        v_lst = hop.inputargs(s_lst)
+        return hop.gendirectcall(ll_len, v_lst)
+
+    def rtype_method_append(s_lst, hop):
+        v_lst, v_value = hop.inputargs(s_lst, s_lst.get_s_items())
+        hop.gendirectcall(ll_append, v_lst, v_value)
+
+
+class __extend__(pairtype(SomeList, SomeInteger)):
+
+    def rtype_getitem((s_lst1, s_int2), hop):
+        v_lst, v_index = hop.inputargs(s_lst1, Signed)
+        if s_int2.nonneg:
+            llfn = ll_getitem_nonneg
+        else:
+            llfn = ll_getitem
+        return hop.gendirectcall(llfn, v_lst, v_index)
+
+
+# ____________________________________________________________
+#
+#  Low-level methods.  These can be run for testing, but are meant to
+#  be direct_call'ed from rtyped flow graphs, which means that they will
+#  get flowed and annotated, mostly with SomePtr.
+
+def ll_len(l):
+    return len(l.items)
+
+def ll_append(l, newitem):
+    length = len(l.items)
+    newitems = malloc(typeOf(l).TO.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 ll_getitem_nonneg(l, i):
+    return l.items[i].item
+
+def ll_getitem(l, i):
+    if i<0:
+        i += len(l.items)
+    return l.items[i].item
+
+def ll_setitem_nonneg(l, i, newitem):
+    l.items[i].item = newitem
+
+# ____________________________________________________________
+#
+#  Irregular operations.
+
+def ll_newlist(LISTPTR, length):
+    l = malloc(LISTPTR.TO)
+    l.items = malloc(LISTPTR.TO.items.TO, length)
+    return l
+
+def rtype_newlist(hop):
+    nb_args = hop.nb_args
+    s_list = hop.s_result
+    s_listitem = s_list.get_s_items()
+    c1 = hop.inputconst(Void, s_list.lowleveltype())
+    c2 = hop.inputconst(Signed, nb_args)
+    v_result = hop.gendirectcall(ll_newlist, c1, c2)
+    for i in range(nb_args):
+        ci = hop.inputconst(Signed, i)
+        v_item = hop.inputarg(s_listitem, arg=i)
+        hop.gendirectcall(ll_setitem_nonneg, v_result, ci, v_item)
+    return v_result

Modified: pypy/branch/pycompiler/rpython/test/test_llann.py
==============================================================================
--- pypy/branch/pycompiler/rpython/test/test_llann.py	(original)
+++ pypy/branch/pycompiler/rpython/test/test_llann.py	Mon May 30 16:50:36 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
  

Deleted: /pypy/branch/pycompiler/rpython/test/test_lltypes.py
==============================================================================
--- /pypy/branch/pycompiler/rpython/test/test_lltypes.py	Mon May 30 16:50:36 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/branch/pycompiler/rpython/test/test_rlist.py
==============================================================================
--- pypy/branch/pycompiler/rpython/test/test_rlist.py	(original)
+++ pypy/branch/pycompiler/rpython/test/test_rlist.py	Mon May 30 16:50:36 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():
@@ -13,10 +13,10 @@
     typer = RPythonTyper(t.annotator)
     typer.specialize()
     #t.view()
-    assert "did not crash"
+    t.checkgraphs()
 
 
-def NOT_READY_test_append():
+def test_append():
     def dummyfn():
         l = []
         l.append(5)
@@ -27,5 +27,5 @@
     t.annotate([])
     typer = RPythonTyper(t.annotator)
     typer.specialize()
-    t.view()
-    assert "did not crash"
+    #t.view()
+    t.checkgraphs()

Deleted: /pypy/branch/pycompiler/rpython/test/test_typer.py
==============================================================================
--- /pypy/branch/pycompiler/rpython/test/test_typer.py	Mon May 30 16:50:36 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/branch/pycompiler/rpython/typer.py
==============================================================================
--- /pypy/branch/pycompiler/rpython/typer.py	Mon May 30 16:50:36 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/branch/pycompiler/tool/sourcetools.py
==============================================================================
--- pypy/branch/pycompiler/tool/sourcetools.py	(original)
+++ pypy/branch/pycompiler/tool/sourcetools.py	Mon May 30 16:50:36 2005
@@ -221,5 +221,17 @@
             f.func_dict.update(func.func_dict) 
         return f 
 else:
-    def func_with_new_name(func, newname):
-        return func
+    raise Exception("sorry, Python 2.2 not supported")
+    # because we need to return a new function object -- impossible in 2.2,
+    # cannot create functions with closures without using veeeery strange code
+
+PY_IDENTIFIER = ''.join([(('0' <= chr(i) <= '9' or
+                           'a' <= chr(i) <= 'z' or
+                           'A' <= chr(i) <= 'Z') and chr(i) or '_')
+                         for i in range(256)])
+
+def valid_identifier(stuff):
+    stuff = str(stuff).translate(PY_IDENTIFIER)
+    if not stuff or ('0' <= stuff[0] <= '9'):
+        stuff = '_' + stuff
+    return stuff

Modified: pypy/branch/pycompiler/translator/annrpython.py
==============================================================================
--- pypy/branch/pycompiler/translator/annrpython.py	(original)
+++ pypy/branch/pycompiler/translator/annrpython.py	Mon May 30 16:50:36 2005
@@ -435,6 +435,7 @@
             
             if isinstance(link.exitcase, (types.ClassType, type)) \
                    and issubclass(link.exitcase, Exception):
+                assert last_exception_var and last_exc_value_var
                 last_exception_object = annmodel.SomeObject()
                 last_exception_object.knowntype = type
                 if isinstance(last_exception_var, Constant):
@@ -454,10 +455,10 @@
             for a,v in zip(link.args,link.target.inputargs):
                 renaming.setdefault(a, []).append(v)
             for a,v in zip(link.args,link.target.inputargs):
-                if a is last_exception_var:
+                if a == last_exception_var:
                     assert in_except_block
                     cells.append(last_exception_object)
-                elif a is last_exc_value_var:
+                elif a == last_exc_value_var:
                     assert in_except_block
                     cells.append(last_exc_value_object)
                     last_exc_value_vars.append(v)

Modified: pypy/branch/pycompiler/translator/c/database.py
==============================================================================
--- pypy/branch/pycompiler/translator/c/database.py	(original)
+++ pypy/branch/pycompiler/translator/c/database.py	Mon May 30 16:50:36 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
@@ -14,13 +13,13 @@
 
 class LowLevelDatabase:
 
-    def __init__(self):
+    def __init__(self, rtyper=None):
         self.structdefnodes = {}
         self.structdeflist = []
         self.containernodes = {}
         self.containerlist = []
         self.namespace = CNameManager()
-        self.pyobjmaker = PyObjMaker(self.namespace, self.get)
+        self.pyobjmaker = PyObjMaker(self.namespace, self.get, rtyper)
 
     def gettypedefnode(self, T, varlength=1):
         if varlength <= 1:
@@ -103,6 +102,28 @@
             else:
                 raise Exception("don't know about %r" % (obj,))
 
+    def cincrefstmt(self, expr, T):
+        if isinstance(T, _PtrType) and 'gc' in T.flags:
+            if T.TO == PyObject:
+                return 'Py_INCREF(%s);' % expr
+            else:
+                defnode = self.gettypedefnode(T.TO)
+                if defnode.refcount is not None:
+                    return '%s->%s++;' % (expr, defnode.refcount)
+        return ''
+
+    def cdecrefstmt(self, expr, T):
+        if isinstance(T, _PtrType) and 'gc' in T.flags:
+            if T.TO == PyObject:
+                return 'Py_DECREF(%s);' % expr
+            else:
+                defnode = self.gettypedefnode(T.TO)
+                if defnode.refcount is not None:
+                    return 'if (!--%s->%s) %s(%s);' % (expr, defnode.refcount,
+                                               defnode.deallocator or 'OP_FREE',
+                                                       expr)
+        return ''
+
     def complete(self):
         i = 0
         while True:

Modified: pypy/branch/pycompiler/translator/c/funcgen.py
==============================================================================
--- pypy/branch/pycompiler/translator/c/funcgen.py	(original)
+++ pypy/branch/pycompiler/translator/c/funcgen.py	Mon May 30 16:50:36 2005
@@ -1,10 +1,10 @@
 from __future__ import generators
-from pypy.translator.gensupp import ordered_blocks
 from pypy.translator.c.support import cdecl, ErrorValue
 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.objspace.flow.model import traverse, uniqueitems, last_exception
+from pypy.rpython.lltype import GcPtr, NonGcPtr, PyObject, Void
+from pypy.rpython.lltype import pyobjectptr, Struct, Array
 
 
 PyObjGcPtr    = GcPtr(PyObject)
@@ -17,12 +17,15 @@
     from a flow graph.
     """
 
-    def __init__(self, graph, gettype, getvalue):
+    def __init__(self, graph, db):
         self.graph = graph
-        self.getvalue = getvalue
-        self.typemap, self.returntype = self.collecttypes(gettype)
+        self.db = db
+        self.lltypemap = self.collecttypes()
+        self.typemap = {}
+        for v, T in self.lltypemap.items():
+            self.typemap[v] = db.gettype(T)
 
-    def collecttypes(self, gettype):
+    def collecttypes(self):
         # collect all variables and constants used in the body,
         # and get their types now
         result = []
@@ -31,21 +34,19 @@
                 result.extend(block.inputargs)
                 for op in block.operations:
                     result.extend(op.args)
+                    result.append(op.result)
                 for link in block.exits:
                     result.extend(link.args)
         traverse(visit, self.graph)
-        typemap = {}
-        returnvar = self.graph.getreturnvar()
-        result.append(returnvar)
+        resultvar = self.graph.getreturnvar()
+        lltypemap = {resultvar: Void}   # default value, normally overridden
         for v in uniqueitems(result):
             if isinstance(v, Variable):
                 T = getattr(v, 'concretetype', PyObjGcPtr)
             else:
                 T = getattr(v, 'concretetype', PyObjNonGcPtr)
-            typemap[v] = gettype(T)
-            if v is returnvar:
-                returntype = T
-        return typemap, returntype
+            lltypemap[v] = T
+        return lltypemap
 
     def argnames(self):
         return [v.name for v in self.graph.getargs()]
@@ -57,24 +58,24 @@
         return [v for v in self.typemap if isinstance(v, Constant)]
 
     def allconstantvalues(self):
-        for v, T in self.typemap.iteritems():
+        for v in self.typemap:
             if isinstance(v, Constant):
                 yield llvalue_from_constant(v)
 
-    def decl(self, v):
-        assert isinstance(v, Variable), repr(v)
-        return cdecl(self.typemap[v], v.name)
-
     def expr(self, v):
         if isinstance(v, Variable):
-            return v.name
+            if self.lltypemap[v] == Void:
+                return '/* nothing */'
+            else:
+                return v.name
         elif isinstance(v, Constant):
-            return self.getvalue(llvalue_from_constant(v))
+            return self.db.get(llvalue_from_constant(v))
         else:
             raise TypeError, "expr(%r)" % (v,)
 
     def error_return_value(self):
-        return self.getvalue(ErrorValue(self.returntype))
+        returnlltype = self.lltypemap[self.graph.getreturnvar()]
+        return self.db.get(ErrorValue(returnlltype))
 
     # ____________________________________________________________
 
@@ -86,16 +87,24 @@
 
         for v in self.allvariables():
             if v not in inputargset:
-                yield '%s;' % self.decl(v)
+                result = cdecl(self.typemap[v], v.name) + ';'
+                if self.lltypemap[v] == Void:
+                    result = '/*%s*/' % result
+                yield result
 
     # ____________________________________________________________
 
     def cfunction_body(self):
         graph = self.graph
 
+        blocknum = {}
+        allblocks = []
+
         # generate an incref for each input argument
         for a in self.graph.getargs():
-            yield self.cincref(a)
+            line = self.cincref(a)
+            if line:
+                yield line
 
         def gen_link(link, linklocalvars=None):
             "Generate the code to jump across the given Link."
@@ -105,6 +114,8 @@
                 linklocalvars[v] = self.expr(v)
             has_ref = linklocalvars.copy()
             for a1, a2 in zip(link.args, link.target.inputargs):
+                if self.lltypemap[a2] == Void:
+                    continue
                 if a1 in linklocalvars:
                     src = linklocalvars[a1]
                 else:
@@ -113,20 +124,23 @@
                 if a1 in has_ref:
                     del has_ref[a1]
                 else:
-                    ct1 = self.ctypeof(a1)
-                    ct2 = self.ctypeof(a2)
-                    assert ct1 == ct2
+                    assert self.lltypemap[a1] == self.lltypemap[a2]
                     line += '\t' + self.cincref(a2)
                 yield line
             for v in has_ref:
-                yield self.cdecref(v, linklocalvars[v])
+                line = self.cdecref(v, linklocalvars[v])
+                if line:
+                    yield line
             yield 'goto block%d;' % blocknum[link.target]
 
         # collect all blocks
-        allblocks = ordered_blocks(graph)
-        blocknum = {}
-        for block in allblocks:
-            blocknum[block] = len(blocknum)
+        def visit(block):
+            if isinstance(block, Block):
+                allblocks.append(block)
+                blocknum[block] = len(blocknum)
+        traverse(visit, graph)
+
+        assert graph.startblock is allblocks[0]
 
         # generate the body of each block
         for block in allblocks:
@@ -143,7 +157,7 @@
                     lst = [self.expr(v) for v in op.args]
                     lst.append(self.expr(op.result))
                     lst.append(err)
-                    yield '%s(%s);' % (macro, ', '.join(lst))
+                    yield '%s(%s)' % (macro, ', '.join(lst))
                 to_release.append(op.result)
 
             err_reachable = False
@@ -181,7 +195,7 @@
                 for link in block.exits[1:]:
                     assert issubclass(link.exitcase, Exception)
                     yield 'if (PyErr_ExceptionMatches(%s)) {' % (
-                        self.genc.nameofvalue(link.exitcase),)
+                        self.db.get(pyobjectptr(link.exitcase)),)
                     yield '\tPyObject *exc_cls, *exc_value, *exc_tb;'
                     yield '\tPyErr_Fetch(&exc_cls, &exc_value, &exc_tb);'
                     yield '\tif (exc_value == NULL) {'
@@ -197,18 +211,20 @@
                 err_reachable = True
             else:
                 # block ending in a switch on a value
-                ct = self.ctypeof(block.exitswitch)
+                TYPE = self.lltypemap[block.exitswitch]
                 for link in block.exits[:-1]:
                     assert link.exitcase in (False, True)
-                    yield 'if (%s == %s) {' % (self.expr(block.exitswitch),
-                                       self.genc.nameofvalue(link.exitcase, ct))
+                    expr = self.expr(block.exitswitch)
+                    if not link.exitcase:
+                        expr = '!' + expr
+                    yield 'if (%s) {' % expr
                     for op in gen_link(link):
                         yield '\t' + op
                     yield '}'
                 link = block.exits[-1]
                 assert link.exitcase in (False, True)
-                yield 'assert(%s == %s);' % (self.expr(block.exitswitch),
-                                       self.genc.nameofvalue(link.exitcase, ct))
+                #yield 'assert(%s == %s);' % (self.expr(block.exitswitch),
+                #                       self.genc.nameofvalue(link.exitcase, ct))
                 for op in gen_link(block.exits[-1]):
                     yield op
                 yield ''
@@ -264,44 +280,109 @@
         return 'OP_CALL_ARGS((%s), %s, %s)' % (', '.join(args), r, err)
 
     def OP_DIRECT_CALL(self, op, err):
-        args = [self.expr(v) for v in op.args]
-        r = self.expr(op.result)
-        return '%s = %s(%s); if (PyErr_Occurred()) FAIL(%s)' % (
-            r, args[0], ', '.join(args[1:]), err)
-
-    def OP_INST_GETATTR(self, op, err):
-        return '%s = INST_ATTR_%s__%s(%s);' % (
-            self.expr(op.result),
-            op.args[0].concretetype.typename,
-            op.args[1].value,
-            self.expr(op.args[0]))
-
-    def OP_INST_SETATTR(self, op, err):
-        return 'INST_ATTR_%s__%s(%s) = %s;' % (
-            op.args[0].concretetype.typename,
-            op.args[1].value,
-            self.expr(op.args[0]),
-            self.expr(op.args[2]))
-
-    def OP_CONV_TO_OBJ(self, op, err):
-        v = op.args[0]
-        return '%s = CONV_TO_OBJ_%s(%s); if (PyErr_Occurred()) FAIL(%s)' % (
-            self.expr(op.result), self.ctypeof(v).typename, self.expr(v), err)
-
-    def OP_CONV_FROM_OBJ(self, op, err):
-        v = op.args[0]
-        return '%s = CONV_FROM_OBJ_%s(%s); if (PyErr_Occurred()) FAIL(%s)' %(
-            self.expr(op.result), self.ctypeof(op.result).typename,
-            self.expr(v), err)
-
-    def OP_INCREF(self, op, err):
-        return self.cincref(op.args[0])
-
-    def OP_DECREF(self, op, err):
-        return self.cdecref(op.args[0])
+        # skip 'void' arguments
+        args = [self.expr(v) for v in op.args if self.lltypemap[v] != Void]
+        if self.lltypemap[op.result] == Void:
+            # skip assignment of 'void' return value
+            return '%s(%s); if (PyErr_Occurred()) FAIL(%s)' % (
+                args[0], ', '.join(args[1:]), err)
+        else:
+            r = self.expr(op.result)
+            return '%s = %s(%s); if (PyErr_Occurred()) FAIL(%s)' % (
+                r, args[0], ', '.join(args[1:]), err)
+
+    # low-level operations
+    def OP_GETFIELD(self, op, err, ampersand=''):
+        assert isinstance(op.args[1], Constant)
+        STRUCT = self.lltypemap[op.args[0]].TO
+        structdef = self.db.gettypedefnode(STRUCT)
+        fieldname = structdef.c_struct_field_name(op.args[1].value)
+        newvalue = self.expr(op.result)
+        result = ['%s = %s%s->%s;' % (newvalue,
+                                      ampersand,
+                                      self.expr(op.args[0]),
+                                      fieldname)]
+        # need to adjust the refcount of the result
+        T = self.lltypemap[op.result]
+        increfstmt = self.db.cincrefstmt(newvalue, T)
+        if increfstmt:
+            result.append(increfstmt)
+        return '\t'.join(result)
+
+    def OP_SETFIELD(self, op, err):
+        assert isinstance(op.args[1], Constant)
+        STRUCT = self.lltypemap[op.args[0]].TO
+        structdef = self.db.gettypedefnode(STRUCT)
+        fieldname = structdef.c_struct_field_name(op.args[1].value)
+        oldvalue = '%s->%s' % (self.expr(op.args[0]),
+                               fieldname)
+        newvalue = self.expr(op.args[2])
+        result = ['%s = %s;' % (oldvalue, newvalue)]
+
+        # need to adjust some refcounts
+        T = structdef.c_struct_field_type(op.args[1].value)
+        decrefstmt = self.db.cdecrefstmt('prev', T)
+        increfstmt = self.db.cincrefstmt(newvalue, T)
+        if increfstmt:
+            result.append(increfstmt)
+        if decrefstmt:
+            result.insert(0, '{ %s = %s;' % (
+                cdecl(self.typemap[op.args[2]], 'prev'),
+                oldvalue))
+            result.append('if (prev) ' + decrefstmt)
+            result.append('}')
+        return '\t'.join(result)
+
+    def OP_GETSUBSTRUCT(self, op, err):
+        return self.OP_GETFIELD(op, err, ampersand='&')
+
+    def OP_GETARRAYITEM(self, op, err):
+        return '%s = %s->items + %s;' % (self.expr(op.result),
+                                         self.expr(op.args[0]),
+                                         self.expr(op.args[1]))
+
+    def OP_GETARRAYSIZE(self, op, err):
+        return '%s = %s->length;' % (self.expr(op.result),
+                                     self.expr(op.args[0]))
+
+    def OP_MALLOC(self, op, err):
+        TYPE = self.lltypemap[op.result].TO
+        typename = self.db.gettype(TYPE)
+        eresult = self.expr(op.result)
+        result = ['OP_ZERO_MALLOC(sizeof(%s), %s, %s)' % (cdecl(typename, ''),
+                                                          eresult,
+                                                          err),
+                  '%s->%s = 1;' % (eresult,
+                                   self.db.gettypedefnode(TYPE).refcount),
+                  ]
+        return '\t'.join(result)
+
+    def OP_MALLOC_VARSIZE(self, op, err):
+        TYPE = self.lltypemap[op.result].TO
+        typename = self.db.gettype(TYPE)
+        if isinstance(TYPE, Struct):
+            TYPE = TYPE._arrayfld
+        assert isinstance(TYPE, Array)
+        itemtypename = self.db.gettype(TYPE.OF)
+        elength = self.expr(op.args[1])
+        eresult = self.expr(op.result)
+        size = 'sizeof(%s)+((%s-1)*sizeof(%s))' % (cdecl(typename, ''),
+                                                   elength,
+                                                   cdecl(itemtypename, ''))
+        result = ['OP_ZERO_MALLOC(%s, %s, %s)' % (size,
+                                                  eresult,
+                                                  err),
+                  '%s->length = %s;' % (eresult,
+                                        elength),
+                  '%s->%s = 1;' % (eresult,
+                                   self.db.gettypedefnode(TYPE).refcount),
+                  ]
+        return '\t'.join(result)
 
     def cincref(self, v):
-        return '/*XXX INCREF*/'
+        T = self.lltypemap[v]
+        return self.db.cincrefstmt(v.name, T)
 
     def cdecref(self, v, expr=None):
-        return '/*XXX DECREF*/'
+        T = self.lltypemap[v]
+        return self.db.cdecrefstmt(expr or v.name, T)

Modified: pypy/branch/pycompiler/translator/c/g_include.h
==============================================================================
--- pypy/branch/pycompiler/translator/c/g_include.h	(original)
+++ pypy/branch/pycompiler/translator/c/g_include.h	Mon May 30 16:50:36 2005
@@ -14,4 +14,6 @@
 #include "g_support.h"
 #include "g_module.h"
 
+#include "int_include.h"
+#include "ll_include.h"
 #include "pyobj_include.h"

Modified: pypy/branch/pycompiler/translator/c/g_module.h
==============================================================================
--- pypy/branch/pycompiler/translator/c/g_module.h	(original)
+++ pypy/branch/pycompiler/translator/c/g_module.h	Mon May 30 16:50:36 2005
@@ -3,12 +3,20 @@
  /***  C header subsection: CPython-extension-module-ness  ***/
 
 
-#define MODULE_INITFUNC(modname) \
-	static PyMethodDef no_methods[] = { (char *)NULL, (PyCFunction)NULL }; \
+#ifndef COUNT_OP_MALLOCS
+# define MODULE_INITFUNC(modname) \
+	static PyMethodDef my_methods[] = { (char *)NULL, (PyCFunction)NULL }; \
 	PyMODINIT_FUNC init##modname(void)
+#else
+# define MODULE_INITFUNC(modname) \
+	static PyMethodDef my_methods[] = { \
+		{ "malloc_counters", malloc_counters }, \
+		{ (char *)NULL, (PyCFunction)NULL } }; \
+	PyMODINIT_FUNC init##modname(void)
+#endif
 
 #define SETUP_MODULE(modname)					\
-	PyObject *m = Py_InitModule(#modname, no_methods); \
+	PyObject *m = Py_InitModule(#modname, my_methods); \
 	PyModule_AddStringConstant(m, "__sourcefile__", __FILE__); \
 	this_module_globals = PyModule_GetDict(m); \
 	PyGenCFunction_Type.tp_base = &PyCFunction_Type;	\

Modified: pypy/branch/pycompiler/translator/c/g_support.h
==============================================================================
--- pypy/branch/pycompiler/translator/c/g_support.h	(original)
+++ pypy/branch/pycompiler/translator/c/g_support.h	Mon May 30 16:50:36 2005
@@ -9,8 +9,6 @@
 #define MIN(a,b) (((a)<(b))?(a):(b))
 #endif /* MIN */
 
-#define MOVE(x, y)             y = x;
-
 #define FAIL_EXCEPTION(err, exc, msg) \
 	{ \
 		PyErr_SetString(exc, msg); \
@@ -336,7 +334,7 @@
 	}
 	PyErr_Format(PyExc_TypeError, "%s() got only %d argument(s)",
 		     PyString_AS_STRING(fname),
-		     position-1);
+		     position);
 	return NULL;
 }
 

Modified: pypy/branch/pycompiler/translator/c/node.py
==============================================================================
--- pypy/branch/pycompiler/translator/c/node.py	(original)
+++ pypy/branch/pycompiler/translator/c/node.py	Mon May 30 16:50:36 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, _PtrType
 from pypy.translator.c.funcgen import FunctionCodeGenerator
 from pypy.translator.c.support import cdecl, somelettersfrom
 
@@ -11,13 +11,16 @@
         return False
     if isinstance(T, GcStruct):
         if T._names and isinstance(T._flds[T._names[0]], GC_CONTAINER):
-            return False   # refcount already in the first first
+            return False   # refcount already in the first field
     return True
 
 
 class StructDefNode:
+    refcount = None
+    deallocator = None
 
     def __init__(self, db, STRUCT, varlength=1):
+        self.db = db
         self.STRUCT = STRUCT
         if varlength == 1:
             basename = STRUCT._name
@@ -29,16 +32,34 @@
         self.fields = []
         self.prefix = somelettersfrom(STRUCT._name) + '_'
         for name in STRUCT._names:
-            T = STRUCT._flds[name]
+            T = self.c_struct_field_type(name)
             if name == STRUCT._arrayfld:
                 typename = db.gettype(T, varlength=varlength, who_asks=self)
             else:
                 typename = db.gettype(T, who_asks=self)
             self.fields.append((self.c_struct_field_name(name), typename))
 
+        # look up the reference counter field
+        if needs_refcount(STRUCT):
+            self.refcount = 'refcount'
+        elif isinstance(STRUCT, GcStruct):
+            # refcount in the first field
+            T = self.c_struct_field_type(STRUCT._names[0])
+            assert isinstance(T, GC_CONTAINER)
+            firstfieldname, firstfieldtype = self.fields[0]
+            firstdefnode = db.gettypedefnode(T)
+            self.refcount = '%s.%s' % (firstfieldname, firstdefnode.refcount)
+
+        # is a specific deallocator needed?
+        if self.refcount and varlength == 1 and list(self.deallocator_lines('')):
+            self.deallocator = db.namespace.uniquename('dealloc_'+self.name)
+
     def c_struct_field_name(self, name):
         return self.prefix + name
 
+    def c_struct_field_type(self, name):
+        return self.STRUCT._flds[name]
+
     def access_expr(self, baseexpr, fldname):
         fldname = self.c_struct_field_name(fldname)
         return '%s.%s' % (baseexpr, fldname)
@@ -50,11 +71,35 @@
         for name, typename in self.fields:
             yield '\t%s;' % cdecl(typename, name)
         yield '};'
+        if self.deallocator:
+            yield 'void %s(struct %s *p) {' % (self.deallocator, self.name)
+            for line in self.deallocator_lines('p->'):
+                yield '\t' + line
+            yield '\tOP_FREE(p);'
+            yield '}'
+
+    def deallocator_lines(self, prefix):
+        STRUCT = self.STRUCT
+        for name in STRUCT._names:
+            FIELD_T = self.c_struct_field_type(name)
+            if isinstance(FIELD_T, _PtrType) and 'gc' in FIELD_T.flags:
+                cname = self.c_struct_field_name(name)
+                line = self.db.cdecrefstmt('%s%s' % (prefix, cname), FIELD_T)
+                if line:
+                    yield line
+            elif isinstance(FIELD_T, ContainerType):
+                defnode = self.db.gettypedefnode(FIELD_T)
+                cname = self.c_struct_field_name(name)
+                for line in defnode.deallocator_lines('%s%s.' %(prefix, cname)):
+                    yield line
 
 
 class ArrayDefNode:
+    refcount = None
+    deallocator = None
 
     def __init__(self, db, ARRAY, varlength=1):
+        self.db = db
         self.ARRAY = ARRAY
         if varlength == 1:
             basename = 'array'
@@ -66,6 +111,14 @@
         self.structname = db.gettype(ARRAY.OF, who_asks=self)
         self.varlength = varlength
 
+        # look up the reference counter field
+        if needs_refcount(ARRAY):
+            self.refcount = 'refcount'
+
+        # is a specific deallocator needed?
+        if self.refcount and varlength == 1 and list(self.deallocator_lines('')):
+            self.deallocator = db.namespace.uniquename('dealloc_'+self.name)
+
     def access_expr(self, baseexpr, index):
         return '%s.items[%d]' % (baseexpr, index)
 
@@ -76,6 +129,33 @@
         yield '\tlong length;'
         yield '\t%s;' % cdecl(self.structname, 'items[%d]' % self.varlength)
         yield '};'
+        if self.deallocator:
+            yield 'void %s(struct %s *a) {' % (self.deallocator, self.name)
+            for line in self.deallocator_lines('a->'):
+                yield '\t' + line
+            yield '\tOP_FREE(a);'
+            yield '}'
+
+    def deallocator_lines(self, prefix):
+        ARRAY = self.ARRAY
+        defnode = self.db.gettypedefnode(ARRAY.OF)
+        varname = 'p%d' % len(prefix)
+        body = list(defnode.deallocator_lines('%s->' % varname))
+        if body:
+            yield '{'
+            yield '\tstruct %s *%s = %sitems;' % (defnode.name,
+                                                  varname,
+                                                  prefix)
+            yield '\tstruct %s *%s_end = %s + %slength;' % (defnode.name,
+                                                            varname,
+                                                            varname,
+                                                            prefix)
+            yield '\twhile (%s != %s_end) {' % (varname, varname)
+            for line in body:
+                yield '\t\t' + line
+            yield '\t\t%s++;' % varname
+            yield '\t}'
+            yield '}'
 
 # ____________________________________________________________
 
@@ -185,7 +265,7 @@
 
     def __init__(self, db, T, obj):
         graph = obj.graph # only user-defined functions with graphs for now
-        self.funcgen = FunctionCodeGenerator(graph, db.gettype, db.get)
+        self.funcgen = FunctionCodeGenerator(graph, db)
         self.db = db
         self.T = T
         self.obj = obj
@@ -246,6 +326,41 @@
         yield '}'
 
 
+class CExternalFuncNode(ContainerNode):
+    globalcontainer = True
+
+    def __init__(self, db, T, obj):
+        self.db = db
+        self.T = T
+        self.obj = obj
+        #self.dependencies = {}
+        self.typename = db.gettype(T)  #, who_asks=self)
+        self.name = obj._name
+        self.ptrname = self.name
+
+    def enum_dependencies(self):
+        return []
+
+    def implementation(self):
+        return []
+
+    def forward_declaration(self):
+        return []
+
+    def implementation(self):
+        return []
+
+
+def funcnodemaker(db, T, obj):
+    if hasattr(obj, 'graph'):
+        cls = FuncNode
+    elif getattr(obj, 'external', None) == 'C':
+        cls = CExternalFuncNode
+    else:
+        raise ValueError, "don't know about %r" % (obj,)
+    return cls(db, T, obj)
+
+
 class PyObjectNode(ContainerNode):
     globalcontainer = True
     typename = 'PyObject @'
@@ -271,6 +386,6 @@
     GcStruct:     StructNode,
     Array:        ArrayNode,
     GcArray:      ArrayNode,
-    FuncType:     FuncNode,
+    FuncType:     funcnodemaker,
     PyObjectType: PyObjectNode,
     }

Modified: pypy/branch/pycompiler/translator/c/primitive.py
==============================================================================
--- pypy/branch/pycompiler/translator/c/primitive.py	(original)
+++ pypy/branch/pycompiler/translator/c/primitive.py	Mon May 30 16:50:36 2005
@@ -1,4 +1,4 @@
-from pypy.rpython.lltypes import *
+from pypy.rpython.lltype import *
 
 # ____________________________________________________________
 #

Modified: pypy/branch/pycompiler/translator/c/pyobj.py
==============================================================================
--- pypy/branch/pycompiler/translator/c/pyobj.py	(original)
+++ pypy/branch/pycompiler/translator/c/pyobj.py	Mon May 30 16:50:36 2005
@@ -3,10 +3,10 @@
 from types import FunctionType, CodeType, InstanceType, ClassType
 
 from pypy.objspace.flow.model import Variable, Constant
-from pypy.translator.gensupp import builtin_base, NameManager
+from pypy.translator.gensupp import builtin_base
 
 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
@@ -22,9 +22,10 @@
     reconstruct them.
     """
 
-    def __init__(self, namespace, getvalue):
+    def __init__(self, namespace, getvalue, rtyper=None):
         self.namespace = namespace
         self.getvalue = getvalue
+        self.rtyper = rtyper
         self.initcode = [      # list of lines for the module's initxxx()
             'import new, types, sys',
             ]
@@ -33,6 +34,7 @@
                                #   for later in initxxx() -- for recursive
                                #   objects
         self.debugstack = ()  # linked list of nested nameof()
+        self.wrappers = {}    # {'pycfunctionvariable': ('name', 'wrapperfn')}
 
     def nameof(self, obj, debug=None):
         if debug:
@@ -41,7 +43,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
@@ -77,6 +79,17 @@
         self.initcode_python(name, "object()")
         return name
 
+    def nameof_NoneType(self, value):
+        assert value is None
+        return 'Py_None'
+
+    def nameof_bool(self, value):
+        assert value is False or value is True
+        if value:
+            return 'Py_True'
+        else:
+            return 'Py_False'
+
     def nameof_module(self, value):
         assert value is os or not hasattr(value, "__file__") or \
                not (value.__file__.endswith('.pyc') or
@@ -116,14 +129,11 @@
 
     def nameof_str(self, value):
         name = self.uniquename('gstr_' + value[:32])
-##        if [c for c in value if c<' ' or c>'~' or c=='"' or c=='\\']:
-##            # non-printable string
-##            s = 'chr_%s' % name
-##            self.globaldecl.append('static char %s[] = { %s };' % (
-##                s, ', '.join(['%d' % ord(c) for c in value])))
-##        else:
-##            # printable string
-##            s = '"%s"' % value
+        self.initcode_python(name, repr(value))
+        return name
+
+    def nameof_unicode(self, value):
+        name = self.uniquename('guni_' + str(value[:32]))
         self.initcode_python(name, repr(value))
         return name
 
@@ -144,16 +154,25 @@
         self.initcode.append('  raise NotImplementedError')
         return name
 
-    def nameof_function(self, func, progress=['-\x08', '\\\x08',
-                                              '|\x08', '/\x08']):
-        funcdef = self.genc().getfuncdef(func)
-        if funcdef is None:
-            return self.skipped_function(func)
-        if not self.translator.frozen:
-            p = progress.pop(0)
-            sys.stderr.write(p)
-            progress.append(p)
-        return funcdef.get_globalobject()
+    def nameof_function(self, func):
+        assert self.rtyper is not None, (
+            "for now, rtyper must be specified to build a PyObject "
+            "wrapper for %r" % (func,))
+        # look for skipped functions
+        a = self.rtyper.annotator
+        if a.translator.frozen:
+            if func not in a.translator.flowgraphs:
+                return self.skipped_function(func)
+        else:
+            if (func.func_doc and
+                func.func_doc.lstrip().startswith('NOT_RPYTHON')):
+                return self.skipped_function(func)
+
+        from pypy.translator.c.wrapper import gen_wrapper
+        fwrapper = gen_wrapper(func, self.rtyper)
+        pycfunctionobj = self.uniquename('gfunc_' + func.__name__)
+        self.wrappers[pycfunctionobj] = func.__name__, self.getvalue(fwrapper)
+        return pycfunctionobj
 
     def nameof_staticmethod(self, sm):
         # XXX XXX XXXX

Modified: pypy/branch/pycompiler/translator/c/support.py
==============================================================================
--- pypy/branch/pycompiler/translator/c/support.py	(original)
+++ pypy/branch/pycompiler/translator/c/support.py	Mon May 30 16:50:36 2005
@@ -1,4 +1,4 @@
-from pypy.rpython import lltypes
+from pypy.rpython import lltype
 from pypy.translator.gensupp import NameManager
 
 class ErrorValue:
@@ -34,10 +34,13 @@
     try:
         T = c.concretetype
     except AttributeError:
-        return lltypes.pyobject(c.value)
+        return lltype.pyobjectptr(c.value)
     else:
-        assert lltypes.typeOf(c.value) == T
-        return c.value
+        if T == lltype.Void:
+            return None
+        else:
+            assert lltype.typeOf(c.value) == T
+            return c.value
 
 
 class CNameManager(NameManager):

Modified: pypy/branch/pycompiler/translator/c/test/test_database.py
==============================================================================
--- pypy/branch/pycompiler/translator/c/test/test_database.py	(original)
+++ pypy/branch/pycompiler/translator/c/test/test_database.py	Mon May 30 16:50:36 2005
@@ -1,10 +1,10 @@
 import autopath, sys
-from pypy.rpython.lltypes import *
+from pypy.rpython.lltype import *
+from pypy.rpython.rtyper import RPythonTyper
 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 +130,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 +151,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()
@@ -164,3 +164,101 @@
     db.get(s)
     db.complete()
     dump_on_stdout(db)
+
+def test_function_call():
+    def g(x, y):
+        return x-y
+    def f(x):
+        return g(1, x)
+    t = Translator(f)
+    a = t.annotate([int])
+    RPythonTyper(t.annotator).specialize()
+
+    F = FuncType([Signed], Signed)
+    f = functionptr(F, "f", graph=t.getflowgraph())
+    db = LowLevelDatabase()
+    db.get(f)
+    db.complete()
+    dump_on_stdout(db)
+
+def test_func_as_pyobject():
+    def f(x):
+        return x+1
+    t = Translator(f)
+    a = t.annotate([int])
+    rtyper = RPythonTyper(t.annotator)
+    rtyper.specialize()
+
+    db = LowLevelDatabase(rtyper)
+    db.get(pyobjectptr(f))
+    db.complete()
+    dump_on_stdout(db)
+
+
+def test_malloc():
+    S = GcStruct('testing', ('x', Signed), ('y', Signed))
+    def ll_f(x):
+        p = malloc(S)
+        p.x = x
+        p.y = x+1
+        return p.x * p.y
+    t = Translator(ll_f)
+    a = t.annotate([int])
+    rtyper = RPythonTyper(t.annotator)
+    rtyper.specialize()
+    db = LowLevelDatabase(rtyper)
+    db.get(rtyper.getfunctionptr(ll_f))
+    db.complete()
+    dump_on_stdout(db)
+
+def test_multiple_malloc():
+    S1 = GcStruct('testing1', ('x', Signed), ('y', Signed))
+    S = GcStruct('testing', ('ptr1', GcPtr(S1)),
+                            ('ptr2', GcPtr(S1)),
+                            ('z', Signed))
+    def ll_f(x):
+        ptr1 = malloc(S1)
+        ptr1.x = x
+        ptr2 = malloc(S1)
+        ptr2.x = x+1
+        s = malloc(S)
+        s.ptr1 = ptr1
+        s.ptr2 = ptr2
+        return s.ptr1.x * s.ptr2.x
+    t = Translator(ll_f)
+    a = t.annotate([int])
+    rtyper = RPythonTyper(t.annotator)
+    rtyper.specialize()
+    db = LowLevelDatabase(rtyper)
+    db.get(rtyper.getfunctionptr(ll_f))
+    db.complete()
+    dump_on_stdout(db)
+
+def test_nested_gcstruct():
+    S1 = GcStruct('inlined', ('x', Signed), ('y', GcPtr(PyObject)))
+    S = GcStruct('testing', ('head', S1),
+                            ('ptr2', GcPtr(S1)),
+                            ('z', Signed))
+    def ll_f(x):
+        ptr2 = malloc(S1)
+        ptr2.x = x+1
+        s = malloc(S)
+        s.head.x = x
+        s.ptr2 = ptr2
+        return s.head.x * s.ptr2.x
+    t = Translator(ll_f)
+    a = t.annotate([int])
+    rtyper = RPythonTyper(t.annotator)
+    rtyper.specialize()
+    db = LowLevelDatabase(rtyper)
+    db.get(rtyper.getfunctionptr(ll_f))
+    db.complete()
+    dump_on_stdout(db)
+
+def test_array():
+    A = GcArray(('obj', GcPtr(PyObject)))
+    a = malloc(A, 10)
+    db = LowLevelDatabase()
+    db.get(a)
+    db.complete()
+    dump_on_stdout(db)

Modified: pypy/branch/pycompiler/translator/genc/ctyper.py
==============================================================================
--- pypy/branch/pycompiler/translator/genc/ctyper.py	(original)
+++ pypy/branch/pycompiler/translator/genc/ctyper.py	Mon May 30 16:50:36 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/branch/pycompiler/translator/genc/lltype.py
==============================================================================
--- pypy/branch/pycompiler/translator/genc/lltype.py	(original)
+++ pypy/branch/pycompiler/translator/genc/lltype.py	Mon May 30 16:50:36 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/branch/pycompiler/translator/genc/test/test_lltyped.py
==============================================================================
--- pypy/branch/pycompiler/translator/genc/test/test_lltyped.py	(original)
+++ pypy/branch/pycompiler/translator/genc/test/test_lltyped.py	Mon May 30 16:50:36 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

Modified: pypy/branch/pycompiler/translator/goal/translate_pypy.py
==============================================================================
--- pypy/branch/pycompiler/translator/goal/translate_pypy.py	(original)
+++ pypy/branch/pycompiler/translator/goal/translate_pypy.py	Mon May 30 16:50:36 2005
@@ -56,6 +56,7 @@
         run_async_server()
     if not options['-no-a']:
         a = t.annotate(inputtypes, overrides=pypy_overrides)
+        sanity_check_exceptblocks(t)
         worstblocks_topten(a)
         if not options['-no-s']:
             a.simplify()
@@ -66,6 +67,25 @@
             options['-no-mark-some-objects'] = True # Do not do this again
             find_someobjects(t)
 
+def sanity_check_exceptblocks(translator):
+    annotator = translator.annotator
+    irreg = 0
+    for graph in translator.flowgraphs.itervalues():
+        et, ev = graph.exceptblock.inputargs
+        s_et = annotator.binding(et, extquery=True)
+        s_ev = annotator.binding(ev, extquery=True)
+        if s_et:
+            if s_et.knowntype == type:
+                if s_et.__class__ == SomeObject:
+                    if hasattr(s_et, 'is_type_of') and  s_et.is_type_of == [ev]:
+                        continue
+                else:
+                    if s_et.__class__ == annmodel.SomePBC:
+                        continue
+            print "*****", graph.name, "exceptblock is not completely sane"
+            irreg += 1
+    if irreg == 0:
+        print "*** All exceptblocks seem sane."
 
 def find_someobjects(translator, quiet=False):
     """Find all functions in that have SomeObject in their signature."""

Modified: pypy/branch/pycompiler/translator/llvm/build_llvm_module.py
==============================================================================
--- pypy/branch/pycompiler/translator/llvm/build_llvm_module.py	(original)
+++ pypy/branch/pycompiler/translator/llvm/build_llvm_module.py	Mon May 30 16:50:36 2005
@@ -14,7 +14,7 @@
 from pypy.translator.tool.buildpyxmodule import make_c_from_pyxfile
 from pypy.translator.tool import stdoutcapture
 
-debug = 1
+debug = False
 
 class CompileError(exceptions.Exception):
     pass
@@ -27,22 +27,31 @@
     lastdir = path.local()
     os.chdir(str(dirpath))
     modname = pyxfile.purebasename
-    ops1 = ["llvm-as %s -f -o %s.bc" % (llvmfile, llvmfile.purebasename), 
-            "opt %s -f %s.bc -o %s_optimized.bc" % (OPTIMIZATION_SWITCHES,
-                                                    llvmfile.purebasename,
-                                                    llvmfile.purebasename),
-            "llc -enable-correct-eh-support %s_optimized.bc -f -o %s.s" % \
-            (llvmfile.purebasename, llvmfile.purebasename),
-            "as %s.s -o %s.o" % (llvmfile.purebasename, llvmfile.purebasename)]
-    if not optimize:
-        ops1 = ["llvm-as %s -f" % llvmfile,
-                "llc -enable-correct-eh-support %s.bc -f -o %s.s" % \
-                (llvmfile.purebasename, llvmfile.purebasename),
-                "as %s.s -o %s.o" % (llvmfile.purebasename,
-                                     llvmfile.purebasename)]
-    ops2 = ["gcc -c -fPIC -I/usr/include/python2.3 %s.c" % pyxfile.purebasename,
-           "gcc -shared %s.o %s.o -o %s.so" % (llvmfile.purebasename,
-                                               modname, modname)]
+    b = llvmfile.purebasename
+
+    if sys.maxint == 2147483647:        #32 bit platform
+        if optimize:
+            ops1 = ["llvm-as %s.ll -f -o %s.bc" % (b, b), 
+                    "opt %s -f %s.bc -o %s_optimized.bc" % (OPTIMIZATION_SWITCHES, b, b),
+                    "llc -enable-correct-eh-support %s_optimized.bc -f -o %s.s" % (b, b),
+                    "as %s.s -o %s.o" % (b, b)]
+        else:
+            ops1 = ["llvm-as %s.ll -f -o %s.bc" % (b, b),
+                    "llc -enable-correct-eh-support %s.bc -f -o %s.s" % (b, b),
+                    "as %s.s -o %s.o" % (b, b)]
+        ops2 = ["gcc -c -shared -I/usr/include/python2.3 %s.c" % pyxfile.purebasename,
+                "gcc -shared %s.o %s.o -o %s.so" % (b, modname, modname)]
+    else:       #assume 64 bit platform (x86-64?)
+        #this special case for x86-64 (called ia64 in llvm) can go as soon as llc supports ia64 assembly output!
+        if optimize:
+            ops1 = ["llvm-as %s.ll -f -o %s.bc" % (b, b), 
+                    "opt %s -f %s.bc -o %s_optimized.bc" % (OPTIMIZATION_SWITCHES, b, b),
+                    "llc -enable-correct-eh-support %s_optimized.bc -march=c -f -o %s.c" % (b, b)]
+        else:
+            ops1 = ["llvm-as %s.ll -f -o %s.bc" % (b, b),
+                    "llc -enable-correct-eh-support %s.bc -march=c -f -o %s.c" % (b, b)]
+        ops2 = ["gcc -shared -fPIC -I/usr/include/python2.3 %s.c %s.c -o %s.so" % (b, modname, modname)]
+
     try:
         if debug: print "modname", modname
         c = stdoutcapture.Capture(mixed_out_err = True)
@@ -50,11 +59,11 @@
         try:
             try:
                 for op in ops1:
-                    print op
+                    if debug: print op
                     cmdexec(op)
                 make_c_from_pyxfile(pyxfile)
                 for op in ops2:
-                    print op
+                    if debug: print op
                     cmdexec(op)
             finally:
                 foutput, foutput = c.done()

Modified: pypy/branch/pycompiler/translator/llvm/classrepr.py
==============================================================================
--- pypy/branch/pycompiler/translator/llvm/classrepr.py	(original)
+++ pypy/branch/pycompiler/translator/llvm/classrepr.py	Mon May 30 16:50:36 2005
@@ -21,8 +21,8 @@
 from pypy.translator.llvm.funcrepr import VirtualMethodRepr
 from pypy.translator.llvm.memorylayout import MemoryLayout
 
-debug = True
-lazy_debug = True
+debug = False
+lazy_debug = False
 
 class ClassRepr(TypeRepr):
     l_classes = {}
@@ -122,7 +122,7 @@
 
     def get_globals(self):
         s = "\n%s = internal global %%std.class {%%std.class* null, uint %i}"
-        s = s % (self.objectname, abs(id(self)))
+        s = s % (self.objectname, abs(id(self)) & 0xFFFFFFF)
         return self.definition + s
 
     def collect_init_code(self, lblock, l_func):
@@ -247,7 +247,7 @@
         self.objectname = gen.get_global_tmp("class.%s.object" %
                                              self.exception.__name__)
         s = "%s = internal global %%std.class {%%std.class* null, uint %i}"
-        self.definition = s % (self.objectname, abs(id(exception)))
+        self.definition = s % (self.objectname, abs(id(exception)) & 0xFFFFFFF)
         self.dependencies = sets.Set()
 
     lazy_attributes = ['l_base', 'memlayout']

Modified: pypy/branch/pycompiler/translator/llvm/funcrepr.py
==============================================================================
--- pypy/branch/pycompiler/translator/llvm/funcrepr.py	(original)
+++ pypy/branch/pycompiler/translator/llvm/funcrepr.py	Mon May 30 16:50:36 2005
@@ -250,15 +250,22 @@
         l_op = getattr(l_arg0, "op_" + op.opname, None)
         if l_op is not None:
             l_op(l_target, op.args, self.lblock, self.l_func)
-        elif op.opname in INTRINSIC_OPS:
+            return
+        try:
+            l_arg0.op(op.opname, l_target, op.args, self.lblock, self.l_func)
+        except NotImplementedError:
+            pass
+        except CompileError:
+            pass
+        if op.opname in INTRINSIC_OPS:
             l_args = [self.gen.get_repr(arg) for arg in op.args[1:]]
             self.l_func.dependencies.update(l_args)
             self.lblock.spaceop(l_target, op.opname, [l_arg0] + l_args)
-        else:
-            s = "SpaceOperation %s not supported. Target: %s " \
-                "Args: %s " % (op.opname, l_target, op.args) + \
-                "Dispatched on: %s" % l_arg0
-            raise CompileError, s
+            return
+        s = "SpaceOperation %s not supported. Target: %s " \
+            "Args: %s " % (op.opname, l_target, op.args) + \
+            "Dispatched on: %s" % l_arg0
+        raise CompileError, s
 
     def create_terminator_instr(self):
         if debug:
@@ -342,7 +349,7 @@
         if len(l_exits) == 1 and self.pyblock.exits[1].exitcase == Exception:
             lexcblock.uncond_branch("%" + l_exits[0].toblock)
         else:
-            sw = [(str(abs(id(ex.exitcase))), "%" + l_l.toblock)
+            sw = [(str(abs(id(ex.exitcase)) & 0xFFFFFFF), "%" + l_l.toblock)
                   for ex, l_l in zip(self.pyblock.exits[1:], l_exits)]
             lexcblock.switch(l_ui, "%" + self.lblock.label + ".unwind", sw)
             lunwindblock = llvmbc.BasicBlock(self.lblock.label + ".unwind")
@@ -628,7 +635,7 @@
         entryblock.getelementptr(l_uip, l_cl, [0, 1])
         entryblock.load(l_ui, l_uip)
         entryblock.switch(l_ui, "%" + self.l_commonbase.classdef.cls.__name__,
-                          [(str(abs(id(l_c))), "%" + l_c.classdef.cls.__name__)
+                          [(str(abs(id(l_c)) & 0xFFFFFFF), "%" + l_c.classdef.cls.__name__)
                            for l_c in self.l_classes])
         lfunc = llvmbc.Function(self.llvmfuncdef(), entryblock)
         for i, l_cls in enumerate(self.l_classes):

Modified: pypy/branch/pycompiler/translator/llvm/genllvm.py
==============================================================================
--- pypy/branch/pycompiler/translator/llvm/genllvm.py	(original)
+++ pypy/branch/pycompiler/translator/llvm/genllvm.py	Mon May 30 16:50:36 2005
@@ -13,8 +13,11 @@
 import autopath
 import sets, StringIO
 
-from pypy.objspace.flow.model import Constant 
+from pypy.objspace.flow.model import Constant, Variable
 from pypy.annotation import model as annmodel
+
+from pypy.rpython import rtyper, lltype
+
 from pypy.translator import transform
 from pypy.translator.translator import Translator
 from pypy.translator.llvm import llvmbc
@@ -29,7 +32,9 @@
 from pypy.translator.llvm.representation import CompileError
 from pypy.translator.llvm.funcrepr import EntryFunctionRepr
 
-debug = False
+from pypy.translator.llvm import reprmap
+
+debug = True
 
 
 def llvmcompile(transl, optimize=False):
@@ -37,6 +42,9 @@
     return gen.compile(optimize)
 
 def get_key(obj):
+    if isinstance(obj, list):
+        return id(obj)
+    return obj
     #XXX Get rid of this:
     #LLVMGenerator should only cache gen_repr requestes,
     #the Repr classes should be responsible for deciding which queries
@@ -60,6 +68,8 @@
     def __init__(self, transl):
         self.translator = transl
         self.annotator = self.translator.annotator
+        self.rtyper = rtyper.RPythonTyper(self.annotator)
+        self.rtyper.specialize()
         self.global_counts = {}
         self.local_counts = {}
         self.repr_classes = []
@@ -75,8 +85,8 @@
         self.l_entrypoint = EntryFunctionRepr("%__entry__" + self.entryname,
                                               self.translator.functions[0],
                                               self)
-        classrepr.create_builtin_exceptions(self,
-                                            self.l_entrypoint.dependencies)
+##         classrepr.create_builtin_exceptions(
+##             self, self.l_entrypoint.get_dependencies())
         self.local_counts[self.l_entrypoint] = 0
         self.l_entrypoint.setup()
 
@@ -107,11 +117,12 @@
 
     def get_local_tmp(self, type, l_function):
         self.local_counts[l_function] += 1
-        return TmpVariableRepr("tmp_%i" % self.local_counts[l_function], type,
+        return TmpVariableRepr("tmp.%i" % self.local_counts[l_function], type,
                                self)
 
     def get_repr(self, obj):
         self.depth += 1
+        key = get_key(obj)
         if debug:
             print "  " * self.depth,
             print "looking for object", obj, type(obj).__name__,
@@ -119,24 +130,44 @@
         if isinstance(obj, LLVMRepr):
             self.depth -= 1
             return obj
-        if get_key(obj) in self.llvm_reprs:
+        if key in self.llvm_reprs:
             self.depth -= 1
             if debug:
-                print "->exists already:", self.llvm_reprs[get_key(obj)]
-            return self.llvm_reprs[get_key(obj)]
+                print "->exists already:", self.llvm_reprs[key]
+            return self.llvm_reprs[key]
+        elif isinstance(obj, Variable):
+            try:
+                obj.concretetype
+            except AttributeError:
+                self.rtyper.setconcretetype(obj)
+            result = representation.VariableRepr(obj, self)
+            self.llvm_reprs[result] = result
+            self.depth -= 1
+            return result
+        elif isinstance(obj, lltype.Primitive):
+            result = reprmap.PRIMITIVE_TYPES[obj](self)
+            self.llvm_reprs[key] = result
+            self.depth -= 1
+            return result
+        if isinstance(obj, Constant):
+            try:
+                T = lltype.typeOf(obj)
+                if isinstance(T, lltype.Primitive):
+                    result = reprmap.PRIMITIVE_REPRS[concretetype](obj, self)
+                    self.llvm_reprs[key] = result
+                    self.depth -= 1
+                    return result
+                #XXX find the right type if it is not a Primitive
+            except AttributeError:
+                pass
         for cl in self.repr_classes:
             try:
                 g = cl.get(obj, self)
             except AttributeError:
                 continue
             if g is not None:
-                self.llvm_reprs[get_key(obj)] = g
+                self.llvm_reprs[key] = g
                 self.local_counts[g] = 0
-##                 if not hasattr(g.__class__, "lazy_attributes"):
-##                     if debug:
-##                         print "  " * self.depth,
-##                         print "calling setup of %s, repr of %s" % (g, obj)
-##                     g.setup()
                 self.depth -= 1
                 return g
         raise CompileError, "Can't get repr of %s, %s" % (obj, obj.__class__)
@@ -182,7 +213,7 @@
     def unlazyify(self):
         if debug:
             print 
-            print "$$$$$$$$$$$$$$ unlazyify"
+            print "unlazyify"
         while len(self.lazy_objects):
             obj = self.lazy_objects.pop()
             if debug:
@@ -226,3 +257,11 @@
             remove_loops(l_dep, seen_repr.union(sets.Set([l_repr])))
     deps.difference_update(remove)
 
+## def f():
+##     l = [10,20,30]
+##     return l[2]
+
+## t = Translator(f)
+## a = t.annotate([])
+
+## flg = t.getflowgraph()

Modified: pypy/branch/pycompiler/translator/llvm/llvmbc.py
==============================================================================
--- pypy/branch/pycompiler/translator/llvm/llvmbc.py	(original)
+++ pypy/branch/pycompiler/translator/llvm/llvmbc.py	Mon May 30 16:50:36 2005
@@ -86,6 +86,14 @@
         self.phi_done = True
         self.instructions.append("unwind")
 
+    #Arithmetic instructions
+    def binary_instruction(self, instr, l_target, l_a, l_b):
+        self.phi_done = True
+        assert l_a.llvmtype() == l_b.llvmtype()
+        s = "%s = %s %s, %s" % (l_target.llvmname(), instr,
+                                   l_a.typed_name(), l_b.llvmname())
+        self.instructions.append(s)
+
     #Memory access instructions
     def load(self, l_target, l_pter):
         self.phi_done = True

Modified: pypy/branch/pycompiler/translator/llvm/pbcrepr.py
==============================================================================
--- pypy/branch/pycompiler/translator/llvm/pbcrepr.py	(original)
+++ pypy/branch/pycompiler/translator/llvm/pbcrepr.py	Mon May 30 16:50:36 2005
@@ -85,7 +85,7 @@
         self.memlayout = MemoryLayout(attribs, l_types, self.gen)
         self.definition = "%s = %s" % (self.name, self.memlayout.definition())
         s = "\n%s = internal global %%std.class {%%std.class* null, uint %i}"
-        self.definition += s % (self.objectname, abs(id(self)))
+        self.definition += s % (self.objectname, abs(id(self)) & 0xFFFFFFF)
 
     def llvmtype(self):
         return "%std.class*"

Modified: pypy/branch/pycompiler/translator/llvm/representation.py
==============================================================================
--- pypy/branch/pycompiler/translator/llvm/representation.py	(original)
+++ pypy/branch/pycompiler/translator/llvm/representation.py	Mon May 30 16:50:36 2005
@@ -21,15 +21,20 @@
 
 from pypy.objspace.flow.model import Variable, Constant
 from pypy.objspace.flow.model import last_exception
-# this is only used as a token for the pointer to the last exception object
-last_exc_value = object()
+
+from pypy.rpython import lltype
 
 from pypy.annotation import model as annmodel
 from pypy.translator.llvm.lazyattribute import MetaLazyRepr
+
 LLVM_SIMPLE_TYPES = {annmodel.SomeChar: "sbyte",
                      annmodel.SomeBool: "bool",
                      annmodel.SomeFloat: "double"}
 
+# this is only used as a token for the pointer to the last exception object
+last_exc_value = object()
+
+
 debug = False
 
 
@@ -65,6 +70,14 @@
     def llvmtype(self):
         return self.type.typename()
 
+    def llvmsize(self):
+        raise NotImplementedError, "This object has no size!"
+
+    def op(self, opname, l_target, args, lblock, l_func):
+        if hasattr(self, "type") and hasattr(self.type, "t_op"):
+            return self.type.t_op(opname, l_target, args, lblock, l_func)
+        raise CompileError, "op '%s' not supported" % opname
+
     def typed_name(self):
         return self.llvmtype() + " " + self.llvmname()
 
@@ -74,7 +87,68 @@
         except AttributeError:
             return sets.Set()
 
+class SignedRepr(LLVMRepr):
+    def __init__(self, value, gen):
+        if debug:
+            print "SignedRepr: %d" % value
+        self.value = value
+        self.gen = gen
+        self.type = self.gen.get_repr(lltype.Signed)
+
+    def llvmname(self):
+        return str(self.value)
+
+    def get_dependencies(self):
+        return [self.type]
+
+class UnsignedRepr(LLVMRepr):
+    def __init__(self, value, gen):
+        if debug:
+            print "UnsignedRepr: %d" % value
+        self.value = value
+        self.gen = gen
+        self.type = self.gen.get_repr(lltype.Unsigned)
 
+    def llvmname(self):
+        return str(self.value)
+
+    def get_dependencies(self):
+        return [self.type]
+
+class BoolRepr(LLVMRepr):
+    def __init__(self, value, gen):
+        if debug:
+            print "BoolRepr: %d" % value
+        self.value = bool(value)
+        self.gen = gen
+        self.type = self.gen.get_repr(lltype.Bool)
+
+    def llvmname(self):
+        return str(self.value).lower()
+        
+    def get_dependencies(self):
+        return [self.type]
+
+class CharRepr(LLVMRepr):
+    def __init__(self, value, gen):
+        if debug:
+            print "CharRepr: %d" % value
+        assert len(value) == 1
+        self.value = value
+        self.gen = gen
+        self.type = self.gen.get_repr(lltype.Char)
+
+    def llvmname(self):
+        value = value
+        if ' ' <= value < '\x7f':
+            return "'%s'" % (value.replace("'", r"\'"),)
+        else:
+            return '%d' % ord(value)
+        
+    def get_dependencies(self):
+        return [self.type]
+
+       
 class SimpleRepr(LLVMRepr):
     """Representation of values that only need simple representation:
 bool, char (string of length 1), last_exception, last_exc_value"""
@@ -163,14 +237,19 @@
         if debug:
             print "VariableRepr: %s" % (var.name)
         self.var = var
-        type_ = gen.annotator.binding(var)
+        try:
+            type_ = var.concretetype
+        except AttributeError:
+            type_ = gen.annotator.binding(var.c)
         self.type = gen.get_repr(type_)
+        print "XXXXXXXXXXXXXXXX", self.type
         self.dependencies = sets.Set([self.type])
 
     def llvmname(self):
         return "%" + self.var.name
 
     def __getattr__(self, name):
+        print "$%%%%%%%%%%%%%%%%%getattr called", name, self.type.typename()
         if name.startswith("op_"):
             return getattr(self.type, "t_" + name, None)
         elif name.startswith("cast_"):

Modified: pypy/branch/pycompiler/translator/llvm/test/test_class.py
==============================================================================
--- pypy/branch/pycompiler/translator/llvm/test/test_class.py	(original)
+++ pypy/branch/pycompiler/translator/llvm/test/test_class.py	Mon May 30 16:50:36 2005
@@ -14,6 +14,7 @@
 
 class TestClass(object):
     def setup_method(self, method):
+        py.test.skip("nothing works for now")
         if not llvm_found:
             py.test.skip("llvm-as not found on path.")
 
@@ -71,6 +72,6 @@
         assert f(True) == -36
         assert f(False) == 14
     
-    def test_circular_classdef(self):
+    def DONOTtest_circular_classdef(self):
         f = compile_function(llvmsnippet.circular_classdef, [])
         assert f() == 10

Modified: pypy/branch/pycompiler/translator/llvm/test/test_genllvm.py
==============================================================================
--- pypy/branch/pycompiler/translator/llvm/test/test_genllvm.py	(original)
+++ pypy/branch/pycompiler/translator/llvm/test/test_genllvm.py	Mon May 30 16:50:36 2005
@@ -62,7 +62,7 @@
         f = compile_function(llvmsnippet.simple2, [])
         assert f() == 0
 
-    def test_simple4(self):
+    def DONOTtest_simple4(self):
         f = compile_function(llvmsnippet.simple4, [])
         assert f() == 4
 
@@ -71,7 +71,7 @@
         assert f(1) == 12
         assert f(0) == 13
 
-    def test_ackermann(self):
+    def DONOTtest_ackermann(self):
         f = compile_function(llvmsnippet.ackermann, [int, int])
         for i in range(10):
             assert f(0, i) == i + 1
@@ -79,26 +79,27 @@
             assert f(2, i) == 2 * i + 3
             assert f(3, i) == 2 ** (i + 3) - 3
 
-    def test_calling(self):
+    def DONOTtest_calling(self):
         f = compile_function(llvmsnippet.calling1, [int])
         assert f(10) == 1
 
-    def test_call_default_arguments(self):
+    def DONOTtest_call_default_arguments(self):
         f = compile_function(llvmsnippet.call_default_arguments, [int, int])
         for i in range(3):
             assert f(i + 3, i) == llvmsnippet.call_default_arguments(i + 3, i)
 
-    def test_call_list_default_argument(self):
+    def DONOTtest_call_list_default_argument(self):
         f = compile_function(llvmsnippet.call_list_default_argument, [int])
         for i in range(20):
             assert f(i) == llvmsnippet.call_list_default_argument(i)
 
-    def test_return_none(self):
+    def DONOTtest_return_none(self):
         f = compile_function(llvmsnippet.return_none, [])
         assert f() is None
 
 class TestFloat(object):
     def setup_method(self, method):
+        py.test.skip("nothing works for now")
         if not llvm_found:
             py.test.skip("llvm-as not found on path.")
 
@@ -113,6 +114,7 @@
 
 class TestString(object):
     def setup_method(self, method):
+        py.test.skip("nothing works for now")
         if not llvm_found:
             py.test.skip("llvm-as not found on path.")
 
@@ -123,6 +125,7 @@
 
 class TestException(object):
     def setup_method(self,method):
+        py.test.skip("nothing works for now")
         if not llvm_found:
             py.test.skip("llvm-as not found on path")
 
@@ -159,6 +162,7 @@
         
 class TestPBC(object):
     def setup_method(self, method):
+        py.test.skip("nothing works for now")
         if not llvm_found:
             py.test.skip("llvm-as not found on path.")
 
@@ -169,7 +173,7 @@
         assert f(2) == 6
         assert f(3) == 8
 
-    def test_pbc_function2(self):
+    def DONOTtest_pbc_function2(self):
         f = compile_function(llvmsnippet.pbc_function2, [int])
         assert f(0) == 13
         assert f(1) == 15

Modified: pypy/branch/pycompiler/translator/llvm/test/test_seq.py
==============================================================================
--- pypy/branch/pycompiler/translator/llvm/test/test_seq.py	(original)
+++ pypy/branch/pycompiler/translator/llvm/test/test_seq.py	Mon May 30 16:50:36 2005
@@ -14,6 +14,7 @@
 
 class TestLLVMArray(object):
     def setup_method(self, method):
+        py.test.skip("nothing works for now")
         if not llvm_found:
             py.test.skip("llvm-as not found on path.")
 
@@ -107,6 +108,7 @@
 
 class TestTuple(object):
     def setup_method(self, method):
+        py.test.skip("nothing works for now")
         if not llvm_found:
             py.test.skip("llvm-as not found on path.")
 

Modified: pypy/branch/pycompiler/translator/llvm/test/test_snippet.py
==============================================================================
--- pypy/branch/pycompiler/translator/llvm/test/test_snippet.py	(original)
+++ pypy/branch/pycompiler/translator/llvm/test/test_snippet.py	Mon May 30 16:50:36 2005
@@ -14,6 +14,7 @@
 
 class TestSnippet(object):
     def setup_method(self, method):
+        py.test.skip("nothing works for now")
         if not llvm_found:
             py.test.skip("llvm-as not found on path.")
         

Modified: pypy/branch/pycompiler/translator/llvm/typerepr.py
==============================================================================
--- pypy/branch/pycompiler/translator/llvm/typerepr.py	(original)
+++ pypy/branch/pycompiler/translator/llvm/typerepr.py	Mon May 30 16:50:36 2005
@@ -16,6 +16,12 @@
 from pypy.translator.llvm.representation import LLVM_SIMPLE_TYPES
 
 
+import sys
+if 2147483647 == sys.maxint:
+    BYTES_IN_INT = 4
+else:
+    BYTES_IN_INT = 8
+
 
 class TypeRepr(LLVMRepr):
     def get(obj, gen):
@@ -56,10 +62,92 @@
         return self.name
 
     def llvmname(self):
-        raise CompileError, "This type is not an object."
+        raise NotImplementedError, "This type is not an object."
 
     def llvmtype(self):
-        raise CompileError, "This type is not an object."
+        raise NotImplementedError, \
+              "This type is not an object. %s" % self.__class__
+
+    def llvmsize(self):
+        raise NotImplementedError, "This type does not have a size."
+        
+
+class SignedTypeRepr(TypeRepr):
+    directly_supported_ops = {
+        "int_add": "add",
+        "int_sub": "sub",
+        "int_mul": "mul",
+        "int_div": "div",
+        "int_mod": "rem",
+        "int_xor": "xor",
+        "int_and_": "and",
+        "int_eq": "seteq",
+        "int_ne": "setne",
+        "int_gt": "setgt",
+        "int_ge": "setge",
+        "int_lt": "setlt",
+        "int_le": "setle"}
+        
+    def __init__(self, gen):
+        if debug:
+            print "SignedTypeRepr"
+        self.gen = gen
+
+    def t_op(self, opname, l_target, args, lblock, l_func):
+        if opname in SignedTypeRepr.directly_supported_ops:
+            assert len(args) == 2
+            l_args = [self.gen.get_repr(arg) for arg in args]
+            l_func.dependencies.update(l_args)
+            lblock.binary_instruction(
+                SignedTypeRepr.directly_supported_ops[opname], l_target,
+                l_args[0], l_args[1])
+
+    def t_op_int_is_true(self, l_target, args, lblock, l_func):
+        l_arg = self.gen.get_repr(args[0])
+        l_func.dependencies.add(l_arg)
+        lblock.cast(l_target, l_arg)
+
+    def typename(self):
+        return "int"
+
+    def llvmsize(self):
+        return BYTES_IN_INT
+
+class UnsignedTypeRepr(TypeRepr):
+    def __init__(self, gen):
+        if debug:
+            print "UnsignedTypeRepr"
+        self.gen = gen
+
+    def typename(self):
+        return "uint"
+
+    def llvmsize(self):
+        return BYTES_IN_INT
+
+class BoolTypeRepr(TypeRepr):
+    def __init__(self, gen):
+        if debug:
+            print "BoolTypeRepr"
+        self.gen = gen
+
+    def typename(self):
+        return "bool"
+
+    def llvmsize(self):
+        return 1
+
+class CharTypeRepr(TypeRepr):
+    def __init__(self, gen):
+        if debug:
+            print "CharTypeRepr"
+        self.gen = gen
+
+    def typename(self):
+        return "sbyte"
+
+    def llvmsize(self):
+        return 1
 
 
 class StringTypeRepr(TypeRepr):

Modified: pypy/branch/pycompiler/translator/test/test_annrpython.py
==============================================================================
--- pypy/branch/pycompiler/translator/test/test_annrpython.py	(original)
+++ pypy/branch/pycompiler/translator/test/test_annrpython.py	Mon May 30 16:50:36 2005
@@ -1037,7 +1037,15 @@
         finally:
             sys.argv = oldvalue
         assert s is not None
-            
+
+    def test_pow(self):
+        def f(n):
+            n **= 2
+            return 2 ** n
+        a = self.RPythonAnnotator()
+        s = a.build_types(f, [int])
+        # result should be an integer
+        assert s.knowntype == int
 
 
 def g(n):



More information about the Pypy-commit mailing list