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.https://github.com/jcmvbkbc/esp32-linux-build
ESP32-S3 N16R8 is <$5 on aliexpress:
- Dual-core Xtensa 240 MHz
- 16 MB NOR flash (eXecute-in-place supported)
- 8 MB (PS)RAM
- Wi-Fi 2.4 GHz 802.11n, Bluetooth
As well as Zephyr, NuttX RTOSes, MicroPython.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.
cramfs parses ELF files and marks XIP only a .text/ro segments of it, not the whole file.
https://github.com/npitre/cramfs-tools/commit/2325ed2de8fd17...
What I found troublesome were not really the caching of array count, but when and where should the side effect be represented in AST, for example this one: https://godbolt.org/z/rcT1d8WWe the puts() call is a side effect for automatic variable but completely ignored for static variable.
Even Dennis Ritchie and Ken Thompson themselves, went on with Alef, Limbo and Go.
I have been contributing by reducing my C, and C++ footprint on the planet, and security enforcement at various assignments.
It is like gardening, slowly taking away all the paths bad weeds are still able to spoil the garden.
We might not remove all of them, however if they are only able to thrive on a little gardner corner surrouned by sand is already an improvement.
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.
I think people have no clue how powerful ESP 32 actually is.
There is a lively movement for coding in Rust for esp32, that works, just not on the device I think.