[pypy-svn] r72232 - in pypy/branch/avm/pypy/translator/avm2: . test

magcius at codespeak.net magcius at codespeak.net
Mon Mar 15 02:01:02 CET 2010


Author: magcius
Date: Mon Mar 15 02:01:00 2010
New Revision: 72232

Modified:
   pypy/branch/avm/pypy/translator/avm2/avm2gen.py
   pypy/branch/avm/pypy/translator/avm2/class_.py
   pypy/branch/avm/pypy/translator/avm2/constant.py
   pypy/branch/avm/pypy/translator/avm2/database.py
   pypy/branch/avm/pypy/translator/avm2/function.py
   pypy/branch/avm/pypy/translator/avm2/genavm.py
   pypy/branch/avm/pypy/translator/avm2/query.py
   pypy/branch/avm/pypy/translator/avm2/sudanpython.py
   pypy/branch/avm/pypy/translator/avm2/test/mylib.py
   pypy/branch/avm/pypy/translator/avm2/test/test_carbonpython.py
   pypy/branch/avm/pypy/translator/avm2/types_.py
Log:
More work on tests and sudanpython

Modified: pypy/branch/avm/pypy/translator/avm2/avm2gen.py
==============================================================================
--- pypy/branch/avm/pypy/translator/avm2/avm2gen.py	(original)
+++ pypy/branch/avm/pypy/translator/avm2/avm2gen.py	Mon Mar 15 02:01:00 2010
@@ -12,6 +12,8 @@
 from pypy.translator.oosupport.treebuilder import SubOperation
 from pypy.translator.oosupport.metavm import Generator
 from pypy.translator.oosupport.constant import push_constant
+from pypy.translator.oosupport.function import render_sub_op
+
 
 from itertools import chain
 
@@ -19,7 +21,7 @@
 
     def __init__(self, db, abc):
         super(PyPyAvm2ilasm, self).__init__(abc)
-        self.db = db
+        self.db  = db
         self.cts = db.genoo.TypeSystem(db)
 
     def _get_type(self, TYPE):
@@ -47,6 +49,8 @@
                 self.push_local(v)
         elif isinstance(v, flowmodel.Constant):
             push_constant(self.db, v.concretetype, v.value, self)
+        elif isinstance(v, SubOperation):
+            render_sub_op(v, self.db, self)
         else:
             super(PyPyAvm2ilasm, self).load(v)
 
@@ -102,6 +106,36 @@
         self.I(instructions.getproperty(constants.QName("length")))
     
     def call_graph(self, graph, func_name=None):
+        """
+        Call a graph.
+        """
         if func_name is None:
             self.db.pending_function(graph)
+        func_name = func_name or graph.name
+        namespace = getattr(graph.func, '_namespace_', None)
+        if namespace:
+            qname = constants.packagedQName(namespace, func_name)
+        else:
+            qname = constants.QName(func_name)
+        self.emit('findpropstrict', qname)
+        self.emit('callproperty', qname)
+
+    def store(self, v):
+        """
+        Pop a value off the stack and store it in the variable.
+        """
+        self.store_var(v.name)
+
+    def push_local(self, v):
+        """
+        Get the local occupied to "name" and push it to the stack.
+        """
+        self.push_var(v.name)
+
+    push_arg = push_local
 
+    def new(self, TYPE):
+        # XXX: assume no args for now
+        TYPE = self._get_type(TYPE)
+        self.emit('findpropstrict', TYPE)
+        self.emit('constructprop', TYPE, 0)

Modified: pypy/branch/avm/pypy/translator/avm2/class_.py
==============================================================================
--- pypy/branch/avm/pypy/translator/avm2/class_.py	(original)
+++ pypy/branch/avm/pypy/translator/avm2/class_.py	Mon Mar 15 02:01:00 2010
@@ -1,7 +1,6 @@
 from pypy.rpython.ootypesystem import ootype
 from pypy.translator.cli.node import Node
 from pypy.translator.oosupport.constant import push_constant
-from pypy.translator.cli.ilgenerator import CLIBaseGenerator
 
 from mech.fusion.avm2 import constants as c, traits
 from pypy.translator.avm2 import types_ as types

Modified: pypy/branch/avm/pypy/translator/avm2/constant.py
==============================================================================
--- pypy/branch/avm/pypy/translator/avm2/constant.py	(original)
+++ pypy/branch/avm/pypy/translator/avm2/constant.py	Mon Mar 15 02:01:00 2010
@@ -1,36 +1,9 @@
-"""
-___________________________________________________________________________
-CLI Constants
-
-This module extends the oosupport/constant.py to be specific to the
-CLI.  Most of the code in this file is in the constant generators, which
-determine how constants are stored and loaded (static fields, lazy
-initialization, etc), but some constant classes have been overloaded or
-extended to allow for special handling.
-
-The CLI implementation is broken into three sections:
-
-* Constant Generators: different generators implementing different
-  techniques for loading constants (Static fields, singleton fields, etc)
-
-* Mixins: mixins are used to add a few CLI-specific methods to each
-  constant class.  Basically, any time I wanted to extend a base class
-  (such as AbstractConst or DictConst), I created a mixin, and then
-  mixed it in to each sub-class of that base-class.
-
-* Subclasses: here are the CLI specific classes.  Eventually, these
-  probably wouldn't need to exist at all (the JVM doesn't have any,
-  for example), or could simply have empty bodies and exist to
-  combine a mixin and the generic base class.  For now, though, they
-  contain the create_pointer() and initialize_data() routines.
-"""
 
 from pypy.translator.oosupport.constant import \
      push_constant, WeakRefConst, StaticMethodConst, CustomDictConst, \
      ListConst, ClassConst, InstanceConst, RecordConst, DictConst, \
      BaseConstantGenerator, AbstractConst, ArrayConst
 from pypy.rpython.ootypesystem import ootype
-from pypy.translator.cli.comparer import EqualityComparer
 from pypy.translator.avm2 import types_ as types
 from pypy.rpython.lltypesystem import lltype
 
@@ -38,10 +11,6 @@
 
 CONST_CLASS = constants.packagedQName("pypy.runtime", "Constants")
 
-DEBUG_CONST_INIT = False
-DEBUG_CONST_INIT_VERBOSE = False
-SERIALIZE = False
-
 # ______________________________________________________________________
 # Constant Generators
 #
@@ -97,6 +66,15 @@
     def _store_constant(self, gen, const):
         gen.emit('initproperty', constants.QName(const.name))
 
+    def _initialize_data(self, gen, all_constants):
+        """ Iterates through each constant, initializing its data. """
+        for const in all_constants:
+            self._consider_step(gen)
+            self._push_constant_during_init(gen, const)
+            self.current_const = const
+            if not const.initialize_data(self, gen):
+                gen.pop()
+
     def _declare_step(self, gen, stepnum):
         pass
 
@@ -184,7 +162,7 @@
         SELFTYPE = self.value._TYPE
         for f_name, (FIELD_TYPE, f_default) in self.value._TYPE._fields.iteritems():
             if FIELD_TYPE is not ootype.Void:
-                gen.dup(SELFTYPE)
+                gen.dup()
                 value = self.value._items[f_name]
                 push_constant(self.db, FIELD_TYPE, value, gen)
                 gen.set_field(f_name)
@@ -212,7 +190,7 @@
         # Store each of our fields in the sorted order
         for FIELD_TYPE, INSTANCE, name, value in const_list:
             constgen._consider_split_current_function(gen)
-            gen.dup(SELFTYPE)
+            gen.dup()
             push_constant(self.db, FIELD_TYPE, value, gen)
             gen.set_field(name)
 
@@ -251,15 +229,14 @@
         self.db.const_count.inc('List', self.value._TYPE.ITEM)
         self.db.const_count.inc('List', llen)
         gen.oonewarray(self.value._TYPE, llen)
-        
+
     def initialize_data(self, constgen, gen):
         assert not self.is_null()
         
         # check for special cases and avoid initialization
         if self._do_not_initialize():
             return
-
-        # set each item in the list using the OOTYPE methods
+        
         for idx, item in enumerate(self.value._array):
             gen.dup()
             gen.emit('setproperty', constants.Multiname(

Modified: pypy/branch/avm/pypy/translator/avm2/database.py
==============================================================================
--- pypy/branch/avm/pypy/translator/avm2/database.py	(original)
+++ pypy/branch/avm/pypy/translator/avm2/database.py	Mon Mar 15 02:01:00 2010
@@ -1,7 +1,6 @@
 import string
 #from pypy.translator.avm.class_ import Class
 from pypy.rpython.ootypesystem import ootype
-from pypy.translator.cli.support import Counter
 from pypy.translator.avm2 import runtime, types_ as types, class_ as c, record
 from pypy.translator.oosupport.database import Database as OODatabase
 
@@ -10,6 +9,23 @@
 except NameError:
     from sets import Set as set
 
+class Counter(object):
+    def __init__(self):
+        self.counters = {}
+
+    def inc(self, *label):
+        cur = self.counters.get(label, 0)
+        self.counters[label] = cur+1
+
+    def dump(self, filename):
+        f = file(filename, 'w')
+        keys = self.counters.keys()
+        keys.sort()
+        for key in keys:
+            label = ', '.join([str(item) for item in key])
+            f.write('%s: %d\n' % (label, self.counters[key]))
+        f.close()
+
 class LowLevelDatabase(OODatabase):
     def __init__(self, genoo):
         OODatabase.__init__(self, genoo)

Modified: pypy/branch/avm/pypy/translator/avm2/function.py
==============================================================================
--- pypy/branch/avm/pypy/translator/avm2/function.py	(original)
+++ pypy/branch/avm/pypy/translator/avm2/function.py	Mon Mar 15 02:01:00 2010
@@ -45,21 +45,24 @@
     def begin_render(self):
         self._set_args()
         self._set_locals()
-        print self.args
-        print self.locals
         if not self.args:
             self.args = ()
 
+        if self.is_method:
+            self.args = self.args[1:]
+        
         returntype, returnvar = self.cts.llvar_to_cts(self.graph.getreturnvar())
 
         if self.classname:
-            self.generator.begin_method(self.name, self.args[1:], returntype, override=self.override)
-        else:
-            self.generator.begin_method(self.name, self.args, returntype, static=True, override=self.override)
+            self.generator.begin_class(constants.packagedQName(self.namespace, self.classname))
+        
+        self.generator.begin_method(self.name, self.args, returntype, static=not self.is_method, override=self.override)
         
     def end_render(self):
         # if self.generator.scope.islabel:
         #     self.generator.exit_scope()
+        if self.classname:
+            self.generator.exit_context()
         self.generator.exit_context()
         
     def render_return_block(self, block):

Modified: pypy/branch/avm/pypy/translator/avm2/genavm.py
==============================================================================
--- pypy/branch/avm/pypy/translator/avm2/genavm.py	(original)
+++ pypy/branch/avm/pypy/translator/avm2/genavm.py	Mon Mar 15 02:01:00 2010
@@ -38,7 +38,7 @@
     
     def create_assembler(self):
         self.abc = AbcFile()
-        return PyPyAvm2ilasm(self, self.abc)
+        return PyPyAvm2ilasm(self.db, self.abc)
 
     def generate_source(self):
         if self.ilasm is None:
@@ -52,5 +52,5 @@
         return self.abc.serialize()
 
     # Don't do treebuilding stuff
-    def stack_optimization(self):
-        pass
+    # def stack_optimization(self):
+    #     pass

Modified: pypy/branch/avm/pypy/translator/avm2/query.py
==============================================================================
--- pypy/branch/avm/pypy/translator/avm2/query.py	(original)
+++ pypy/branch/avm/pypy/translator/avm2/query.py	Mon Mar 15 02:01:00 2010
@@ -6,7 +6,6 @@
 from pypy.tool.udir import udir
 from pypy.rpython.ootypesystem import ootype
 from pypy.translator import avm2
-from pypy.translator.cli.support import log
 from mech.fusion.avm2.constants import QName
 
 Types = {} # TypeName -> ClassDesc
@@ -35,6 +34,12 @@
 #         clr.AddReference(pypylib)
 #     load_assembly(pypylib)
 
+def getattr_ex(target, attr):
+    parts = attr.split('.')
+    for part in parts:
+        target = getattr(target, part)
+    return target
+
 def load_playerglobal():
     _cache = get_cachedir()
     outfile = _cache.join('avm2_playerglobal.pickle')
@@ -203,7 +208,6 @@
 
     def _buildtree(self):
         assert self._name is None, '_buildtree can be called only on top-level Runtime, not on namespaces'
-        from pypy.translator.cli.support import getattr_ex
         load_playerglobal()
         for fullname in sorted(list(Namespaces)):
             if '.' in fullname:

Modified: pypy/branch/avm/pypy/translator/avm2/sudanpython.py
==============================================================================
--- pypy/branch/avm/pypy/translator/avm2/sudanpython.py	(original)
+++ pypy/branch/avm/pypy/translator/avm2/sudanpython.py	Mon Mar 15 02:01:00 2010
@@ -15,11 +15,10 @@
 from pypy.translator.avm2.entrypoint import LibraryEntryPoint
 
 class AbcDef:
-    def __init__(self, name, namespace, functions=[], dontmangle=True, isnetmodule=False):
+    def __init__(self, name, namespace, functions=[], dontmangle=True):
         self.name = name
         self.namespace = namespace
         self.functions = functions # [(function, annotation), ...]
-        self.isnetmodule = isnetmodule
         self.driver = TranslationDriver()
         if dontmangle:
             self.driver.config.translation.ootype.mangle = False
@@ -30,7 +29,7 @@
 
     def get_entrypoint(self, bk):
         graphs = [bk.getdesc(f).cachedgraph(None) for f, _ in self.functions]
-        return LibraryEntryPoint(self.name, graphs, self.isnetmodule)
+        return LibraryEntryPoint(self.name, graphs)
 
     def compile(self):
         # add all functions to the appropriate namespace
@@ -38,7 +37,7 @@
             for func, _ in self.functions:
                 if not hasattr(func, '_namespace_'):
                     func._namespace_ = self.namespace
-        self.driver.proceed(['compile_cli'])
+        self.driver.proceed(['compile_tamarin'])
 
 class export(object):
     def __new__(self, *args, **kwds):
@@ -119,7 +118,7 @@
     return mydict[name]
 
 
-def compile_abc(filename, abcname=None, copy_dll=True):
+def compile_abc(filename, abcname=None):
     dirname, name = os.path.split(filename)
     if abcname is None:
         abcname, _ = os.path.splitext(name)
@@ -131,11 +130,9 @@
     execfile(filename, module.__dict__)
     sys.path.pop(0)
 
-    dll = AbcDef(dllname, namespace)
-    dll.functions = collect_entrypoints(module.__dict__)
-    dll.compile()
-    if copy_dll:
-        dll.driver.copy_cli_dll()
+    abc = AbcDef(abcname, namespace)
+    abc.functions = collect_entrypoints(module.__dict__)
+    abc.compile()
 
 def main(argv):
     if len(argv) == 2:
@@ -153,7 +150,7 @@
     if not os.path.exists(filename):
         print >> sys.stderr, "Cannot find file %s" % filename
         sys.exit(1)
-    compile_dll(filename, dllname)
+    compile_abc(filename, dllname)
 
 if __name__ == '__main__':
     main(sys.argv)

Modified: pypy/branch/avm/pypy/translator/avm2/test/mylib.py
==============================================================================
--- pypy/branch/avm/pypy/translator/avm2/test/mylib.py	(original)
+++ pypy/branch/avm/pypy/translator/avm2/test/mylib.py	Mon Mar 15 02:01:00 2010
@@ -1,4 +1,4 @@
-from pypy.translator.cli.carbonpython import export
+from pypy.translator.avm2.sudanpython import export
 
 @export(int, int)
 def sum(a, b):

Modified: pypy/branch/avm/pypy/translator/avm2/test/test_carbonpython.py
==============================================================================
--- pypy/branch/avm/pypy/translator/avm2/test/test_carbonpython.py	(original)
+++ pypy/branch/avm/pypy/translator/avm2/test/test_carbonpython.py	Mon Mar 15 02:01:00 2010
@@ -4,7 +4,7 @@
 import os
 import os.path
 from pypy.tool import udir
-from pypy.translator.cli.rte import Target
+from pypy.translator.cli.1rte import Target
 from pypy.translator.cli.carbonpython import DllDef, export, collect_entrypoints,\
      collect_class_entrypoints, compile_dll
 from pypy.translator.cli.test.runtest import CliFunctionWrapper, CliTest

Modified: pypy/branch/avm/pypy/translator/avm2/types_.py
==============================================================================
--- pypy/branch/avm/pypy/translator/avm2/types_.py	(original)
+++ pypy/branch/avm/pypy/translator/avm2/types_.py	Mon Mar 15 02:01:00 2010
@@ -88,10 +88,9 @@
     # weakref = CliClassType('pypylib', 'pypy.runtime.WeakReference')
     type   =  T('Class')
     object =  T('Object')
-    # list   =  N('List', 'pypy.lib')
     list   =  Avm2ArrayType
-    dict   =  N('Dict', 'pypy.lib')
-    sb     =  N('StringBuilder', 'pypy.lib')
+    dict   =  T('Object')
+#    sb     =  N('StringBuilder', 'pypy.lib')
 del T
 
 _lltype_to_cts = {
@@ -105,10 +104,10 @@
     ootype.Char: types.string,
     ootype.UniChar: types.string,
     ootype.Class: types.type,
-    ootype.String: types.string,
-    ootype.StringBuilder: types.sb,
-    ootype.Unicode: types.string,
-    ootype.UnicodeBuilder: types.sb,
+#   ootype.String: types.string,
+#   ootype.StringBuilder: types.sb,
+#   ootype.Unicode: types.string,
+#   ootype.UnicodeBuilder: types.sb,
 
     # maps generic types to their ordinal
     ootype.List.SELFTYPE_T: types.list,
@@ -175,6 +174,14 @@
 
     def escape_name(self, name):
         return name
+
+    def graph_to_qname(self, graph):
+        func_name = self.graph.name
+        namespace = getattr(self.graph, '_namespace_', None)
+        if namespace:
+            return constants.packagedQName(namespace, func_name)
+        else:
+            return constants.QName(func_name)
     
     # def ctor_name(self, t):
     #     return 'instance void %s::.ctor()' % self.lltype_to_cts(t)



More information about the Pypy-commit mailing list