Com S 641 meeting -*- Outline -*- * type structure abstractions (2.11-12) ** separating the parts of a variable declaration (2.11) Idea: since a var decl is part abstraction (naming) and part command (allocation) we can use the semantics to guide the design of more orthogonal features perhaps these will be more powerful? more useful? Q: what's in the semantics that we don't have a way to name yet? the allocation semantic function... we'll call this a type structure ------------------------------------------ TYPE STRUCTURE ABSTRACTIONS (2.11) def: a *type structure* is a Examples: Abstract syntax: D \in Declaration T \in Type-structure D ::= T ::= Example: class N = newint; var x: N, var y: N, var temp: newint; proc swap = (temp := @x; x := @y; y := @temp) in x := 5; y := 4; call swap ------------------------------------------ ... storage allocation primitive ... newint, cons, record D end you could also have initialization involved, these are exercises ... D ::= var I:T that's eager evaluation, we'll call lazy eval a class ... D ::= ... | class I = T some languages use the keyword "type", but this shows connection to OOP ... T ::= newint | I Q: should x and y be different locations? yes, N is lazy, and only allocates when called ** record structures ------------------------------------------ RECORD STRUCTURES Abstract syntax: D \in Declaration C \in Command T \in Type-structure E \in Expression D ::= var I:T | class I=T | D1,D2 | D1;D2 | proc I=C | fun I=E | const I=N T ::= newint | I | Example: class complex = record var x:newint, var y:newint end; var x:complex, var y: complex in ... ------------------------------------------ ... record D end Q: Are we missing anything in the language? How to access parts of records ------------------------------------------ IDENTIFIER EXPRESSIONS Abstract syntax: D \in Declaration C \in Command T \in Type-structure E \in Expression X \in D ::= var I:T | class I=T | D1,D2 | D1;D2 | proc I=C | fun I=E | const I=N T ::= newint | record D end | C ::= L:=E | C1;C2 | if E then C1 else C2 | while E do C od | skip | E ::= N | @L | E1 + E2 | E1 = E2 | not E | L ::= N ::= | n, where n \in Integer X ::= I | Example: var arg: newint; class point = record var x:newint, var y:newint; proc set_x = (x := @arg), proc set_y = (y := @arg), proc north = (x := @x + 1), proc south = (y := @x + -1) end; var p1:point in arg := 0; p1.set_x; arg := 1; p1.set_y; p1.north ------------------------------------------ ... Identifier-expr ... X ::= I | X.I actually, the C++ grammar has something like this... ... fill in T ::= X C ::= call X E ::= X L ::= X N ::= X | n (the X is from a const decl) we could also have alias decls, but don't really have that syntax domain anymore... say how this program executes. ------------------------------------------ TYPE ATTRIBUTES (2.12) Attributes: pi ::= {i : theta_i} , J finite i \in J theta ::= t | t exp | comm | pi dec | delta ::= t ::= int | bool Meaning for type structure attributes: [[delta class ]] = ------------------------------------------ Q: What other things can be bound to names? locations, records, and classes i.e., type structures and type structure abstractions Q: What kinds of classes are there? ones that allocate integer locations, and records Can we think of these as the same thing? not really, as the integer locs are anonymous This suggests the rules for theta and delta ... theta ::= ... delta | delta class ... delta ::= delta ::= intloc | pi ... [[delta class]] = Store -> ([[delta]] x Store) Also, recall the following for delta [[intloc]] = Location [[{i:theta_i}]] = {i:[[theta_i]]} (environment) ------------------------------------------ TYPING RULES theta ::= t | t exp | comm | pi dec | delta | delta class delta ::= int loc | pi FOR YOU TO DO Finish the typing rules below... |- newint : int loc class _________________________________ |- record D end : _________________________________ |- (var I: T) : _________________________________ |- class I = T : |- I : theta, if (I:theta) \in ______________, if |- X.I:theta ------------------------------------------ ... see p. 56 ** semantics (2.12) ------------------------------------------ SEMANTICS OF TYPE STRUCTURES (2.12) For Declaration: [[pi|-(var I:T):{I:delta}dec]] e s = For Type-structure [[pi|- newint:int loc class]] e s = [[pi|- record D end: pi1 class]] e s = [[pi|- X: delta class]]e s = For Identifier-expr: [[pi|-I:theta]]e = v, where (I=v) \in e [[pi|-X.I:theta]]e = v, where ------------------------------------------ see p. 57-8 for all of it ... ({I=v,s'}), where (v,s') = [[pi|-T:delta class]]e s ... allocate(s) where allocate [n1...nk] = ... ... [[pi|-D:pi1 dec]] e s ... p(s), where p = [[pi|-X:delta class]]e in this the semantics recurses down to [[.]] for Identifier-expr (clearer in Haskell) ... r = [[pi|-X:pi1]]e, and (I=v) \in r i.e., get meaning of X, which is an environment, then extract I from it Q: what programming language is this like now? something like COBOL, but more orthogonal procedures, but no parameters