[pypy-svn] r57805 - in pypy/branch/oo-jit/pypy: jit/codegen/cli jit/codegen/cli/test jit/rainbow translator/oosupport
antocuni at codespeak.net
antocuni at codespeak.net
Thu Sep 4 11:59:38 CEST 2008
Author: antocuni
Date: Thu Sep 4 11:59:37 2008
New Revision: 57805
Modified:
pypy/branch/oo-jit/pypy/jit/codegen/cli/operation.py
pypy/branch/oo-jit/pypy/jit/codegen/cli/rgenop.py
pypy/branch/oo-jit/pypy/jit/codegen/cli/test/test_gencli_interpreter.py
pypy/branch/oo-jit/pypy/jit/rainbow/codewriter.py
pypy/branch/oo-jit/pypy/translator/oosupport/constant.py
Log:
fix a bug in gencli when handling null ootype._object constants; add the logic
to codegen/cli to turn the oosends to String objects into call to the static
method helpers in pypy.runtime.String
Modified: pypy/branch/oo-jit/pypy/jit/codegen/cli/operation.py
==============================================================================
--- pypy/branch/oo-jit/pypy/jit/codegen/cli/operation.py (original)
+++ pypy/branch/oo-jit/pypy/jit/codegen/cli/operation.py Thu Sep 4 11:59:37 2008
@@ -226,10 +226,10 @@
self.meth = meth
self.gv_self = gv_self
self.args_gv = args_gv
- self.methodinfo = methtoken.getMethodInfo()
+ self.methtoken = methtoken
def restype(self):
- clitype = self.methodinfo.get_ReturnType()
+ clitype = self.methtoken.getReturnType()
if clitype is typeof(System.Void):
return None
return clitype
@@ -238,7 +238,7 @@
self.gv_self.load(self.meth)
for gv_arg in self.args_gv:
gv_arg.load(self.meth)
- self.meth.il.Emit(OpCodes.Callvirt, self.methodinfo)
+ self.methtoken.emit_call(self.meth.il)
if self.restype() is not None:
self.storeResult()
Modified: pypy/branch/oo-jit/pypy/jit/codegen/cli/rgenop.py
==============================================================================
--- pypy/branch/oo-jit/pypy/jit/codegen/cli/rgenop.py (original)
+++ pypy/branch/oo-jit/pypy/jit/codegen/cli/rgenop.py Thu Sep 4 11:59:37 2008
@@ -27,6 +27,7 @@
cChar = classof(System.Char)
cUtils = classof(CLR.pypy.runtime.Utils)
cFlexSwitchCase = classof(FlexSwitchCase)
+cpypyString = classof(CLR.pypy.runtime.String)
class SigToken:
def __init__(self, args, res, funcclass):
@@ -44,6 +45,7 @@
return clitype.GetField(str(self.name))
class MethToken:
+
def __init__(self, ooclass, name):
self.ooclass = ooclass
self.name = name
@@ -52,6 +54,31 @@
clitype = class2type(self.ooclass)
return clitype.GetMethod(str(self.name))
+ def getReturnType(self):
+ methodinfo = self.getMethodInfo()
+ return methodinfo.get_ReturnType()
+
+ def emit_call(self, il):
+ raise NotImplementedError
+
+
+class VirtualMethToken(MethToken):
+
+ def emit_call(self, il):
+ methodinfo = self.getMethodInfo()
+ il.Emit(OpCodes.Callvirt, methodinfo)
+
+
+class StaticMethodToken(MethToken):
+ def __init__(self, ooclass, name):
+ self.ooclass = ooclass
+ self.name = name
+
+ def emit_call(self, il):
+ methodinfo = self.getMethodInfo()
+ il.Emit(OpCodes.Call, methodinfo)
+
+
class AllocToken:
def __init__(self, ooclass):
self.ooclass = ooclass
@@ -316,8 +343,11 @@
@staticmethod
@specialize.memo()
def methToken(TYPE, methname):
- ooclass = ootype.runtimeClass(TYPE)
- return MethToken(ooclass, methname)
+ if TYPE is ootype.String:
+ return StaticMethodToken(cpypyString, methname)
+ else:
+ ooclass = ootype.runtimeClass(TYPE)
+ return VirtualMethToken(ooclass, methname)
@staticmethod
@specialize.memo()
Modified: pypy/branch/oo-jit/pypy/jit/codegen/cli/test/test_gencli_interpreter.py
==============================================================================
--- pypy/branch/oo-jit/pypy/jit/codegen/cli/test/test_gencli_interpreter.py (original)
+++ pypy/branch/oo-jit/pypy/jit/codegen/cli/test/test_gencli_interpreter.py Thu Sep 4 11:59:37 2008
@@ -83,7 +83,6 @@
def test_compile_time_const_tuple(self):
py.test.skip("Fails, and it seems to be related to missing support for constant arguments")
- test_builtin_oosend_with_green_args = skip
test_residual_red_call = skip
test_residual_red_call_with_exc = skip
test_simple_meth = skip
Modified: pypy/branch/oo-jit/pypy/jit/rainbow/codewriter.py
==============================================================================
--- pypy/branch/oo-jit/pypy/jit/rainbow/codewriter.py (original)
+++ pypy/branch/oo-jit/pypy/jit/rainbow/codewriter.py Thu Sep 4 11:59:37 2008
@@ -229,7 +229,6 @@
call_bm = 'result = bound_meth(%s)' % ', '.join(bm_args)
src = py.code.Source("""
def do_perform_call(rgenop, args_gv):
- try:
assert len(args_gv) + voidargcount == numargs
this = args_gv[0].revealconst(SELFTYPE)
args = revealargs(args_gv[1:])
@@ -239,8 +238,6 @@
return None
else:
return rgenop.genconst(result)
- except Exception, e:
- import pdb;pdb.xpm()
""" % call_bm)
exec src.compile() in locals()
self.do_perform_call = do_perform_call
Modified: pypy/branch/oo-jit/pypy/translator/oosupport/constant.py
==============================================================================
--- pypy/branch/oo-jit/pypy/translator/oosupport/constant.py (original)
+++ pypy/branch/oo-jit/pypy/translator/oosupport/constant.py Thu Sep 4 11:59:37 2008
@@ -38,6 +38,16 @@
def is_primitive(TYPE):
return TYPE in PRIMITIVE_TYPES
+def get_primitive_constant(TYPE, value):
+ if is_primitive(TYPE):
+ return TYPE, value
+ if TYPE is ootype.Object:
+ obj = value.obj
+ T2 = ootype.typeOf(obj)
+ if obj is not None and is_primitive(T2):
+ return T2, obj
+ return None, None
+
def push_constant(db, TYPE, value, gen):
""" General method that pushes the value of the specified constant
onto the stack. Use this when you want to load a constant value.
@@ -50,15 +60,10 @@
"""
constgen = db.constant_generator
-
- if is_primitive(TYPE):
- return constgen.push_primitive_constant(gen, TYPE, value)
- if TYPE is ootype.Object:
- obj = value.obj
- T2 = ootype.typeOf(obj)
- if is_primitive(T2):
- return constgen.push_primitive_constant(gen, T2, obj)
+ TYPE2, value2 = get_primitive_constant(TYPE, value)
+ if TYPE2 is not None:
+ return constgen.push_primitive_constant(gen, TYPE2, value2)
const = constgen.record_const(value)
if const.is_inline():
@@ -435,7 +440,8 @@
# Internal helpers
def _record_const_if_complex(self, TYPE, value):
- if not is_primitive(TYPE):
+ TYPE2, value2 = get_primitive_constant(TYPE, value)
+ if not TYPE2:
self.db.constant_generator.record_const(value)
More information about the Pypy-commit
mailing list