Author: Stephan <[email protected]>
Branch:
Changeset: r230:4af363c21896
Date: 2012-05-24 18:45 +0200
http://bitbucket.org/pypy/lang-js/changeset/4af363c21896/
Log: add DEBUG
diff --git a/js/functions.py b/js/functions.py
--- a/js/functions.py
+++ b/js/functions.py
@@ -90,6 +90,7 @@
return self.opcodes[pc]
def run(self, ctx):
+ from js.globals import DEBUG
if len(self.opcodes) == 0:
from js.jsobj import w_Undefined
return w_Undefined
@@ -100,7 +101,8 @@
break
opcode = self._get_opcode(pc)
result = opcode.eval(ctx)
- #print("%3d %25s %s" % (pc, str(opcode), str([str(s) for s in
ctx._stack_])))
+ if DEBUG:
+ print(u'%3d %25s %s' % (pc, str(opcode), unicode([unicode(s)
for s in ctx._stack_])))
assert result is None
from js.opcodes import RETURN
diff --git a/js/js_interactive.py b/js/js_interactive.py
--- a/js/js_interactive.py
+++ b/js/js_interactive.py
@@ -32,10 +32,8 @@
except ImportError:
pass
-DEBUG = False
-
def debugjs(this, args):
- global DEBUG
+ from js.globals import DEBUG
DEBUG = not DEBUG
return W_Boolean(DEBUG)
@@ -128,7 +126,9 @@
banner = 'PyPy JavaScript Interpreter'
code.InteractiveConsole.interact(self, banner)
-def main(inspect=False, files=[]):
+def main(inspect = False, debug = False, files=[]):
+ import js.globals
+ js.globals.DEBUG = debug
jsi = JSInterpreter()
for filename in files:
jsi.runcodefromfile(filename)
@@ -143,11 +143,15 @@
action='store_true', default=False,
help='inspect interactively after running script')
+ parser.add_option('-d', dest='debug',
+ action='store_true', default=False,
+ help='debug')
+
# ... (add other options)
opts, args = parser.parse_args()
if args:
- main(inspect=opts.inspect, files=args)
+ main(inspect=opts.inspect, debug = opts.debug, files=args)
else:
- main(inspect=opts.inspect)
+ main(inspect=opts.inspect, debug = opts.debug)
sys.exit(0)
diff --git a/js/jsobj.py b/js/jsobj.py
--- a/js/jsobj.py
+++ b/js/jsobj.py
@@ -1140,7 +1140,7 @@
return self.to_string() == other_string
def __str__(self):
- return 'W_String("%s")' % (str(self._strval_),)
+ return u'W_String("%s")' % (unicode(self._strval_),)
def ToObject(self):
return W_StringObject(self)
@@ -1290,6 +1290,9 @@
def to_list(self):
return self.values
+ def __str__(self):
+ return 'W_List(%s)' % ( str([str(v) for v in self.values]) )
+
class W_Iterator(W_Root):
def __init__(self, elements_w):
self.elements_w = elements_w
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit