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

fijal at codespeak.net fijal at codespeak.net
Mon Oct 30 16:01:00 CET 2006


Author: fijal
Date: Mon Oct 30 16:00:59 2006
New Revision: 33903

Modified:
   pypy/dist/pypy/lang/js/astgen.py
   pypy/dist/pypy/lang/js/interpreter.py
   pypy/dist/pypy/lang/js/test/test_interp.py
Log:
(santagada, fijal) - Added print statement


Modified: pypy/dist/pypy/lang/js/astgen.py
==============================================================================
--- pypy/dist/pypy/lang/js/astgen.py	(original)
+++ pypy/dist/pypy/lang/js/astgen.py	Mon Oct 30 16:00:59 2006
@@ -35,6 +35,19 @@
     def __init__(self, num):
         self.num = num
 
+class Call(Node):
+    def __init__(self, identifier, arglist):
+        self.identifier = identifier
+        self.arglist = arglist
+
+class Identifier(Node):
+    def __init__(self, name):
+        self.name = name
+
+class List(Node):
+    def __init__(self, nodes):
+        self.nodes = nodes
+
 #class Print(Node):
 #    def __init__(self, expr):
 #        

Modified: pypy/dist/pypy/lang/js/interpreter.py
==============================================================================
--- pypy/dist/pypy/lang/js/interpreter.py	(original)
+++ pypy/dist/pypy/lang/js/interpreter.py	Mon Oct 30 16:00:59 2006
@@ -17,3 +17,12 @@
     def call(self):
         for node in self.nodes:
             node.call()
+
+class __extend__(Call):
+    def call(self):
+        assert self.identifier.name == 'print'
+        print ",".join([str(i) for i in self.arglist.call()])
+
+class __extend__(List):
+    def call(self):
+        return [node.call() for node in self.nodes]

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	Mon Oct 30 16:00:59 2006
@@ -2,7 +2,17 @@
 from pypy.lang.js.astgen import *
 from pypy.lang.js import interpreter
 
+import sys
+from StringIO import StringIO
+
 def test_simple():
     assert Plus(Number(3), Number(4)).call() == 7
 #    s = Script([Semicolon(Plus(Number(3), Number(4)))], [], [])
 #    s.call()
+    s = StringIO()
+    oldstdout = sys.stdout
+    sys.stdout = s
+
+    Script([Semicolon(Call(Identifier('print'), List([Number(1), Number(2)])))],[],[]).call()
+    assert s.getvalue() == '1,2\n'
+    sys.stdout = oldstdout



More information about the Pypy-commit mailing list