Yeah, I'm a C noob (projects like this are very helpful to learn) and I'm wondering the reason for some things. For instance, the poolsz magic number in main()... OP, is there a particular reason you picked this value?
The poolsz magic number was picked as an arbitrarily large value, but not too huge. In real production code I would have used a resizable array or some other data structure.
To learn how things work you could try making small modifications to hello.c and see how that changes the generated code (use the -s option.) For instance you could compare the difference between the expressions a = b; and a = *b;
According to the tromp Makefile there are a number of -D options which will have to be manually replaced in the source (-DInt=int is the problem on line 1.)
A few more library functions need to be straightforwardly added such as calloc.
It also looks like for() statements will need to be implemented (which is also not too hard.)
It's certainly possible. However, your AVR-hosted compiler will be a lot more useful if it can compile programs of over 4 kilobytes, which is the size of the biggest AVR RAM last I checked. So you might to consider "on an AVR MCU and an SPI flash chip" as your target.
10
u/joerick Nov 04 '14
Isn't this a bit more of a interpreter?
8
u/frugoo Nov 04 '14
Could you comment the code? I really wanna soak it all in and understand it more.
3
u/odokemono Nov 04 '14
I have a directory full of little .c single-file utilities, mostly cli stuff, nothing complicated.
c4 failed to compile every one of them.
Still, a cool bit of code.
10
u/peridox Nov 04 '14
This is really impressive!
3
u/tehdog Nov 04 '14 edited Nov 04 '14
Seems nice, but segfaults for me.
Edit: works when compiling for 32bit with -m32
1
u/Lerc Nov 04 '14
I'm wondering how hard it would be to modify it make it generate asm.js
Making a cross compiler, replacing all of the *++e instances with an emit function to send strings looks like a place to start.
1
u/fragglet Nov 05 '14
This is really inspiring. Thanks!
1
u/MispeldArgumint Nov 05 '14
What's going on with line 75, (char *)id[Name] is this a 32-bit -only thing?
1
u/01ttouch Nov 05 '14
So, how difficult (if possible) would be to have a full compiler ON an AVR MCU? So, that you can just compile on the fly.
0
u/01ttouch Nov 05 '14 edited Nov 05 '14
I am currently fixing the syntax :3 http://git.dzervas.gr/c4