Source

jaspyon / targetjsstandalone.py

Full commit
"""
A simple standalone target for the javascript interpreter.

Usage: jaspyon-c [-f] jsourcefile [-f] other_source ...
"""

import sys
from jaspyon.interpreter import *
from jaspyon.console import JSConsole

# __________  Entry point  __________

def run_file(interp, name):
    t = load_file(name)
    interp.run(t)    

def entry_point(argv):
    i = 1
    
    if len(argv) == 1:
        console = JSConsole()
        console.interact()
        return 0
    
    interp = Interpreter()
    while i < len(argv):
        arg = argv[i]
        if arg == '-f':
            if i == len(argv) - 1:
                print __doc__
                return 1
            i += 1
            run_file(interp, argv[i])
        elif arg.startswith('-'):
            print "Unsupported option %s" % arg
            print __doc__
            return 1
        else:
            run_file(interp, argv[i])
        i += 1
    return 0
# _____ Define and setup target ___

def target(driver, args):
    driver.exe_name = 'jaspyon-%(backend)s'
    return entry_point, None

if __name__ == '__main__':
    entry_point(sys.argv)