I probably should call it a compiler for a 'C-like language' because it implements a tiny subset of C, just enough to implement some basic functions. Currently it supports int and char as well as pointers and you can define and call functions. Control structures are limited to while, if/else and return but quite a few binary and unary operators have been implemented already.
Because the compiler is based on the pycparser module that can recognize the full C99 spec it will be rather straight forward to implement missing features.
Pain points
Even for the small string manipulation functions it quickly becomes clear that additional instructions for the CPU would be welcome. The biggest benefit would probably be to have:
- Conditional branch instructions with a larger offset than just one byte.
- Pop/push instructions.
Currently implemented as two instructions, one to change the stack pointer and another to load or store the register. This approach makes it possible to use any register as a stack pointer but for compiled c we need just one.
- Better byte loading.
If we load a byte into a register we often have to zero it out before load it. This way we can easily change just the lower byte of the flags register but otherwise it is less convenient.
- alu operation to convert an int to a boolean
This would greatly reduce the overhead in expressiins involving && and ||
Plenty of room for improvement here 😁