An idea.

W

winlinchu

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?
 
T

Thomas Guettler

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.

Regards,
Thomas
 
D

Dan Bishop

Thomas Guettler said:
Am Wed, 21 Jul 2004 03:59:37 -0700 schrieb winlinch:


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.
 
W

winlinchu

Thomas Guettler said:
Am Wed, 21 Jul 2004 03:59:37 -0700 schrieb winlinch:


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!!!!
 
C

Chris S.

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?

What's the point? What's wrong with GCC? It's fast, comprehensive, and
supported on all major platforms. Unless it solves a specific task, like
Pysco or SWIG, it's purpose will be merely academic.
 
W

winlinchu

Chris S. said:
What's the point? What's wrong with GCC? It's fast, comprehensive, and
supported on all major platforms. Unless it solves a specific task, like
Pysco or SWIG, it's purpose will be merely academic.

The idea was that one to create a Python platform, without to use
large compilers (I refer above all to MSVC++!!!!!!!), but a compiler
part of the standard library to quickly compile a module.
 
L

Leif K-Brooks

The idea was that one to create a Python platform, without to use
large compilers (I refer above all to MSVC++!!!!!!!), but a compiler
part of the standard library to quickly compile a module.

But if it was capable of compiling any C extension module, it would have
to be a full-fledged (large!) C compiler.
 
C

Christopher T King

But if it was capable of compiling any C extension module, it would have
to be a full-fledged (large!) C compiler.

Not if it eschews most/all optimizations, obscure GCC/MSVC extensions,
full-blown assembler/linker, etc. It's quite possible to make a small C
compiler (tinycc (http://www.tinycc.org/) comes to mind...).
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top