logoalt Hacker News

guerrilla11/07/20243 repliesview on HN

> What would be a use-case?

Maybe bootstapping a new language with no dependencies.


Replies

sph11/07/2024

Yes. Go for example doesn't use glibc and instead interfaces with syscalls directly.

https://pkg.go.dev/syscall

show 4 replies
matheusmoreira11/07/2024

I've been working on that language for a while now!

https://github.com/lone-lang/lone

It's a lisp interpreter with a built in system-call primitive. The plan is to implement everything else from inside the language. Completely freestanding, no libc needed. In the future I expect to be able to boot Linux directly into this thing.

Only major feature still needed for kernel support is a binary structure parser for the C structures. I already implemented and tested the primitives for it. I even added support for unaligned memory accesses.

Iteration is the only major language feature that's still missing. I'm working on implementing continuations in the interpreter so that I can have elegant Ruby style iteration. This is taking longer than expected.

This interpreter can make the Linux kernel load lisp modules before its code even runs. I invented a self-contained ELF loading system that allows embedding arbitrary data into a loadable ELF segment that the kernel automatically maps into memory. Then it's just a matter of reaching it via the auxiliary vector, The interpreter uses this to automatically run code, allowing it to become a freestanding lisp executable.

I wrote an article about how it works here:

https://www.matheusmoreira.com/articles/self-contained-lone-...

show 1 reply
jcalabro11/07/2024

Indeed, Zig does this for instance (at least for x86_64 linux [0]) as a way to avoid having to link libc at all

[0] https://github.com/ziglang/zig/blob/ee9f00d673f2bccddc2751c3...