[pypy-svn] r9242 - in pypy/dist/pypy/translator/llvm: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Wed Feb 16 00:11:39 CET 2005


Author: cfbolz
Date: Wed Feb 16 00:11:38 2005
New Revision: 9242

Added:
   pypy/dist/pypy/translator/llvm/list.c
   pypy/dist/pypy/translator/llvm/representation.py
Modified:
   pypy/dist/pypy/translator/llvm/genllvm.py
   pypy/dist/pypy/translator/llvm/list_template.ll
   pypy/dist/pypy/translator/llvm/llvmbc.py
   pypy/dist/pypy/translator/llvm/operations.ll
   pypy/dist/pypy/translator/llvm/test/llvmsnippet.py
   pypy/dist/pypy/translator/llvm/test/test_genllvm.py
Log:
Added rudimentary class support to genllvm (no class attributes, inheritance, ...) and improved lists.

Modified: pypy/dist/pypy/translator/llvm/genllvm.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/genllvm.py	(original)
+++ pypy/dist/pypy/translator/llvm/genllvm.py	Wed Feb 16 00:11:38 2005
@@ -17,41 +17,44 @@
 from pypy.translator.test import snippet as test
 
 
-INTRINSIC_OPS = ["lt", "le", "eq", "ne", "gt", "ge", "is", "is_true", "len",
-                 "neg", "pos", "invert", "add", "sub", "mul", "truediv",
-                 "floordiv", "div", "mod", "pow", "lshift", "rshift", "and",
-                 "or", "xor", "inplace_add", "inplace_sub", "inplace_mul",
-                 "inplace_truediv", "inplace_floordiv", "inplace_div",
-                 "inplace_mod", "inplace_pow", "inplace_lshift",
-                 "inplace_rshift", "inplace_and", "inplace_or", "inplace_xor",
-                 "getitem", "setitem", "delitem", "contains", "newlist",
-                 "alloc_and_set"]
-
-C_SIMPLE_TYPES = {annmodel.SomeChar: "char",
-                  annmodel.SomeBool: "unsigned char",
-                  annmodel.SomeInteger: "int"}
+from pypy.translator.llvm.representation import *
 
-debug = 0
+
+debug = 1
 
 
 def llvmcompile(transl, optimize=False):
     gen = LLVMGenerator(transl)
     return gen.compile(optimize)
 
-
-class CompileError(exceptions.Exception):
-    pass
+def get_key(obj):
+    if isinstance(obj, Constant):
+        #To avoid getting "bool true" as representation for int 1
+        if obj.value is True or obj.value is False:
+            return obj
+        return obj.value
+    if isinstance(obj, annmodel.SomeInstance):
+        return obj.classdef.cls
+    return obj
 
 class LLVMGenerator(object):
     def __init__(self, transl):
         self.translator = transl
         self.annotator = self.translator.annotator
-        self.global_count = 0
+##         transform.transform_allocate(self.annotator)
+        self.global_counts = {}
+        self.local_counts = {}
         self.repr_classes = [eval(s)
                              for s in dir(sys.modules.get(self.__module__))
                              if "Repr" in s]
         self.llvm_reprs = {}
-        self.l_entrypoint = self.get_repr(self.translator.functions[0])
+        self.depth = 0
+        try:
+            self.l_entrypoint = self.get_repr(
+                Constant(self.translator.functions[0]))
+        except:
+##             self.translator.view()
+            raise
 
     def compile(self, optimize=False):
         from pypy.tool.udir import udir
@@ -69,22 +72,42 @@
         return getattr(mod, "wrap_%s" % name)
 
     def get_global_tmp(self, used_by=None):
-        self.global_count += 1
-        return "%%glb.%s.%i" % ((used_by or "unknown"), self.global_count)
+        used_by = (used_by or "unknown")
+        if used_by in self.global_counts:
+            self.global_counts[used_by] += 1
+            return "%%glb.%s.%i" % (used_by, self.global_counts[used_by])
+        else:
+            self.global_counts[used_by] = 0
+            return "%%glb.%s" % used_by
+
+    def get_local_tmp(self, l_repr):
+        self.local_counts[l_repr] += 1
+        return "%%tmp_%i" % self.local_counts[l_repr]
 
     def get_repr(self, obj):
+        self.depth += 1
         if debug:
+            print "  " * self.depth,
             print "looking for object", obj, type(obj).__name__, obj.__class__,
-        if obj in self.llvm_reprs:
+            print id(obj), get_key(obj),
+        if isinstance(obj, LLVMRepr):
+            self.depth -= 1
+            return obj
+        if get_key(obj) in self.llvm_reprs:
+            self.depth -= 1
             if debug:
-                print "->exists already"
-            return self.llvm_reprs[obj]
+                print "->exists already:", self.llvm_reprs[get_key(obj)]
+            return self.llvm_reprs[get_key(obj)]
         for cl in self.repr_classes:
-            if debug:
-                print "trying", cl
             g = cl.get(obj, self)
             if g is not None:
-                self.llvm_reprs[obj] = g
+                self.llvm_reprs[get_key(obj)] = g
+                self.local_counts[g] = 0
+                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__)
 
@@ -121,404 +144,4 @@
         for l_dep1 in traverse_dependencies(l_dep, seen_reprs):
             yield l_dep1
     yield l_repr
-        
-class LLVMRepr(object):
-    def get(obj, gen):
-        return None
-    get = staticmethod(get)
-    
-    def get_globals(self):
-        return ""
-
-    def get_functions(self):
-        return ""
-
-    def llvmname(self):
-        return ""
-
-    def llvmtype(self):
-        return self.type.llvmname()
-
-    def typed_name(self):
-        return self.llvmtype() + " " + self.llvmname()
-
-    def get_dependencies(self):
-        try:
-            return self.dependencies
-        except exceptions.AttributeError:
-            return []
-
-class SimpleRepr(LLVMRepr):
-    """Representation of values that are directly mapped to types in LLVM:
-int, bool, char (string of length 1)"""
-
-    LLVM_SIMPLE_TYPES = {annmodel.SomeInteger: "int",
-                         annmodel.SomeChar: "sbyte",
-                         annmodel.SomeBool: "bool"}
-
-    def get(obj, gen):
-        if not isinstance(obj, Constant):
-            return None
-        type = gen.annotator.binding(obj)
-        if type.__class__ in SimpleRepr.LLVM_SIMPLE_TYPES:
-            llvmtype = SimpleRepr.LLVM_SIMPLE_TYPES[type.__class__]
-            l_repr = SimpleRepr(llvmtype, repr(obj.value), gen)
-            return l_repr
-        return None
-    get = staticmethod(get)
-    
-    def __init__(self, type, llvmname, gen):
-        if debug:
-            print "SimpleRepr: %s, %s" % (type, llvmname)
-        self.type = type
-        if llvmname in ("False", "True"):
-            llvmname = llvmname.lower()
-        self.name = llvmname
-        self.gen = gen
-
-    def llvmname(self):
-        return self.name
-
-    def llvmtype(self):
-        return self.type
-
-
-class VariableRepr(LLVMRepr):
-    def get(obj, gen):
-        if isinstance(obj, Variable):
-            return VariableRepr(obj, gen)
-        return None
-    get = staticmethod(get)
-
-    def __init__(self, var, gen):
-        if debug:
-            print "VariableRepr: %s" % (var.name)
-        self.var = var
-        type = gen.annotator.binding(var)
-        self.type = gen.get_repr(type)
-        self.dependencies = [self.type]
-
-    def llvmname(self):
-        return "%" + self.var.name
-        
-
-class StringRepr(LLVMRepr):
-    def get(obj, gen):
-        if isinstance(obj, Constant):
-            type = gen.annotator.binding(obj)
-            if type.__class__ is annmodel.SomeString:
-                l_repr = StringRepr(obj, gen)
-                return l_repr
-        return None
-    get = staticmethod(get)
-
-    def __init__(self, obj, gen):
-        if debug:
-            print "StringRepr: %s" % obj.value
-        self.s = obj.value
-        self.gen = gen
-        self.glvar1 = gen.get_global_tmp("StringRepr")
-        self.glvar2 = gen.get_global_tmp("StringRepr")
-        self.type = gen.get_repr(gen.annotator.binding(obj))
-        self.dependencies = [self.type]
-
-    def llvmname(self):
-        return self.glvar2
-
-    def get_globals(self):
-        d = {"len": len(self.s), "gv1": self.glvar1, "gv2": self.glvar2,
-             "type": self.type.llvmname_wo_pointer(), "string": self.s}
-        s = """%(gv1)s = internal constant [%(len)i x sbyte] c"%(string)s"
-%(gv2)s = internal constant %(type)s {uint %(len)i,\
-sbyte* getelementptr ([%(len)i x sbyte]* %(gv1)s, uint 0, uint 0)}"""
-        return s % d
-
-class TypeRepr(LLVMRepr):
-    l_stringtype = None
-    def get(obj, gen):
-##         print "TypeRepr", obj
-        if obj.__class__ is annmodel.SomeString or obj is str:
-            if TypeRepr.l_stringtype is None:
-                l_repr = TypeRepr("%std.string",
-                                  "%std.string = type {uint, sbyte*}",
-                                  "string.ll", gen)
-                TypeRepr.l_stringtype = l_repr
-            return TypeRepr.l_stringtype
-    get = staticmethod(get)
-
-    def __init__(self, llvmname, definition, includefile, gen):
-        if debug:
-            print "TypeRepr: %s, %s" % (llvmname, definition)
-        self.name = llvmname
-        self.definition = definition
-        self.gen = gen
-        self.includefile = includefile
-
-    def get_globals(self):
-        try:
-            return self.definition
-        except exceptions.AttributeError:
-            return ""
-
-    def get_functions(self):
-        if self.includefile != "":
-            f = file(autopath.this_dir + "/" + self.includefile, "r")
-            s = f.read()
-            f.close()
-            return s
-        return ""
-
-    def llvmname(self):
-        return self.name + "*"
-
-    def llvmname_wo_pointer(self):
-        return self.name
-
-class ListTypeRepr(TypeRepr):
-    l_listtypes = {}
-    def get(obj, gen):
-        if obj.__class__ is annmodel.SomeList:
-            if obj.s_item.__class__ in ListTypeRepr.l_listtypes:
-                return ListTypeRepr.l_listtypes[obj.s_item.__class__]
-            l_repr = ListTypeRepr(obj, gen)
-            ListTypeRepr.l_listtypes[obj.s_item.__class__] = l_repr
-            return l_repr
-        return None
-    get = staticmethod(get)
-
-    def __init__(self, obj, gen):
-        if debug:
-            print "ListTypeRepr: %s, %s" % (obj, obj.s_item)
-        self.gen = gen
-        self.l_itemtype = gen.get_repr(obj.s_item)
-        self.dependencies = [self.l_itemtype]
-        itemtype = self.l_itemtype.llvmname()
-        self.name = "%%std.list.%s" % itemtype.strip("%")
-        self.definition = self.name + " = type {uint, %s*}" % itemtype
-
-    def get_functions(self):
-        f = file(autopath.this_dir + "/list_template.ll", "r")
-        s = f.read()
-        f.close()
-        s = s.replace("%(item)s", self.l_itemtype.llvmname().strip("%"))
-        #XXX assuming every type consists of 4 bytes
-        s = s.replace("%(sizeof)i", str(4))
-        return s
-
-class SimpleTypeRepr(TypeRepr):
-    def get(obj, gen):
-        if obj.__class__ in [annmodel.SomeInteger, int]:
-            l_repr = SimpleTypeRepr("int", gen)
-            return l_repr            
-        elif obj.__class__ in [annmodel.SomeBool, bool]:
-            l_repr = SimpleTypeRepr("bool", gen)
-            return l_repr            
-        return None
-    get = staticmethod(get)
-
-    def __init__(self, llvmname, gen):
-        if debug:
-            print "SimpleTypeRepr: %s" % llvmname
-        self.name = llvmname
-        self.gen = gen
-        self.definition = ""
-        self.includefile = ""
-
-    def llvmname(self):
-        return self.name
-
-class ImpossibleValueRepr(TypeRepr):
-    def get(obj, gen):
-        if obj.__class__ is annmodel.SomeImpossibleValue:
-            return ImpossibleValueRepr()
-        return None
-    get = staticmethod(get)
-    
-    def __init__(self):
-        self.definition = ""
-        self.dependencies = []
-        self.includefile = ""
-
-    def llvmname(self):
-        return "void"
-
-    def typed_name(self):
-        return self.llvmtype() + " " + self.llvmname()
-
-class BuiltinFunctionRepr(LLVMRepr):
-    def get(obj, gen):
-        if isinstance(obj, Constant) and \
-           type(obj.value).__name__ == 'builtin_function_or_method':
-            l_repr = BuiltinFunctionRepr(obj.value, gen)
-            return l_repr
-        return None
-    get = staticmethod(get)
-
-    def __init__(self, bi, gen):
-        self.name = "%std." + bi.__name__
-        self.gen = gen
-
-    def llvmname(self):
-        return self.name
-
-class FunctionRepr(LLVMRepr):
-    def get(obj, gen):
-        if isinstance(obj, Constant) and \
-               type(obj.value).__name__ == 'function':
-            name = obj.value.__name__
-            l_repr = FunctionRepr(name, obj.value, gen)
-            return l_repr
-        elif type(obj).__name__ == 'function':
-            name = obj.__name__
-            l_repr = FunctionRepr(name, obj, gen)
-            return l_repr
-        return None
-    get = staticmethod(get)
-
-    def __init__(self, name, function, gen):
-        if debug:
-            print "FunctionRepr: %s" % name
-        self.gen = gen
-        self.func = function
-        self.translator = gen.translator
-        self.translator.simplify()
-        self.name = "%" + name
-        self.graph = self.translator.getflowgraph(self.func)
-        self.annotator = gen.translator.annotator
-        transform.transform_allocate(self.annotator)
-        self.blocknum = {}
-        self.allblocks = []
-        self.pyrex_source = ""
-        self.dependencies = sets.Set()
-        self.get_bbs()
-        self.build_bbs()
-
-    def get_bbs(self):
-        def visit(node):
-            if isinstance(node, Block) and node not in self.blocknum:
-                self.allblocks.append(node)
-                self.blocknum[node] = len(self.blocknum)
-        traverse(visit, self.graph)
-        self.same_origin_block = [False] * len(self.allblocks)
-
-    def build_bbs(self):
-        a = self.annotator
-        for number, pyblock in enumerate(self.allblocks):
-            lblock = llvmbc.BasicBlock("block%i" % number)
-            pyblock = self.allblocks[number]
-            if number == 0:
-                self.llvm_func = llvmbc.Function(self.llvmfuncdef(), lblock)
-            else:
-                self.llvm_func.basic_block(lblock)
-            #Create Phi nodes (but not for the first node)
-            incoming_links = []
-            def visit(node):
-                if isinstance(node, Link) and node.target == pyblock:
-                    incoming_links.append(node)
-            traverse(visit, self.graph)
-            #special case if the incoming links are from the same block
-            if len(incoming_links) == 2 and \
-               incoming_links[0].prevblock == incoming_links[1].prevblock:
-                for i, arg in enumerate(pyblock.inputargs):
-                    l_select = self.gen.get_repr(
-                        incoming_links[0].prevblock.exitswitch)
-                    l_arg = self.gen.get_repr(arg)
-                    l_v1 = self.gen.get_repr(incoming_links[1].args[i])
-                    l_v2 = self.gen.get_repr(incoming_links[0].args[i])
-                    self.dependencies.update([l_arg, l_switch, l_v1, l_v2])
-                    lblock.select(l_arg, l_select, l_v1, l_v2)
-            elif len(incoming_links) != 0:
-                for i, arg in enumerate(pyblock.inputargs):
-                    l_arg = self.gen.get_repr(arg)
-                    l_values = [self.gen.get_repr(l.args[i])
-                                for l in incoming_links]
-                    self.dependencies.add(l_arg)
-                    self.dependencies.update(l_values)
-                    lblock.phi(l_arg, l_values,
-                               ["%%block%i" % self.blocknum[l.prevblock]
-                                for l in incoming_links])
-            #Create a function call for every operation in the block
-            for op in pyblock.operations:
-                if op.opname == "simple_call" and \
-                       isinstance(op.args[0], Constant) and \
-                       op.args[0].value == self.func:
-                    l_args = [self] + \
-                             [self.gen.get_repr(arg) for arg in op.args[1:]]
-                else:
-                    l_args = [self.gen.get_repr(arg) for arg in op.args]
-                l_target = self.gen.get_repr(op.result)
-                self.dependencies.update(l_args)
-                self.dependencies.add(l_target)
-                if op.opname in INTRINSIC_OPS:
-                    lblock.spaceop(l_target, op.opname, l_args)
-                elif op.opname == "simple_call":
-                    lblock.call(l_target, l_args[0], l_args[1:])
-                else:
-                    self.translator.view()
-                    raise CompileError, "Unhandeled SpaceOp %s" % op.opname
-            #Create branches
-            if pyblock.exitswitch is None:
-                if pyblock.exits == ():
-                    l_returnvalue = self.gen.get_repr(pyblock.inputargs[0])
-                    self.dependencies.add(l_returnvalue)
-                    lblock.ret(l_returnvalue)
-                else:
-                    lblock.uncond_branch(
-                        "%%block%i" % self.blocknum[pyblock.exits[0].target])
-            else:
-                assert isinstance(a.binding(pyblock.exitswitch),
-                                  annmodel.SomeBool)
-                l_switch = self.gen.get_repr(pyblock.exitswitch)
-                self.dependencies.add(l_switch)
-                lblock.cond_branch(
-                    l_switch,
-                    "%%block%i" % self.blocknum[pyblock.exits[1].target],
-                    "%%block%i" % self.blocknum[pyblock.exits[0].target])
-
-    def cfuncdef(self):
-        a = self.translator.annotator
-        retv = self.graph.returnblock.inputargs[0]
-        rettype_c = C_SIMPLE_TYPES[a.binding(retv).__class__]
-        args = self.graph.startblock.inputargs
-        argtypes_c = [C_SIMPLE_TYPES[a.binding(v).__class__] for v in args]
-        fd = "%s %s(%s)" % (rettype_c, self.func.func_name,
-                            ", ".join(argtypes_c))
-        return fd
-
-    def llvmfuncdef(self):
-        a = self.translator.annotator
-        l_retv = self.gen.get_repr(self.graph.returnblock.inputargs[0])
-        l_args = [self.gen.get_repr(ar)
-                  for ar in self.graph.startblock.inputargs]
-        self.dependencies.update(l_args)
-        self.dependencies.add(l_retv)
-        s = "%s %s(" % (l_retv.llvmtype(), self.name)
-        return s + ", ".join([a.typed_name() for a in l_args]) + ")"
-        return llvmbc.function(l_retv, self.name, l_args)
-
-    def get_pyrex_source(self):
-        name = self.func.func_name
-        args = self.graph.startblock.inputargs
-        self.pyrex_source = ["cdef extern %s\n" %
-                             (self.cfuncdef())]
-        self.pyrex_source += ["def wrap_%s(" % name]
-        t = []
-        for i, a in enumerate(args):
-            t += ["%s" % a]
-        t = ", ".join(t)
-        self.pyrex_source += t + "):\n\treturn %s(%s)\n\n" % (name, t)
-        self.pyrex_source += "\ndef test(a):\n\treturn a + 1\n\n"
-        self.pyrex_source = "".join(self.pyrex_source)
-        return self.pyrex_source
-
-
-    def get_functions(self):
-        return str(self.llvm_func)
-
-    def llvmname(self):
-        return self.name
-
-    def llvmtype(self):
-        assert self.llvmfuncdef().count(self.name) == 1
-        return self.llvmfuncdef().replace(self.name + "(", "(")
 

Added: pypy/dist/pypy/translator/llvm/list.c
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/llvm/list.c	Wed Feb 16 00:11:38 2005
@@ -0,0 +1,92 @@
+#include <stdio.h>
+
+struct item {
+    char* dummy;
+};
+
+struct list {
+    unsigned int length;
+    struct item** data;
+};
+
+
+void copy(struct item** from, struct item** to, unsigned int length) {
+    unsigned int i = 0;
+    while(i < length) {
+	to[i] = from[i];
+	i += 1;
+    }
+}
+
+struct list* newlist(struct item* value) {
+    struct list* nlist = malloc(sizeof(struct list));
+    nlist->length = 1;
+    nlist->data = malloc(sizeof(struct item*));
+    nlist->data[0] = value;
+    return nlist;
+}
+
+struct list* alloc_and_set(unsigned int length, struct item* init) {
+    unsigned int i = 0;
+    struct list* nlist = malloc(sizeof(struct list));
+    nlist->length = length;
+    nlist->data = malloc(sizeof(struct item*) * length);
+    while (i < length) {
+	nlist->data[i] = init;
+	i += 1;
+    }
+    return nlist;
+}
+
+struct item* getitem(struct list* l, int index) {
+    if (index < 0)
+	index = l->length + index;
+    return l->data[index];
+}
+
+void setitem(struct list* l, int index, struct item* value) {
+    if (index < 0)
+	index = l->length + index;
+    l->data[index] = value;
+}
+
+struct list* add(struct list* a, struct list* b) {
+    struct list* nlist = malloc(sizeof(struct list));
+    unsigned int newlength = a->length + b->length;
+    nlist->length = newlength;
+    nlist->data = malloc(sizeof(struct item*) * newlength);
+    copy(a->data, nlist->data, a->length);
+    copy(b->data, nlist->data + a->length, newlength - a->length);
+    return nlist;
+}
+
+struct list* mul(struct list* a, int times) {
+    struct list* nlist = malloc(sizeof(struct list));
+    unsigned int newlength = a->length * times;
+    int i = 0;
+    nlist->length = newlength;
+    nlist->data = malloc(sizeof(struct item*) * newlength);
+    while (i < times) {
+	copy(a->data, nlist->data + i * a->length, a->length);
+	i += 1;
+    }
+    return nlist;
+}
+
+void inplace_add(struct list* a, struct list* b) {
+    struct item** newdata = malloc(sizeof(struct item*) * (a->length + b->length));
+    copy(a->data, newdata, a->length);
+    copy(b->data, newdata + a->length, b->length);
+    a->length +=  b->length;
+    free(a->data);
+    a->data = newdata;
+}
+
+struct list* append(struct list* a, struct item* value) {
+    struct item** newdata = malloc(sizeof(struct item*) * (a->length + 1));
+    copy(a->data, newdata, a->length);
+    a->length += 1;
+    free(a->data);
+    a->data = newdata;
+    return a;
+}

Modified: pypy/dist/pypy/translator/llvm/list_template.ll
==============================================================================
--- pypy/dist/pypy/translator/llvm/list_template.ll	(original)
+++ pypy/dist/pypy/translator/llvm/list_template.ll	Wed Feb 16 00:11:38 2005
@@ -1,57 +1,284 @@
-;Template for lists
+internal void %copy(%(item)s* %from, %(item)s* %to, uint %length) {
+entry:
+	%tmp.25 = seteq uint %length, 0
+	br bool %tmp.25, label %return, label %no_exit
 
-internal uint %std.len(%std.list.%(item)s* %a) {
-	%p = getelementptr %std.list.%(item)s* %a, int 0, uint 0
-	%length1 = load uint* %p
-	ret uint %length1
-}
-
-internal int %std.len(%std.list.%(item)s* %a) {
-	%length1 = call uint %std.len(%std.list.%(item)s* %a)
-	%length = cast uint %length1 to int
-	ret int %length
+no_exit:
+	%i.0.0 = phi uint [ %tmp.14, %no_exit ], [ 0, %entry ]
+	%tmp.7 = getelementptr %(item)s* %to, uint %i.0.0
+	%tmp.11 = getelementptr %(item)s* %from, uint %i.0.0
+	%tmp.12 = load %(item)s* %tmp.11
+	store %(item)s %tmp.12, %(item)s* %tmp.7
+	%tmp.14 = add uint %i.0.0, 1
+	%tmp.2 = setlt uint %tmp.14, %length
+	br bool %tmp.2, label %no_exit, label %return
+
+return:
+	ret void
+}
+
+internal %std.list.%(name)s* %std.newlist(%(item)s %value) {
+entry:
+	%tmp.0 = malloc %std.list.%(name)s
+	%tmp.3 = getelementptr %std.list.%(name)s* %tmp.0, int 0, uint 0
+	store uint 1, uint* %tmp.3
+	%tmp.5 = getelementptr %std.list.%(name)s* %tmp.0, int 0, uint 1
+	%tmp.6 = malloc %(item)s
+	store %(item)s* %tmp.6, %(item)s** %tmp.5
+	store %(item)s %value, %(item)s* %tmp.6
+	ret %std.list.%(name)s* %tmp.0
+}
+
+internal %std.list.%(name)s* %std.alloc_and_set(uint %length, %(item)s %init) {
+entry:
+	%tmp.0 = malloc %std.list.%(name)s
+	%tmp.3 = getelementptr %std.list.%(name)s* %tmp.0, int 0, uint 0
+	store uint %length, uint* %tmp.3
+	%tmp.6 = getelementptr %std.list.%(name)s* %tmp.0, int 0, uint 1
+	%tmp.7 = malloc %(item)s, uint %length
+	store %(item)s* %tmp.7, %(item)s** %tmp.6
+	%tmp.134 = seteq uint %length, 0
+	br bool %tmp.134, label %loopexit, label %no_exit
+
+no_exit:
+	%i.0.0 = phi uint [ %tmp.23, %no_exit ], [ 0, %entry ]
+	%tmp.17 = load %(item)s** %tmp.6
+	%tmp.20 = getelementptr %(item)s* %tmp.17, uint %i.0.0
+	store %(item)s %init, %(item)s* %tmp.20
+	%tmp.23 = add uint %i.0.0, 1
+	%tmp.13 = setlt uint %tmp.23, %length
+	br bool %tmp.13, label %no_exit, label %loopexit
+
+loopexit:
+	ret %std.list.%(name)s* %tmp.0
+}
+
+internal %std.list.%(name)s* %std.alloc_and_set(int %length, %(item)s %init) {
+entry:
+	%ul = cast int %length to uint
+	%r = call %std.list.%(name)s* %std.alloc_and_set(uint %ul, %(item)s %init)
+	ret %std.list.%(name)s* %r
 }
 
+internal %(item)s %std.getitem(%std.list.%(name)s* %l, int %index.1) {
+entry:
+	%tmp.1 = setlt int %index.1, 0
+	%tmp.11 = getelementptr %std.list.%(name)s* %l, int 0, uint 1
+	br bool %tmp.1, label %then, label %endif
 
-internal %std.list.%(item)s* %std.make(uint %len, %(item)s* %s) {
-	%ret = malloc %std.list.%(item)s, uint 1
-	%lenp = getelementptr %std.list.%(item)s* %ret, int 0, uint 0
-	%lsp = getelementptr %std.list.%(item)s* %ret, int 0, uint 1
-	store uint %len, uint* %lenp
-	store %(item)s* %s, %(item)s** %lsp
-	ret %std.list.%(item)s* %ret
+then:
+	%tmp.4 = getelementptr %std.list.%(name)s* %l, int 0, uint 0
+	%tmp.5 = load uint* %tmp.4
+	%tmp.5 = cast uint %tmp.5 to int
+	%tmp.9 = add int %tmp.5, %index.1
+	%tmp.121 = load %(item)s** %tmp.11
+	%tmp.142 = getelementptr %(item)s* %tmp.121, int %tmp.9
+	%tmp.153 = load %(item)s* %tmp.142
+	ret %(item)s %tmp.153
+
+endif:
+	%tmp.12 = load %(item)s** %tmp.11
+	%tmp.14 = getelementptr %(item)s* %tmp.12, int %index.1
+	%tmp.15 = load %(item)s* %tmp.14
+	ret %(item)s %tmp.15
 }
 
+internal void %std.setitem(%std.list.%(name)s* %l, int %index.1, %(item)s %value) {
+entry:
+	%tmp.1 = setlt int %index.1, 0
+	%tmp.11 = getelementptr %std.list.%(name)s* %l, int 0, uint 1
+	br bool %tmp.1, label %then, label %endif
+
+then:
+	%tmp.4 = getelementptr %std.list.%(name)s* %l, int 0, uint 0
+	%tmp.5 = load uint* %tmp.4
+	%tmp.5 = cast uint %tmp.5 to int
+	%tmp.9 = add int %tmp.5, %index.1
+	%tmp.121 = load %(item)s** %tmp.11
+	%tmp.142 = getelementptr %(item)s* %tmp.121, int %tmp.9
+	store %(item)s %value, %(item)s* %tmp.142
+	ret void
 
-internal %std.list.%(item)s* %std.newlist(%(item)s %init) {
-	%nmem = malloc %(item)s, uint 1
-	%ret = call %std.list.%(item)s* %std.make(uint 1, %(item)s* %nmem)
-	call void %std.setitem(%std.list.%(item)s* %ret, int 0, %(item)s %init)
-	ret %std.list.%(item)s* %ret
-}	
-
-internal %(item)s %std.getitem(%std.list.%(item)s* %s, int %p) {
-	%sp1 = getelementptr %std.list.%(item)s* %s, int 0, uint 1
-	%s1 = load %(item)s** %sp1
-	%len = call uint %std.len(%std.list.%(item)s* %s)
-	%ilen = cast uint %len to int
-	%negpos = add int %ilen, %p
-	%is_negative = setlt int %p, 0
-	%usedpos = select bool %is_negative, int %negpos, int %p
-	%p_item = getelementptr %(item)s* %s1, int %usedpos
-	%value = load %(item)s* %p_item
-	ret %(item)s %value
-}
-
-internal void %std.setitem(%std.list.%(item)s* %s, int %p, %(item)s %n) {
-	%sp1 = getelementptr %std.list.%(item)s* %s, int 0, uint 1
-	%s1 = load %(item)s** %sp1
-	%len = call uint %std.len(%std.list.%(item)s* %s)
-	%ilen = cast uint %len to int
-	%negpos = add int %ilen, %p
-	%is_negative = setlt int %p, 0
-	%usedpos = select bool %is_negative, int %negpos, int %p
-	%itemp = getelementptr %(item)s* %s1, int %usedpos
-	store %(item)s %n, %(item)s* %itemp
+endif:
+	%tmp.12 = load %(item)s** %tmp.11
+	%tmp.14 = getelementptr %(item)s* %tmp.12, int %index.1
+	store %(item)s %value, %(item)s* %tmp.14
 	ret void
 }
+
+internal %std.list.%(name)s* %std.add(%std.list.%(name)s* %a, %std.list.%(name)s* %b) {
+entry:
+	%tmp.0 = malloc %std.list.%(name)s
+	%tmp.3 = getelementptr %std.list.%(name)s* %a, int 0, uint 0
+	%tmp.4 = load uint* %tmp.3
+	%tmp.6 = getelementptr %std.list.%(name)s* %b, int 0, uint 0
+	%tmp.7 = load uint* %tmp.6
+	%tmp.8 = add uint %tmp.7, %tmp.4
+	%tmp.10 = getelementptr %std.list.%(name)s* %tmp.0, int 0, uint 0
+	store uint %tmp.8, uint* %tmp.10
+	%tmp.13 = getelementptr %std.list.%(name)s* %tmp.0, int 0, uint 1
+	%tmp.14 = malloc %(item)s, uint %tmp.8
+	store %(item)s* %tmp.14, %(item)s** %tmp.13
+	%tmp.19 = getelementptr %std.list.%(name)s* %a, int 0, uint 1
+	%tmp.20 = load %(item)s** %tmp.19
+	%tmp.2.i14 = seteq uint %tmp.4, 0
+	br bool %tmp.2.i14, label %copy.entry, label %no_exit.i
+
+no_exit.i:
+	%i.0.i.0 = phi uint [ %tmp.14.i, %no_exit.i ], [ 0, %entry ]
+	%tmp.7.i = getelementptr %(item)s* %tmp.14, uint %i.0.i.0
+	%tmp.11.i = getelementptr %(item)s* %tmp.20, uint %i.0.i.0
+	%tmp.12.i = load %(item)s* %tmp.11.i
+	store %(item)s %tmp.12.i, %(item)s* %tmp.7.i
+	%tmp.14.i = add uint %i.0.i.0, 1
+	%tmp.2.i = setlt uint %tmp.14.i, %tmp.4
+	br bool %tmp.2.i, label %no_exit.i, label %copy.entry
+
+copy.entry:
+	%tmp.28 = getelementptr %std.list.%(name)s* %b, int 0, uint 1
+	%tmp.29 = load %(item)s** %tmp.28
+	%tmp.42 = sub uint %tmp.8, %tmp.4
+	%tmp.2.i319 = seteq uint %tmp.8, %tmp.4
+	br bool %tmp.2.i319, label %copy.entry9, label %no_exit.i4
+
+no_exit.i4:
+	%i.0.i2.0 = phi uint [ %tmp.14.i8, %no_exit.i4 ], [ 0, %copy.entry ]
+	%tmp.37.sum = add uint %i.0.i2.0, %tmp.4
+	%tmp.7.i5 = getelementptr %(item)s* %tmp.14, uint %tmp.37.sum
+	%tmp.11.i6 = getelementptr %(item)s* %tmp.29, uint %i.0.i2.0
+	%tmp.12.i7 = load %(item)s* %tmp.11.i6
+	store %(item)s %tmp.12.i7, %(item)s* %tmp.7.i5
+	%tmp.14.i8 = add uint %i.0.i2.0, 1
+	%tmp.2.i3 = setlt uint %tmp.14.i8, %tmp.42
+	br bool %tmp.2.i3, label %no_exit.i4, label %copy.entry9
+
+copy.entry9:
+	ret %std.list.%(name)s* %tmp.0
+}
+
+
+
+internal %std.list.%(name)s* %std.mul(%std.list.%(name)s* %a, int %times) {
+entry:
+	%tmp.0 = malloc %std.list.%(name)s
+	%tmp.3 = getelementptr %std.list.%(name)s* %a, int 0, uint 0
+	%tmp.4 = load uint* %tmp.3
+	%tmp.6 = cast int %times to uint
+	%tmp.7 = mul uint %tmp.4, %tmp.6
+	%tmp.9 = getelementptr %std.list.%(name)s* %tmp.0, int 0, uint 0
+	store uint %tmp.7, uint* %tmp.9
+	%tmp.12 = getelementptr %std.list.%(name)s* %tmp.0, int 0, uint 1
+	%tmp.13 = malloc %(item)s, uint %tmp.7
+	store %(item)s* %tmp.13, %(item)s** %tmp.12
+	%tmp.194 = setgt int %times, 0
+	br bool %tmp.194, label %no_exit.preheader, label %loopexit
+
+no_exit.preheader:
+	%tmp.22 = getelementptr %std.list.%(name)s* %a, int 0, uint 1
+	br label %no_exit
+
+no_exit:
+	%indvar = phi uint [ 0, %no_exit.preheader ], [ %indvar.next10, %copy.entry ]
+	%i.0.0 = cast uint %indvar to int
+	%tmp.23 = load %(item)s** %tmp.22
+	%tmp.26 = load %(item)s** %tmp.12
+	%tmp.29 = load uint* %tmp.3	
+	%tmp.32 = mul uint %indvar, %tmp.29
+	%tmp.2.i9 = seteq uint %tmp.29, 0
+	br bool %tmp.2.i9, label %copy.entry, label %no_exit.i
+
+no_exit.i:
+	%i.0.i.2 = phi uint [ %tmp.14.i, %no_exit.i ], [ 0, %no_exit ]
+	%tmp.34.sum = add uint %i.0.i.2, %tmp.32
+	%tmp.7.i = getelementptr %(item)s* %tmp.26, uint %tmp.34.sum
+	%tmp.11.i = getelementptr %(item)s* %tmp.23, uint %i.0.i.2	
+	%tmp.12.i = load %(item)s* %tmp.11.i
+	store %(item)s %tmp.12.i, %(item)s* %tmp.7.i
+	%tmp.14.i = add uint %i.0.i.2, 1
+	%tmp.2.i = setlt uint %tmp.14.i, %tmp.29
+	br bool %tmp.2.i, label %no_exit.i, label %copy.entry
+
+copy.entry:
+	%tmp.39 = add int %i.0.0, 1
+	%tmp.19 = setlt int %tmp.39, %times
+	%indvar.next10 = add uint %indvar, 1
+	br bool %tmp.19, label %no_exit, label %loopexit
+
+loopexit:
+	ret %std.list.%(name)s* %tmp.0
+}
+
+internal void %std.inplace_add(%std.list.%(name)s* %a, %std.list.%(name)s* %b) {
+entry:
+	%tmp.2 = getelementptr %std.list.%(name)s* %a, int 0, uint 0
+	%tmp.3 = load uint* %tmp.2
+	%tmp.5 = getelementptr %std.list.%(name)s* %b, int 0, uint 0
+	%tmp.6 = load uint* %tmp.5
+	%tmp.7 = add uint %tmp.6, %tmp.3
+	%tmp.0 = malloc %(item)s, uint %tmp.7
+	%tmp.11 = getelementptr %std.list.%(name)s* %a, int 0, uint 1
+	%tmp.12 = load %(item)s** %tmp.11
+	%tmp.2.i14 = seteq uint %tmp.3, 0
+	br bool %tmp.2.i14, label %copy.entry, label %no_exit.i
+
+no_exit.i:
+	%i.0.i.0 = phi uint [ %tmp.14.i, %no_exit.i ], [ 0, %entry ]
+	%tmp.7.i = getelementptr %(item)s* %tmp.0, uint %i.0.i.0
+	%tmp.11.i = getelementptr %(item)s* %tmp.12, uint %i.0.i.0
+	%tmp.12.i = load %(item)s* %tmp.11.i
+	store %(item)s %tmp.12.i, %(item)s* %tmp.7.i
+	%tmp.14.i = add uint %i.0.i.0, 1
+	%tmp.2.i = setlt uint %tmp.14.i, %tmp.3
+	br bool %tmp.2.i, label %no_exit.i, label %copy.entry
+
+copy.entry:
+	%tmp.18 = getelementptr %std.list.%(name)s* %b, int 0, uint 1
+	%tmp.19 = load %(item)s** %tmp.18
+	%tmp.2.i319 = seteq uint %tmp.6, 0
+	br bool %tmp.2.i319, label %copy.entry9, label %no_exit.i4
+
+no_exit.i4:
+	%i.0.i2.0 = phi uint [ %tmp.14.i8, %no_exit.i4 ], [ 0, %copy.entry ]	
+	%tmp.25.sum = add uint %i.0.i2.0, %tmp.3
+	%tmp.7.i5 = getelementptr %(item)s* %tmp.0, uint %tmp.25.sum
+	%tmp.11.i6 = getelementptr %(item)s* %tmp.19, uint %i.0.i2.0
+	%tmp.12.i7 = load %(item)s* %tmp.11.i6
+	store %(item)s %tmp.12.i7, %(item)s* %tmp.7.i5
+	%tmp.14.i8 = add uint %i.0.i2.0, 1
+	%tmp.2.i3 = setlt uint %tmp.14.i8, %tmp.6
+	br bool %tmp.2.i3, label %no_exit.i4, label %copy.entry9
+
+copy.entry9:
+	store uint %tmp.7, uint* %tmp.2
+	free %(item)s* %tmp.12
+	store %(item)s* %tmp.0, %(item)s** %tmp.11
+	ret void
+}
+
+internal %std.list.%(name)s* %std.append(%std.list.%(name)s* %a, %(item)s %value) {
+entry:
+	%tmp.2 = getelementptr %std.list.%(name)s* %a, int 0, uint 0
+	%tmp.3 = load uint* %tmp.2
+	%tmp.3-off = add uint %tmp.3, 1
+	%tmp.0 = malloc %(item)s, uint %tmp.3-off
+	%tmp.8 = getelementptr %std.list.%(name)s* %a, int 0, uint 1
+	%tmp.9 = load %(item)s** %tmp.8
+	%tmp.2.i5 = seteq uint %tmp.3, 0
+	br bool %tmp.2.i5, label %copy.entry, label %no_exit.i
+
+no_exit.i:
+	%i.0.i.0 = phi uint [ %tmp.14.i, %no_exit.i ], [ 0, %entry ]
+	%tmp.7.i = getelementptr %(item)s* %tmp.0, uint %i.0.i.0
+	%tmp.11.i = getelementptr %(item)s* %tmp.9, uint %i.0.i.0
+	%tmp.12.i = load %(item)s* %tmp.11.i
+	store %(item)s %tmp.12.i, %(item)s* %tmp.7.i
+	%tmp.14.i = add uint %i.0.i.0, 1
+	%tmp.2.i = setlt uint %tmp.14.i, %tmp.3
+	br bool %tmp.2.i, label %no_exit.i, label %copy.entry
+
+copy.entry:
+	store uint %tmp.3-off, uint* %tmp.2
+	free %(item)s* %tmp.9
+	store %(item)s* %tmp.0, %(item)s** %tmp.8
+	ret %std.list.%(name)s* %a
+}

Modified: pypy/dist/pypy/translator/llvm/llvmbc.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/llvmbc.py	(original)
+++ pypy/dist/pypy/translator/llvm/llvmbc.py	Wed Feb 16 00:11:38 2005
@@ -41,6 +41,8 @@
     def phi(self, l_arg, l_values, blocks):
         assert len(l_values) == len(blocks)
         vars_string = []
+        print "inserting phi node", l_arg, l_values, blocks
+        print l_arg.llvmname(), l_arg.llvmtype()
         fd = "" + "%s = phi %s " % (l_arg.llvmname(), l_arg.llvmtype())
         fd += ", ".join(["[%s, %s]" % (v.llvmname(), b)
                for v, b in zip(l_values, blocks)])
@@ -56,11 +58,20 @@
             ", ".join([a.typed_name() for a in l_args]) + ")")
         
     def call(self, l_target, l_func, l_args):
-        s = "%s = call %s %s(" % (l_target.llvmname(), l_target.llvmtype(),
+        if l_target.llvmtype() == "void":
+            s = "call void %%std.%s(" % opname
+        elif  l_target.llvmtype() == "%std.void":
+            s = "call %std.void %%std.%s(" % opname
+        s = "%s = call %s %s(" % (l_target.llvmname(), l_func.rettype(),
                                   l_func.llvmname())
         self.instructions.append(s + 
             ", ".join([a.typed_name() for a in l_args]) + ")")
 
+    def call_void(self, l_func, l_args):
+        s = "call %s %s(" % (l_func.rettype(), l_func.llvmname())
+        self.instructions.append(s +
+            ", ".join([a.typed_name() for a in l_args]) + ")")
+
     def ret(self, l_value):
         self.instructions.append("ret %s" % l_value.typed_name())
 
@@ -72,6 +83,34 @@
                                            blocktrue, blockfalse)
         self.instructions.append(s)
 
+    def malloc(self, l_target, l_type, num=1):
+        s = "%s = malloc %s" % (l_target.llvmname(),
+                                l_type.llvmname_wo_pointer())
+        if num > 1:
+            s += ", uint %i" % num
+        self.instructions.append(s)
+
+    def getelementptr(self, target, l_ptr, adresses):
+        s = "%s = getelementptr %s %s, " % (target, l_ptr.llvmtype(),
+                                            l_ptr.llvmname())
+        adr = []
+        for a in adresses:
+            if a >= 0:
+                adr.append("uint %i" % a)
+            else:
+                adr.append("int %i" % a)
+        self.instructions.append(s + ", ".join(adr))
+
+    def load(self, l_target, pter):
+        s = "%s = load %s* %s" % (l_target.llvmname(), l_target.llvmtype(),
+                                  pter)
+        self.instructions.append(s)
+
+    def store(self, l_value, pter):
+        s = "store %s %s, %s* %s" % (l_value.llvmtype(), l_value.llvmname(),
+                                     l_value.llvmtype(), pter)
+        self.instructions.append(s)
+
 
     def __str__(self):
         s = [self.label + ":\n"]

Modified: pypy/dist/pypy/translator/llvm/operations.ll
==============================================================================
--- pypy/dist/pypy/translator/llvm/operations.ll	(original)
+++ pypy/dist/pypy/translator/llvm/operations.ll	Wed Feb 16 00:11:38 2005
@@ -1,4 +1,6 @@
 ;implementation of space operations for simple types
+
+
 implementation
 
 declare void %llvm.memmove(sbyte*, sbyte*, uint, uint)
@@ -6,6 +8,8 @@
 declare void %llvm.memset(sbyte*, ubyte, uint, uint)
 
 
+
+
 ;Basic operations for ints
 internal int %std.add(int %a, int %b) {
 	%r = add int %a, %b
@@ -112,7 +116,7 @@
 }
 
 ;Logical operations for ints
-internal int %std.and(int %a, int %b) {
+internal int %std.and_(int %a, int %b) {
 	%r = and int %a, %b
 	ret int %r
 }

Added: pypy/dist/pypy/translator/llvm/representation.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/llvm/representation.py	Wed Feb 16 00:11:38 2005
@@ -0,0 +1,621 @@
+import autopath
+import exceptions, sets, StringIO
+
+from types import FunctionType
+
+from pypy.objspace.flow.model import Variable, Constant, SpaceOperation
+from pypy.objspace.flow.model import FunctionGraph, Block, Link
+from pypy.objspace.flow.model import last_exception, last_exc_value
+from pypy.objspace.flow.model import traverse, uniqueitems, checkgraph
+from pypy.annotation import model as annmodel
+from pypy.annotation.classdef import ClassDef
+from pypy.translator import transform
+from pypy.translator.llvm import llvmbc
+
+
+INTRINSIC_OPS = ["lt", "le", "eq", "ne", "gt", "ge", "is", "is_true", "len",
+                 "neg", "pos", "invert", "add", "sub", "mul", "truediv",
+                 "floordiv", "div", "mod", "pow", "lshift", "rshift", "and_",
+                 "or", "xor", "inplace_add", "inplace_sub", "inplace_mul",
+                 "inplace_truediv", "inplace_floordiv", "inplace_div",
+                 "inplace_mod", "inplace_pow", "inplace_lshift",
+                 "inplace_rshift", "inplace_and", "inplace_or", "inplace_xor",
+                 "contains", "newlist", "alloc_and_set"]
+
+C_SIMPLE_TYPES = {annmodel.SomeChar: "char",
+                  annmodel.SomeBool: "unsigned char",
+                  annmodel.SomeInteger: "int"}
+
+
+debug = 1
+
+
+class CompileError(exceptions.Exception):
+    pass
+
+
+class LLVMRepr(object):
+    def get(obj, gen):
+        return None
+    get = staticmethod(get)
+
+    def __init__(self, obj, gen):
+        pass
+
+    def setup(self):
+        pass
+    
+    def get_globals(self):
+        return ""
+
+    def get_functions(self):
+        return ""
+
+    def llvmname(self):
+        return ""
+
+    def llvmtype(self):
+        return self.type.llvmname()
+
+    def typed_name(self):
+        return self.llvmtype() + " " + self.llvmname()
+
+    def get_dependencies(self):
+        try:
+            return self.dependencies
+        except exceptions.AttributeError:
+            return []
+
+
+class SimpleRepr(LLVMRepr):
+    """Representation of values that are directly mapped to types in LLVM:
+int, bool, char (string of length 1)"""
+
+    LLVM_SIMPLE_TYPES = {annmodel.SomeInteger: "int",
+                         annmodel.SomeChar: "sbyte",
+                         annmodel.SomeBool: "bool"}
+    def get(obj, gen):
+        if not isinstance(obj, Constant):
+            return None
+        type = gen.annotator.binding(obj)
+        if type.__class__ in SimpleRepr.LLVM_SIMPLE_TYPES:
+            llvmtype = SimpleRepr.LLVM_SIMPLE_TYPES[type.__class__]
+            l_repr = SimpleRepr(llvmtype, repr(obj.value), gen)
+            return l_repr
+        return None
+    get = staticmethod(get)
+    
+    def __init__(self, type, llvmname, gen):
+        if debug:
+            print "SimpleRepr: %s, %s" % (type, llvmname)
+        self.type = type
+        if llvmname in ("False", "True"):
+            llvmname = llvmname.lower()
+        self.name = llvmname
+        self.gen = gen
+        self.dependencies = sets.Set()
+
+    def llvmname(self):
+        return self.name
+
+    def llvmtype(self):
+        return self.type
+
+    def __getattr__(self, name):
+        return getattr(self.type, name, None)
+
+
+class VariableRepr(LLVMRepr):
+    def get(obj, gen):
+        if isinstance(obj, Variable):
+            return VariableRepr(obj, gen)
+        return None
+    get = staticmethod(get)
+
+    def __init__(self, var, gen):
+        if debug:
+            print "VariableRepr: %s" % (var.name)
+        self.var = var
+        type = gen.annotator.binding(var)
+        self.type = gen.get_repr(type)
+        self.dependencies = sets.Set([self.type])
+
+    def llvmname(self):
+        return "%" + self.var.name
+
+    def __getattr__(self, name):
+        if name.startswith("op_"):
+            return getattr(self.type, "t_" + name, None)
+        else:
+            raise AttributeError, ("VariableRepr instance has no attribute %s"
+                                   % repr(name))
+
+class StringRepr(LLVMRepr):
+    def get(obj, gen):
+        if isinstance(obj, Constant):
+            type = gen.annotator.binding(obj)
+            if type.__class__ is annmodel.SomeString:
+                l_repr = StringRepr(obj, gen)
+                return l_repr
+        return None
+    get = staticmethod(get)
+
+    def __init__(self, obj, gen):
+        if debug:
+            print "StringRepr: %s" % obj.value
+        self.s = obj.value
+        self.gen = gen
+        self.glvar1 = gen.get_global_tmp("StringRepr")
+        self.glvar2 = gen.get_global_tmp("StringRepr")
+        self.type = gen.get_repr(gen.annotator.binding(obj))
+        self.dependencies = sets.Set([self.type])
+
+    def llvmname(self):
+        return self.glvar2
+
+    def get_globals(self):
+        d = {"len": len(self.s), "gv1": self.glvar1, "gv2": self.glvar2,
+             "type": self.type.llvmname_wo_pointer(), "string": self.s}
+        s = """%(gv1)s = internal constant [%(len)i x sbyte] c"%(string)s"
+%(gv2)s = internal constant %(type)s {uint %(len)i,\
+sbyte* getelementptr ([%(len)i x sbyte]* %(gv1)s, uint 0, uint 0)}"""
+        return s % d
+
+class TypeRepr(LLVMRepr):
+    l_stringtype = None
+    def get(obj, gen):
+##         print "TypeRepr", obj
+        if obj.__class__ is annmodel.SomeString or obj is str:
+            if TypeRepr.l_stringtype is None:
+                l_repr = TypeRepr("%std.string",
+                                  "%std.string = type {uint, sbyte*}",
+                                  "string.ll", gen)
+                TypeRepr.l_stringtype = l_repr
+            return TypeRepr.l_stringtype
+        if (isinstance(obj, annmodel.SomePBC) and \
+               obj.prebuiltinstances.keys()[0] is None) or obj is type(None):
+            return TypeRepr("%std.void", "%std.void = type sbyte", "", gen)
+    get = staticmethod(get)
+
+    def __init__(self, llvmname, definition, includefile, gen):
+        if debug:
+            print "TypeRepr: %s, %s" % (llvmname, definition)
+        self.name = llvmname
+        self.definition = definition
+        self.gen = gen
+        self.includefile = includefile
+
+    def get_globals(self):
+        try:
+            return self.definition
+        except exceptions.AttributeError:
+            return ""
+
+    def get_functions(self):
+        try:
+            if self.includefile != "":
+                f = file(autopath.this_dir + "/" + self.includefile, "r")
+                s = f.read()
+                f.close()
+                return s
+        except exceptions.AttributeError:
+            pass
+        return ""
+
+    def llvmname(self):
+        return self.name + "*"
+
+    def llvmname_wo_pointer(self):
+        return self.name
+
+class ListTypeRepr(TypeRepr):
+    l_listtypes = {}
+    def get(obj, gen):
+        if obj.__class__ is annmodel.SomeList:
+            if (obj.s_item.__class__, gen) in ListTypeRepr.l_listtypes:
+                return ListTypeRepr.l_listtypes[(obj.s_item.__class__, gen)]
+            l_repr = ListTypeRepr(obj, gen)
+            ListTypeRepr.l_listtypes[(obj.s_item.__class__, gen)] = l_repr
+            return l_repr
+        return None
+    get = staticmethod(get)
+
+    def __init__(self, obj, gen):
+        if debug:
+            print "ListTypeRepr: %s, %s" % (obj, obj.s_item)
+        self.gen = gen
+        self.l_itemtype = gen.get_repr(obj.s_item)
+        self.dependencies = sets.Set([self.l_itemtype])
+        itemtype = self.l_itemtype.llvmname()
+        self.name = "%%std.list.%s" % itemtype.strip("%").replace("*", "")
+        self.definition = self.name + " = type {uint, %s*}" % itemtype
+
+    def get_functions(self):
+        f = file(autopath.this_dir + "/list_template.ll", "r")
+        s = f.read()
+        f.close()
+        itemtype = self.l_itemtype.llvmname()
+        s = s.replace("%(item)s", self.l_itemtype.llvmname())
+        s = s.replace("%(name)s", itemtype.strip("%").replace("*", ""))
+        return s
+
+    def t_op_getitem(self, l_target, args, lblock, l_func):
+        l_args = [self.gen.get_repr(arg) for arg in args]
+        l_func.dependencies.update(l_args)
+        lblock.spaceop(l_target, "getitem", l_args)
+
+    def t_op_setitem(self, l_target, args, lblock, l_func):
+        l_args = [self.gen.get_repr(arg) for arg in args]
+        l_func.dependencies.update(l_args)
+        lblock.spaceop(l_target, "setitem", l_args)
+
+    def t_op_delitem(self, l_target, args, lblock, l_func):
+        l_args = [self.gen.get_repr(arg) for arg in args]
+        l_func.dependencies.update(l_args)
+        lblock.spaceop(l_target, "delitem", l_args)
+    
+
+class SimpleTypeRepr(TypeRepr):
+    def get(obj, gen):
+        if obj.__class__ in [annmodel.SomeInteger, int]:
+            l_repr = SimpleTypeRepr("int", gen)
+            return l_repr            
+        elif obj.__class__ in [annmodel.SomeBool, bool]:
+            l_repr = SimpleTypeRepr("bool", gen)
+            return l_repr            
+        return None
+    get = staticmethod(get)
+
+    def __init__(self, llvmname, gen):
+        if debug:
+            print "SimpleTypeRepr: %s" % llvmname
+        self.name = llvmname
+        self.gen = gen
+        self.definition = ""
+        self.includefile = ""
+
+    def llvmname(self):
+        return self.name
+
+class ImpossibleValueRepr(TypeRepr):
+    def get(obj, gen):
+        if obj.__class__ is annmodel.SomeImpossibleValue:
+            return ImpossibleValueRepr()
+        return None
+    get = staticmethod(get)
+    
+    def __init__(self):
+        self.definition = ""
+        self.dependencies = sets.Set()
+        self.includefile = ""
+
+    def llvmname(self):
+        return "void"
+
+class NoneRepr(TypeRepr):
+    def get(obj, gen):
+        if isinstance(obj, Constant) and obj.value is None:
+            return NoneRepr(gen)
+    get = staticmethod(get)
+
+    def __init__(self, gen):
+        self.gen = gen
+        self.type = gen.get_repr(type(None))
+        self.dependencies = sets.Set([self.type])
+        if debug:
+            print "NoneRepr, llvmname: %s, llvmtype: %s" % (self.llvmname(),
+                                                            self.llvmtype())
+
+    def llvmname(self):
+        return "null"
+
+
+class ClassRepr(TypeRepr):
+    def get(obj, gen):
+        if obj.__class__ is Constant:
+            bind = gen.annotator.binding(obj)
+            if bind.__class__ is annmodel.SomePBC and \
+               bind.const.__class__ == type:
+                classdef = gen.annotator.bookkeeper.userclasses[bind.const]
+                return ClassRepr(classdef, gen)
+        if isinstance(obj, annmodel.SomeInstance):
+            return ClassRepr(obj.classdef, gen)
+        return None
+    get = staticmethod(get)
+
+    def __init__(self, obj, gen):
+        if 1:
+            print "ClassRepr: %s", obj
+        self.classdef = obj
+        self.gen = gen
+        self.includefile = ""
+        self.name = gen.get_global_tmp("class.%s" % self.classdef.cls.__name__)
+        self.dependencies = sets.Set()
+        self.attr_num = {}
+        self.se = False
+
+    def setup(self):
+        self.se = True
+        print "ClassRepr.setup()", id(self)
+        gen = self.gen
+        attribs = []
+        meth = []
+        print "attributes"
+        for key, attr in self.classdef.attrs.iteritems():
+            print key, attr, attr.sources, attr.s_value,
+            if len(attr.sources) != 0:
+                func = self.classdef.cls.__dict__[attr.name]
+                meth.append((key, func))
+                print "--> method"
+                continue
+            if isinstance(attr.s_value, annmodel.SomePBC) and \
+               attr.s_value.knowntype is FunctionType:
+                func = self.classdef.cls.__dict__[attr.name]
+                meth.append((key, func))
+                print "--> method"
+                continue
+            attribs.append(attr)
+            print "--> value"
+        self.l_attrs_types = [gen.get_repr(attr.s_value) for attr in attribs]
+        self.dependencies = sets.Set(self.l_attrs_types)
+        attributes = ", ".join([at.llvmname() for at in self.l_attrs_types])
+        self.definition = "%s = type {int*, %s}" % (self.name, attributes)
+        self.attr_num = {}
+        for i, attr in enumerate(attribs):
+            self.attr_num[attr.name] = i + 1
+        self.methods = dict(meth)
+        print "setup: ", self, self.attr_num, self.methods
+
+    def op_simple_call(self, l_target, args, lblock, l_func):
+        l_init = self.gen.get_repr(self.methods["__init__"])
+        l_func.dependencies.add(l_init)
+        l_args = [self.gen.get_repr(arg) for arg in args[1:]]
+        self.dependencies.update(l_args)
+        lblock.malloc(l_target, self)
+        lblock.call_void(l_init, [l_target] + l_args)
+
+    def t_op_getattr(self, l_target, args, lblock, l_func):
+        print "t_op_getattrs", l_target, args
+        if not isinstance(args[1], Constant):
+            raise CompileError,"getattr called with non-constant: %s" % args[1]
+        if args[1].value in self.attr_num:
+            l_args0 = self.gen.get_repr(args[0])
+            l_func.dependencies.add(l_args0)
+            pter = self.gen.get_local_tmp(l_func)
+            lblock.getelementptr(pter, l_args0,
+                                 [0, self.attr_num[args[1].value]])
+            lblock.load(l_target, pter)
+        elif args[1].value in self.methods:
+            print "method", 
+            l_args0 = self.gen.get_repr(args[0])
+            print l_args0, l_args0.typed_name()
+            l_func.dependencies.add(l_args0)
+            l_method = BoundMethodRepr(self.methods[args[1].value],
+                                       l_args0, self, self.gen)
+            l_target.type = l_method
+
+    def t_op_setattr(self, l_target, args, lblock, l_func):
+        if not isinstance(args[1], Constant):
+            raise CompileError,"setattr called with non-constant: %s" % args[1]
+        if args[1].value in self.attr_num:
+            l_args0 = self.gen.get_repr(args[0])
+            l_value = self.gen.get_repr(args[2])
+            self.dependencies.update([l_args0, l_value])
+            pter = self.gen.get_local_tmp(l_func)
+            lblock.getelementptr(pter, l_args0,
+                                 [0, self.attr_num[args[1].value]])
+            lblock.store(l_value, pter)
+
+
+class BuiltinFunctionRepr(LLVMRepr):
+    def get(obj, gen):
+        if isinstance(obj, Constant) and \
+           type(obj.value).__name__ == 'builtin_function_or_method':
+            l_repr = BuiltinFunctionRepr(obj.value, gen)
+            return l_repr
+        return None
+    get = staticmethod(get)
+
+    def __init__(self, bi, gen):
+        self.name = "%std." + bi.__name__
+        self.gen = gen
+
+    def llvmname(self):
+        return self.name
+
+class FunctionRepr(LLVMRepr):
+    def get(obj, gen):
+        if isinstance(obj, Constant) and \
+               type(obj.value).__name__ == 'function':
+            name = obj.value.__name__
+            l_repr = FunctionRepr(name, obj.value, gen)
+            return l_repr
+        elif isinstance(obj, annmodel.SomePBC):
+            obj = obj.prebuiltinstances.keys()[0]
+        if type(obj).__name__ == 'function':
+            name = obj.__name__
+            l_repr = FunctionRepr(name, obj, gen)
+            return l_repr
+        return None
+    get = staticmethod(get)
+
+    def __init__(self, name, function, gen):
+        if debug:
+            print "FunctionRepr: %s" % name
+        self.gen = gen
+        self.func = function
+        self.translator = gen.translator
+        self.name = "%" + name
+        self.graph = self.translator.getflowgraph(self.func)
+        self.annotator = gen.translator.annotator
+        self.blocknum = {}
+        self.allblocks = []
+        self.pyrex_source = ""
+        self.dependencies = sets.Set()
+        self.get_bbs()
+
+    def setup(self):
+        self.retvalue = self.gen.get_repr(self.graph.returnblock.inputargs[0])
+        self.dependencies.add(self.retvalue)
+        self.build_bbs()
+
+    def get_returntype():
+        return self.rettype.llvmname()
+
+    def get_bbs(self):
+        def visit(node):
+            if isinstance(node, Block) and node not in self.blocknum:
+                self.allblocks.append(node)
+                self.blocknum[node] = len(self.blocknum)
+        traverse(visit, self.graph)
+        self.same_origin_block = [False] * len(self.allblocks)
+
+    def build_bbs(self):
+        a = self.annotator
+        for number, pyblock in enumerate(self.allblocks):
+            lblock = llvmbc.BasicBlock("block%i" % number)
+            pyblock = self.allblocks[number]
+            if number == 0:
+                self.llvm_func = llvmbc.Function(self.llvmfuncdef(), lblock)
+            else:
+                self.llvm_func.basic_block(lblock)
+            #Create Phi nodes (but not for the first node)
+            incoming_links = []
+            def visit(node):
+                if isinstance(node, Link) and node.target == pyblock:
+                    incoming_links.append(node)
+            traverse(visit, self.graph)
+            #special case if the incoming links are from the same block
+            if len(incoming_links) == 2 and \
+               incoming_links[0].prevblock == incoming_links[1].prevblock:
+                for i, arg in enumerate(pyblock.inputargs):
+                    l_select = self.gen.get_repr(
+                        incoming_links[0].prevblock.exitswitch)
+                    l_arg = self.gen.get_repr(arg)
+                    l_v1 = self.gen.get_repr(incoming_links[1].args[i])
+                    l_v2 = self.gen.get_repr(incoming_links[0].args[i])
+                    self.dependencies.update([l_arg, l_switch, l_v1, l_v2])
+                    lblock.select(l_arg, l_select, l_v1, l_v2)
+            elif len(incoming_links) != 0:
+                for i, arg in enumerate(pyblock.inputargs):
+                    l_arg = self.gen.get_repr(arg)
+                    l_values = [self.gen.get_repr(l.args[i])
+                                for l in incoming_links]
+                    self.dependencies.add(l_arg)
+                    self.dependencies.update(l_values)
+                    lblock.phi(l_arg, l_values,
+                               ["%%block%i" % self.blocknum[l.prevblock]
+                                for l in incoming_links])
+            #Create a function call for every operation in the block
+            for op in pyblock.operations:
+                l_target = self.gen.get_repr(op.result)
+                self.dependencies.add(l_target)
+                if op.opname in INTRINSIC_OPS:
+                    l_args = [self.gen.get_repr(arg) for arg in op.args]
+                    self.dependencies.update(l_args)
+                    lblock.spaceop(l_target, op.opname, l_args)
+                else:
+                    l_arg0 = self.gen.get_repr(op.args[0])
+                    self.dependencies.add(l_arg0)
+                    l_op = getattr(l_arg0, "op_" + op.opname, None)
+                    if l_op is None:
+                        s = "SpaceOperation %s not supported. Target: %s " \
+                            "Args: %s" % (op.opname, l_target, op.args)
+                        raise CompileError, s
+                    l_op(l_target, op.args, lblock, self)
+            #Create branches
+            if pyblock.exitswitch is None:
+                if pyblock.exits == ():
+                    l_returnvalue = self.gen.get_repr(pyblock.inputargs[0])
+                    self.dependencies.add(l_returnvalue)
+                    lblock.ret(l_returnvalue)
+                else:
+                    lblock.uncond_branch(
+                        "%%block%i" % self.blocknum[pyblock.exits[0].target])
+            else:
+                assert isinstance(a.binding(pyblock.exitswitch),
+                                  annmodel.SomeBool)
+                l_switch = self.gen.get_repr(pyblock.exitswitch)
+                self.dependencies.add(l_switch)
+                lblock.cond_branch(
+                    l_switch,
+                    "%%block%i" % self.blocknum[pyblock.exits[1].target],
+                    "%%block%i" % self.blocknum[pyblock.exits[0].target])
+
+    def cfuncdef(self):
+        a = self.translator.annotator
+        retv = self.graph.returnblock.inputargs[0]
+        rettype_c = C_SIMPLE_TYPES[a.binding(retv).__class__]
+        args = self.graph.startblock.inputargs
+        argtypes_c = [C_SIMPLE_TYPES[a.binding(v).__class__] for v in args]
+        fd = "%s %s(%s)" % (rettype_c, self.func.func_name,
+                            ", ".join(argtypes_c))
+        return fd
+
+    def llvmfuncdef(self):
+        a = self.translator.annotator
+        l_args = [self.gen.get_repr(ar)
+                  for ar in self.graph.startblock.inputargs]
+        self.dependencies.update(l_args)
+        s = "%s %s(" % (self.retvalue.llvmtype(), self.name)
+        return s + ", ".join([a.typed_name() for a in l_args]) + ")"
+
+    def get_pyrex_source(self):
+        name = self.func.func_name
+        args = self.graph.startblock.inputargs
+        self.pyrex_source = ["cdef extern %s\n" %
+                             (self.cfuncdef())]
+        self.pyrex_source += ["def wrap_%s(" % name]
+        t = []
+        for i, a in enumerate(args):
+            t += ["%s" % a]
+        t = ", ".join(t)
+        self.pyrex_source += t + "):\n\treturn %s(%s)\n\n" % (name, t)
+        self.pyrex_source += "\ndef test(a):\n\treturn a + 1\n\n"
+        self.pyrex_source = "".join(self.pyrex_source)
+        return self.pyrex_source
+
+    def rettype(self):
+        return self.retvalue.llvmtype()
+
+    def get_functions(self):
+        return str(self.llvm_func)
+
+    def llvmname(self):
+        return self.name
+
+    def llvmtype(self):
+        assert self.llvmfuncdef().count(self.name) == 1
+        return self.llvmfuncdef().replace(self.name + "(", "(") + "*"
+
+    def op_simple_call(self, l_target, args, lblock, l_func):
+        l_args = [self.gen.get_repr(arg) for arg in args]
+        self.dependencies.update(l_args)
+        lblock.call(l_target, l_args[0], l_args[1:])
+
+class BoundMethodRepr(LLVMRepr):
+    def get(obj, gen):
+        return None
+    get = staticmethod(get)
+
+    def __init__(self, func, l_self, l_class, gen):
+        self.gen = gen
+        self.func = func
+        self.l_self = l_self
+        self.l_class = l_class
+        self.dependencies = sets.Set([l_self, l_class])
+        self.se = False
+
+    def setup(self):
+        print "setup BoundMethodRepr"
+        self.se = True
+        self.l_func = self.gen.get_repr(self.func)
+        self.dependencies.add(self.l_func)
+
+
+    def t_op_simple_call(self, l_target, args, lblock, l_func):
+        if not self.se:
+            self.setup()
+        self.l_func.op_simple_call(l_target,
+                                   [self.l_func, self.l_self] + args[1:],
+                                   lblock, l_func)

Modified: pypy/dist/pypy/translator/llvm/test/llvmsnippet.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/test/llvmsnippet.py	(original)
+++ pypy/dist/pypy/translator/llvm/test/llvmsnippet.py	Wed Feb 16 00:11:38 2005
@@ -1,5 +1,6 @@
 import autopath
 
+#function snippets
 def simple1():
     return 1
 
@@ -31,17 +32,117 @@
         return ackermann(n - 1, 1)
     return ackermann(n - 1, ackermann(n, m - 1))
 
+def calling1(m):
+    if m > 1:
+        return calling2(m - 1)
+    return m
+
+def calling2(m):
+    if m > 1:
+        return calling1(m - 1)
+    return m
 
-def arraytestsimple():
+#array snippets
+
+def array_simple():
     a = [42]
     return a[0]
 
-def arraytestsimple1():
-    a = [43]
-    return a[-1]
-
-def arraytestsetitem(i):
-    a = [43]
-    a[0] = i * 2
-    return a[-1]
-
+def array_simple1(item):
+    a = [item] * 10
+    i = 0
+    v = 0
+    while i < 10:
+        v += a[i]
+        i += 1
+    return v
+
+def array_setitem(i):
+    a = [1] * 10
+    a[i] = i
+    a[1] = 12
+    a[2] = 13
+    return a[i]
+
+def array_add(a0, a1, b0, b1, i):
+    a = [0] * 2
+    b = [0] * 2
+    a[0] = a0
+    a[1] = a1
+    b[0] = b0
+    b[1] = b1
+    return (a + b)[i]
+
+def double_array():
+    a = [15]
+    b = [a]
+    return b[0][0]
+
+def double_array_set():
+    a = [15] * 3
+    b = [a] * 3
+    b[0][0] = 1
+    return b[1][0]
+
+def bool_array():
+    a = [False] * 100
+    a[12] = True
+    return a[12]
+
+def callee(array):
+    return array[0]
+
+def array_arg(i):
+    a = [i - 5] * 12
+    return callee(a)
+
+#class snippets
+
+class A(object):
+    def __init__(self):
+        self.a = 14
+        self.b = False
+
+def class_simple():
+    a = A()
+    return a.a
+
+class B(object):
+    def __init__(self):
+        self.a = 14
+        self.b = False
+ 
+    def change(self, newa):
+        self.a = newa * 5
+
+def class_simple1(newa):
+    b = B()
+    b.change(newa)
+    return b.a
+
+class C(object):
+    def __init__(self, a):
+        self.a = a
+        self.b = 1
+
+def class_simple2(newa):
+    b = B()
+    b.change(newa)
+    c = C(b)
+    return c.a.a
+
+class D(object):
+    def __init__(self, a, length):
+        self.a = [a] * length
+        self.length = length
+
+    def set_range(self):
+        i = 0
+        while i < self.length:
+            self.a[i] = i
+            i += 1
+
+def id_int(i):
+    d = D(1, i + 1)
+    d.set_range()
+    return d.a[i]

Modified: pypy/dist/pypy/translator/llvm/test/test_genllvm.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/test/test_genllvm.py	(original)
+++ pypy/dist/pypy/translator/llvm/test/test_genllvm.py	Wed Feb 16 00:11:38 2005
@@ -16,6 +16,7 @@
 def compile_function(function, annotate):
     t = Translator(function)
     a = t.annotate(annotate)
+    t.simplify()
     gen = LLVMGenerator(t)
     return gen.compile()
 
@@ -28,6 +29,10 @@
         return True
 
 class TestLLVMRepr(object):
+    def setup_method(self,method):
+        if not llvm_found:
+            py.test.skip("llvm-as not found on path")
+
     def DONOT_test_simple1(self):
         t = Translator(llvmsnippet.simple1)
         a = t.annotate([])
@@ -64,7 +69,7 @@
         l_repr = gen.get_repr(str)
         assert l_repr.llvmname() == "%std.string*"
 
-    def test_stringrepr(self):
+    def DONOT_test_stringrepr(self):
         t = Translator(llvmsnippet.simple3)
         a = t.annotate([])
         gen = LLVMGenerator(t)
@@ -107,22 +112,72 @@
             assert f(2, i) == 2 * i + 3
             assert f(3, i) == 2 ** (i + 3) - 3
 
+    def test_calling(self):
+        f = compile_function(llvmsnippet.calling1, [int])
+        assert f(10) == 1
+
 class TestLLVMArray(object):
     def setup_method(self, method):
         if not llvm_found:
             py.test.skip("llvm-as not found on path.")
 
-    def test_simplearray(self):
-        f = compile_function(llvmsnippet.arraytestsimple, [])
+    def test_array(self):
+        f = compile_function(llvmsnippet.array_simple, [])
         assert f() == 42
 
-    def test_simplearray1(self):
-        f = compile_function(llvmsnippet.arraytestsimple1, [])
-        assert f() == 43
-
-    def test_simplearray_setitem(self):
-        f = compile_function(llvmsnippet.arraytestsetitem, [int])
-        assert f(32) == 64
+    def test_array1(self):
+        f = compile_function(llvmsnippet.array_simple1, [int])
+        assert f(1) == 10
+        assert f(-42) == -420
+
+    def test_array_setitem(self):
+        f = compile_function(llvmsnippet.array_setitem, [int])
+        print f(1), f(2), f(3)
+        assert f(1) == 12
+        assert f(2) == 13
+        assert f(3) == 3
+
+    def test_array_add(self):
+        f = compile_function(llvmsnippet.array_add, [int, int, int, int, int])
+        assert f(1,2,3,4,0) == 1
+        assert f(1,2,3,4,1) == 2
+        assert f(1,2,3,4,2) == 3
+        assert f(1,2,5,6,3) == 6
+
+    def test_array_double(self):
+        f = compile_function(llvmsnippet.double_array, [])
+        assert f() == 15
+
+    def test_bool_array(self):
+        f = compile_function(llvmsnippet.bool_array, [])
+        assert f() == 1
+
+    def test_array_arg(self):
+        f = compile_function(llvmsnippet.array_arg, [int])
+        assert f(5) == 0
+
+
+class TestClass(object):
+    def setup_method(self, method):
+        if not llvm_found:
+            py.test.skip("llvm-as not found on path.")
+
+    def test_classsimple(self):
+        f = compile_function(llvmsnippet.class_simple, [])
+        assert f() == 14
+
+    def test_classsimple1(self):
+        f = compile_function(llvmsnippet.class_simple1, [int])
+        assert f(2) == 10
+
+    def test_classsimple2(self):
+        f = compile_function(llvmsnippet.class_simple2, [int])
+        assert f(2) == 10
+
+    def test_id_int(self):
+        f = compile_function(llvmsnippet.id_int, [int])
+        for i in range(1, 20):
+            assert f(i) == i
 
 class TestSnippet(object):
     def setup_method(self, method):
@@ -155,6 +210,13 @@
         while_func = compile_function(test.while_func, [int])
         assert while_func(10) == 55
 
+    def test_time_waster(self):
+        f = compile_function(test.time_waster, [int])
+        assert f(1) == 1
+        assert f(2) == 2
+        assert f(3) == 6
+        assert f(4) == 12
+
     def test_factorial2(self):
         factorial2 = compile_function(test.factorial2, [int])
         assert factorial2(5) == 120
@@ -162,3 +224,14 @@
     def test_factorial(self):
         factorial = compile_function(test.factorial, [int])
         assert factorial(5) == 120
+
+    def test_two_plus_two(self):
+        f = compile_function(test.two_plus_two, [])
+        assert f() == 4
+
+    def test_sieve_of_eratosthenes(self):
+        f = compile_function(test.sieve_of_eratosthenes, [])
+        assert f() == 1028
+
+
+



More information about the Pypy-commit mailing list