[pypy-svn] r45347 - in pypy/dist/pypy/lang/js: . js test
santagada at codespeak.net
santagada at codespeak.net
Thu Jul 26 15:30:33 CEST 2007
Author: santagada
Date: Thu Jul 26 15:30:32 2007
New Revision: 45347
Removed:
pypy/dist/pypy/lang/js/js/
Modified:
pypy/dist/pypy/lang/js/astbuilder.py
pypy/dist/pypy/lang/js/commit
pypy/dist/pypy/lang/js/driver.py
pypy/dist/pypy/lang/js/interpreter.py
pypy/dist/pypy/lang/js/js_interactive.py
pypy/dist/pypy/lang/js/jsobj.py
pypy/dist/pypy/lang/js/operations.py
pypy/dist/pypy/lang/js/test/test_astbuilder.py
pypy/dist/pypy/lang/js/test/test_interp.py
pypy/dist/pypy/lang/js/test/test_parser.py (props changed)
Log:
modified exception printing, now the ast know the filename on some nodes, also removed narcisus code as it is not needed anymore
Modified: pypy/dist/pypy/lang/js/astbuilder.py
==============================================================================
--- pypy/dist/pypy/lang/js/astbuilder.py (original)
+++ pypy/dist/pypy/lang/js/astbuilder.py Thu Jul 26 15:30:32 2007
@@ -46,6 +46,13 @@
'{': operations.ObjectInit,
}
+ def __init__(self):
+ self.sourcename = ""
+ RPythonVisitor.__init__(self)
+
+ def set_sourcename(self, sourcename):
+ self.sourcename = sourcename #XXX I should call this
+
def get_pos(self, node):
value = ''
source_pos = None
@@ -219,7 +226,7 @@
nodes.append(node)
var_decl = self.varlists.pop().keys()
func_decl = self.funclists.pop()
- return operations.SourceElements(pos, var_decl, func_decl, nodes)
+ return operations.SourceElements(pos, var_decl, func_decl, nodes, self.sourcename)
def functioncommon(self, node, declaration=True):
pos = self.get_pos(node)
Modified: pypy/dist/pypy/lang/js/commit
==============================================================================
--- pypy/dist/pypy/lang/js/commit (original)
+++ pypy/dist/pypy/lang/js/commit Thu Jul 26 15:30:32 2007
@@ -1 +1 @@
-py.test -x --tb=no|grep -q "1 failed" || svn commit
+py.test -x --tb=no && svn commit
Modified: pypy/dist/pypy/lang/js/driver.py
==============================================================================
--- pypy/dist/pypy/lang/js/driver.py (original)
+++ pypy/dist/pypy/lang/js/driver.py Thu Jul 26 15:30:32 2007
@@ -23,7 +23,7 @@
results = open('results.txt', 'w')
for f in pwd.dirpath('test', 'ecma').visit(filter):
print f.basename
- cmd = './js_interactive.py -n -f %s -f %s'%(shell, f)
+ cmd = './js_interactive.py %s %s'%(shell, f)
p = Popen(cmd, shell=True, stdout=PIPE)
passed = 0
Modified: pypy/dist/pypy/lang/js/interpreter.py
==============================================================================
--- pypy/dist/pypy/lang/js/interpreter.py (original)
+++ pypy/dist/pypy/lang/js/interpreter.py Thu Jul 26 15:30:32 2007
@@ -12,13 +12,14 @@
def writer(x):
print x
-def load_source(script_source):
+def load_source(script_source, sourcename):
temp_tree = parse(script_source)
+ ASTBUILDER.sourcename = sourcename
return ASTBUILDER.dispatch(temp_tree)
def load_file(filename):
f = open_file_as_stream(filename)
- t = load_source(f.readall())
+ t = load_source(f.readall(), filename)
f.close()
return t
@@ -104,7 +105,7 @@
else:
code = W_String('')
try:
- node = load_source(code.ToString(ctx))
+ node = load_source(code.ToString(ctx), 'evalcode')
except ParseError, e:
raise ThrowException(W_String('SintaxError: '+str(e)))
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 Jul 26 15:30:32 2007
@@ -56,7 +56,7 @@
def runcodefromfile(self, filename):
f = open_file_as_stream(filename)
- self.runsource(f.readall())
+ self.runsource(f.readall(), filename)
f.close()
def runcode(self, ast):
@@ -89,7 +89,7 @@
3) The input is complete. Executes the source code.
"""
try:
- ast = load_source(source)
+ ast = load_source(source, filename)
except ParseError, exc:
if exc.source_pos.i == len(source):
# Case 2
Modified: pypy/dist/pypy/lang/js/jsobj.py
==============================================================================
--- pypy/dist/pypy/lang/js/jsobj.py (original)
+++ pypy/dist/pypy/lang/js/jsobj.py Thu Jul 26 15:30:32 2007
@@ -5,7 +5,15 @@
class SeePage(NotImplementedError):
pass
-class JsBaseExcept(Exception): pass
+class JsBaseExcept(Exception):
+ pass
+
+#XXX Just an idea for now
+class JsRuntimeExcept(Exception):
+ def __init__(self, pos, message, exception_object):
+ self.pos = pos
+ self.message = message
+ self.exception_object = exception_object # JS Exception Object
class ExecutionReturned(JsBaseExcept):
def __init__(self, type='normal', value=None, identifier=None):
Modified: pypy/dist/pypy/lang/js/operations.py
==============================================================================
--- pypy/dist/pypy/lang/js/operations.py (original)
+++ pypy/dist/pypy/lang/js/operations.py Thu Jul 26 15:30:32 2007
@@ -775,11 +775,12 @@
"""
SourceElements nodes are found on each function declaration and in global code
"""
- def __init__(self, pos, var_decl, func_decl, nodes):
+ def __init__(self, pos, var_decl, func_decl, nodes, sourcename = ''):
self.pos = pos
self.var_decl = var_decl
self.func_decl = func_decl
self.nodes = nodes
+ self.sourcename = sourcename
def execute(self, ctx):
for varname in self.var_decl:
@@ -798,7 +799,7 @@
return e.value
else:
# TODO: proper exception handling
- print "exception in line: %s, on: %s%s"%(node.pos.lineno, node, os.linesep)
+ print "%s:%d: %s"%(self.sourcename, node.pos.lineno, node)
raise
Modified: pypy/dist/pypy/lang/js/test/test_astbuilder.py
==============================================================================
--- pypy/dist/pypy/lang/js/test/test_astbuilder.py (original)
+++ pypy/dist/pypy/lang/js/test/test_astbuilder.py Thu Jul 26 15:30:32 2007
@@ -7,7 +7,9 @@
print s
tp = parse(s)
print tp
- return ASTBuilder().dispatch(tp)
+ astb = ASTBuilder()
+ astb.sourcename = "test"
+ return astb.dispatch(tp)
def test_simple():
yield to_ast, "1;"
@@ -31,3 +33,7 @@
c1 = p.body.nodes[0]
assert isinstance(c1, Call)
assert isinstance(c1.left, Call)
+
+def test_sourcename():
+ p = to_ast('x()()').body
+ assert p.sourcename == 'test'
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 Thu Jul 26 15:30:32 2007
@@ -19,7 +19,7 @@
jsint = interpreter.Interpreter()
ctx = jsint.w_Global
try:
- jsint.run(interpreter.load_source(code))
+ jsint.run(interpreter.load_source(code, ''))
except ThrowException, excpt:
l.append("uncaught exception: "+str(excpt.exception.ToString(ctx)))
print l, prints
@@ -32,7 +32,7 @@
jsint = interpreter.Interpreter()
ctx = jsint.w_Global
try:
- code_val = jsint.run(interpreter.load_source(code)).GetValue()
+ code_val = jsint.run(interpreter.load_source(code, '')).GetValue()
except ThrowException, excpt:
code_val = excpt.exception
print code_val, value
@@ -49,7 +49,7 @@
def asserte(code, value):
jsint = interpreter.Interpreter()
- py.test.raises(value, 'jsint.run(interpreter.load_source(code))')
+ py.test.raises(value, 'jsint.run(interpreter.load_source(code, ""))')
def test_interp_parse():
More information about the Pypy-commit
mailing list