hydromatic / morel

Standard ML interpreter, with relational extensions, implemented in Java
Apache License 2.0
291 stars 15 forks source link

Closures should not copy the whole environment #152

Open julianhyde opened 2 years ago

julianhyde commented 2 years ago

Closures currently copy the whole environment. (It's not quite as bad as it sounds, because an environment is a binding to a value plus a pointer to the parent environment.) But the expression in a closure does not require the entire environment, just a small number of variables that can be determined by analyzing the expression at compile time. Those variables should be converted into numbered 'slots', the slots are populated when the closure is created, and when the expression is evaluated, it should look to those slots for values.