Implementing my own Python interpreter

Discussion in 'Python' started by Ognjen Bezanov, Oct 13, 2008.

  1. Hello All,

    I am a third year computer science student and I'm the process of
    selection for my final year project.

    One option that was thought up was the idea of implement my own version
    of the python interpreter (I'm referring to CPython here). Either as a
    process running on another OS or as a process running directly on the CPU.

    Now, I can't seem to find a decent source of information on the python
    interpreter. I have made the assumption that Python works very much like
    Java, you have code that is compiled into bytecode, which is then
    executed in a virtual machine. IS this correct? Is there a good source
    to give me an overview of Python internals? (I can look at the code, but
    I would find it easier to understand if I can see the "big picture" as well)

    Also, any pro's out there willing to chime on the feasibility of
    implementing python to run directly on the hardware (without an
    underlying OS)? I don't expect 100% compatibility, but would the basics
    (branching, looping, arithmatic) be feasible?

    Thank you,


    Ognjen
     
    Ognjen Bezanov, Oct 13, 2008
    #1
    1. Advertising

  2. Grant Edwards wrote:
    > On 2008-10-13, Ognjen Bezanov <> wrote:
    >
    >> I am a third year computer science student and I'm the process of
    >> selection for my final year project.
    >>
    >> One option that was thought up was the idea of implement my
    >> own version of the python interpreter (I'm referring to
    >> CPython here). Either as a process running on another OS or as
    >> a process running directly on the CPU.
    >>
    >> Now, I can't seem to find a decent source of information on
    >> the python interpreter.

    >
    > You mean the virtual machine?


    Yes, I presume there is a CPU implementation that executes the byte
    code, but that is pretty much the limit of my knowlede
    >
    >> I have made the assumption that Python works very much like
    >> Java, you have code that is compiled into bytecode, which is
    >> then executed in a virtual machine. IS this correct?

    >
    > Yes. There are python compilers that generate bytecode for a
    > variety of VMs:
    >
    > * CPython -- Python Virtual Machine (PVM)
    > * Jython -- Java Virtual Machine (JVM)
    > * Iron Python -- .Net Virtual Machine
    >
    >> Is there a good source to give me an overview of Python
    >> internals? (I can look at the code, but I would find it easier
    >> to understand if I can see the "big picture" as well)

    >
    > The internals of what? One of the compilers? The PVM?


    Well, how does python execute code (note, when I talk about "Python", I
    mean the CPython implementation)? I know that for C we first compile
    into into assembly, then assemble that into machine code. What is the
    process for Python? I assume:

    Python code ---[compile]--> Python bytecode ---[execute on Virtual
    machine]--> machine code.

    But I'm not sure.

    >
    >> Also, any pro's out there willing to chime on the feasibility
    >> of implementing python to run directly on the hardware
    >> (without an underlying OS)? I don't expect 100% compatibility,
    >> but would the basics (branching, looping, arithmatic) be
    >> feasible?

    >
    > I would think so.
    >
    > Without any file, terminal, or network I/O, I don't see how
    > you'll be able to do anything useful...
    >


    Well, It is more of a academic task, I don't think I will end up with a
    groundbreaking python implementation or anything like that, but it would
    be interesting (and a learning experience for me).

    I would probably implement some simple I/O (so keyboard input and
    character output to screen) as part of the implementation.
     
    Ognjen Bezanov, Oct 14, 2008
    #2
    1. Advertising

  3. Ognjen Bezanov wrote:
    > Also, any pro's out there willing to chime on the feasibility of
    > implementing python to run directly on the hardware (without an
    > underlying OS)? I don't expect 100% compatibility, but would the basics
    > (branching, looping, arithmatic) be feasible?


    You should take a look at Cython, which translates Python code to C. It does
    not build a complete Interpreter (it doesn't reimplement the data types and
    their operations, for example), but it does implement most of the control flow
    and a lot of other things that make the generated code fast. In case you come
    to the conclusion that reimplementing Python is too big for a final year
    project, you might as well find a couple of good ideas in Cython's list of
    potential enhancements. Check the Wiki.

    http://cython.org/

    Stefan
     
    Stefan Behnel, Oct 14, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Pradeep

    Implementing our own providers

    Pradeep, Jun 7, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    1,815
    john_teague
    Jun 7, 2006
  2. Replies:
    3
    Views:
    773
    Ziga Seilnacht
    Jan 3, 2007
  3. Rajan

    Implementing my own memcpy

    Rajan, Jun 25, 2005, in forum: C Programming
    Replies:
    70
    Views:
    2,952
    Netocrat
    Jul 11, 2005
  4. metaperl
    Replies:
    0
    Views:
    556
    metaperl
    Aug 22, 2007
  5. Philipp Huber
    Replies:
    11
    Views:
    201
    Daryl Richter
    Sep 1, 2005
Loading...

Share This Page