💾 Archived View for stack.tilde.cafe › gemlog › 2022-09-14.gmi captured on 2023-09-28 at 16:12:33. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2023-09-08)
-=-=-=-=-=-=-
My Forth bender is moving along nicely. I can parse numbers (in any base, 16 or less), search for words, and do rudimentary output. In well under 2K of code.
I fully expect to be defining words today. My assembly craving is being satisfied, and I am almost sorry to be so close to done with this part of the project.
I am conidering doing something else in assembly, but a Forth-like assembly. That is, imposing the datastack paradigm for parameter passing, and maybe adding some macros for structuring. That will help me organize code and still enjoy the low-level fun of assembly, with no HLL shackles.
The first point was discussed in a previous post; the second is worth considering.
Normal Forth has two states: compilation and interpretation. State-aware words can do different things based on the state: literals, for instance, place themselves on the stack in interpreted mode and compile code to place themselves on the stack otherwise. Normal words are treated as immediate, and executed instead of compiling a token. This gets messy with words like IF and other control structures, requiring alternate words for interpreted mode, such as [IF].
To avoid this mess, I will treat my Forth as a compiler. Everything is compiled, always. To emulate an interpreter, the code compiled on the command line is immediately executed and erased. Defining words such as : adjust the top pointer so that the erasure does not affect the newly-defined word.
There are some consequences to these new semantics. Care must be taken to not leave garbage in the dictionary when combining regular words and defining words. Placing definitions inside control structures for instance, may leave some code prior to the definition unerased, as the definition will adjust the top past itself.
But the is much cleaner otherwise.
I've done this with Forth-like systems that do native compilation, but never tried it in a minimal simplistic Forth.