Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 10th, 2004, 10:24 AM   #1
G.I.Josh
Programmer
 
G.I.Josh's Avatar
 
Join Date: Aug 2004
Location: Eastern U.S
Posts: 51
Rep Power: 4 G.I.Josh is on a distinguished road
Send a message via AIM to G.I.Josh
I stopped focusing on Python for a while and started reading a lot of Linux docs; but I just now decided to get back into programming. It got me thinking about how interpreters work. Do they take the instructions as they get them, convert them to ml in ram, and send it to the cpu, or do they not have to convert it at all?

Thanks,
Josh
__________________
http://exponentialab.blogspot.com/ - w00t, I've started a blog!
G.I.Josh is offline   Reply With Quote
Old Oct 11th, 2004, 5:23 PM   #2
thechristelegacy
Expert Programmer
 
thechristelegacy's Avatar
 
Join Date: Jul 2004
Location: Somerset, Pa
Posts: 707
Rep Power: 5 thechristelegacy is on a distinguished road
Send a message via AIM to thechristelegacy Send a message via MSN to thechristelegacy
Internally, Python source code is always translated into a bytecode representation, and this bytecode is then executed by the Python virtual machine. In order to avoid the overhead of repeatedly parsing and translating modules that rarely change, this byte code is written into a file whose name ends in ".pyc" whenever a module is parsed. When the corresponding .py file is changed, it is parsed and translated again and the .pyc file is rewritten.

There is no performance difference once the .pyc file has been loaded, as the bytecode read from the .pyc file is exactly the same as the bytecode created by direct translation. The only difference is that loading code from a .pyc file is faster than parsing and translating a .py file, so the presence of precompiled .pyc files improves the start-up time of Python scripts. If desired, the Lib/compileall.py module can be used to create valid .pyc files for a given set of modules.

Note that the main script executed by Python, even if its filename ends in .py, is not compiled to a .pyc file. It is compiled to bytecode, but the bytecode is not saved to a file. Usually main scripts are quite short, so this doesn't cost much speed.

That tidbit was pulled from the Python FAQ

http://www.python.org/doc/faq/general.html...-other-language
I was going to try and explain it myself, but I figured the FAQ would have a better explination.
thechristelegacy is offline   Reply With Quote
Old Oct 15th, 2004, 3:24 AM   #3
Daggerhex_Flynn
Programmer
 
Join Date: Oct 2004
Location: Canada
Posts: 82
Rep Power: 4 Daggerhex_Flynn is on a distinguished road
Quote:
Originally posted by G.I.Josh@Oct 10 2004, 03:24 PM
I stopped focusing on Python for a while and started reading a lot of Linux docs; but I just now decided to get back into programming. It got me thinking about how interpreters work. Do they take the instructions as they get them, convert them to ml in ram, and send it to the cpu, or do they not have to convert it at all?

Thanks,
Josh
Interpreters take as input an executable specification and produce as output the result of executing the specification. This is different than a compiler because a compiler takes as input a source program, and translates it into a target program. The interpreter does examine the input program and determines whether or not it is a valid program, both an interpreter and compiler build an internal model of the structure and meaning of a program, both determine where to store values during execution, however interpreting the code to produce a result is quite different from emitting a translated program than can be executed to produce a result. The modern day languages (Java, Perl 6) use a compiler to create an intermediate representation, and then they use an interpreter (or another compiler than an interpreter) to execute the program.
Daggerhex_Flynn is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:07 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC