Closed patricksurry closed 5 months ago
I think this looks like a good compromise across size/speed/readability. When compared to the original speed, it's a massive speed boost. I only found a couple of things in the comments that could be better. I think you had mentioned that you wanted to clean things up and maybe update the documentation. Just let me know when you want me to pull this one.
I think the PR itself is good to go. I haven't tried to build documentation yet but there are a couple of things there that I should probably update now. Do you mind if I do that in a follow-on PR?
No issues doing the documentation as a separate PR. I'll often just open an issue to keep track of ongoing documentation updates that are needed, and then I handle them all at once. I find that works best for me. I should have time to review and pull this PR this coming weekend.
I do have "reorganizing the docs" still on the to-do list so that readers get less of that deja-vu effect if they read it linearly, and I agree that a little tutorial that people can follow along with that shows the basics of getting started with Forth is also a very good idea. If you think it makes sense to do that reorganization effort first, let me know. Otherwise (or perhaps regardless), you are likely to want docs/ch_internals.adoc
and search for "Control Flow", which describes how branches and loops are implemented.
fixed #53
I think this ends up as the best compromise. It doesn't try to cache
i
or do any other complicated conditional runtime so the code is straightforward. Each loop control block is 4 bytes on page 1, and we only cache the LSB of loopindex in zp as loopidx0 since we can often get away with only modifying that value and not checking anything in the LCB.Not speculatively calculating
i
inloop
makes tests withi
look worse here. Butloop
(and now+loop
) are shorter and faster. Thei
word is 20 bytes so just small enough to default to native compile, whilej
defaults to jsr. That's probably the right default, but now is your choice: by changing nc-limiit you can get both native or both jsr.For comparison here's the dodowordij test result if you force J to be native compile as well.