Explicit TCE
bearophile
bearophileHUGS at lycos.com
Fri Oct 12 11:02:56 PDT 2012
Tyler Jameson Little:
> D could use something like Newsqueak's become keyword. If
> you're not familial with Newsqueak, become is just like a
> return, except it replaces the stack frame with the function
> that it calls.
Are you talking about CPS?
http://en.wikipedia.org/wiki/Continuation_passing_style
> DMD should optimize this already, but explicitly stating become
> is a key to the compiler that the user wants this call to be
> eliminated. Then, more interesting things can be implemented
> more simply, like a state machine:
>
> void stateA() {
> become stateB();
> }
>
> void stateB() {
> become stateC();
> }
>
> void stateC() {
> return;
> }
>
> void main() {
> become stateA();
> }
Seems nice.
> I'm not sure how D handles stack sizes, so this may be an issue
> as well if stack sizes are determined at runtime.
D doesn't currently support C99 VLAs, but it supports alloca(),
so stack frames are sized dynamically. But maybe this is not a
big problem for CPS.
Bye,
bearophile
More information about the Digitalmars-d
mailing list