proomt

Search

Search posts, papers, and topics

All posts

Lobsters9 min readintermediate

How I Wrote a Forth (Without Knowing How)

Summary

The author details building MoonForth, a Forth interpreter written in C that leverages Lua's C API for stack manipulation and word storage. The process was surprisingly straightforward, reinforcing the idea that Forth "writes itself" by iteratively filling missing functionality.

  • JonesForth's x86 assembly source served as a conceptual guide for Forth word implementation, despite being in a different language.
  • Lua's C API stack was directly used to implement core Forth stack manipulation words, treating it as the Forth data stack.
  • Forth words are stored as Lua tables containing C function pointers, allowing flexible redefinition and literal storage.
  • The "Forth writes itself" principle means development progresses by implementing missing words as needed to enable desired functionality.

Engineers interested in language implementation, Forth, or leveraging Lua's C API will find practical insights into building a stack-based language and interfacing C with Lua.

7/10

Related reading

  1. Article: Your Next DSL Author Is a Language Model

    Typed Domain Grounding (TDG) embeds a DSL inside a mainstream language the LLM already knows (e.g., Kotlin) and uses the host compiler as an oracle. The author describes five building blocks—embedding, choosing a host language with high training‑data frequency, compiler‑driven type safety, a generate‑compile‑repair loop, and an on‑demand teaching tool—and shows measured results from kUML, a Kotli…

    InfoQinfoq.com18 min
  2. Telling a Computer to Do Things

    The author explains how learning shell scripting unlocked the ability to automate and stitch together tools, emphasizing that proficiency is more about a rich CLI toolbox than syntax. He provides concrete tips, tool suggestions, and examples for writing maintainable scripts.

    Hacker News front pagewill-keleher.com7 minHN8736