[pypy-svn] r40091 - in pypy/dist/pypy/lang/js: . test/ecma
santagada at codespeak.net
santagada at codespeak.net
Thu Mar 8 18:48:30 CET 2007
Author: santagada
Date: Thu Mar 8 18:48:27 2007
New Revision: 40091
Added:
pypy/dist/pypy/lang/js/js.cleanup (contents, props changed)
Modified:
pypy/dist/pypy/lang/js/interpreter.py
pypy/dist/pypy/lang/js/js_interactive.py
pypy/dist/pypy/lang/js/operations.py
pypy/dist/pypy/lang/js/test/ecma/conftest.py
Log:
some bug fixes and now using cpickle to not parse files multiple times
Modified: pypy/dist/pypy/lang/js/interpreter.py
==============================================================================
--- pypy/dist/pypy/lang/js/interpreter.py (original)
+++ pypy/dist/pypy/lang/js/interpreter.py Thu Mar 8 18:48:27 2007
@@ -2,6 +2,8 @@
import math
from pypy.lang.js.jsparser import parse, parse_bytecode
from pypy.lang.js.operations import *
+from pypy.rlib.objectmodel import we_are_translated
+
def writer(x):
print x
@@ -14,6 +16,26 @@
temp_tree = parse_bytecode(bytecode)
return from_tree(temp_tree)
+def load_file(filename):
+ # NOT RPYTHON
+ import cPickle as pickle
+ import os.path
+ base, ext = os.path.splitext(filename)
+ jscname = base+".jsc"
+ if os.path.isfile(jscname):
+ jsc = open(jscname, 'r')
+ t = pickle.load(jsc)
+ jsc.close()
+ else:
+ f = open(filename)
+ t = parse(f.read())
+ f.close()
+ jsc = open(jscname, 'w')
+ pickle.dump(t, jsc, protocol=2)
+ jsc.close()
+ return from_tree(t)
+
+
def evaljs(ctx, args, this):
if len(args) >= 1:
code = args[0]
Added: pypy/dist/pypy/lang/js/js.cleanup
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/lang/js/js.cleanup Thu Mar 8 18:48:27 2007
@@ -0,0 +1,24 @@
+#!/usr/bin/env python
+
+"""\
+js.cleanup [PATH]
+
+Delete jsc file recursively, starting from PATH (which defaults to the current
+working directory). Don't follow links and don't recurse into directories with
+a ".".
+"""
+import autopath
+import py
+
+parser = py.compat.optparse.OptionParser(usage=__doc__)
+
+if __name__ == '__main__':
+ (options, args) = parser.parse_args()
+
+ if not args:
+ args = ["."]
+ for arg in args:
+ path = py.path.local(arg)
+ print "cleaning path", path
+ for x in path.visit('*.jsc', lambda x: x.check(dotfile=0, link=0)):
+ x.remove()
Modified: pypy/dist/pypy/lang/js/js_interactive.py
==============================================================================
--- pypy/dist/pypy/lang/js/js_interactive.py (original)
+++ pypy/dist/pypy/lang/js/js_interactive.py Thu Mar 8 18:48:27 2007
@@ -41,9 +41,7 @@
def loadjs(ctx, args, this):
filename = args[0]
- f = open(filename.ToString())
- t = load_source(f.read())
- f.close()
+ t = load_file(filename.ToString())
return t.execute(ctx)
def tracejs(ctx, args, this):
Modified: pypy/dist/pypy/lang/js/operations.py
==============================================================================
--- pypy/dist/pypy/lang/js/operations.py (original)
+++ pypy/dist/pypy/lang/js/operations.py Thu Mar 8 18:48:27 2007
@@ -127,7 +127,6 @@
opcode = 'ARRAY_INIT'
def eval(self, ctx):
- #d = dict(enumerate(self.items))
array = W_Array()
for i in range(len(self.list)):
array.Put(str(i), self.list[i].eval(ctx).GetValue())
Modified: pypy/dist/pypy/lang/js/test/ecma/conftest.py
==============================================================================
--- pypy/dist/pypy/lang/js/test/ecma/conftest.py (original)
+++ pypy/dist/pypy/lang/js/test/ecma/conftest.py Thu Mar 8 18:48:27 2007
@@ -36,7 +36,7 @@
cls.interp = Interpreter()
ctx = cls.interp.global_context
shellpath = rootdir/'shell.js'
- t = load_source(shellpath.read())
+ t = load_file(str(shellpath))
t.execute(ctx)
cls.testcases = cls.interp.global_context.resolve_identifier('testcases')
cls.tc = cls.interp.global_context.resolve_identifier('tc')
@@ -54,7 +54,7 @@
return
self.init_interp()
#actually run the file :)
- t = load_source(self.fspath.read())
+ t = load_file(str(self.fspath))
try:
t.execute(self.interp.global_context)
except JsSyntaxError:
More information about the Pypy-commit
mailing list