Blog

The return of the Forth

In which I discover the return stack The return stack is used in many Forth systems to record return addresses when executing defined words. We currently don't need this because the return stack is implicit in the Swift stack. However, the return stack can be used for temporary storage. Furthermore, at some point, we would … Continue reading The return of the Forth

Forth Next: Loops

In which I go loopy In Forth if, while, and similar control flow constructs are not builtin but implemented. Implement them in your Forth.http://beza1e1.tuxen.de/articles/forth.html Since the last blog, I've fixed the comment unit test failure and I've moved stackTop from being a local variable to being a property of the Forth engine. Looking at the timed run: … Continue reading Forth Next: Loops

Go Forth Again

In which I learn how to regain control. In Forth if, while, and similar control flow constructs are not builtin but implemented. Implement them in your Forth.http://beza1e1.tuxen.de/articles/forth.html Let's start with IF ... ELSE ... THEN. This construct doesn't have a run time primitive word (or words). Instead it compiles as follows: cond IF conditional-words THEN trailing-words becomes … Continue reading Go Forth Again

Forth Amendment

In which I comment on things Define words ( and ) in Forth. Make ( read words until ) and do nothing with them. This is how Forth implements comments.http://beza1e1.tuxen.de/articles/forth.html I didn't quite follow the prescription above. I found that gforth will happily parse things like 3 ( 4 hgfd) . and (in this case) return 3. So it is not a case … Continue reading Forth Amendment

Go Forth and Multiply – or Don’t

In which I provide my Forth machine with the ability to make decisions Now it is time to revisit branching. Provide builtin branch and branch? words.http://beza1e1.tuxen.de/articles/forth.html We'll first need to do some refactoring because, in order to jump somewhere, our list of instructions needs to be indexable. In fact, it needs to be bidirectionally indexable. The branch instruction will … Continue reading Go Forth and Multiply – or Don’t

May the Forth be With You – Programs

In which I create a state machine and compile simple programs but I don't implement branches Provide builtin branch and branch? words.http://beza1e1.tuxen.de/articles/forth.html Seems simple enough... ... oh wait, how can I branch somewhere if I don't have the concept of a program, or a list of words at the least. I'll create the words for now, but I won't … Continue reading May the Forth be With You – Programs