-- -- A compiler for Minila programs -- -- -- - Function compile takes a Minila program and converts it into -- an instruction sequence. -- - Function generator actually does this. -- - genForExp does this for expression. -- mod! COMPILE { pr(STM) pr(ILIST) op compile : Stm -> IList . op generate : Stm -> IList . op genForExp : Exp -> IList . vars E E1 E2 : Exp . vars S S1 S2 : Stm . var V : Var . var N : Nat . var IL : IList . -- compile -- generate -- genForExp } eof open COMPILE + VM . ops x y z tmp : -> Var . op p1 : -> Stm . eq p1 = x := n(1) ; y := n(1) ; while y < n(10) || y === n(10) { x := x * y ; y := y + n(1) ; } . red run(compile(p1)) . op p2 : -> Stm . eq p2 = x := n(1) ; for y n(1) n(10) { x := y * x ; } . red run(compile(p2)) . op p3 : -> Stm . eq p3 = x := n(24) ; y := n(30) ; while y =!= n(0) { z := x % y ; x := y ; y := z ; } . red run(compile(p3)) . op p4 : -> Stm . eq p4 = x := n(20000000000000000) ; y := n(0) ; z := x ; while y =!= z { if ((z - y) % n(2)) === n(0) { tmp := y + (z - y) / n(2) ; } else { tmp := y + ((z - y) / n(2)) + n(1) ; } if tmp * tmp > x { z := tmp - n(1) ; } else { y := tmp ; } } . red run(compile(p4)) . close