[pypy-svn] r34362 - in pypy/dist/pypy/translator: cli jvm oosupport
niko at codespeak.net
niko at codespeak.net
Wed Nov 8 12:52:55 CET 2006
Author: niko
Date: Wed Nov 8 12:52:54 2006
New Revision: 34362
Modified:
pypy/dist/pypy/translator/cli/class_.py
pypy/dist/pypy/translator/cli/constant.py
pypy/dist/pypy/translator/cli/function.py
pypy/dist/pypy/translator/cli/ilgenerator.py
pypy/dist/pypy/translator/jvm/constant.py
pypy/dist/pypy/translator/jvm/genjvm.py
pypy/dist/pypy/translator/jvm/node.py
pypy/dist/pypy/translator/oosupport/constant.py
pypy/dist/pypy/translator/oosupport/function.py
pypy/dist/pypy/translator/oosupport/genoo.py
Log:
1. adapt the JVM code to the changes I made in cli/oosupport; though I checked
this in before, but apparently not.
2. make the CLI constants for Records and Instances rely only upon the generic
setup code in oosupport; others remain the same
Modified: pypy/dist/pypy/translator/cli/class_.py
==============================================================================
--- pypy/dist/pypy/translator/cli/class_.py (original)
+++ pypy/dist/pypy/translator/cli/class_.py Wed Nov 8 12:52:54 2006
@@ -75,8 +75,8 @@
return
self.ilasm = ilasm
+ self.gen = CLIBaseGenerator(self.db, ilasm)
- gen = CLIBaseGenerator(self.db, ilasm)
if self.namespace:
ilasm.begin_namespace(self.namespace)
@@ -113,7 +113,7 @@
if isinstance(METH.RESULT, ootype.OOType):
ilasm.opcode('ldnull')
else:
- push_constant(self.db, METH.RESULT, 0, gen)
+ push_constant(self.db, METH.RESULT, 0, self.gen)
ilasm.opcode('ret')
ilasm.end_function()
@@ -132,7 +132,7 @@
f_name = self.cts.escape_name(f_name)
if cts_type != 'void':
self.ilasm.opcode('ldarg.0')
- push_constant(self.db, F_TYPE, f_default, self)
+ push_constant(self.db, F_TYPE, f_default, self.gen)
class_name = self.db.class_name(self.INSTANCE)
self.ilasm.set_field((cts_type, class_name, f_name))
Modified: pypy/dist/pypy/translator/cli/constant.py
==============================================================================
--- pypy/dist/pypy/translator/cli/constant.py (original)
+++ pypy/dist/pypy/translator/cli/constant.py Wed Nov 8 12:52:54 2006
@@ -34,9 +34,8 @@
push_constant, WeakRefConst, StaticMethodConst, CustomDictConst, \
ListConst, ClassConst, InstanceConst, RecordConst, DictConst, \
BaseConstantGenerator
-from pypy.translator.cli.support import string_literal
+from pypy.translator.cli.ilgenerator import CLIBaseGenerator
from pypy.rpython.ootypesystem import ootype
-from pypy.rlib.objectmodel import CDefinedIntSymbolic
from pypy.translator.cli.comparer import EqualityComparer
from pypy.rpython.lltypesystem import lltype
from pypy.translator.cli.cts import PYPY_DICT_OF_VOID, WEAKREF
@@ -50,8 +49,6 @@
MAX_CONST_PER_STEP = 100
SERIALIZE = False
-DEFINED_INT_SYMBOLICS = {'MALLOC_ZERO_FILLED':1}
-
def isnan(v):
return v != v*1.0 or (v == 1.0 and v == 2.0)
@@ -59,26 +56,6 @@
return v!=0 and (v == v*2)
# ______________________________________________________________________
-# MetaVM Generator interface
-
-class CLIGeneratorForConstants(object):
-
- ''' Very minimal "implementation" of oosupport.metavm.Generator
- interface. Just what is actually used. '''
-
- def __init__(self, ilasm):
- self.ilasm = ilasm
-
- def add_section(self, text):
- return
-
- def add_comment(self, text):
- return
-
- def pop(self, OOTYPE):
- self.ilasm.pop()
-
-# ______________________________________________________________________
# Constant Generators
#
# Different generators implementing different techniques for loading
@@ -97,7 +74,7 @@
def _begin_gen_constants(self, ilasm, all_constants):
self.ilasm = ilasm
self.begin_class()
- gen = CLIGeneratorForConstants(ilasm)
+ gen = CLIBaseGenerator(self.db, ilasm)
return gen
def _end_gen_constants(self, gen, numsteps):
@@ -115,35 +92,6 @@
def _declare_const(self, gen, const):
self.ilasm.field(const.name, const.get_type(), static=True)
- def push_primitive_constant(self, gen, TYPE, value):
- ilasm = gen.ilasm
- if TYPE is ootype.Void:
- pass
- elif TYPE is ootype.Bool:
- ilasm.opcode('ldc.i4', str(int(value)))
- elif TYPE is ootype.Char or TYPE is ootype.UniChar:
- ilasm.opcode('ldc.i4', ord(value))
- elif TYPE is ootype.Float:
- if isinf(value):
- ilasm.opcode('ldc.r8', '(00 00 00 00 00 00 f0 7f)')
- elif isnan(value):
- ilasm.opcode('ldc.r8', '(00 00 00 00 00 00 f8 ff)')
- else:
- ilasm.opcode('ldc.r8', repr(value))
- elif isinstance(value, CDefinedIntSymbolic):
- ilasm.opcode('ldc.i4', DEFINED_INT_SYMBOLICS[value.expr])
- elif TYPE in (ootype.Signed, ootype.Unsigned):
- ilasm.opcode('ldc.i4', str(value))
- elif TYPE in (ootype.SignedLongLong, ootype.UnsignedLongLong):
- ilasm.opcode('ldc.i8', str(value))
- elif TYPE is ootype.String:
- if value._str is None:
- ilasm.opcode('ldnull')
- else:
- ilasm.opcode("ldstr", string_literal(value._str))
- else:
- assert False, "Unexpected constant type"
-
def downcast_constant(self, gen, const, EXPECTED_TYPE):
type = self.cts.lltype_to_cts(EXPECTED_TYPE)
gen.ilasm.opcode('castclass', type)
@@ -414,75 +362,17 @@
# the generator interface in the CLI.
class CLIRecordConst(CLIBaseConstMixin, RecordConst):
- # Eventually code should look more like this:
- #def create_pointer(self, gen):
- # self.db.const_count.inc('Record')
- # super(CLIRecordConst, self).create_pointer(gen)
-
def create_pointer(self, gen):
- assert not self.is_null()
- class_name = self.get_type(False)
- gen.ilasm.new('instance void class %s::.ctor()' % class_name)
self.db.const_count.inc('Record')
-
- def initialize_data(self, gen):
- assert not self.is_null()
- class_name = self.get_type(False)
- for f_name, (FIELD_TYPE, f_default) in self.value._TYPE._fields.iteritems():
- if FIELD_TYPE is not ootype.Void:
- f_type = self.cts.lltype_to_cts(FIELD_TYPE)
- value = self.value._items[f_name]
- gen.ilasm.opcode('dup')
- push_constant(self.db, FIELD_TYPE, value, gen)
- gen.ilasm.set_field((f_type, class_name, f_name))
+ super(CLIRecordConst, self).create_pointer(gen)
class CLIInstanceConst(CLIBaseConstMixin, InstanceConst):
# Eventually code should look more like this:
- #def create_pointer(self, gen):
- # self.db.const_count.inc('Instance')
- # self.db.const_count.inc('Instance', INSTANCE)
- # super(CLIInstanceConst, self).create_pointer(gen)
-
def create_pointer(self, gen):
- assert not self.is_null()
- INSTANCE = self.value._TYPE
- gen.ilasm.new('instance void class %s::.ctor()' % self.db.class_name(INSTANCE))
self.db.const_count.inc('Instance')
- self.db.const_count.inc('Instance', INSTANCE)
+ self.db.const_count.inc('Instance', self.OOTYPE())
+ super(CLIInstanceConst, self).create_pointer(gen)
- def initialize_data(self, gen):
- assert not self.is_null()
- INSTANCE = self.value._TYPE
- if INSTANCE is not self.static_type:
- gen.ilasm.opcode('castclass', self.cts.lltype_to_cts(INSTANCE, include_class=False))
-
- # XXX, horrible hack: first collect all consts, then render
- # CustomDicts at last because their ll_set could need other
- # fields already initialized. We should really think a more
- # general way to handle such things.
- const_list = []
- while INSTANCE is not None:
- for name, (TYPE, default) in INSTANCE._fields.iteritems():
- if TYPE is ootype.Void:
- continue
- value = getattr(self.value, name)
- const_list.append((TYPE, INSTANCE, name, value))
- INSTANCE = INSTANCE._superclass
-
- def mycmp(x, y):
- if isinstance(x[0], ootype.CustomDict) and not isinstance(y[0], ootype.CustomDict):
- return 1 # a CustomDict is always greater than non-CustomDicts
- elif isinstance(y[0], ootype.CustomDict) and not isinstance(x[0], ootype.CustomDict):
- return -1 # a non-CustomDict is always less than CustomDicts
- else:
- return cmp(x, y)
- const_list.sort(mycmp)
-
- for TYPE, INSTANCE, name, value in const_list:
- type_ = self.cts.lltype_to_cts(TYPE)
- gen.ilasm.opcode('dup')
- push_constant(self.db, TYPE, value, gen)
- gen.ilasm.opcode('stfld %s %s::%s' % (type_, self.db.class_name(INSTANCE), name))
class CLIClassConst(CLIBaseConstMixin, ClassConst):
def is_inline(self):
@@ -495,7 +385,6 @@
gen.ilasm.call('class [mscorlib]System.Type class [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)')
return
super(CLIClassConst, self).push_inline(gen, EXPECTED_TYPE)
- pass
class CLIListConst(CLIBaseConstMixin, ListConst):
Modified: pypy/dist/pypy/translator/cli/function.py
==============================================================================
--- pypy/dist/pypy/translator/cli/function.py (original)
+++ pypy/dist/pypy/translator/cli/function.py Wed Nov 8 12:52:54 2006
@@ -59,15 +59,6 @@
self.store(link.last_exc_value)
self._setup_link(link)
- def field_name(self, obj, field):
- INSTANCE, type_ = obj._lookup_field(field)
- assert type_ is not None, 'Cannot find the field %s in the object %s' % (field, obj)
-
- class_name = self.class_name(INSTANCE)
- field_type = self.cts.lltype_to_cts(type_)
- field = self.cts.escape_name(field)
- return '%s %s::%s' % (field_type, class_name, field)
-
def begin_render(self):
returntype, returnvar = self.cts.llvar_to_cts(self.graph.getreturnvar())
if self.is_method:
Modified: pypy/dist/pypy/translator/cli/ilgenerator.py
==============================================================================
--- pypy/dist/pypy/translator/cli/ilgenerator.py (original)
+++ pypy/dist/pypy/translator/cli/ilgenerator.py Wed Nov 8 12:52:54 2006
@@ -1,9 +1,11 @@
from pypy.rpython.lltypesystem.lltype import Signed, Unsigned, Void, Bool, Float
from pypy.rpython.lltypesystem.lltype import SignedLongLong, UnsignedLongLong
+from pypy.rlib.objectmodel import CDefinedIntSymbolic
from pypy.rpython.ootypesystem import ootype
from pypy.translator.oosupport.metavm import Generator
from pypy.translator.oosupport.constant import push_constant
from pypy.objspace.flow import model as flowmodel
+from pypy.translator.cli.support import string_literal
class CodeGenerator(object):
def __init__(self, out, indentstep = 4, startblock = '{', endblock = '}'):
@@ -249,6 +251,8 @@
def flush(self):
pass
+DEFINED_INT_SYMBOLICS = {'MALLOC_ZERO_FILLED':1}
+
class CLIBaseGenerator(Generator):
""" Implements those parts of the metavm generator that are not
@@ -259,6 +263,9 @@
self.db = db
self.cts = db.genoo.TypeSystem(db)
+ def pop(self, TYPE):
+ self.ilasm.opcode('pop')
+
def add_comment(self, text):
pass
@@ -290,6 +297,15 @@
def new(self, obj):
self.ilasm.new(self.cts.ctor_name(obj))
+ def field_name(self, obj, field):
+ INSTANCE, type_ = obj._lookup_field(field)
+ assert type_ is not None, 'Cannot find the field %s in the object %s' % (field, obj)
+
+ class_name = self.class_name(INSTANCE)
+ field_type = self.cts.lltype_to_cts(type_)
+ field = self.cts.escape_name(field)
+ return '%s %s::%s' % (field_type, class_name, field)
+
def set_field(self, obj, name):
self.ilasm.opcode('stfld ' + self.field_name(obj, name))
@@ -322,3 +338,35 @@
def branch_conditionally(self, cond, target_label):
self.ilasm.branch_if(cond, target_label)
+
+ def push_primitive_constant(self, TYPE, value):
+ ilasm = self.ilasm
+ if TYPE is ootype.Void:
+ pass
+ elif TYPE is ootype.Bool:
+ ilasm.opcode('ldc.i4', str(int(value)))
+ elif TYPE is ootype.Char or TYPE is ootype.UniChar:
+ ilasm.opcode('ldc.i4', ord(value))
+ elif TYPE is ootype.Float:
+ if isinf(value):
+ ilasm.opcode('ldc.r8', '(00 00 00 00 00 00 f0 7f)')
+ elif isnan(value):
+ ilasm.opcode('ldc.r8', '(00 00 00 00 00 00 f8 ff)')
+ else:
+ ilasm.opcode('ldc.r8', repr(value))
+ elif isinstance(value, CDefinedIntSymbolic):
+ ilasm.opcode('ldc.i4', DEFINED_INT_SYMBOLICS[value.expr])
+ elif TYPE in (ootype.Signed, ootype.Unsigned):
+ ilasm.opcode('ldc.i4', str(value))
+ elif TYPE in (ootype.SignedLongLong, ootype.UnsignedLongLong):
+ ilasm.opcode('ldc.i8', str(value))
+ elif TYPE is ootype.String:
+ if value._str is None:
+ ilasm.opcode('ldnull')
+ else:
+ ilasm.opcode("ldstr", string_literal(value._str))
+ else:
+ assert False, "Unexpected constant type"
+
+ def dup(self, TYPE):
+ self.ilasm.opcode('dup')
Modified: pypy/dist/pypy/translator/jvm/constant.py
==============================================================================
--- pypy/dist/pypy/translator/jvm/constant.py (original)
+++ pypy/dist/pypy/translator/jvm/constant.py Wed Nov 8 12:52:54 2006
@@ -1,9 +1,9 @@
from pypy.translator.jvm.generator import \
- Field, Method, ACONST_NULL, ICONST, LDC, DCONST_0, DCONST_1, LDC2
+ Field, Method
from pypy.translator.oosupport.constant import \
- RecordConst, InstanceConst, ClassConst
+ BaseConstantGenerator, RecordConst, InstanceConst, ClassConst
from pypy.translator.jvm.typesystem import \
- jPyPyConst, jObject
+ jPyPyConst, jObject, jVoid
# ___________________________________________________________________________
# Constant Generator
@@ -30,9 +30,10 @@
def _begin_gen_constants(self, gen, all_constants):
gen.begin_class(jPyPyConst, jObject)
+ return gen
def _declare_const(self, gen, const):
- gen.add_field(c.fieldobj)
+ gen.add_field(const.fieldobj)
def _declare_step(self, gen, stepnum):
next_nm = "constant_init_%d" % stepnum
@@ -46,7 +47,7 @@
# The static init code just needs to call constant_init_1..N
gen.begin_function('<clinit>', [], [], jVoid, True)
for x in range(numsteps):
- m = jvmgen.Method.s(jPyPyConst, "constant_init_%d" % x, [], jVoid)
+ m = Method.s(jPyPyConst, "constant_init_%d" % x, [], jVoid)
gen.emit(m)
gen.return_val(jVoid)
gen.end_function()
Modified: pypy/dist/pypy/translator/jvm/genjvm.py
==============================================================================
--- pypy/dist/pypy/translator/jvm/genjvm.py (original)
+++ pypy/dist/pypy/translator/jvm/genjvm.py Wed Nov 8 12:52:54 2006
@@ -15,6 +15,7 @@
from pypy.translator.jvm.log import log
from pypy.translator.jvm.node import EntryPoint, Function
from pypy.translator.jvm.opcodes import opcodes
+from pypy.translator.jvm.constant import JVMConstantGenerator
class JvmError(Exception):
""" Indicates an error occurred in JVM backend """
@@ -173,9 +174,7 @@
opcodes = opcodes
log = log
- RecordConst = jvmconst.JVMRecordConst
- InstanceConst = jvmconst.JVMInstanceConst
- ClassConst = jvmconst.JVMClassConst
+ ConstantGenerator = JVMConstantGenerator
def __init__(self, tmpdir, translator, entrypoint):
"""
Modified: pypy/dist/pypy/translator/jvm/node.py
==============================================================================
--- pypy/dist/pypy/translator/jvm/node.py (original)
+++ pypy/dist/pypy/translator/jvm/node.py Wed Nov 8 12:52:54 2006
@@ -27,6 +27,8 @@
class Node(object):
def set_db(self, db):
self.db = db
+ def dependencies(self):
+ pass
class EntryPoint(Node):
Modified: pypy/dist/pypy/translator/oosupport/constant.py
==============================================================================
--- pypy/dist/pypy/translator/oosupport/constant.py (original)
+++ pypy/dist/pypy/translator/oosupport/constant.py Wed Nov 8 12:52:54 2006
@@ -426,9 +426,9 @@
for f_name, (FIELD_TYPE, f_default) in self.value._TYPE._fields.iteritems():
if FIELD_TYPE is not ootype.Void:
gen.dup(SELFTYPE)
+ value = self.value._items[f_name]
push_constant(self.db, FIELD_TYPE, value, gen)
gen.set_field(SELFTYPE, f_name)
- gen.pop(SELFTYPE)
# ______________________________________________________________________
# Instances
@@ -508,9 +508,6 @@
push_constant(self.db, FIELD_TYPE, value, gen)
gen.set_field(INSTANCE, name)
- # Pop selves from stack when done.
- gen.pop(SELFTYPE)
-
# ______________________________________________________________________
# Class constants
Modified: pypy/dist/pypy/translator/oosupport/function.py
==============================================================================
--- pypy/dist/pypy/translator/oosupport/function.py (original)
+++ pypy/dist/pypy/translator/oosupport/function.py Wed Nov 8 12:52:54 2006
@@ -173,9 +173,6 @@
assert isinstance(instr_list, InstructionList)
instr_list.render(self.generator, op)
- def field_name(self, obj, field):
- raise NotImplementedError
-
# ---------------------------------------------------------#
# These methods are quite backend independent, but not #
# used in all backends. Invoke them from your __init__ if #
Modified: pypy/dist/pypy/translator/oosupport/genoo.py
==============================================================================
--- pypy/dist/pypy/translator/oosupport/genoo.py (original)
+++ pypy/dist/pypy/translator/oosupport/genoo.py Wed Nov 8 12:52:54 2006
@@ -2,7 +2,7 @@
"""
from pypy.config.config import Config
from pypy.config.pypyoption import pypy_optiondescription
-
+from pypy.translator.oosupport import constant as ooconst
class GenOO(object):
TypeSystem = None
@@ -15,14 +15,14 @@
# _create_complex_const:
ConstantGenerator = None
- InstanceConst = None
- RecordConst = None
- ClassConst = None
- ListConst = None
- StaticMethodConst = None
- CustomDictConst = None
- DictConst = None
- WeakRefConst = None
+ InstanceConst = ooconst.InstanceConst
+ RecordConst = ooconst.RecordConst
+ ClassConst = ooconst.ClassConst
+ ListConst = ooconst.ListConst
+ StaticMethodConst = ooconst.StaticMethodConst
+ CustomDictConst = ooconst.CustomDictConst
+ DictConst = ooconst.DictConst
+ WeakRefConst = ooconst.WeakRefConst
def __init__(self, tmpdir, translator, entrypoint, config=None):
self.tmpdir = tmpdir
More information about the Pypy-commit
mailing list