In which I refactor word lists and primitives I've made a lot of progress with the core test suite, but unfortunately, I have come to the test case for ' and EXECUTE. These tests assume you can put an execution token on the data stack. An execution token is a number which refers to a … Continue reading Go Forth and Execute
Author: jeremy pereira
The Forth Test at Trent Bridge
In which we start to get serious about the test suite In the course of writing the blog about loops, I discovered the Forth 2012 Test Suite. I thought it would be pretty cool to include something similar. If I reimplement the entire suite and my interpreter passes it, then it is compliant with the … Continue reading The Forth Test at Trent Bridge
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
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
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