4 ms·
Theaded code always interests me, but there definitely is a price to it. Should be noted though that a lot of newer Forths diverge from the classic threaded cod
by shadowofneptune 4y ago
Theaded code always interests me, but there definitely is a price to it. Should be noted though that a lot of newer Forths diverge from the classic threaded code model. Because it is a concatenative language, it is possible to have one that compiles native code by copying inlined subroutines (https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.56.1353&rep=rep1&type=pdf https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.56...).
For example to compile : SQUARE DUP + ; all the compiler has to do is copy the machine code of DUP to the place where SQUARE is being compiled, remove the ret instruction at the end of it, and copy the machine code of + after it. It can also do some small optimizations to remove redundant instructions.
You can do this with other languages, but concatenative languages can make it as simple as literally concatenating bits of code.
- kragen 4y agoYeah, that's pretty much how Ur-Scheme compiles, inspired by bigForth: http://canonical.org/~kragen/sw/urscheme http://canonical.org/~kragen/sw/urscheme
- j6a 4y agokragen, I emailed you on the 28th, can you please check it?
- kragen 4y agoNot finding anything with from-address containing "j6a". Sorry, I'm not doing very well, so I apologize if I should recognize you.
- j6a 4y agono reason you'd recognize this account that i just made, but I just resent the email and added j6a to the subject, so can you please check again.
- j6a 4y agohere's a hint: you sent me this link a while ago. also, i sent you something and am trying to make sure you get it. https://news.ycombinator.com/item?id=28936057 https://news.ycombinator.com/item?id=28936057
- 0xdeadbeefbabe 4y agoIt's like the compiler becomes the CPU you wanted in the first place.
- yiyus 4y agoIt would be nice if the compiler could tell you: ERROR: DUP + is not SQUARE. Did you mean DOUBLE?
- shadowofneptune 4y agoYeah, that was a mistake. Changed it from * to + at some point when writing it and forgot to update it.