[pypy-svn] r40006 - in pypy/dist/pypy/lang/js: . test
santagada at codespeak.net
santagada at codespeak.net
Wed Mar 7 01:01:40 CET 2007
Author: santagada
Date: Wed Mar 7 01:01:36 2007
New Revision: 40006
Modified:
pypy/dist/pypy/lang/js/interpreter.py
pypy/dist/pypy/lang/js/jsparser.py
pypy/dist/pypy/lang/js/operations.py
pypy/dist/pypy/lang/js/test/test_interp.py
Log:
more rpython corrections, and a new test
Modified: pypy/dist/pypy/lang/js/interpreter.py
==============================================================================
--- pypy/dist/pypy/lang/js/interpreter.py (original)
+++ pypy/dist/pypy/lang/js/interpreter.py Wed Mar 7 01:01:36 2007
@@ -22,10 +22,11 @@
return load_source(code.ToString()).execute(ctx)
def functionjs(ctx, args, this):
- if len(args) >= 1:
- fbody = args[-1].GetValue().ToString()
+ tam = len(args)
+ if tam >= 1:
+ fbody = args[tam-1].GetValue().ToString()
argslist = []
- for i in range(len(args)-1):
+ for i in range(tam-1):
argslist.append(args[i].GetValue().ToString())
fargs = ','.join(argslist)
functioncode = "__anon__ = function (%s) {%s}"%(fargs, fbody)
Modified: pypy/dist/pypy/lang/js/jsparser.py
==============================================================================
--- pypy/dist/pypy/lang/js/jsparser.py (original)
+++ pypy/dist/pypy/lang/js/jsparser.py Wed Mar 7 01:01:36 2007
@@ -9,7 +9,7 @@
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
+from pypy.rlib.streamio import open_file_as_stream, fdopen_as_stream
DEBUG = False
@@ -57,10 +57,11 @@
except OSError:
pass
cmd = ['/bin/sh', '-c', 'js -f '+fname]
- os.execvp(cmd[0], cmd)
+ os.execv(cmd[0], cmd)
os.close(c2pwrite)
- retval = os.read(c2pread, -1)
- os.close(c2pread)
+ f = fdopen_as_stream(c2pread, 'r', 0)
+ retval = f.readall()
+ f.close()
if not retval.startswith("{"):
raise JsSyntaxError(retval)
if DEBUG:
@@ -71,7 +72,10 @@
def unquote(t):
if isinstance(t, Symbol):
if t.symbol == "QUOTED_STRING":
- t.additional_info = t.additional_info[1:-1].replace("\\'", "'").replace("\\\\", "\\")
+ stop = len(t.additional_info)-1
+ if stop < 0:
+ stop = 0
+ t.additional_info = t.additional_info[1:].replace("\\'", "'").replace("\\\\", "\\")
else:
for i in t.children:
unquote(i)
Modified: pypy/dist/pypy/lang/js/operations.py
==============================================================================
--- pypy/dist/pypy/lang/js/operations.py (original)
+++ pypy/dist/pypy/lang/js/operations.py Wed Mar 7 01:01:36 2007
@@ -14,7 +14,7 @@
is used to match the AST operation to the efective execution node.
"""
opcode = None
- def __init__(self, t=None, type='', value='', lineno=0, start=0, end=0):
+ def __init__(self, t=None, type_='', value='', lineno=0, start=0, end=0):
"""
Not to be overriden by subclasses, this method thakes the basic node
information from the AST needed for tracing and debuging. if you want
@@ -22,7 +22,7 @@
call.
"""
if t is None:
- self.type = type
+ self.type = type_
self.value = value
self.lineno = lineno
self.start = start
@@ -152,11 +152,11 @@
elif op == "%":
val = Mod().mathop(ctx, v1.GetValue(), v3)
elif op == "&":
- val = BitwiseAnd().mathop(ctx, v1.GetValue(), v3)
+ val = BitwiseAnd().decision(ctx, v1.GetValue().ToInt32(), v3.ToInt32())
elif op == "|":
- val = BitwiseOR().mathop(ctx, v1.GetValue(), v3)
+ val = BitwiseOR().decision(ctx, v1.GetValue().ToInt32(), v3.ToInt32())
elif op == "^":
- val = BitwiseXOR().mathop(ctx, v1.GetValue(), v3)
+ val = BitwiseXOR().decision(ctx, v1.GetValue().ToInt32(), v3.ToInt32())
else:
print op
raise NotImplementedError()
@@ -709,8 +709,8 @@
opcode = 'MOD'
def mathop(self, ctx, nleft, nright):
- fleft = nleft.ToNumber()
- fright = nright.ToNumber()
+ fleft = nleft.ToInt32()
+ fright = nright.ToInt32()
return W_Number(fleft % fright)
@@ -718,8 +718,8 @@
opcode = 'DIV'
def mathop(self, ctx, nleft, nright):
- fleft = nleft.ToNumber()
- fright = nright.ToNumber()
+ fleft = nleft.ToInt32()
+ fright = nright.ToInt32()
return W_Number(fleft / fright)
class Minus(BinaryNumberOp):
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 Mar 7 01:01:36 2007
@@ -496,3 +496,10 @@
}
print(x)
""", ['4', '2', '3', '4'])
+
+ def test_bitops(self):
+ self.assert_prints("""
+ print(2 ^ 2)
+ print(2 & 3)
+ print(2 | 3)
+ """, ['0', '2', '3'])
More information about the Pypy-commit
mailing list