C compiler written in Python Was: An idea.

winlinchu at yahoo.it winlinchu at yahoo.it
Fri Jul 23 04:24:40 EDT 2004


danb_83 at yahoo.com (Dan Bishop) wrote in message news:<ad052e5c.0407211647.18d74510 at posting.google.com>...
> "Thomas Guettler" <guettli at thomas-guettler.de> wrote in message news:<pan.2004.07.21.12.43.33.694021 at thomas-guettler.de>...
> > Am Wed, 21 Jul 2004 03:59:37 -0700 schrieb winlinch:
> > 
> > > 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 use GCC, Microsoft Visual C++,
> > > or other.
> > > It must have an common API to all platforms, even if obviously the
> > > implementation is various.
> > > Could be write in 100% Python pure.
> > > 
> > > It is a bad idea?
> > 
> > Hi,
> > 
> > I like the idea very much. A C compiler
> > written in python. Someone already started
> > this. There was a post in this newsgroup, 
> > maybe one month ago.
> 
> The link to this compiler is here:
> 
> http://people.cs.uchicago.edu/~varmaa/mini_c/
> 
> Another good idea would be to write an improved C preprocessor that
> 
> * is more consistent with the C language.  For example,
>      macro SQUARE(x) = x * x;
>   would be equivalent to
>      #define SQUARE(x) ((x) * (x))
> * in addition to MACRO and MACRO(args), allows forms as complex as:
>      macro NEW T[arraysize] = calloc(arraysize, sizeof(T));
>      macro NEW T(...) = T ## _new(...);
>      macro ALLOCATOR typename(...) {init} =
>         T* T##_new(...) {
>            T* self = malloc(sizeof(T));
>            init;
>            return self;
>         }
>      ;
>    which would allow you to write code like
>       ALLOCATOR String(char *s) {
>          self->length = strlen(self);
>          self->data = NEW char[self->length + 1];
>          strcpy(self->data, s);
>       }
>       int foo() {
>          s = NEW String("Hello, world!");
>          // ...
>       }
> * Has "typeof" as part of the preprocessor, so that code like
>      macro DESTRUCTOR T {cleanup} =
>         void T##_delete(T* self) {
>            cleanup;
>            free(self);
>         }
>      ;
>      macro DELETE p = typeof(p)##_delete(p);
>   will work.

I have seen http://people.cs.uchicago.edu/~varmaa/mini_c/ and I must
say that is good, even if I thought to a compiler written without
other modules instead of standard library's, already useful.
For me, the idea of an improvements of C preprocessor has the
disadvantage of having to learn additional syntax, when instead can be
a compiler in the standard library.

I attend answers, critics and ideas!!!!



More information about the Python-list mailing list