6 ms·
A standalone zero-dependency Lisp for Linux
- nerdponx 3y ago> Lone is a freestanding Lisp interpreter designed to run directly on top of the Linux kernel with full support for Linux system calls. It has zero dependencies, not even the C standard library. Cool project! Not sure if I'm going to start using it any time soon, but cool nonetheless.
- matheusmoreira 3y agoThank you!
- ashton314 3y agoVery cool! In a similar vein there’s Zuo: https://github.com/racket/zuo https://github.com/racket/zuo
- ape4 3y agoA quick glance shows it uses GNU Make but that's only a build time dependency, I guess.
- yjftsjthsd-h 3y agoAll software needs dependencies at build time, saying no dependencies always means runtime.
- blueflow 3y agoI'm surprised the Kernel doesn't count here.
- yjftsjthsd-h 3y agoAt that point we really get into semantics... But now that you mention it, I would be interested to see if it could be built with APE to benefit from their bare metal support.
- rollcat 3y agoIt does. Writing your software to directly use the syscalls of a specific kernel does not make it "zero dependency", it makes it "one dependency" - and non-portable. The author elaborates on their rationale and the technical details in a blog post: <https://www.matheusmoreira.com/articles/linux-system-calls https://www.matheusmoreira.com/articles/linux-system-calls> TBH I have mixed feelings about this approach. It's true that this is more or less what Go or (Cosmopolitan libc) do, but the motivation in their case is to maximize portability (by making cross-compilation trivial). However when you #include <linux/...>, you not only make your software non-portable, you also make it a PITA to cross-compile as you need the kernel headers on the host machine. In contrast, with Go or cosmo, I can trivially build a tiny /sbin/init for amd64 Linux, pack it up with cpio, and run it with qemu-system-x86_64 -initrd - all from a Mac/arm64 host.
- craftkiller 3y agoSurely its more than one dependency. For example, you'll need a processor. Not just any processor, but a processor for which a C compiler has been written.
- matheusmoreira 3y agoThat's a great question... I wonder if Justine would be interested in that. She has her own sector lisp too.
- 3y ago
- matheusmoreira 3y agoYes. It has zero runtime dependencies but development currently assumes GNU tools. The test suite for example is entirely written in bash and uses GNU coreutils. I submitted a patch to coreutils to allow env to set argv[0] of programs specifically so I could use it in my test suite. Currently lone is a single C source file. It could easily be compiled manually if necessary. I've started reorganizing the repository though so that's likely to change.
- nvy 3y ago>Currently lone is a single C source file. Is there a plan to write a lone compiler so as to eventually have lone bootstrapping/compiling itself so that you no longer have to sully your hands with C?
- shrimp_emoji 3y agoYou don't have to; you get to! ;D
- nvy 3y agoHey some people like debasing themselves with C; I'm not gonna kink-shame.
- matheusmoreira 3y agoI would like that. I wanted to create the simplest possible reference C implementation first so the language can always be bootstrapped with a C compiler. After that, I'll probably make a better one. I'm considering a Rust implementation as well. At least that's what I tell myself. Just this simple interpreter has already generated a lifetime of work. It's making me wish I had infinite time to work on it.
- nanolith 3y agoThis is interesting. Although, I think it's always useful to point out that runtimes that directly make system calls will have portability issues in other *nix systems. For instance, OpenBSD has recently restricted system calls to a single offset of their libc in order to reduce ROP attacks. If Lone wishes to be portable, it will need to consider a libc dependency as an option. If not, it can probably get away with direct syscalls on Linux unless Linux kernel developers decide to add support for pinning system calls. I doubt that this would ever be a hard requirement in the kernel, as it would break userland all over, but I could see this being an option for certain distributions as a ROP mitigation. Many features like these flow from OpenBSD to other OSes.
- edgyquant 3y agoConsidering the title and use case it seems to be intentionally pretty specific to Linux
- nanolith 3y agoMany projects start this way. But, as per my comment, the assumption that direct syscall support will be maintained in future Linux distros is also risky.
- matheusmoreira 3y agoI worry about that risk as well. I assume that even if Linux were to introduce a mechanism for system call authentication, it would be something lone would be able to use to mark its system call primitive as allowed.
- nanolith 3y agoPerhaps. To be fair, I'm not aware of anything on the horizon, other than the fact that OpenBSD has been showing off their pinning implementation. As long as you know it's a possibility, then the point of my original comment is met. Good luck on this project. I look forward to seeing it progress.
- mfreeman451 3y ago[dead]
- netbioserror 3y agoSo I guess the difference from Janet is no C standard library dependency; is this being targeted for hyper-slim and embedded uses? Because Janet seems like a good choice for most desktop and server cases.
- matheusmoreira 3y agoYes. My current goal is to boot Linux directly into Lisp and bring up the rest of the system from there. Perhaps even create a Lisp user space.
- FredPret 3y agoI'm new to Lisp - would this then be a modern Lisp machine?
- f1shy 3y agoWell, if by lisp machine we understand a processor that can run native lisp, of course not, but I was dreaming with a modern lisp machine, and this is the best that can be practically made
- matheusmoreira 3y agoIt's certainly what I had in mind when I started the project. Writing a full Lisp operating system is extremely hard, better to take advantage of Linux and its drivers so as to avoid spending an entire lifetime recreating them. It's my understanding that a true Lisp machine would have hardware support for Lisp abstractions at the instruction set level, so I don't think the concept would apply to lone. I would be seriously honored if people considered it one though, even if only in spirit.
- thomastjeffery 3y agoHave you looked into GUIX? I think it would be really interesting to load the init system (scheme-based GNU Shepherd in this case) directly from the kernel instead of ever loading a shell environment. I bet we could factor out a lot of cruft from the current GNU OS implementation that way, especially if you are managing your system environment/configuration declaratively via scheme/lisp.
- matheusmoreira 3y agoHello everyone! I started this project, happy to answer any questions. I was hoping to polish it up a bit more so it would be worthy of a Show HN, never thought someone else would submit it here. Really made my day!
- schemescape 3y agoWhat’s the minimum kernel version required? (No need for an exact answer, I just want to know if it’s “in the last 3 years” vs “in the last 10 years” etc.) And is it possible to resolve network names or do anything network related? (Or is it planned?) I’m always looking for some way to create portable Linux binaries, and I happen to like Lisps. Right now, my best bets are Janet compiled against musl libc or maybe ECL… or just use Python (distributed as source)… Edit to add: I love the idea. Great work!
- matheusmoreira 3y ago> What’s the minimum kernel version required? In order to build lone, any version after the Linux UAPI headers split should do. https://lwn.net/Articles/507794/ https://lwn.net/Articles/507794/ https://stackoverflow.com/q/18858190/512904 https://stackoverflow.com/q/18858190/512904 https://github.com/torvalds/linux/tree/master/include/uapi https://github.com/torvalds/linux/tree/master/include/uapi These are the only headers that lone currently requires. When lone is built, a script will read all the system calls defined in those headers and create a table mapping symbols to system call numbers. This is so that you can write symbolic code such as: (system-call 'write fd buffer length) Instead of: (system-call 1 fd buffer length); write is system call 1 on x86_64 Once compiled, however, it should work with literally any version of Linux. The system call primitive can issue any system call given its number and its parameters. If an unsupported system call is made, Linux will simply return -ENOSYS which can be handled at runtime and should not crash the program. > I’m always looking for some way to create portable Linux binaries, and I happen to like Lisps. I have this vision in my mind: embedding lone modules into sections of the lone ELF and shipping it out. Zero dependencies, self-contained. Linux passes processes a pointer to their own ELF header via the auxiliary vector. Lone already grabs this data and puts it into a nice lisp object. Now I just need to code that feature in somehow: parse the header, find the sections, read them into a lone module and evaluate...
- rcarmo 3y agoNice. I can see something like this being used with circle (https://github.com/rsta2/circle https://github.com/rsta2/circle) to run bare metal on a Pi, too.
- gigatexal 3y agoVery cool project. Not commenting on that. Lisp and it's derivatives often hits the front page of HN and I always wonder why. What is it about lisp that is so powerful? so much so that some see it as the platonic ideal of programming languages or so it seems?
- packetslave 3y agoIt doesn't hurt that HN is written in LISP.
- f1shy 3y agoWell, Y combinator, the domain of HN is intimately related to Lisp, as the founder Paul Graham. That is how I landed in this site to begin, and I assume is so for many around. That could explain it a little bit.
- barbazoo 3y ago> Ask HN: Why is everyone here so obsessed with Lisp? https://news.ycombinator.com/item?id=20697493 https://news.ycombinator.com/item?id=20697493
- vbezhenar 3y agoLisp code is made of lists. And lists are the main data type for lisp programs. So you can naturally produce and transform lisp code using lisp code. Not all lisps allow that, though, but I think that's the main differentiator and it's unique in that aspect. So it's like generating JS code text from JS, but working with JS code as a text is much more confusing compared to working with lisp code as a list.
- jng 3y agoBeautiful. Also, after 30+ years of writing C and C++, I learned one thing by casually browsing the source code: you can use a preprocessor macro in an #include statement. Thanks.
- matheusmoreira 3y agoYes! GCC calls it computed includes. https://gcc.gnu.org/onlinedocs/cpp/Computed-Includes.html https://gcc.gnu.org/onlinedocs/cpp/Computed-Includes.html I used it to include architecture-specific source code and also a generated C file containing a table of Linux system calls defined by the Linux UAPI lone is compiled against. The makefile defines those macros by passing flags: -D LONE_ARCH_SOURCE='"$(ARCH.c)"' -D LONE_NR_SOURCE='"NR.c"'
- jng 3y agoOh so it's a GCC-specific thing... that explains it. In any case, congratulations on the lisp! It's beautiful code. I wish my current codebase was that beautiful. I mean, it's a lot of us contributing to it so the beauty is a kind of "meeting of the minds" situation... but still :) PS: My current project implements a lisp... rendered as JSON. Some other angle on beauty...
- matheusmoreira 3y agoThanks, I mean it. I've been programming alone for a long time, it really means a lot to read that. > My current project implements a lisp... rendered as JSON. Some other angle on beauty... Hey, feel free to share it. I'm curious about your project.
- jakobson14 3y agoJust compile regular Lisp with cosmopolitan. Then the same binary will run on windows, linux, mac, and BIOS. /s This has been done with Lua, see: https://github.com/jart/cosmopolitan/issues/61 https://github.com/jart/cosmopolitan/issues/61
- matheusmoreira 3y agoThat reminds me I should go debug the patch I sent to cosmopolitan, it ran on my machine but failed continuous integration...
- snvzz 3y ago>zero dependency >for Linux There's your dependency.
- matheusmoreira 3y agoI understand what you mean. By dependencies I meant user space libraries such as glibc and musl. The language itself is fully self-contained. It initializes itself with nothing but a static array of bytes. Could be possible to modify lone to run on bare metal instead. Perhaps by replacing the Linux system call code with BIOS I/O functions and replacing the Linux process entry point code with boot code that initializes the CPU and hardware. https://wiki.osdev.org/Printing_to_Screen https://wiki.osdev.org/Printing_to_Screen That would just shift the dependency from Linux to the firmware though.
- snvzz 3y ago>Could be possible to modify lone to run on bare metal instead. Perhaps by replacing the Linux system call code with BIOS I/O functions and replacing the Linux process entry point code with boot code that initializes the CPU and hardware. Just don't make the mistake golang made. In most systems, the "stable interface to the kernel" isn't the syscall, but the c library. (re: golang on openbsd)
- matheusmoreira 3y agoAbsolutely. I've written about this topic and how Linux is different: https://www.matheusmoreira.com/articles/linux-system-calls https://www.matheusmoreira.com/articles/linux-system-calls My plan is to target Linux exclusively.
- snvzz 3y agoI have always found it absurd that Linux insists on stable syscall ABI, and yet does not have a standard driver API. Hopefully, the world will migrate to a better system at some point. It will be exactly the opposite: It will not provide a stable syscall ABI, and it will have a standard driver API. Incidentally, it'll be microkernel, multiserver. Many articles will then be written about the maintenance burden Linux had, and how we should have done this much earlier.
- andxor 3y agoGreat project. I love your style of coding and documenting.
- matheusmoreira 3y agoThank you. I've been a lone programmer from a long time, means a lot to me to read that.
- keyle 3y agoProps to the author, if the code is as well designed and written as the README, this is looking good.