473,396 Members | 1,827 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,396 software developers and data experts.

C compiler written in Python

Doing an independent study with Dave Beazley this quarter, Atul Varma
has written a C compiler on his own in Python. It generates annotated
x86 assembly code from arbitrary C files.

Quoting Atul's website:

* The different stages of compilation are encapsulated in visitor
classes, which (in my opinion) makes the code quite readable, and also
made writing the compiler a lot easier. The yacc rules merely generate
the abstract syntax tree and visitors do the rest.

* The code generator is also a visitor, which makes the process very
modular; for instance, although this compiler doesn't generate
intermediate code (which is what most compilers that compile for
different architectures use), one could simply write, say, a SPARC code
generation visitor and run the AST through it to generate assembly for
that architecture. This separation also means that the rest of the
compiler is independent of machine architecture.

* Writing the compiler in Python allowed me to focus entirely on the
task at hand (compilation), without being distracted by issues of memory
management and low-level data structure creation. Using such a
high-level language also made reading and refactoring the code a lot
easier.
Have a look:
http://people.cs.uchicago.edu/~varmaa/mini_c/

And this is the annotated assembly output:
http://people.cs.uchicago.edu/~varmaa/mini_c/foo.s

Jul 18 '05 #1
3 5796
Am Wed, 02 Jun 2004 23:32:07 -0500 schrieb Tim Freeman:
Doing an independent study with Dave Beazley this quarter, Atul Varma
has written a C compiler on his own in Python. It generates annotated
x86 assembly code from arbitrary C files.


[cut]

Cool. Next goal could be to
compile python with it.

Thomas
Jul 18 '05 #2
Thomas Guettler wrote:
Am Wed, 02 Jun 2004 23:32:07 -0500 schrieb Tim Freeman:

Doing an independent study with Dave Beazley this quarter, Atul Varma
has written a C compiler on his own in Python. It generates annotated
x86 assembly code from arbitrary C files.


Cool. Next goal could be to
compile python with it.


Then run Mini-C with that so you can compile Wine and run Cygwin under
it. :-)
Jul 18 '05 #3
From: "Thomas Guettler" <gu*****@thomas-guettler.de> writes

Cool. Next goal could be to
compile python with it.

Thomas

And the goal after could be to get rid of C :-)

Yes I really think about this:
Let us start from the bottom

Let us start with Assembler. Maybe High Level Assembler with clever macros.
Add higher datatypes if possible (I wish list and dict). Build an
environment that allows you to generate and execute assembler at runtime

This could be the basic building block for clever JIT virtual machines
(something like parrot - but small, lightweight please - if possible)

Higher level languages on top of this machine will go the Psyco/JIT way-
taking the best of Compiler and Interpreter technology. This means: not all
can be compiled at compile-time, so compile again at hot-spots in the
beginning of loops when type-information is available, save the compiled
stuff and use it as long the loop repeats ...
regards
Günter
Jul 18 '05 #4

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

Similar topics

2
by: Jeff Epler | last post by:
Hello. Recently, Generator Comprehensions were mentioned again on python-list. I have written an implementation for the compiler module. To try it out, however, you must be able to rebuild...
4
by: Jørgen Hermanrud Fjeld | last post by:
On Tue, Aug 26, 2003 at 04:33:17PM -0500, Jeff Epler wrote: > 4. It's possible to write code so that __import__ uses compiler.compile > instead of the written-in-C compiler, but I don't have this...
12
by: rhmd | last post by:
Just found Python and I love it. What an elegant language! I would like to use it for various applications, but the mathematical calculations are way too slow (a million sines 8 seconds in Python...
699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
7
by: winlinchu | last post by:
Hi! I use Python, and writing some extension modules I think which could be written an C compiler, useful only to compile extension modules (I not think an GCC!!!!), so that the user not have to...
188
by: Ilias Lazaridis | last post by:
I'm a newcomer to python: - E01: The Java Failure - May Python Helps? http://groups-beta.google.com/group/comp.lang.python/msg/75f0c5c35374f553 - I've download (as suggested) the python...
14
by: Mark Dufour | last post by:
After nine months of hard work, I am proud to introduce my baby to the world: an experimental Python-to-C++ compiler. It can convert many Python programs into optimized C++ code, without any user...
48
by: meyer | last post by:
Hi everyone, which compiler will Python 2.5 on Windows (Intel) be built with? I notice that Python 2.4 apparently has been built with the VS2003 toolkit compiler, and I read a post from Scott...
2
by: Michael Hudson | last post by:
The PyPy development team has been busy working and we've now packaged our latest improvements, completed work and new experiments as version 0.9.0, our fourth public release. The highlights of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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,...

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.