469,902 Members | 1,949 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,902 developers. It's quick & easy.

Issues in compiling Python to machine code

I've been thinking about what the issues would be in compiling
Python into native machine code, and since type information is
important in Python, it seems possible that Python code can
be compiled into native machine code (albeit with a lot of
extra effort).

For instance, type information is discovered when something is
assigned to a variable or an anonymous piece of data is used
in a program. Compiling Python bytecode into native machine
code could involve a pass over the bytecode to look at all the
uses of a variable or anonymous variable, call some Python
function to discover its variable, then record it in the symbol

Another issue is what to do with objects. Finding the offset
to a pointer which is the object's constructor, for instance,
if that's the way it's done internally in Python.

And then freeing the memory used by an object when it's no
longer needed. Perhaps freeing memory for an object can be
done by inserting machine code to return memory back to the
heap after the first pass over the bytecode and recording the
place a variable is last used (hopefully then it won't be
used in some other way later of course... perhaps it can
record all cases where that variable is referred to by another
name and track them, too.)

Seems like compiled Python would need a lot of support code,
in any case, that gets run at certain times: before the program
starts, whenever a variable is accessed, before an object is
used (to allocate memory), whenever something happens to data
within an object (allocate/reallocate/destroy), and so on...

Are there any reasons why Python would be *impossible* to compile?

Thanks :)

Jul 18 '05 #1
0 1478

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

29 posts views Thread by Maurice LING | last post: by
reply views Thread by pruebauno | last post: by
4 posts views Thread by Martin | last post: by
1 post views Thread by Holger Joukl | last post: by
1 post views Thread by Han-Wen Nienhuys | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.