Hacker News .hnnew | past | comments | ask | show | jobs | submitlogin

Writing a C compiler in pure shell is one of those projects that sounds absurd until you think about bootstrapping. If you want to compile C on a system where you literally have nothing but a POSIX shell, this is exactly what you need. The fact that the parser itself is BNF-generated from shell modules makes it even more interesting as a study in how far you can push shell scripting before it breaks. Would love to see this evolve into a proper repo with tests so it can actually serve as a minimal bootstrapping tool.
 help



> bootstrapping

This project reminds me of:

The Design of a Self-Compiling C Transpiler Targeting POSIX Shell - https://dl.acm.org/doi/10.1145/3687997.3695639

It's not just a toy or a fun hobby project, there's potential for practical use as a step in bootstrapping an entire software stack from human-verifiable artifacts.


It's an ongoing project: https://github.com/udem-dlteam/pnut

See also pnut.sh, but the server seems to be down at the moment.


But how would POSIX shell be available? Wouldn’t it be compiled from C?

A shell is almost always used to setup the bootstrap environment, so the dependency on a shell is more or less always there.

Otherwise, something special with POSIX shell is its large number of independent implementations, making it the ideal starting point for diverse double-compilation (https://arxiv.org/abs/1004.5534). The idea is to bootstrap a toolchain from multiple compilers (shells in this case), and the result compared to verify that no shell introduced a trusting trust attack.


I don't think any realistic system will bootstrap C from shell. What is the shell implemented in if not C?

This shell.c can be compiled from c89cc.sh itself:

https://gist.github.com/alganet/1513d7b6abef5c1a53a324d897c3...

Ouroboros self-hosting. They can self-host one another.

The idea is to make shell.c compile from an even simpler C compiler, such as M2-Planet:

https://github.com/oriansj/M2-Planet

Let me remind you that current stage0 bootstraps tinyc from mes, which is an interpreted lisp. It's not that different from the shell architecturally.

The current stage0 also features kaem as one of the first dependencies. kaem is, in fact, a simpler version of the bourne shell.

It's always a tower. You'll never get a one single clean dependency pass in bootstrapping.


The shell.c ouroboros is really cool. Being able to bootstrap trust through an entirely different language family (shell → C → shell) adds genuine value to the trusting-trust problem beyond just technical novelty.

Even if your shell was compiled in C, it doesn’t mean it wasn’t cross-compiled from another platform.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: