In which we have to reimplement create and does>. Having implemented create and does> as described previously, there are two problems. Consider the following extract from my core tests: t(": DOES1 DOES> @ 1 + ;", expected: "") t(": DOES2 DOES> @ 2 + ;", expected: "") t("CREATE CR1", expected: "") t("CR1 here =", expected: … Continue reading Forth does create
Tag: forth
Does Forth create
In which my head explodes. create and does> are what is currently causing the unit tests of my Forth interpreter to fail. So what do these things do? Well, if you read the Forth specification, it becomes obvious that the main thing they do is make a nice smoothy out of your brain. Fortunately, I … Continue reading Does Forth create
Go Forth and Leave
In which I prematurely exit loops The basic DO loop is done. Now we need to implement LEAVE. This is effectively a "go to the end of the loop". It seems simple enough but there is a problem in that LEAVE can occur - in fact, almost certainly will occur - inside other control structures, … Continue reading Go Forth and Leave
Stacking Forth Returns
In which I create a real return stack So far, the return stack has been a hybrid of the Swift stack for returning from code and a stack implemented within the code for temporary values and loop control. It's time to implement the whole stack in the code. I'm not sure if this will be … Continue reading Stacking Forth Returns
I Do Forth
In which I go loopy trying to implement do loops Do loops are control structures that require a bit more thought than the ones implemented s far. The main problem is the existence of a loop variable, or, in the case of nested do loops, multiple loop variables. We'll deal with that in a minute. … Continue reading I Do Forth
My Fifth Rethink on Execution Tokens
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
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