faster elaborator

Stephen Weeks MLton@sourcelight.com
Wed, 3 Jan 2001 19:30:42 -0800 (PST)


> Mlton having its own real type/syntax checker would truly truly be most
> excellent.  It not existing is the main obstacle to Rico giving it a shot.

Next release definitely.  I'm quite excited about the possibility.

> Can you give me a quick summary of lcc's symbol-table-scoping hack?

Here's what MLton now does. 

* Use one symbol table per name space (i.e. one for variables, one for tycons,
  one for signature ids, one for functor ids, etc)
* Each variable (or sigid or whatever) in a symbol table keeps a list ref
  containing the information for each binding of the variable at enclosing
  scopes.  The list is in order from lexically closest to lexically farthest
  binding.
* The symbol table keeps a unit ref ref storing a unique id for the current
  scope and a list ref of all of the variables in the current scope. 
* Upon entering a new scope, a new unique id is stored in the symbol table
  and the list of variables is set to null (the old list is stashed somewhere).
* To bind a variable in a scope, we check to see if it has already been bound
  in this scope.  If so, we just update this binding.  If not, we add a new 
  entry to the front of the variable's list of bindings.
* Upon leaving a scope, we pop of the bindings for all the variables in the
  scope and restore the list of variables for the previous scope.

Things like local and open complicate things a bit, but it all works out, and is 
quite fast.