4 ms·
2007 actually. Anyway, ask me anything! The project comes in two parts. The first part is linked above. The second part is written in FORTH -- or rather, a
by rwmj 11y ago
2007 actually. Anyway, ask me anything!
The project comes in two parts. The first part is linked above. The second part is written in FORTH -- or rather, a subset of FORTH initially that builds up and adds features as it goes along: https://github.com/nornagon/jonesforth/blob/master/jonesforth.f https://github.com/nornagon/jonesforth/blob/master/jonesfort... Try scrolling down the file, and notice how the comment syntax changes from \ (backslash) to (...) (parentheses), then notice that parenthesis-comments are implemented just before the style change. There's a lot more stuff like that, although that's the most noticeable thing for beginners.
- cartoonfoxes 11y agoI really enjoyed reading jonesforth. I'm just finishing up a forth app for BareMetal OS, and have been having a blast so far. Publishing tutorials is one thing, but taking the time to put together an honest-to-goodness literate program is a step beyond. Thank you for your time and effort!
- carapace 11y agoThank you so much for this. I'm one of the many who have written a FORTH with the help of this document/program and I really, really appreciate it.
- listic 11y ago> Now some easy FORTH primitives. These are written in assembly for speed. To think again, shouldn't a modern C/C++ compiler be able to produce better code than this assembly without the intrinsic unportability? Let's take, e.g. SWAP defcode "SWAP",4,,SWAP pop %eax // swap top two elements on stack pop %ebx push %eax push %ebx NEXT (and NEXT is) /* NEXT macro. */ .macro NEXT lodsl jmp *(%eax) .endm This won't really be blazing fast, or will it?
- rwmj 11y agoThe NEXT macro and terrible use of the stack is kind of integral to threaded code. I'll let you read the tutorial to find out why :-) In general you shouldn't expect FORTH to be fast -- it uses the stack far too much and the way it does branching kills branch prediction on modern CPUs. However it is very small and a lot of fun to write. If you are looking for a system that can run on baremetal and where you can completely understand the system from top to bottom, then that's FORTH for you. Compared to C, FORTH has an extensible syntax and features like exceptions. Compared to FORTH, C is a lot easier to write significant programs in.
- listic 11y agoI am nodding along, but we can't say we write in assembly for speed, if we don't achieve much of it, can we? Especially if portable C turns out to not actually be slower.
- kryptiskt 11y agoThis style of threaded code shines in making it compact. So it's useful for bootloaders and other very constrained environments.
- rwmj 11y agoYeah I'm not going to defend FORTH as a practical language -- it's annoying to write significant programs in it. However it does fit in a smaller space than C (probably). I'm currently writing an ML derivative language for smaller systems and I hope that'll be practical while at the same time being a better alternative to C.
- listic 11y agoWas this system intended primarily as a teaching and learning experience?
- rwmj 11y agoYes -- although mainly as a learning experience for me. It was also a lot of fun to think about and write.
- listic 11y agoAre you familiar with BootForth - a 'Forth bootstrapping framework'? It was originally announced in 2008 in comp.lang.forth https://groups.google.com/forum/#!topic/comp.lang.forth/tc_OnqFOa1w https://groups.google.com/forum/#!topic/comp.lang.forth/tc_O... Maybe by chance you even have the source? It seems to have disappeared from the net, together with Gitorious, and the original author is unavailable.
- rwmj 11y agoNo - I've not heard of that one.