Closed Eszartek closed 7 years ago
Hi! Thanks for the issue, it was caused by a conflict between words used in the block editor and the main dictionary. The block editor reuses name 'i' for an editing command. I have moved the editor to a new file "editor.fth" and added some unit tests that test "do...loops" directly.
Let me know how it goes.
That was it!
I'm just starting to learn forth, and your library is nicely packed with features, examples and notes. I wasn't expecting to hit a bug while practicing a simple loop, but I'm glad it was an easy fix. I'm enjoying the stability of the interpreter. Some others I've tried just segfault on errors, and others have all these language changes because the author feels "Forth has it wrong, and I know better, so I changed xyz".
Well done and thank you!
I'm glad it was an easy fix as well! The editor was the last thing I was testing and I left it where it was without thinking about it.
I know what you mean about Forth interpreters segfaulting at the first mistake, I've tried to make it as bullet proof as possible. There's a few areas where I cannot prevent errors, such as passing invalid pointers to the file word sets ("99 close-file" for example causes a core dump), as it passes its argument to "fclose".
The interpreter is meant to be a tutorial on how Forth works, the Forth code itself could use more commenting.
There are quite a few differences between libforth and ANS Forth, which you will find if you use it more, but I try to resolve differences when I find them. It's not because I think ANS Forth does it wrong but because I have implemented something incorrectly, it's a large standard and it can be quite difficult to mimic the exact semantics of what it specifies.
I started the interpreter to learn how Forth works, so there are things I would do different if I was to do it again.
Thanks!
When I run the do loop example in forth.fth:
: example-1 10 1 do i . i 5 > if cr leave then loop 100 . cr ; example-1
the interpreter throws an error '[check_depth 1411] error: stack underflow 0x1 -> 2267 (line 4536)' instead of printing 1 2 3 4 5 6.
However, running "1 50 primes" , which is also a do loop, runs fine.
My system is 64bit ArchLinux. All the unit tests pass fine, but no tests have a do loop :)