Implementing forward refs in monadic assembler and interpreter
Axel Simon
A.Simon@ukc.ac.uk
Fri, 15 Nov 2002 10:17:08 +0000
On Fri, Nov 15, 2002 at 01:38:03AM -0800, Mike Gunter wrote:
>
> \begin{code}
> compute12 = mdo
> { zero r1
> ; zero r2
> ; addi r2 3 -- loop three times
> ;topLoop <- label
> ; addi r1 4
> ; addi r2 (-1) -- decrement loop counter
> ; brPositive r2 topLoop
> ; mov r3 r1
> ; addi r3 (-10)
> -- !!! Forward branch:
> ; brPositive r3 out -- if r1 > 10 don't add 100
> ; add r1 100
> ;out <- label
> }
> \end{code}
>
> but it's not clear to me how to implement it.
I would suggest a forward declaration like in Pascal. At least it would
fit the monadic style:
out <- forwardLabel
brPositive r3 out
add r1 100
fLabelSet out
I admit it doesn't look that nice, but it's easy to implement.
Axel.