Issues in compiling Python to machine code

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Johnathan Doe

    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
    table.

    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 :)

Working...