Skip to content
Tech News
← Back to articles

The Lone Lisp Heap

read original get Lisp Programming Book → more articles
Why This Matters

The development of Lone Lisp highlights the challenges and ingenuity involved in creating a Lisp interpreter without relying on standard libraries like malloc, emphasizing the importance of custom memory management in constrained environments. This approach demonstrates how foundational programming concepts can be reimagined to build complex systems from scratch, impacting the way developers approach language implementation and embedded systems.

Key Takeaways

The lone lisp heap

Like many dynamic languages out there, lone started out simple. It was essentially a collection of data structures written in C, an union comprising all of those types, a typed value structure containing the union plus metadata, and a custom language whose entire purpose is to bring all these values together into patterns that resemble working programs.

struct lone_lisp_list { } ; struct lone_lisp_vector { } ; struct lone_lisp_table { } ; enum lone_lisp_heap_value_type { LONE_LISP_TYPE_LIST , LONE_LISP_TYPE_VECTOR , LONE_LISP_TYPE_TABLE , } ; struct lone_lisp_heap_value { bool live : 1 ; bool marked : 1 ; enum lone_lisp_heap_value_type type ; union { struct lone_lisp_list list ; struct lone_lisp_vector vector ; struct lone_lisp_table table ; } as ; } ;

When I put it this way, the language itself seems almost incidental to the virtual machine work. That's because it is. Lone was in fact not designed ahead of time. It was and still is being constructed in real time. It's almost as if the language itself is arising as a consequence of its own implementation. It grows in complexity alongside the knowledge and understanding of its creator.

At first I was a neophyte. I was attracted to ideas that were almost painfully simple, almost too naive to cope with the harsh reality of the world. The code reflected that.

Take the above structures, for example. How are such values created? My first instinct is to simply allocate some memory for each object. Call malloc with the size of the structure, then initialize the memory it returns. It's that easy.

Right?

Memory allocation

Lone is a lisp interpreter written in freestanding C. There is no dynamic memory allocation in freestanding C. There is no such thing as malloc . There is no libc . There is only me and the code. If I wanted malloc , I would have to write it myself.

So I wrote it. I read up on everything I could find online about memory and its allocation. Then I made my own memory allocator.

... continue reading