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 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 test_get_printable_location(self): source = "<? $a = 3; ?>" space = getspace() bc = compile_php('<input>', source, space) assert get_printable_location(0, bc) == "<main> 1 VAR_PTR" # it may be called with pc = len(bc.code) during jitting assert get_printable_location(len(bc.code), bc) == "<main> END ?"
def dump(self): from hippy.objspace import getspace interp = getspace().ec.interpreter items = [] dct_w = self.get_instance_attrs(interp) for key, w_value in dct_w.items(): items.append('%s=>%s' % (key, w_value.dump())) return "instance(%s: %s)" % (self.getclass().name, ', '.join(items))
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 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 test_serialize_with_calls(self): source = """<? function f($a) { return $a + 4; } echo f(3); ?>""" space = getspace() bc = compile_php('<input>', source, space) dump = bc.serialize(space) bc2 = unserialize(dump, space) interp = MockInterpreter(space) interp.run_main(space, bc2) assert space.int_w(interp.output[0]) == 3 + 4
def test_serialize_array_constants(self): source = """<? $a = array("a", "b"); $b = array("a"=>"b"); echo $a[1]; echo $b["a"]; ?>""" space = getspace() bc = compile_php('<input>', source, space) dump = bc.serialize(space) bc2 = unserialize(dump, space) interp = MockInterpreter(space) interp.run_main(space, bc2) assert space.str_w(interp.output[0]) == "b" assert space.str_w(interp.output[1]) == "b"
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() 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 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 test_basic_serialize(self): source = "<? $a = 3; var_dump($a);?>" space = getspace() bc = compile_php('<input>', source, space) dump = bc.serialize(space) bc2 = unserialize(dump, space) assert bc.dump() == bc2.dump() assert space.int_w(bc2.consts[0]) == 3 assert bc2.name == bc.name assert bc2.filename == bc.filename assert bc2.startlineno == bc.startlineno assert bc2.sourcelines == bc.sourcelines assert bc.names == bc2.names assert bc.varnames == bc2.varnames interp = MockInterpreter(space) interp.run_main(space, bc2) assert interp.output[0] == 'int(3)\n'
def test_serialize_with_classes(self): source = """<? class X { function __construct() { $this->x = 3; } } $x = new X(); echo $x->x; ?>""" space = getspace() bc = compile_php('<input>', source, space) dump = bc.serialize(space) bc2 = unserialize(dump, space) interp = MockInterpreter(space) interp.run_main(space, bc2) assert space.int_w(interp.output[0]) == 3
def read_code(): source = open(filename).read() space = getspace() bc = compile_php('<input>', source, space) return llstr(bc.serialize(space))
rffi.cast(lltype.Signed, this.timelib_time.c_zone_type)) def _set_date(interp, this, w_value): pass def _set_timezone(interp, this, w_value): pass def _set_timezone_type(interp, this, w_value): pass space = getspace() k_DateTime = def_class('DateTime', [ construct, format, modify, get_timestamp, set_timestamp, get_timezone, set_date, set_iso_date, set_time, set_timezone, create_from_format, get_last_errors, sub, add, diff, get_offset ], [ GetterSetterWrapper(_get_date, _set_date, "date", consts.ACC_PUBLIC), GetterSetterWrapper(_get_timezone_type, _set_timezone_type, "timezone_type", consts.ACC_PUBLIC), GetterSetterWrapper(_get_timezone, _set_timezone, "timezone", consts.ACC_PUBLIC) ], [('ATOM', space.wrap("Y-m-d\TH:i:sP")), ('COOKIE', space.wrap("l, d-M-y H:i:s T")), ('ISO8601', space.wrap("Y-m-d\TH:i:sO")), ('RFC822', space.wrap("D, d M y H:i:s O")),
name='DateTimeZone::listIdentifiers', flags=consts.ACC_STATIC) def identifiers_list(space, what=2047, country=None): return common.timezone_identifiers_list(space, what, country) @wrap_method(['interp', ThisUnwrapper(W_DateTimeZone), Optional(int), Optional(int)], name='DateTimeZone::getTransitions') def get_transition(interp, this, timestamp_begin=-sys.maxint - 1, timestamp_end=sys.maxint): return common.timezone_transitions_get( interp, this, timestamp_begin, timestamp_end) space = getspace() k_DateTimeZone = def_class( 'DateTimeZone', [construct, get_name, get_offset, list_abbreviations, identifiers_list, get_transition], [], [('AFRICA', space.wrap(common.AFRICA)), ('AMERICA', space.wrap(common.AMERICA)),
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