Changes between Version 2 and Version 3 of Scopes
- Timestamp:
- 04/20/11 08:28:30 (15 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Scopes
v2 v3 4 4 This will require changes to front, model, dynamic, state layers. 5 5 6 == Changed to model layer == 6 Scopes form a tree. 7 8 == model layer == 9 10 A local variable will now have associated to it an instance of ScopeIF: 7 11 8 12 ScopeIF: … … 15 19 * ScopeIF newScope(ScopeIF parentScope); 16 20 * LocationIF newLocation(ScopeIF scope, ...); 17 * methods to create locations need to specify scope instead of function21 * all methods to create locations need to specify scope instead of function 18 22 19 23 FunctionIF: 20 * /* creating a function creates one scope automatically: */24 * creating a function creates one scope automatically: the outer-most local scope 21 25 * ScopeIF outerScope(); 26 27 28 == front layer == 29 30 In generating model, you need to keep track of which scope you are in. 31 Use a stack. 32 When you enter a block, push. When you exit a block pop. 33 34 == state layer == 35 36 The state of a Frame on the call stack now changes. 37 In place of list of local variables, there is stack of scopes: each entry gives the state of that scope. 38 The state of the scope gives the list of variable values in that scope. 39 40 == transitions == 41 42 when moving from location to another, look at scope. If it changes, you need to pop up the tree, and push down the tree, 43 to get to the new scope. When you push, you need to initialize the new local variables correctly. 44 45 Find out in C what happens when you jump into the middle of a block: how are variables initialized?
