[pypy-svn] r36374 - pypy/dist/pypy/lang/js

santagada at codespeak.net santagada at codespeak.net
Tue Jan 9 17:13:20 CET 2007


Author: santagada
Date: Tue Jan  9 17:13:18 2007
New Revision: 36374

Added:
   pypy/dist/pypy/lang/js/autopath.py
      - copied unchanged from r36358, pypy/dist/pypy/bin/autopath.py
   pypy/dist/pypy/lang/js/js_interactive.py   (contents, props changed)
Modified:
   pypy/dist/pypy/lang/js/jsobj.py
Log:
new interactive interepreter


Added: pypy/dist/pypy/lang/js/js_interactive.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/lang/js/js_interactive.py	Tue Jan  9 17:13:18 2007
@@ -0,0 +1,60 @@
+#!/usr/bin/env python
+# encoding: utf-8
+"""
+js_interactive.py
+"""
+
+import autopath
+import sys
+import getopt
+from pypy.lang.js.interpreter import *
+from pypy.lang.js.jsobj import W_Builtin
+
+help_message = '''
+The help message goes here.
+'''
+
+
+class Usage(Exception):
+    def __init__(self, msg):
+        self.msg = msg
+
+
+def main(argv=None):
+    if argv is None:
+        argv = sys.argv
+    try:
+        try:
+            opts, args = getopt.getopt(argv[1:], "ho:v", ["help", "output="])
+        except getopt.error, msg:
+            raise Usage(msg)
+    
+        # option processing
+        for option, value in opts:
+            if option == "-v":
+                verbose = True
+            if option in ("-h", "--help"):
+                raise Usage(help_message)
+            if option in ("-o", "--output"):
+                output = value
+    
+    except Usage, err:
+        print >> sys.stderr, sys.argv[0].split("/")[-1] + ": " + str(err.msg)
+        print >> sys.stderr, "\t for help use --help"
+        return 2
+    
+    interp = Interpreter()
+    def quiter():
+        sys.exit(0)
+        return "this should not be printed"
+    
+    interp.w_Global.Put('quit', W_Builtin(quiter))
+    
+    while 1:
+        res = interp.run(load_source(raw_input("pypy-js>")))
+        if res is not None:
+            print res
+
+
+if __name__ == "__main__":
+    sys.exit(main())

Modified: pypy/dist/pypy/lang/js/jsobj.py
==============================================================================
--- pypy/dist/pypy/lang/js/jsobj.py	(original)
+++ pypy/dist/pypy/lang/js/jsobj.py	Tue Jan  9 17:13:18 2007
@@ -305,7 +305,7 @@
     def Call(self, ctx, args=[], this = None):
         assert len(args) == 0
         return W_String(self.builtinfunction()) # ???
-
+    
 class W_List(W_Root):
     def __init__(self, list_w):
         self.list_w = list_w



More information about the Pypy-commit mailing list