In which I continue my war against associated values In my previous post, I ended by trying to eliminate the CompiledWord cases that use associated values. These are: case parsedLiteral(Int) case undefined(Word) case redefined(Word) case definition(Cell) I've got rid of the last of these, but it was a difficult struggle. I did it by introducing … Continue reading My Fifth Rethink on Execution Tokens
Author: jeremy pereira
My Forth Rethink on Execution Tokens
In which we refactor compiled words again It's probably come to your attention that I now have a file called MyForth+Primitives.swift that contains two enormous switch statements. Frankly, I think these need to go away. The easiest way - well, the easiest I've thought of - would be make CompiledWord map to Int with a … Continue reading My Forth Rethink on Execution Tokens
Forth: Cleaning up the execute loop
In which I simplify the execution cycle Every word now has an execution token and most words are interpreted using the function execute(token:,wordStream:,index:, output:). There are still a couple of words that have to be executed outside of this due to their CompiledWord having an associated value. Thus we have this ugly bit of code: … Continue reading Forth: Cleaning up the execute loop
Go Forth and Execute
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
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