Show HN: Xcc700: Self-hosting mini C compiler for ESP32 (Xtensa) in 700 lines
154 points| isitcontent | 2 months ago |github.com
Hi Everyone! I just wrote my first compiler!
- single pass, recursive descent, direct emission
- generates REL ELF binaries, runnable using ESP-IDF elf_loader
- very basic features only, just enough for self-hosting
- treats the Xtensa CPU as a stack machine for simplicity, no register allocation / window usage
- compilable on Mac, probably also Linux, can cross-compile for esp32 there
- wrote for fun / cyberdeck project
Sample output from esp32:
xcc700.elf xcc700.c -o /d/cc.elf
[ xcc700 ] BUILD COMPLETED > OK
> IN : 700 Lines / 7977 Tokens
> SYM : 69 Funcs / 91 Globals
> REL : 152 Literals / 1027 Patches
> MEM : 1041 B .rodata / 17120 B .bss
> OUT : 27735 B .text / 33300 B ELF
[ 40 ms ] >> 17500 Lines/sec <<
My best hope is that some fork might grow into a unique nice language tailored to the esp32 platform. I think it is underrated in userland hobby projects.
ValdikSS|2 months ago
https://github.com/jcmvbkbc/esp32-linux-build
ESP32-S3 N16R8 is <$5 on aliexpress:
As well as Zephyr, NuttX RTOSes, MicroPython.no_time|2 months ago
Losing this when you load ELFs is kind of a bummer. Probably a dumb question but I wonder if it'd be possible to only swap in the parts of the binary that are needed at any given time.
artemonster|2 months ago
uecker|2 months ago
isitcontent|2 months ago
pjmlp|2 months ago
boznz|2 months ago
saidnooneever|2 months ago
fuhsnn|2 months ago
ladyanita22|2 months ago
As a fun of Rust, one thing that saddens me is knowing these things would be difficult to achieve with a Rust compiler, given the language seems to be vastly more complex.
Unless someone created a subset of Rust without (some?) safety checks, I guess.
isitcontent|2 months ago
There is a lively movement for coding in Rust for esp32, that works, just not on the device I think.
pjmlp|2 months ago
I think people have no clue how powerful ESP 32 actually is.
https://en.wikipedia.org/wiki/Amstrad_PC1512
MobiusHorizons|2 months ago
isitcontent|2 months ago
unknown|2 months ago
[deleted]
nunobrito|2 months ago
isitcontent|2 months ago