473,410 Members | 1,953 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,410 software developers and data experts.

Implementing my own Python interpreter

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

Oct 13 '08 #1
4 1988
On 2008-10-13, Ognjen Bezanov <Og****@mailshack.comwrote:
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?
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?
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...

--
Grant Edwards grante Yow! I demand IMPUNITY!
at
visi.com
Oct 13 '08 #2
Grant Edwards wrote:
On 2008-10-13, Ognjen Bezanov <Og****@mailshack.comwrote:
>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.

Oct 13 '08 #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
Oct 14 '08 #4
Stefan Behnel wrote:
You should take a look at Cython, which translates Python code to C.
Also take a gander at RPython in the PyPy project.
It is a restricted subset of Python on top of which they implement
Python.
--Scott David Daniels
Sc***********@Acm.Org
Oct 15 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: vincent Salaun | last post by:
hi all, here's my problem : I've embedded a python interpreter in our java application (based on the NetBeans palteforrm) using the Jython API : http://www.jython.org/docs/javadoc/index.html...
12
by: Anon | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello all I am a beginner teaching myself python, and I am enjoying it immensely :) As a language it is great, I real treat to study, I actually...
118
by: 63q2o4i02 | last post by:
Hi, I've been thinking about Python vs. Lisp. I've been learning Python the past few months and like it very much. A few years ago I had an AI class where we had to use Lisp, and I absolutely...
1
by: Petr Prikryl | last post by:
Do you think that the following could became PEP (pre PEP). Please, read it, comment it, reformulate it,... Abstract Introduction of the mechanism for language extensions via modules...
113
by: John Nagle | last post by:
The major complaint I have about Python is that the packages which connect it to other software components all seem to have serious problems. As long as you don't need to talk to anything outside...
5
by: Adam Atlas | last post by:
Does anyone know if it would be possible to create a CPython extension -- or use the ctypes module -- to access Python's own embedding API (http://docs.python.org/api/initialization.html &c.)?...
3
by: Marcin Kalicinski | last post by:
How do I use multiple Python interpreters within the same process? I know there's a function Py_NewInterpreter. However, how do I use functions like Py_RunString etc. with it? They don't take any...
0
by: Robert Kern | last post by:
Ognjen Bezanov wrote: Mostly. It is worth noting, though, that the Python bytecode is at a higher level than Java bytecode. You can run other languages on top of the JVM using Java bytecode...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.