[pypy-svn] r39989 - pypy/dist/pypy/lang/js

santagada at codespeak.net santagada at codespeak.net
Tue Mar 6 16:56:41 CET 2007


Author: santagada
Date: Tue Mar  6 16:56:41 2007
New Revision: 39989

Modified:
   pypy/dist/pypy/lang/js/jsparser.py
   pypy/dist/pypy/lang/js/operations.py
Log:
some rpython fixes

Modified: pypy/dist/pypy/lang/js/jsparser.py
==============================================================================
--- pypy/dist/pypy/lang/js/jsparser.py	(original)
+++ pypy/dist/pypy/lang/js/jsparser.py	Tue Mar  6 16:56:41 2007
@@ -5,10 +5,11 @@
 # TODO Should be replaced by a real parser
 
 import os
-import py
+import os.path as path
 import re
 from pypy.rlib.parsing.ebnfparse import parse_ebnf, make_parse_function
 from pypy.rlib.parsing.ebnfparse import Symbol
+from pypy.rlib.streamio import open_file_as_stream
 
 DEBUG = False
 
@@ -35,12 +36,18 @@
         print code_string
         print "------ put:"
         print stripped_code
-    jsdir = py.path.local(__file__).dirpath().join("js")
-    jsdefs = jsdir.join("jsdefs.js").read()
-    jsparse = jsdir.join("jsparse.js").read()
-    f = py.test.ensuretemp("jsinterp").join("tobeparsed.js")
+    jsdir = path.join(path.dirname(__file__),"js")
+    f_jsdefs = open_file_as_stream(path.join(jsdir, "jsdefs.js")) 
+    jsdefs = f_jsdefs.readall()
+    f_jsdefs.close()
+    f_jsparse = open_file_as_stream(path.join(jsdir, "jsparse.js"))
+    jsparse = f_jsparse.readall()
+    f_jsparse.close()
+    fname = path.join(path.dirname(__file__) ,"tobeparsed.js")
+    f = open_file_as_stream(fname, 'w')
     f.write(jsdefs+jsparse+"print(parse('%s'));\n" % stripped_code)
-    pipe = os.popen("js -f "+str(f), 'r')
+    f.close()
+    pipe = os.popen("js -f "+fname, 'r')
     retval = pipe.read()
     if not retval.startswith("{"):
         raise JsSyntaxError(retval)

Modified: pypy/dist/pypy/lang/js/operations.py
==============================================================================
--- pypy/dist/pypy/lang/js/operations.py	(original)
+++ pypy/dist/pypy/lang/js/operations.py	Tue Mar  6 16:56:41 2007
@@ -42,7 +42,7 @@
                 self.end = 0
             self.from_tree(t)
 
-    def from_tree(t):
+    def from_tree(self, t):
         """
         Initializes the content from the AST specific for each node type
         """
@@ -444,7 +444,7 @@
         else:
             return W_Boolean(s5)
 
-def AEC(x, y):
+def AEC(ctx, x, y):
     """
     Implements the Abstract Equality Comparison x == y
     trying to be fully to the spec
@@ -474,19 +474,19 @@
            (type1 == "null" and type2 == "undefined"):
             return True
         if type1 == "number" and type2 == "string":
-            return AEC(x, W_Number(y.ToNumber()))
+            return AEC(ctx, x, W_Number(y.ToNumber()))
         if type1 == "string" and type2 == "number":
-            return AEC(W_Number(x.ToNumber()), y)
+            return AEC(ctx, W_Number(x.ToNumber()), y)
         if type1 == "boolean":
-            return AEC(W_Number(x.ToNumber()), y)
+            return AEC(ctx, W_Number(x.ToNumber()), y)
         if type2 == "boolean":
-            return AEC(x, W_Number(y.ToNumber()))
+            return AEC(ctx, x, W_Number(y.ToNumber()))
         if (type1 == "string" or type1 == "number") and \
             type2 == "object":
-            return AEC(x, y.ToPrimitive())
+            return AEC(ctx, x, y.ToPrimitive(ctx))
         if (type2 == "string" or type2 == "number") and \
             type1 == "object":
-            return AEC(x.ToPrimitive(), y)
+            return AEC(ctx, x.ToPrimitive(ctx), y)
         return False
             
         
@@ -505,13 +505,13 @@
     opcode = 'EQ'
     
     def decision(self, ctx, op1, op2):
-        return W_Boolean(AEC(op1, op2))
+        return W_Boolean(AEC(ctx, op1, op2))
 
 class Ne(BinaryComparisonOp):
     opcode = 'NE'
     
     def decision(self, ctx, op1, op2):
-        return W_Boolean(not AEC(op1, op2))
+        return W_Boolean(not AEC(ctx, op1, op2))
 
 def SEC(x,y):
     """
@@ -773,7 +773,7 @@
             if isinstance(e, ExecutionReturned) and e.type == 'return':
                 return e.value
             else:
-                print "exeception in line: %s, on: %s"%(node.lineno, node.value)
+                print "exception in line: %s, on: %s"%(node.lineno, node.value)
                 raise
 
 class Semicolon(Statement):



More information about the Pypy-commit mailing list