[pypy-svn] r28468 - in pypy/dist/pypy/translator/js2: . modules

fijal at codespeak.net fijal at codespeak.net
Wed Jun 7 17:37:34 CEST 2006


Author: fijal
Date: Wed Jun  7 17:37:33 2006
New Revision: 28468

Modified:
   pypy/dist/pypy/translator/js2/database.py
   pypy/dist/pypy/translator/js2/js.py
   pypy/dist/pypy/translator/js2/modules/dom.py
Log:
Added generic ootypesystem backend usage.


Modified: pypy/dist/pypy/translator/js2/database.py
==============================================================================
--- pypy/dist/pypy/translator/js2/database.py	(original)
+++ pypy/dist/pypy/translator/js2/database.py	Wed Jun  7 17:37:33 2006
@@ -24,12 +24,12 @@
     from sets import Set as set
 
 class LowLevelDatabase(object):
-    def __init__(self, type_system_class = JTS, opcode_dict = opcodes, function_class = Function):
+    def __init__(self, backend_mapping = None):
         self._pending_nodes = set()
-        self.opcode_dict = opcode_dict
+        self.opcode_dict = backend_mapping['opcode_dict']
         self._rendered_nodes = set()
-        self.function_class = function_class
-        self.type_system_class = type_system_class
+        self.function_class = backend_mapping['function_class']
+        self.type_system_class = backend_mapping['type_system_class']
         self.classes = {} # classdef --> class_name
         self.functions = {} # graph --> function_name
         self.function_names = {} # graph --> real_name
@@ -39,7 +39,8 @@
         self.const_var = Variable("__consts")
         self.name_manager = JavascriptNameManager(self)
         self.pending_consts = []
-        self.cts = type_system_class(self)
+        self.backend_mapping = backend_mapping
+        self.cts = self.type_system_class(self)
         self.prepare_builtins()
     
     def prepare_builtins(self):
@@ -159,9 +160,6 @@
             const.init_fields(ilasm, self.const_var, name)
             #ilasm.field(name, const.get_type(), static=True)
         
-    def gen_delegate_types(self, ilasm):
-        pass
-    
     def load_const(self, type_, value, ilasm):
         if self.is_primitive(type_):
             ilasm.load_const(self.cts.primitive_repr(type_, value))

Modified: pypy/dist/pypy/translator/js2/js.py
==============================================================================
--- pypy/dist/pypy/translator/js2/js.py	(original)
+++ pypy/dist/pypy/translator/js2/js.py	Wed Jun  7 17:37:33 2006
@@ -23,7 +23,7 @@
 from pypy.translator.js2.function import Function
 from pypy.translator.js2.database import LowLevelDatabase
 
-from pypy.translator.cli.gencli import GenCli
+from pypy.translator.oosupport.genoo import GenOO
 
 from heapq import heappush, heappop
 
@@ -33,10 +33,17 @@
         path = os.path.join(path, p)
     return path
 
-class JS(GenCli):
+class JS(GenOO):
     def __init__(self, translator, functions=[], stackless=False, compress=False, logging=False):
-        GenCli.__init__(self, udir, translator, type_system_class = JTS, opcode_dict = opcodes,\
-            name_suffix = '.js', function_class = Function, database_class = LowLevelDatabase)
+        backend_mapping = {
+            'type_system_class' : JTS,
+            'opcode_dict' : opcodes,
+            'name_suffix' : '.js',
+            'function_class' : Function,
+            'database_class' : LowLevelDatabase,
+            'asm_class' : AsmGen,
+        }
+        GenOO.__init__(self, udir, translator, backend_mapping = backend_mapping, pending_graphs = ())
         self.translator = translator
     
     def gen_pendings(self):
@@ -60,7 +67,7 @@
         # not be used as inlined, rather another script to load
         # this is just workaround
         
-        self.generate_source(AsmGen)
+        self.generate_source()
 
         data = self.tmpfile.open().read()
         src_filename = _path_join(os.path.dirname(__file__), 'jssrc', 'misc.js')

Modified: pypy/dist/pypy/translator/js2/modules/dom.py
==============================================================================
--- pypy/dist/pypy/translator/js2/modules/dom.py	(original)
+++ pypy/dist/pypy/translator/js2/modules/dom.py	Wed Jun  7 17:37:33 2006
@@ -21,10 +21,11 @@
 class Node(object):
     _rpython_hints = {'_suggested_external' : True}
     
-    def __init__(self):
+    def __init__(self, parent = None):
         self.innerHTML = ""
         self.style = None
         self.subnodes = {}
+        self.parent = parent
     
     def getElementById(self, id):
         try:
@@ -33,12 +34,28 @@
             self.subnodes[id] = Node()
             return self.subnodes[id]
     
+    def createElement(self, type):
+        return Node()
+    
     def setAttribute(self, name, style_str):
         if name == 'style':
             self.style = Style( style_str)
+        elif name == 'id':
+            self.id = style_str
+        elif name == 'src':
+            self.src = style_str
+    
+    def appendChild(self, elem):
+        self.subnodes[elem.id] = elem
+
+class Document(Node):
+    def __init__(self):
+        Node.__init__(self)
+        self.body = Node()
+    
 
 def get_document():
-    return Node()
+    return Document()
 
 get_document.suggested_primitive = True
 
@@ -56,3 +73,4 @@
     #pass
 
 setTimeout.suggested_primitive = True
+



More information about the Pypy-commit mailing list