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

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

May the Forth Be With You – The Dictionary

In which I create a dictionary of words and an interpreter This is series of posts based on a blog by Andreas Zwinkau. Exercise 2 Create a dictionary of some sort. Initialize it with the words + and print. Execute programs like 2 3 4 + + print.http://beza1e1.tuxen.de/articles/forth.html This is where things get interesting. Prior to the exercise, Andread … Continue reading May the Forth Be With You – The Dictionary