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

fijal at codespeak.net fijal at codespeak.net
Tue Oct 31 10:29:59 CET 2006


Author: fijal
Date: Tue Oct 31 10:29:57 2006
New Revision: 33934

Modified:
   pypy/dist/pypy/lang/js/astgen.py
   pypy/dist/pypy/lang/js/interpreter.py
   pypy/dist/pypy/lang/js/jsobj.py
   pypy/dist/pypy/lang/js/test/test_interp.py
Log:
(santagada, fijal) - String literals


Modified: pypy/dist/pypy/lang/js/astgen.py
==============================================================================
--- pypy/dist/pypy/lang/js/astgen.py	(original)
+++ pypy/dist/pypy/lang/js/astgen.py	Tue Oct 31 10:29:57 2006
@@ -52,6 +52,10 @@
 class List(Node):
     def __init__(self, nodes):
         self.nodes = nodes
+        
+class String(Node):
+    def __init__(self, strval):
+        self.strval = strval
 
 def getlist(d):
     lgt = int(d['length'])
@@ -77,5 +81,7 @@
         return Plus(from_dict(d['0']), from_dict(d['1']))
     elif tp == 'ASSIGN':
         return Assign(from_dict(d['0']), from_dict(d['1']))
+    elif tp == 'STRING':
+        return String(d['value'])
     else:
         raise NotImplementedError("Dont know how to handler %s" % tp)

Modified: pypy/dist/pypy/lang/js/interpreter.py
==============================================================================
--- pypy/dist/pypy/lang/js/interpreter.py	(original)
+++ pypy/dist/pypy/lang/js/interpreter.py	Tue Oct 31 10:29:57 2006
@@ -56,3 +56,7 @@
 class __extend__(List):
     def call(self, context=None):
         return [node.call(context) for node in self.nodes]
+
+class __extend__(String):
+    def call(self, context=None):
+        return W_String(self.strval)

Modified: pypy/dist/pypy/lang/js/jsobj.py
==============================================================================
--- pypy/dist/pypy/lang/js/jsobj.py	(original)
+++ pypy/dist/pypy/lang/js/jsobj.py	Tue Oct 31 10:29:57 2006
@@ -44,6 +44,7 @@
 #        return self.strval
 
     def __str__(self):
+        # INSANE - should be like 'str' or so
         return self.strval
 
 class W_Number(W_Root):

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	Tue Oct 31 10:29:57 2006
@@ -34,3 +34,11 @@
         self.assert_prints(parse_d("x=3;print(x);"), ["3"])
         self.assert_prints(parse_d("x=3;y=4;print(x+y);"), ["7"])
 
+    def test_string_var(self):
+        self.assert_prints(parse_d("print(\"sss\");"), ["sss"])
+    
+    def test_string_concat(self):
+        self.assert_prints(parse_d('x="xxx"; y="yyy"; print(x+y);'), ["xxxyyy"])
+    
+    def test_string_num_concat(self):
+        self.assert_prints(parse_d('x=4; y="x"; print(x+y, y+x);'), ["4x,x4"])



More information about the Pypy-commit mailing list