Re: execute a function after each source code line ?
--- stef [EMAIL PROTECTED] wrote: doing a simulation of another language (JAL), I translate the other language into Python code, then I execute this converted Python code. [...] (btw the whole program is running as an graphical (wxPython) application) I worked on an open source project that uses Python to intrepret another language (an educational language called Guido van Robot), and it also uses wxPython to allow the user to step through the program one line at a time, and the user gets quite visual feedback. Check out these screen shots, which hopefully illustrate something along the lines of what you're trying to achieve. http://gvr.sourceforge.net/screen_shots/ During the project, we definitely had some lessons learned. The Python-based interpreter originally translated the GvR source into a Python program, and this worked great when the interface was curses. When we went to wxPython, it eventually became clear that it would be very difficult to make this approach work inside of wxPython. I'm not saying it's impossible, but in wxPython, or really any GUI app, it's hard to have your interpreted program drive things, without turing the event loop inside out. It might become easier to turn your own program inside out. I think you know where this is going... You need to build a virtual machine. It might not be quite as hard as it sounds, although it certainly depends on the complexity of the interpreted language. We ended up making the translater create an AST tree, which was essentially a tree of tiny little Python objects. We didn't create bytecode per se; the virtual machine acted directly on the AST. Then we had a stepper class step through the code. Here's the code for the stepper: http://gvr.cvs.sourceforge.net/gvr/GvR/TESTstepper.py?revision=1.28view=markup http://gvr.cvs.sourceforge.net/gvr/GvR/stepper.py?revision=1.36view=markup Here's the code for the translator: http://gvr.cvs.sourceforge.net/gvr/GvR/TESTgvrparser.py?revision=1.23view=markup http://gvr.cvs.sourceforge.net/gvr/GvR/gvrparser.py?revision=1.53view=markup When you call into the stepper, it has no notion of the GUI around it; it just has a world object that it can call simple methods on. http://gvr.cvs.sourceforge.net/gvr/GvR/guiWorld.py?revision=1.5view=markup There's a little more code here, but hopefully the above provides a sketch. http://gvr.cvs.sourceforge.net/gvr/GvR/ It's a pretty small project, so you may just want to download all the source and check it out in action. It should run on Linux and Windows, and I know we had it running on the Macs at one point. TV dinner still cooling? Check out Tonight's Picks on Yahoo! TV. http://tv.yahoo.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: execute a function after each source code line ?
--- Diez B. Roggisch [EMAIL PROTECTED] wrote: Are there any other (simple) ways of achieving this ? (btw the whole program is running as an graphical (wxPython) application) use the python trace facilities. http://docs.python.org/lib/module-trace.html I'm not sure how much that will help in a GUI event-driven environment like wxPython. Since the OP is generating his own Python code, he can insert his own tracing statements. I think the essential problem is how do you run the intrepreted Python program in a mode that you can have the GUI get an event, let the intrepreted program run the next instruction, have the GUI get another event, have the intrepreted program run to the next instruction, etc. There are probably ways to achieve this, such as running the intrepreted Python program in a thread, but my own experience in this in wxPython, with Guido van Robot, led me to believe that it's ultimately easier to create a virtual machine for your intepreted language. But I may be missing your point. Don't get soaked. Take a quick peak at the forecast with the Yahoo! Search weather shortcut. http://tools.search.yahoo.com/shortcuts/#loc_weather -- http://mail.python.org/mailman/listinfo/python-list
Re: execute a function after each source code line ?
Steve Howell wrote: --- stef [EMAIL PROTECTED] wrote: doing a simulation of another language (JAL), I translate the other language into Python code, then I execute this converted Python code. [...] (btw the whole program is running as an graphical (wxPython) application) I worked on an open source project that uses Python to intrepret another language (an educational language called Guido van Robot), and it also uses wxPython to allow the user to step through the program one line at a time, and the user gets quite visual feedback. Check out these screen shots, which hopefully illustrate something along the lines of what you're trying to achieve. http://gvr.sourceforge.net/screen_shots/ Steve, that's exactly what I've in mind. The screen shots, looks really good, and I'll definitely will take a deeper look into your code. I've one advantage over you, the language I want to simulate (JAL), is very Pascal like, and therefor can be easily converted into equivalent Python code. cheers, Stef Mientki -- http://mail.python.org/mailman/listinfo/python-list
Re: execute a function after each source code line ?
Diez B. Roggisch wrote: stef wrote: hello, doing a simulation of another language (JAL), I translate the other language into Python code, then I execute this converted Python code. Now I need todo some checks and give visual feedback to the user, each time a line of code is executed. One way of realizing this, is to add a function call at each source code line under investigation. Are there any other (simple) ways of achieving this ? (btw the whole program is running as an graphical (wxPython) application) use the python trace facilities. http://docs.python.org/lib/module-trace.html thanks Diez, that looks exactly what I need. cheers, Stef Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: execute a function after each source code line ?
stef wrote: hello, doing a simulation of another language (JAL), I translate the other language into Python code, then I execute this converted Python code. Now I need todo some checks and give visual feedback to the user, each time a line of code is executed. One way of realizing this, is to add a function call at each source code line under investigation. Are there any other (simple) ways of achieving this ? (btw the whole program is running as an graphical (wxPython) application) use the python trace facilities. http://docs.python.org/lib/module-trace.html Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: execute a function after each source code line ?
--- stef [EMAIL PROTECTED] wrote: the language I want to simulate (JAL), is very Pascal like, and therefor can be easily converted into equivalent Python code. One more idea. If you haven't already, maybe you can post something to the PyPy community to effect of this: ''' I have a Python-like language that I translate to Python code, and I want to write another Python program in wxPython that executes the former Python program in a step-by-step fashion. ''' I'm sure there are some folks there that eventually want to tackle the same problem, and if nothing else, they might help you out with some terminology for describing your problem. Sick sense of humor? Visit Yahoo! TV's Comedy with an Edge to see what's on, when. http://tv.yahoo.com/collections/222 -- http://mail.python.org/mailman/listinfo/python-list
Re: execute a function after each source code line ?
--- stef [EMAIL PROTECTED] wrote: Steve, that's exactly what I've in mind. The screen shots, looks really good, and I'll definitely will take a deeper look into your code. Cool, good luck. Feel free to contact me privately if you have questions about the implementation. There's also a mailing list for GvR, although it's not that active at the moment. It's not that the project is dead, we just don't have much to add to it at this point. :) I've one advantage over you, the language I want to simulate (JAL), is very Pascal like, and therefor can be easily converted into equivalent Python code. FWIW the language I was interpeting is also Pascal-like, and as I mentioned, we initially translated it into Python code as well. Even when we abandoned the idea of using Python to run the program (er, this is like describing PyPy, we were still using Python at the outer level, just not the inner level), we still kept the code around to translate from GvR to Python. The translations from GvR to Python made it easy for us to write unit tests like this: ''' if front_is_blocked: turnleft if front_is_blocked: turnleft if front_is_blocked: turnleft move ''', ''' if self.FRONT_IS_BLOCKED(0): self.TURNLEFT(1) if self.FRONT_IS_BLOCKED(2): self.TURNLEFT(3) if self.FRONT_IS_BLOCKED(4): self.TURNLEFT(5) self.MOVE(6) ''' More here: http://gvr.cvs.sourceforge.net/*checkout*/gvr/GvR/TESTgvrparser.py?revision=1.23content-type=text%2Fplain Luggage? GPS? Comic books? Check out fitting gifts for grads at Yahoo! Search http://search.yahoo.com/search?fr=oni_on_mailp=graduation+giftscs=bz -- http://mail.python.org/mailman/listinfo/python-list