[pypy-svn] r35410 - in pypy/dist/pypy/lang/js: . test

santagada at codespeak.net santagada at codespeak.net
Wed Dec 6 21:04:43 CET 2006


Author: santagada
Date: Wed Dec  6 21:04:23 2006
New Revision: 35410

Modified:
   pypy/dist/pypy/lang/js/astgen.py
   pypy/dist/pypy/lang/js/interpreter.py
   pypy/dist/pypy/lang/js/parser.py
   pypy/dist/pypy/lang/js/test/test_interp.py
Log:
starting to make the support for named functions

Modified: pypy/dist/pypy/lang/js/astgen.py
==============================================================================
--- pypy/dist/pypy/lang/js/astgen.py	(original)
+++ pypy/dist/pypy/lang/js/astgen.py	Wed Dec  6 21:04:23 2006
@@ -6,6 +6,7 @@
 
 class Node(object):
     __metaclass__ = extendabletype
+    # TODO Add line info for debug
 #    def __init__(self, lineno = 1):
 #        self.lineno = lineno
 
@@ -46,12 +47,11 @@
         self.right = right
 
 class Function(Node):
-    def __init__(self, params, body, scope):
+    def __init__(self, name, params, body, scope):
+        self.name = name
         self.params = params
         self.body = body
         self.scope = scope
-        #w_obj = W_Object({}, function=self)
-        #self.scope = Scope(copy(scope.dict))
 
 class Group(Node):
     def __init__(self, expr):
@@ -107,7 +107,10 @@
 class Script(Node):
     def __init__(self, nodes, var_decl, func_decl):
         self.nodes = nodes
+        import pdb
+        #pdb.set_trace()
         [scope_manager.add_variable(id.name, w_Undefined) for id in var_decl]
+        [scope_manager.add_variable(id.name, id) for id in func_decl]
         self.var_decl = var_decl
         self.func_decl = func_decl
 
@@ -173,13 +176,14 @@
     elif tp == 'DOT':
         return Dot(from_dict(d['0']), from_dict(d['1']))
     elif tp == 'FUNCTION':
+        name = d['name']
         scope = scope_manager.enter_scope()
         body = from_dict(d['body'])
         if d['params'] == '':
             params = []
         else:
             params = d['params'].split(',')
-        f = Function(params, body, scope)
+        f = Function(name, params, body, scope)
         scope_manager.leave_scope()
         return f
     elif tp == 'GROUP':
@@ -219,11 +223,16 @@
         return Return(from_dict(d['value']))
     elif tp == 'SCRIPT':
         # TODO: get function names
+        if isinstance(d['funDecls'], dict):
+            func_decl = [from_dict(d['funDecls']),]
+        else:
+            func_decl = [from_dict(x) for x in d['funDecls']]
+        
         if isinstance(d['varDecls'], dict):
             var_decl = [from_dict(d['varDecls']),]
         else:
             var_decl = [from_dict(x) for x in d['varDecls']]
-        return Script(getlist(d), var_decl, [])
+        return Script(getlist(d), var_decl, func_decl)
     elif tp == 'SEMICOLON':
         return Semicolon(from_dict(d['expression']))
     elif tp == 'STRING':

Modified: pypy/dist/pypy/lang/js/interpreter.py
==============================================================================
--- pypy/dist/pypy/lang/js/interpreter.py	(original)
+++ pypy/dist/pypy/lang/js/interpreter.py	Wed Dec  6 21:04:23 2006
@@ -114,7 +114,6 @@
             return self.elsePart.call(context)
 
 class __extend__(Group):
-    """The __extend__ class."""
     def call(self, context = None):
         return self.expr.call(context)
 
@@ -123,6 +122,7 @@
     Implements the Abstract Relational Comparison x < y
     Still not 100% to the spec
     """
+    # TODO complete the funcion with strings comparison
     s1 = x.ToPrimitive('Number')
     s2 = y.ToPrimitive('Number')
     if not (isinstance(s1, W_String) and isinstance(s2, W_String)):

Modified: pypy/dist/pypy/lang/js/parser.py
==============================================================================
--- pypy/dist/pypy/lang/js/parser.py	(original)
+++ pypy/dist/pypy/lang/js/parser.py	Wed Dec  6 21:04:23 2006
@@ -2,7 +2,8 @@
 """ Using narcisus to generate code
 """
 
-# 1st attempt - exec the code
+# FIXME Rename this file (overwrite the std python lib)
+# TODO Should be replaced by a real parser
 
 import os
 import py

Modified: pypy/dist/pypy/lang/js/test/test_interp.py
==============================================================================
--- pypy/dist/pypy/lang/js/test/test_interp.py	(original)
+++ pypy/dist/pypy/lang/js/test/test_interp.py	Wed Dec  6 21:04:23 2006
@@ -252,4 +252,12 @@
         self.assert_prints(parse_d("""
         var x;x=3; print(x)"""), ["3"])
         
+    def test_fun_decl(self):
+        py.test.skip("still not ready")
+        self.assert_prints(parse_d("""
+        function x () { print('i work')}
+        x()
+        """), ["i work"])
+    
+        
 



More information about the Pypy-commit mailing list