954,541 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Python Virtual Machine Questions

I was a little bored today and I started to google how the Python Virtual Machine works. I found a bunch of helpfull articles and kind of understand at least some of the very basic PVM code using the modules py_compile and dis. I was wondering how to write the actual PVM code to a file (without writing python code to a file and compiling it with py_compile) if i wanted to generate PVM code from another language - kind of like jython and the java interpreter. Ill probably just use it to implement a simple language like brainfsck but maybe branch out if I can/have the willpower. If anybody knows or at least can help point me in the right direction your help will be greatly apreciated.

EAnder
Light Poster
49 posts since Feb 2008
Reputation Points: 26
Solved Threads: 5
 

You can disassemble Python byte code with module dis to something that looks like assembler code, but since there is no Python assembler it's just an analytical tool.

vegaseat
DaniWeb's Hypocrite
Moderator
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
 
[...] but since there is no Python assembler it's just an analytical tool.


Some people might look at that and thinkopportunity! Google Summer of Code is coming up. Can daniweb.com be a mentoring organization?

BearofNH
Posting Whiz
323 posts since May 2007
Reputation Points: 94
Solved Threads: 48
 

One way to learn how to produce python byte code without python is to look in python's source code. See how the compile function is implemented in C, and it should give you a clue. Also I suppose that if you want to do the same from java, you should have a look in Jython's source code.
It doesn't solve the main question: is it useful to write python byte code directly instead of writing python code and compiling it ?
Another thing to consider is : what will you do if the syntax or semantics of python byte code changes with the next version of python ?

Gribouillis
Posting Maven
Moderator
2,786 posts since Jul 2008
Reputation Points: 1,044
Solved Threads: 691
 

Thanks for your help and sorry if I did not make this clear but I need info on the .pyc files. I know they are binary and I need to know the structure of the files and the the byte codes for each instruction. The structure is somewhat explained in this article I just found but the auther is sounding quite confused himself: http://nedbatchelder.com/blog/200804/the_structure_of_pyc_files.html

Edit: Ill have to get a copy of python source code from python.org. Good idea to look into that. Hope I can understand enough of the c. thx

EAnder
Light Poster
49 posts since Feb 2008
Reputation Points: 26
Solved Threads: 5
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You