[pypy-svn] r37868 - in pypy/dist/pypy/lang/js: . test
santagada at codespeak.net
santagada at codespeak.net
Sat Feb 3 14:05:14 CET 2007
Author: santagada
Date: Sat Feb 3 14:05:13 2007
New Revision: 37868
Added:
pypy/dist/pypy/lang/js/driver.py (contents, props changed)
Modified:
pypy/dist/pypy/lang/js/interpreter.py
pypy/dist/pypy/lang/js/jsobj.py
pypy/dist/pypy/lang/js/test/test_interp.py
Log:
driver and some simple opcodes
Added: pypy/dist/pypy/lang/js/driver.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/lang/js/driver.py Sat Feb 3 14:05:13 2007
@@ -0,0 +1,32 @@
+#!/usr/bin/env python
+
+import autopath
+from py import path
+import os
+
+shell = path.local(__file__).dirpath('test', 'ecma', 'shell.js')
+
+exclusionlist = ['shell.js', 'browser.js']
+def filter(filename):
+ if filename.basename in exclusionlist or not filename.basename.endswith('.js'):
+ return False
+ else:
+ return True
+results = open('results.txt', 'w')
+for f in path.local(__file__).dirpath('test', 'ecma').visit(filter):
+ print f.basename
+ stdout = os.popen('./js_interactive.py -n -f %s -f %s'%(shell.strpath,f.strpath), 'r')
+ passed = 0
+ total = 0
+ for line in stdout.readlines():
+ if "PASSED!" in line:
+ passed += 1
+ total += 1
+ elif "FAILED!" in line:
+ total += 1
+
+ results.write('%s passed %s of %s tests\n'%(f.basename, passed, total))
+ results.flush()
+
+
+
Modified: pypy/dist/pypy/lang/js/interpreter.py
==============================================================================
--- pypy/dist/pypy/lang/js/interpreter.py (original)
+++ pypy/dist/pypy/lang/js/interpreter.py Sat Feb 3 14:05:13 2007
@@ -69,7 +69,6 @@
self.right = get_obj(t, '1')
class BinaryComparisonOp(BinaryOp):
- """super class for binary operators"""
def eval(self, ctx):
s2 = self.left.eval(ctx).GetValue()
s4 = self.right.eval(ctx).GetValue()
@@ -81,7 +80,6 @@
raise NotImplementedError
class BinaryLogicOp(BinaryOp):
- """super class for binary operators"""
pass
def writer(x):
@@ -611,6 +609,15 @@
fright = nright.ToNumber()
return W_Number(fleft * fright)
+class Mod(BinaryNumberOp):
+ opcode = 'MOD'
+
+ def mathop(self, ctx, nleft, nright):
+ fleft = nleft.ToNumber()
+ fright = nright.ToNumber()
+ return W_Number(fleft % fright)
+
+
class Div(BinaryNumberOp):
opcode = 'DIV'
@@ -843,11 +850,18 @@
return W_Boolean(not self.expr.eval(ctx).GetValue().ToBoolean())
class UMinus(UnaryOp):
- opcode = "UNARY_MINUS"
+ opcode = 'UNARY_MINUS'
def eval(self, ctx):
return W_Number(-self.expr.eval(ctx).GetValue().ToNumber())
+class UPlus(UnaryOp):
+ opcode = 'UNARY_PLUS'
+
+ def eval(self, ctx):
+ return W_Number(+self.expr.eval(ctx).GetValue().ToNumber())
+
+
astundef = Undefined()
def get_obj(t, objname):
item = get_tree_item(t, objname)
Modified: pypy/dist/pypy/lang/js/jsobj.py
==============================================================================
--- pypy/dist/pypy/lang/js/jsobj.py (original)
+++ pypy/dist/pypy/lang/js/jsobj.py Sat Feb 3 14:05:13 2007
@@ -1,6 +1,6 @@
# encoding: utf-8
-DEBUG = True
+DEBUG = False
class SeePage(NotImplementedError):
pass
@@ -318,7 +318,7 @@
return W_PrimitiveObject.Get(self, P)
def str_builtin(self, ctx, args, this):
- return W_String(ToString())
+ return W_String(self.ToString())
def ToString(self):
return ','.join(self.array)
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 Sat Feb 3 14:05:13 2007
@@ -447,4 +447,10 @@
var testcases = new Array();
var tc = testcases.length;
print('tc'+tc)
- """, ['tc0'])
\ No newline at end of file
+ """, ['tc0'])
+
+ def test_mod_op(self):
+ self.assert_prints("print(2%2)", ['0'])
+
+ def test_unary_plus(self):
+ self.assert_prints("print(+1)", ['1'])
More information about the Pypy-commit
mailing list