Check out the new USENIX Web site. next up previous
Next: Step 3: Back-end translation Up: Step 2: staged interpreter Previous: Interpreter for Commands.

An example.

  The function interpret2 generates a piece of code from a Com datatype. To illustrate this we apply it to the simple program: declare x = 10 in { x := x - 1; print x } and obtain:

<Do %mswo
    { a <- Return %mswo 10
    ; %push a
    ; Do %mswo
      { e <- Do %mswo
             { d <- Do %mswo
                    { b <- %read 1
                    ; c <- Return %mswo 1
                    ; Return %mswo b %- c
                    }
             ; %write 1 d
             }
      ; g <- Do %mswo
             { f <- %read 1
             ; %output f
             }
      ; Return %mswo ()
      }
    ; %pop
    }>

Note that the staged program is essentially a compiler, translating the syntactic representation of the while-program into the above monadic object-program that will compute its meaning. Note that in the object-program all of the compile-time operations have disappeared. This object-program is fully executable. Simply by using the run operator of METAML, it can be executed for prototyping purposes.



Zine-El-abidine Benaissa
Wed Jul 21 11:46:59 PDT 1999