Com S 641 meeting -*- Outline -*- * Variables (2.9-10) ** declarations (2.9) Q: How is alias abstraction different from a variable declaration in a language like C or C++? A var decl allocates new storage, and also binds id to it. may also allow initialization Q: What kind of evaluation is used for variable declarations? eager: allocation and initialization happens right away so a var decl is part declaration (the binding) and part command (the allocation) ------------------------------------------ VARIABLE DECLARATIONS (2.9) Abstract Syntax: D ::= var I | ... C ::= L := E | ... E ::= @L | ... L ::= I Examples: ------------------------------------------ Note that the variable names var x, var y, var temp; proc swap = (temp := @x; x := @y; y := @temp) in x := 5; y := 4; call swap Q: Does the copy rule work for programs like this? ** semantics (2.10) ------------------------------------------ SEMANTICS OF VAR DECLARATIONS (2.10) [[pi |- var I: where and allocate : Store -> (Location x Store) allocate [n1,...,nk] = where init is some arbitrary Integer ------------------------------------------ ... {I:intloc}dec]] e s = ({I=l}, s') ... (l,s') = allocate(s) Q: How does this change the type of the semantic equations for declarations? now takes a store, and returns a pair of environment and store. Q: Do we have to make changes to the other kinds of declarations? yes, need to have them return store also (or use a monad...) ... [[pi |- define I=U: {I:theta}dec]]e s = ({I = f}, s), where f s' = [[pi |- U:theta]]e s' Q: any other changes? need to change the semantics of programs (D in C) to extract the final store from the declaration (D) ... [[D in C: comm]]s = [[pi |- C: comm]]e1 s1, where (e1,s1) = [[ emptyset |- D: pi dec]]\emptyset s