BEGIN CLASS Fibonacci; HIDDEN fn, main; ! private members; BEGIN INTEGER fn; ! communication; PROCEDURE main; ! mimic uC++ coroutine main; BEGIN INTEGER fn1, fn2; fn := 0; fn1 := fn; Detach; ! suspend(); fn := 1; fn2 := fn1; fn1 := fn; Detach; ! suspend(); WHILE TRUE DO BEGIN fn := fn1 + fn2; fn2 := fn1; fn1 := fn; Detach; ! suspend(); END; END; INTEGER PROCEDURE next; BEGIN Call( THIS Fibonacci ); ! resume(); next := fn; END; ! Fibonacci constructor code; Detach; ! return to declaration; main; ! call main as last line of constructor; END Fibonacci; ! program main equivalent; REF(Fibonacci) f1, f2; ! objects are references; INTEGER i; f1 :- NEW Fibonacci; f2 :- NEW Fibonacci; FOR i := 1 STEP 1 UNTIL 10 DO BEGIN OutInt( f1.next, 3 ); OutText( " " ); OutInt( f2.next, 3 ); OutImage; END END; ! Local Variables: ; ! tab-width: 4 ; ! compile-command: "cim Fib.sim" ; ! End: ;