Falling in love with D, but...
Dan
murpsoft at hotmail.com
Mon Apr 16 13:24:59 PDT 2007
Peter Verswyvelen Wrote:
> >An "if" has a buffer that gets executed for the true condition, which, when
> complete, EIP goes to the start of the *next* statement.
>
> > A "while" has exactly the same thing, except that when that buffer is completed,
> EIP goes back to the start of the *same* statement.
>
> Well, it seems you really have to take a look at LISP/Scheme's "continuations"
> then. See http://en.wikipedia.org/wiki/Continuation. Really cool things, but not
> many people understand them, and they make it difficult to debug or read the code,
> but the same could be said about lazy evaluation, closures, etc... I'm not sure if
> D supports continuations? I guess one can do the same with closures anyway.
>
In all honesty, I don't see how a Lisp Continuation relates to flow control other than that it claims to "save state to be continued" and then get back to it after performing something? Like a stack? Wikipedia was using all kinds of word overloading to express the concept. (I hate word overloading)
~~~~
Abstraction of the x86 stack:
Consider the x86 stack a uint[]. The most recent element is always pushed onto the front (the zero side) of the stack. When a function is called, the top item on the stack is thus the first, and so forth.
Thus when we perform a function call in D, we get [EAX, &(ESP+0), &(ESP+4), &(ESP+8)...]
If we thus call the function "naked" and push EAX onto the stack, we then have ESP = arguments[arity];
One would obviously need to know the arity arbitrarily, or if you pass it in EAX, you don't even need to push it and you can store the argument.length there.
~~~~
Comparable to Continuations:
Furthermore, if one examines the x86 stack after PUSHA, they will realize that you have everything you need for a thread state. Allowing single-cpu multithreading merely requires you to provide an interrupt which maintains a flexible ring buffer of ESP's which point to stacks immediately after a PUSHA. Immediately after switching items on the ring buffer, perform a POPA and then IRET. In Ring 0, this costs roughly 118 cycles on a x686; if you port it out of an interrupt to Ring 3, it can take as little as 38 cycles for an x686 system.
More information about the Digitalmars-d
mailing list