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
Tag: 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
Be More Forthright
In which I call for immediacy Implement a way to compile immediate words.http://beza1e1.tuxen.de/articles/forth.html As far as I can tell, immediate words are words that are executed immediately, even in compile mode. An example of this is the ; that ends a word definition. There are two things needed: tell if a compiled word is immediate … Continue reading Be More Forthright
Forth and the Furious
In which we go faster This is a bit of an interlude. At this point, I've built a serviceable computing engine that's not quite a Forth implementation but is capable of any computation. We can now look at refactoring some parts of it with respect to increasing performance. At the same time, we want to … Continue reading Forth and the Furious
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
May the Forth be With You
In which I write a simple word parser My project for the weekend is a Forth interpreter. I stumbled across a web site that tells you how to write one. I say "interpreter" because a compiler involves messy things like machine code and I don't want to go there just yet. Exercise 1 Read Forth … Continue reading May the Forth be With You