def repl(): space = getspace() interp = Interpreter(space) print print '-=- Hippy -=-' print while True: try: line = raw_input("<? ") except EOFError: print break if not line.lstrip() or line.lstrip().startswith('//'): continue try: pc = parse(space, line, 0) bc = compile_ast("<input>", line, pc, space, print_exprs=True) except Exception, e: print >> sys.stderr, '%s: %s' % (e.__class__.__name__, e) continue try: interp.run_main(space, bc) except ExplicitExitException, e: os.write(1, e.message) sys.exit(e.code)
def repl(): space = getspace() interp = Interpreter(space) print print '-=- Hippy -=-' print while True: try: line = raw_input("<? ") except EOFError: print break if not line.lstrip() or line.lstrip().startswith('//'): continue try: pc = parse(space, line, 0, '<input>') bc = compile_ast("<input>", line, pc, space, print_exprs=True) except Exception, e: print >> sys.stderr, '%s: %s' % (e.__class__.__name__, e) continue try: interp.run_main(space, bc) except ExplicitExitException, e: os.write(1, e.message) sys.exit(e.code)
def __init__(self, space, err_stream=None, inp_stream=None): if err_stream is None: self.msgs = [] else: self.msgs = err_stream Interpreter.__init__(self, space) self.tb = [] self.output = [] self.inp_stream = inp_stream
def run(): space = getspace() interp = Interpreter(space) bc = unserialize(hlstr(read_code_ptr()), space) interp.setup(False, {}) try: interp.run_main(space, bc) except ExplicitExitException, e: print "EXITED WITH %d" % e.code return
def main(filename, rest_of_args, cgi, gcdump, debugger_pipes=(-1, -1)): try: f = open(filename) data = f.read() f.close() except: print "Error opening %s" % filename return 2 # space = getspace() interp = Interpreter(space) # load the ini file situated in the current wc try: ini_data = open('hippy.ini').read() except (OSError, IOError): ini_data = None if ini_data is not None: try: load_ini(interp, ini_data) except: os.write(2, "error reading `hippy.ini`") interp.setup(cgi, argv=[filename] + rest_of_args) absname = os.path.abspath(filename) bc = interp.compile_bytecode(absname, data) if bc is None: return 1 # The script originally called is considered an "included file," # so it will be listed together with the files # referenced by include and family. interp.included_files.append(filename) # exitcode = 0 try: try: if debugger_pipes != (-1, -1): interp.setup_debugger(debugger_pipes[0], debugger_pipes[1], start_paused=True) interp.run_main(space, bc, top_main=True) finally: interp.shutdown() except InterpreterError, e: tb = e.traceback if tb is not None: tb = tb[:] tb.reverse() for filename, funcname, line, source in tb: os.write(2, "function %s, file %s:%d\n" % (funcname, filename, line)) os.write(2, source + "\n") if we_are_translated(): os.write(2, "Fatal interpreter error %s\n" % e.msg) else: print >>sys.stderr, "%s: %s\n" % (e.__class__.__name__, e.msg)
def run(args): assert len(args) == 1, "XXX only supports one argument, a php file" filename = args[0] f = open(filename, 'r') source = f.read() f.close() space = getspace() bc = compile_php(filename, source, space) print '-=- %s -=-' % (filename,) interp = Interpreter(space) interp.setup(False, args) try: interp.run_main(space, bc) except ExplicitExitException, e: sys.exit(e.code)
def run(args): assert len(args) == 1, "XXX only supports one argument, a php file" filename = args[0] f = open(filename, 'r') source = f.read(-1) f.close() space = getspace() bc = compile_php(filename, source, space) print '-=- %s -=-' % (filename, ) interp = Interpreter(space) interp.setup(False, args) try: interp.run_main(space, bc) interp.shutdown() except ExplicitExitException, e: sys.exit(e.code)
def main(filename): from hippy.objspace import getspace from hippy.interpreter import Interpreter space = getspace() interp = Interpreter(space) absname = os.path.abspath(filename) try: bc = space.bytecode_cache.compile_file(absname, space) except: print "Error opening %s" % filename sys.exit(1) dump_bytecode(bc)
def main(filename, rest_of_args, cgi, gcdump, debugger_pipes=(-1, -1), bench_mode=False, bench_no=-1): space = getspace() interp = Interpreter(space) try: ini_data = open('hippy.ini').read(-1) except (OSError, IOError): ini_data = None if ini_data is not None: try: load_ini(interp, ini_data) except: os.write(2, "error reading `hippy.ini`") try: bc = space.bytecode_cache.compile_file(filename, space) except ParseError as e: print 'Parse error: %s' % e return 2 except LexerError as e: print 'Parse error: %s on line %d' % (e.message, e.source_pos + 1) return 2 except IOError as e: print 'Could not open input file: %s' % filename return 2 except Exception as e: print 'Got exception: %s' % e return 2 # if bench_mode: no = bench_no else: no = 1 exitcode = 0 space.ec.init_signals() for i in range(no): # load the ini file situated in the current wc interp.setup(cgi, argv=[filename] + rest_of_args) if bc is None: return 1 # The script originally called is considered an "included file," # so it will be listed together with the files # referenced by include and family. interp.cached_files[filename] = bc # exitcode = 0 try: try: if debugger_pipes != (-1, -1): interp.setup_debugger(debugger_pipes[0], debugger_pipes[1], start_paused=True) interp.run_main(space, bc, top_main=True) finally: interp.shutdown() except InterpreterError, e: tb = e.traceback if tb is not None: tb = tb[:] tb.reverse() for filename, funcname, line, source in tb: os.write(2, "function %s, file %s:%d\n" % (funcname, filename, line)) os.write(2, source + "\n") if we_are_translated(): os.write(2, "Fatal interpreter error %s\n" % e.msg) else: print >>sys.stderr, "%s: %s\n" % (e.__class__.__name__, e.msg) except ParseError as e: print e.__str__() return 1
def main(filename, rest_of_args, cgi, gcdump, debugger_pipes=(-1, -1), bench_mode=False, bench_no=-1): space = getspace() interp = Interpreter(space) absname = rpath.abspath(filename) try: ini_data = open('hippy.ini').read(-1) except (OSError, IOError): ini_data = None if ini_data is not None: try: load_ini(interp, ini_data) except: os.write(2, "error reading `hippy.ini`") try: bc = space.bytecode_cache.compile_file(absname, space) except ParseError as e: print 'Parse error: %s' % e return 2 except LexerError as e: print 'Parse error: %s on line %d' % (e.message, e.source_pos + 1) return 2 except IOError as e: print 'Could not open input file: %s' % filename return 2 except Exception as e: print 'Got exception %s with message %s' % (e.__class__.__name__, e) return 2 # if bench_mode: no = bench_no else: no = 1 exitcode = 0 space.ec.init_signals() for i in range(no): # load the ini file situated in the current wc interp.setup(cgi, argv=[filename] + rest_of_args) if bc is None: return 1 # The script originally called is considered an "included file," # so it will be listed together with the files # referenced by include and family. interp.cached_files[filename] = bc # exitcode = 0 try: try: if debugger_pipes != (-1, -1): interp.setup_debugger(debugger_pipes[0], debugger_pipes[1], start_paused=True) interp.run_main(space, bc, top_main=True) finally: interp.shutdown() except InterpreterError, e: tb = e.traceback if tb is not None: tb = tb[:] tb.reverse() for filename, funcname, line, source in tb: os.write( 2, "function %s, file %s:%d\n" % (funcname, filename, line)) os.write(2, source + "\n") if we_are_translated(): os.write(2, "Fatal interpreter error %s\n" % e.msg) else: print >> sys.stderr, "%s: %s\n" % (e.__class__.__name__, e.msg) except ParseError as e: print e.__str__() return 1
os.write(2, "Fatal interpreter error %s\n" % e.msg) else: print >> sys.stderr, "%s: %s\n" % (e.__class__.__name__, e.msg) except ParseError as e: print e.__str__() return 1 except ExplicitExitException, e: os.write(1, e.message) exitcode = e.code except SignalReceived: exitcode = 130 if exitcode: return exitcode if i < no - 1: interp = Interpreter(space) if ini_data is not None: try: load_ini(interp, ini_data) except: os.write(2, "error reading `hippy.ini`") if gcdump is not None: f = os.open(gcdump, os.O_CREAT | os.O_WRONLY, 0777) dump_rpy_heap(f) os.close(f) return exitcode if __name__ == '__main__': sys.exit(entry_point(sys.argv))
def make_space(): """Create a working ObjSpace, that can be used as a prebuilt constant for translation.""" space = ObjSpace() Interpreter(space) # XXX: seriously? return space
def get_conf(self, input): space = ObjSpace() interp = Interpreter(space) self.space = space load_ini(interp, input) return interp.config
def main(filename, rest_of_args, cgi, gcdump, debugger_pipes=(-1, -1)): try: f = open(filename) data = f.read() f.close() except: print "Error opening %s" % filename return 2 # space = getspace() interp = Interpreter(space) # load the ini file situated in the current wc try: ini_data = open('hippy.ini').read() except (OSError, IOError): ini_data = None if ini_data is not None: try: load_ini(interp, ini_data) except: os.write(2, "error reading `hippy.ini`") interp.setup(cgi, argv=[filename] + rest_of_args) absname = os.path.abspath(filename) bc = interp.compile_bytecode(absname, data) if bc is None: return 1 # The script originally called is considered an "included file," # so it will be listed together with the files # referenced by include and family. interp.included_files.append(filename) # exitcode = 0 try: try: if debugger_pipes != (-1, -1): interp.setup_debugger(debugger_pipes[0], debugger_pipes[1], start_paused=True) interp.run_main(space, bc, top_main=True) finally: interp.shutdown() except InterpreterError, e: tb = e.traceback if tb is not None: tb = tb[:] tb.reverse() for filename, funcname, line, source in tb: os.write( 2, "function %s, file %s:%d\n" % (funcname, filename, line)) os.write(2, source + "\n") if we_are_translated(): os.write(2, "Fatal interpreter error %s\n" % e.msg) else: print >> sys.stderr, "%s: %s\n" % (e.__class__.__name__, e.msg)