[pypy-svn] r36415 - in pypy/dist/pypy/translator/js: . test

fijal at codespeak.net fijal at codespeak.net
Wed Jan 10 17:01:09 CET 2007


Author: fijal
Date: Wed Jan 10 17:01:06 2007
New Revision: 36415

Added:
   pypy/dist/pypy/translator/js/test/test_rclass.py
      - copied, changed from r36186, pypy/dist/pypy/translator/js/test/test_rpython.py
Removed:
   pypy/dist/pypy/translator/js/test/test_rpython.py
Modified:
   pypy/dist/pypy/translator/js/_class.py
   pypy/dist/pypy/translator/js/asmgen.py
   pypy/dist/pypy/translator/js/database.py
   pypy/dist/pypy/translator/js/function.py
   pypy/dist/pypy/translator/js/js.py
   pypy/dist/pypy/translator/js/jts.py
   pypy/dist/pypy/translator/js/test/runtest.py
   pypy/dist/pypy/translator/js/test/test_runtest.py
   pypy/dist/pypy/translator/js/test/test_typed.py
Log:
Removed deprecated files.
--Ta linia i następne zostaną zignorowane--

D    modules/test/test_xmlhttp.py
D    modules/xmlhttp.py
D    modules/bltns.py


Modified: pypy/dist/pypy/translator/js/_class.py
==============================================================================
--- pypy/dist/pypy/translator/js/_class.py	(original)
+++ pypy/dist/pypy/translator/js/_class.py	Wed Jan 10 17:01:06 2007
@@ -65,7 +65,8 @@
                 ilasm.inherits(self.name, basename)
         
         for m_name, m_meth in self.classdef._methods.iteritems():
-            f = self.db.genoo.Function(self.db, m_meth.graph, m_name, is_method = True, _class = self.name)
+            graph = getattr(m_meth, 'graph', None)
+            f = self.db.genoo.Function(self.db, graph, m_name, is_method = True, _class = self.name)
             f.render(ilasm)
         
         self.db.record_class(self.classdef, self.name)

Modified: pypy/dist/pypy/translator/js/asmgen.py
==============================================================================
--- pypy/dist/pypy/translator/js/asmgen.py	(original)
+++ pypy/dist/pypy/translator/js/asmgen.py	Wed Jan 10 17:01:06 2007
@@ -226,7 +226,7 @@
     def begin_consts(self, name):
         # load consts, maybe more try to use stack-based features?
         self.codegenerator.writeline("%s = {};"%name)
-    
+
     def new_obj(self):
         self.right_hand.append("{}")
     
@@ -249,6 +249,9 @@
     
     def load_void(self):
         self.right_hand.append("undefined")
+
+    def load_void_obj(self):
+        self.right_hand.append("{}")
     
     def begin_try(self):
         self.codegenerator.write("try ")

Modified: pypy/dist/pypy/translator/js/database.py
==============================================================================
--- pypy/dist/pypy/translator/js/database.py	(original)
+++ pypy/dist/pypy/translator/js/database.py	Wed Jan 10 17:01:06 2007
@@ -6,7 +6,6 @@
 from pypy.translator.js.opcodes import opcodes
 from pypy.translator.js.function import Function
 from pypy.translator.js.log import log
-from pypy.translator.js.jts import JTS
 from pypy.translator.js._class import Class
 from pypy.translator.js.support import JavascriptNameManager
 
@@ -124,18 +123,20 @@
         else:
             return const
 
-    def gen_constants(self, ilasm):
-        if not self.rendered:
-            ilasm.begin_consts(self.const_var.name)
-        
+    def gen_constants(self, ilasm, pending):
         try:
             while True:
                 const,name = self.pending_consts.pop()
                 const.record_fields()
         except IndexError:
             pass
-        
 
+        if pending:
+            return
+
+        if not self.rendered:
+            ilasm.begin_consts(self.const_var.name)
+        
         def generate_constants(consts):
             all_c = [const for const,name in consts.iteritems()]
             dep_ok = set()
@@ -162,15 +163,18 @@
         log("Consts: %r"%self.consts)
         # We need to keep track of fields to make sure
         # our items appear earlier than us
-        for const,name in generate_constants(self.consts):
+        to_init = []
+        for const, name in generate_constants(self.consts):
             log("Recording %r %r"%(const,name))
             ilasm.load_local(self.const_var)
             const.init(ilasm)
             ilasm.set_field(None, name)
             ilasm.store_void()
-            const.init_fields(ilasm, self.const_var, name)
+            to_init.append((const, name))
             #ilasm.field(name, const.get_type(), static=True)
-    
+        for const, name in to_init:
+            const.init_fields(ilasm, self.const_var, name)
+
     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/js/function.py
==============================================================================
--- pypy/dist/pypy/translator/js/function.py	(original)
+++ pypy/dist/pypy/translator/js/function.py	Wed Jan 10 17:01:06 2007
@@ -19,42 +19,6 @@
 
 import re
 
-class LoopFinder(object):
-
-    def __init__(self, startblock):
-        self.loops = {}
-        self.parents = {startblock: startblock}
-        self.temps = {}
-        self.seen = set ()
-        self.block_seeing_order = {}
-        self.visit_Block(startblock)
-   
-    def visit_Block(self, block, switches=[]):
-        #self.temps.has_key()
-        self.seen.add(block)
-        self.block_seeing_order[block] = []
-        if block.exitswitch:
-            switches.append(block)
-            self.parents[block] = block
-        for link in block.exits:
-            self.block_seeing_order[block].append(link)
-            self.visit_Link(link, switches) 
-
-    def visit_Link(self, link, switches):
-        if link.target in switches:
-            #if self.loops.has_key(link.target):
-            #    # double loop
-            #    pass
-            block_switch = self.block_seeing_order[link.target]
-            if len(self.block_seeing_order[link.target]) == 1:
-                self.loops[(block_switch[0].exitcase,link.target)] = block_switch[0].exitcase
-            else:
-                self.loops[(block_switch[1].exitcase,link.target)] = block_switch[1].exitcase
-            
-        if not link.target in self.seen:
-            self.parents[link.target] = self.parents[link.prevblock]
-            self.visit_Block(link.target, switches)
-
 class Function(Node, Generator):
     def __init__(self, db, graph, name=None, is_method=False, is_entrypoint=False, _class = None):
         self.db = db

Modified: pypy/dist/pypy/translator/js/js.py
==============================================================================
--- pypy/dist/pypy/translator/js/js.py	(original)
+++ pypy/dist/pypy/translator/js/js.py	Wed Jan 10 17:01:06 2007
@@ -99,7 +99,7 @@
         self.gen_entrypoint()
         while self.db._pending_nodes:
             self.gen_pendings()
-            self.db.gen_constants(self.ilasm)
+            self.db.gen_constants(self.ilasm, self.db._pending_nodes)
         self.ilasm.close()
         return self.tmpfile.strpath
         

Modified: pypy/dist/pypy/translator/js/jts.py
==============================================================================
--- pypy/dist/pypy/translator/js/jts.py	(original)
+++ pypy/dist/pypy/translator/js/jts.py	Wed Jan 10 17:01:06 2007
@@ -67,13 +67,11 @@
         # TODO: use callvirt only when strictly necessary
         if isinstance(obj, ootype.Instance):
             owner, meth = obj._lookup(name)
-            class_name = obj._name
-            return self.graph_to_signature(meth.graph, True, class_name)
-
+            METH = meth._TYPE
+            return obj._name, METH.ARGS
         elif isinstance(obj, ootype.BuiltinType):
             meth = oopspec.get_method(obj, name)
             class_name = self.lltype_to_cts(obj)
-            #arg_list = ', '.join(arg_types)
             return class_name,meth.ARGS
         else:
             assert False
@@ -105,6 +103,8 @@
         elif _type is UniChar or _type is Char:
             #log("Constant %r"%v)
             s = repr(v)
+            if s.startswith('u'):
+                s = s[1:]
             if s != "'\''":
                 s.replace("'", '"')
             val = s

Modified: pypy/dist/pypy/translator/js/test/runtest.py
==============================================================================
--- pypy/dist/pypy/translator/js/test/runtest.py	(original)
+++ pypy/dist/pypy/translator/js/test/runtest.py	Wed Jan 10 17:01:06 2007
@@ -1,5 +1,4 @@
 '''
-    Skipped tests should still be fixed. (or only run with py.test --browser)
     Sests with DONT in front of them will probably not be fixed for the time being.
 '''
 
@@ -109,6 +108,11 @@
         for s in output.split('\n'):
             log(s)
 
+        return self.reinterpret(s)
+
+    def reinterpret(cls, s):
+        while s.startswith(" "):
+            s = s[1:] # :-) quite inneficient, but who cares
         if s == 'false':
             res = False
         elif s == 'true':
@@ -121,13 +125,16 @@
             res = (1e300 * 1e300) / (1e300 * 1e300)
         elif s.startswith("uncaught exception:"):
             raise LLException(str(s))
+        elif s.startswith('[') or s.startswith('('):
+            l = s[1:-1].split(',')
+            res = [cls.reinterpret(i) for i in l]
         else:
-            log('javascript result:', s)
             try:
-                res = eval(s)
-            except:
+                res = float(s)
+            except ValueError:
                 res = str(s)
         return res
+    reinterpret = classmethod(reinterpret)
 
 class JsTest(BaseRtypingTest, OORtypeMixin):
     #def __init__(self):
@@ -143,7 +150,7 @@
         #    self._func = fn
         #    self._ann = ann
         #    self._cli_func = compile_function(fn, ann)
-        #    return self._cli_func
+        #   return self._cli_func
         source = py.code.Source("""
         def %s():
             from pypy.rlib.nonconst import NonConstant

Modified: pypy/dist/pypy/translator/js/test/test_runtest.py
==============================================================================
--- pypy/dist/pypy/translator/js/test/test_runtest.py	(original)
+++ pypy/dist/pypy/translator/js/test/test_runtest.py	Wed Jan 10 17:01:06 2007
@@ -51,6 +51,11 @@
     assert f(False, 13, 12.5) == combined_params(False, 13, 12.5)
     assert f(True , 13, 12.5) == combined_params(True , 13, 12.5)
 
+def test_return_function():
+    rp = compile_function.reinterpret
+    assert rp('[a,b]') == ["a", "b"]
+    #assert rp('(true,[a,b])') == [True, ["a", "b"]]
+
 ##def test_multiple_function():
 ##    def one():
 ##        return 1

Modified: pypy/dist/pypy/translator/js/test/test_typed.py
==============================================================================
--- pypy/dist/pypy/translator/js/test/test_typed.py	(original)
+++ pypy/dist/pypy/translator/js/test/test_typed.py	Wed Jan 10 17:01:06 2007
@@ -172,7 +172,7 @@
             assert res == testfn(i, j)
 
 def test_unichr_eq():
-    py.test.skip("Unicode support")
+    #py.test.skip("Unicode support")
     l = list(u'Hello world')
     def f(i, j):
         return l[i] == l[j]
@@ -183,7 +183,7 @@
             assert res == f(i,j) 
 
 def test_unichr_ne():
-    py.test.skip("Unicode support")
+    #py.test.skip("Unicode support")
     l = list(u'Hello world')
     def f(i, j):
         return l[i] != l[j]
@@ -195,7 +195,7 @@
 
 def test_unichr_ord():
     #py.test.skip("ord semantics")
-    py.test.skip("Unicode support")
+    #py.test.skip("Unicode support")
     l = list(u'Hello world')
     def f(i):
         return ord(l[i]) 
@@ -205,7 +205,7 @@
         assert res == f(i)
 
 def test_unichr_unichr():
-    py.test.skip("Unicode support")
+    #py.test.skip("Unicode support")
     l = list(u'Hello world')
     def f(i, j):
         return l[i] == unichr(j)



More information about the Pypy-commit mailing list