[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Ah, those uninitiated people...
- From: Tony Finch <dot@...>
- Date: Wed, 13 Jan 2010 19:01:23 +0000
On Wed, 13 Jan 2010, David Kastrup wrote:
> Tony Finch <dot@dotat.at> writes:
> >
> > What I meant was how to represent the coupling between the instruction
> > pointer and the program state in the source code. You can represent
> > each state as a function so that state transitions are tailcalls.
>
> But that often causes contortions as well. You gain a lot more
> expressive power if "state transitions are calls" merely. Sometimes it
> is not easy to arrange for a call to get tail.
If you implement a state transition as a non-tail-call then you'll get
unbounded stack growth.
> > If C supported tail calls, then I could implement each state as a
> > function, state transitions as tail calls, and nesting as a normal
> > function call. No need for a trans_table[], no process() loop, and no
> > need for an explicit ifstate[] array of nested states.
>
> But nesting does not work as a tail call, so you can't save the state
> between state machine invocations.
The point about nesting is that unifdef can have multiple versions of its
state machine active at any time, if the program has multiple nested #if
blocks. These nested states are represented by an array, but if the code
were rewritten to use a tailcall state machine, it could implement nested
saved states using the language's call stack.
Tony.
--
f.anthony.n.finch <dot@dotat.at> http://dotat.at/
GERMAN BIGHT HUMBER: SOUTHWEST 5 TO 7. MODERATE OR ROUGH. SQUALLY SHOWERS.
MODERATE OR GOOD.
- References:
- Ah, those uninitiated people..., Alexander Gladysh
- Re: Ah, those uninitiated people..., Enrico Colombini
- Re: Ah, those uninitiated people..., Roberto Ierusalimschy
- Re: Ah, those uninitiated people..., Andrew Wilson
- Re: Ah, those uninitiated people..., Mark Hamburg
- Re: Ah, those uninitiated people..., steve donovan
- Re: Ah, those uninitiated people..., David Given
- Re: Ah, those uninitiated people..., Tony Finch
- Re: Ah, those uninitiated people..., Wesley Smith
- Re: Ah, those uninitiated people..., David Kastrup
- Re: Ah, those uninitiated people..., Tony Finch
- Re: Ah, those uninitiated people..., David Kastrup