[pypy-svn] r14710 - in pypy/dist/pypy/translator/llvm2: . test
rxe at codespeak.net
rxe at codespeak.net
Fri Jul 15 22:00:35 CEST 2005
Author: rxe
Date: Fri Jul 15 22:00:33 2005
New Revision: 14710
Modified:
pypy/dist/pypy/translator/llvm2/funcnode.py
pypy/dist/pypy/translator/llvm2/test/test_genllvm.py
Log:
Skip getfield() / getsubstruct() which return void. Thanks perdronis.
Aside - there were asserts in the code, which makes me think that remove_void()
transformation should of been preventing this (although it looks as if it it
doing something entirely different). In either case - I actually prefer to
have a comment in the generated code.
Modified: pypy/dist/pypy/translator/llvm2/funcnode.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/funcnode.py (original)
+++ pypy/dist/pypy/translator/llvm2/funcnode.py Fri Jul 15 22:00:33 2005
@@ -387,29 +387,36 @@
struct, structtype = self.db.repr_argwithtype(op.args[0])
fieldnames = list(op.args[0].concretetype.TO._names)
index = fieldnames.index(op.args[1].value)
- self.codewriter.getelementptr(tmpvar, structtype, struct, ("uint", index))
targetvar = self.db.repr_arg(op.result)
targettype = self.db.repr_arg_type(op.result)
- r = op.result
- assert targettype != "void"
- self.codewriter.load(targetvar, targettype, tmpvar)
-
+ if targettype != "void":
+ self.codewriter.getelementptr(tmpvar, structtype, struct,
+ ("uint", index))
+ self.codewriter.load(targetvar, targettype, tmpvar)
+ else:
+ self.codewriter.comment("***Skipping operation getfield()***",
+ indent=True)
+
def getsubstruct(self, op):
struct, structtype = self.db.repr_argwithtype(op.args[0])
fieldnames = list(op.args[0].concretetype.TO._names)
index = fieldnames.index(op.args[1].value)
targetvar = self.db.repr_arg(op.result)
- self.codewriter.getelementptr(targetvar, structtype,
- struct, ("uint", index))
targettype = self.db.repr_arg_type(op.result)
- assert targettype != "void"
+ if targettype != "void":
+ self.codewriter.getelementptr(targetvar, structtype,
+ struct, ("uint", index))
+ else:
+ self.codewriter.comment("***Skipping operation getsubstruct()***",
+ indent=True)
def setfield(self, op):
tmpvar = self.db.repr_tmpvar()
struct, structtype = self.db.repr_argwithtype(op.args[0])
fieldnames = list(op.args[0].concretetype.TO._names)
index = fieldnames.index(op.args[1].value)
- self.codewriter.getelementptr(tmpvar, structtype, struct, ("uint", index))
+ self.codewriter.getelementptr(tmpvar, structtype, struct,
+ ("uint", index))
valuevar, valuetype = self.db.repr_argwithtype(op.args[2])
assert valuetype != "void"
self.codewriter.store(valuetype, valuevar, tmpvar)
Modified: pypy/dist/pypy/translator/llvm2/test/test_genllvm.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/test/test_genllvm.py (original)
+++ pypy/dist/pypy/translator/llvm2/test/test_genllvm.py Fri Jul 15 22:00:33 2005
@@ -301,28 +301,6 @@
f = compile_function(string_simple, [int, int, int, int])
assert f(0, 0, 1, 4) == ord("h") + ord("d")
-def Xtest_dict_creation():
- d = {'hello' : 23,
- 'world' : 21}
- l = ["hello", "world"]
- def createdict(i, j):
- return d[l[i]] + d[l[j]]
- f = compile_function(createdict, [int, int], view=True)
-
- assert createdict(0, 1) == 43
-
-def Xtest_method_call():
- class MyBase:
- def m(self, x):
- return self.z + x
-
- def method_call(a, b):
- obj = MyBase()
- obj.z = a
- return obj.z + b
- f = compile_function(method_call, [int, int], view=True)
- assert f(4, 5) == 9
-
def test_attrs_class():
class MyBase:
pass
@@ -343,6 +321,16 @@
f = compile_function(attrs_class_pbc, [])
assert f() == 16
+def test_method_call():
+ class MyBase:
+ def m(self): return self.z
+ obj = MyBase()
+ obj.z = 4
+ def method_call():
+ return obj.m()
+ f = compile_function(method_call, [])
+ assert f() == 4
+
class TestException(Exception):
pass
@@ -358,3 +346,13 @@
except TestException:
return 0
f = compile_function(catch, [int])
+
+def Xtest_dict_creation():
+ d = {'hello' : 23,
+ 'world' : 21}
+ l = ["hello", "world"]
+ def createdict(i, j):
+ return d[l[i]] + d[l[j]]
+ f = compile_function(createdict, [int, int], view=True)
+
+ assert createdict(0, 1) == 43
More information about the Pypy-commit
mailing list