Com S 641 meeting -*- Outline -*- * Command Blocks (4.1) These are typical in Algol 60 and Pascal, even C has them ** syntax and typing ------------------------------------------ COMMAND BLOCKS (4.1) Syntax: C ::= ... | begin D in C end Type Rule: Example: begin var A: newint; proc P = begin var C: newint in C:= @A end; proc Q = begin var B: newint; var A: newint in A := 1; call P end in A := 0; call P; call Q end ------------------------------------------ pi1 |- D: pi2 dec, pi3 |- C: comm _________________________________ where pi3 = pi1 `unionMinus` pi2 pi1 |- begin D in C: comm Annotate the example to show a typing, if desired. ** semantics (4.1.1) Q: How is storage used in the previous example? show it as a stack. ------------------------------------------ SEMANTICS (4.1.1) Behavior of the store: ------------------------------------------ So what we need is something to pop the store back to the original level when we're done ------------------------------------------ NEW STORE OPERATIONS > type Store storable = [storable] ... > sizeOf :: Store storable -> Integer > sizeOf = genericLength > free :: Integer -> Store storable > -> Store storable > free = genericTake ------------------------------------------ Show how free 3 [1..7] works, and sizeOf [1..7] ------------------------------------------ SEMANTICS OF COMMAND BLOCKS data C = ... | Begin D C meaningC((Begin d c)) env s = ------------------------------------------ ... free (sizeOf s) s2 where (env1, s1) = meaningD((D)) env s s2 = meaningC((C)) (env `unionMinus` env1) s Want this to be strict in both the environment and store, which will be the case if the base cases for declarations and commands are (as we've been doing).