473,698 Members | 2,432 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2005
On 2008-10-13, Ognjen Bezanov <Og****@mailsha ck.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****@mailsha ck.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***********@A cm.Org
Oct 15 '08 #5

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

Similar topics

0
1994
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 So, i've used the PythonInterpreter class to instanciate an interpreter and to integrate it but the its environnement doesn't seem to be the
12
2396
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 find it fun to study the language heh Anyways to the point of my post.....
118
6707
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 hated it, having learned C++ a few years prior. They didn't teach Lisp at all and instead expected us to learn on our own. I wasn't aware I had to uproot my thought process to "get" it and wound up feeling like a moron. In learning Python I've...
1
2082
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 written using other languages. Extensions of Python could be done via special interpreter extensions. From Python sources, the special modules would look like other modules, with the Python API (the key feature from
113
5274
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 the Python world, you're fine. But once you do, things go downhill. MySQLdb has version and platform compatibility problems. So does M2Crypto. The built-in SSL support is weak. Even basic sockets don't quite work right; the socket module...
5
1641
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.)? Could a Python program itself create a sub-interpreter, and work with it with all the privileges and capabilities that an actual C program would have? I realize that this may be a bit too... mystical? ... for a lot of people's tastes, but I'm just...
3
9165
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 arguments that would tell on which interpreter to run the string...? Marcin
0
1587
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 (Python, for one), but Python bytecode is geared very much towards running Python code with Python's object model. Several years ago, there was someone who wrote up such a document for a university project. Unfortunately, my Google-fu has failed...
0
8609
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8899
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8871
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7737
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5861
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4621
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2333
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.