Here's a working shot at making while loops work purely iterative, i.e. without flow-control exceptions and without deepening the evaluator's stacks. It does appear to work for while loops...however:
- It uses marker interfaces and dummy instructions to mark spots of interest in the instruction stack...for example, a Redoable instruction is used to mark the spot where redos return to. I'm not particularly fond of this method of doing things, but in the absence of a richer AST or an intermediate compilation into primitive jmp-like instructions, it's a simple way. - I did not implement any next/redo/break logic for OptN nodes, so they'll be pretty busted with this patch. - Ditto for Until nodes. - I did not implement next logic for yields, so they won't work right with next either. - It's slower than what's on HEAD (mainly because there's a lot more work done) but probably more memory-efficient (since each loop doesn't create multiple additional eval stacks). Speed issues can be worked out in the future...there's better ways to do this I think it's a pretty good proof of concept. Digging back down the stack isn't beautiful, and instanceof causes lip cancer (so I hear), but it's functional. Removing the flow-control exception roadblock, all that remains to fully iterative evaluation is regular exception handling and a green thread implementation. I'll be playing with this over the weekend to try to improve and clean it up, and to make it work for all cases. - Charlie
pure_iterative_while_loop.patch
Description: Binary data
