wiki:Scopes

Scopes

Support for nested scopes within a function body will be added. This will require changes to front, model, dynamic, state layers.

Scopes form a tree.

model layer

A local variable will now have associated to it an instance of ScopeIF:

ScopeIF:

  • Collection<LocalVariableIF> variables();
  • ScopeIF parent();
  • Iterator<ScopeIF> children();
  • int numChildren();

ModelIF:

  • ScopeIF newScope(ScopeIF parentScope);
  • LocationIF newLocation(ScopeIF scope, ...);
  • all methods to create locations need to specify scope instead of function

FunctionIF:

  • creating a function creates one scope automatically: the outer-most local scope
  • ScopeIF outerScope();

front layer

In generating model, you need to keep track of which scope you are in. Use a stack. When you enter a block, push. When you exit a block pop.

state layer

The state of a Frame on the call stack now changes. In place of list of local variables, there is stack of scopes: each entry gives the state of that scope. The state of the scope gives the list of variable values in that scope.

transitions

when moving from location to another, look at scope. If it changes, you need to pop up the tree, and push down the tree, to get to the new scope. When you push, you need to initialize the new local variables correctly.

Find out in C what happens when you jump into the middle of a block: how are variables initialized?

Last modified 15 years ago Last modified on 04/20/11 08:28:30
Note: See TracWiki for help on using the wiki.