On Thu, Jul 5, 2012 at 1:27 PM, Bert Freudenberg bert@freudenbergs.dewrote:
On 2012-07-05, at 19:15, Colin Putney wrote:
On Thu, Jul 5, 2012 at 8:11 AM, Frank Shearar frank.shearar@gmail.com
wrote:
Right. So what you're saying is that if you want proper modules, you need VM support.
Not necessarily. For the next experiment, I've been thinking about implementing selector spaces. Here's how it might work:
• Each environment has its own Symbol table • The scanner delegates interning of symbols to the environment • When interning a symbol the environment searches its imports • If no imported environment has the symbol, it creates one in its own symbol table
This would mean that an environment could add extension methods to classes in other environments, without colliding with other extensions. It would also make it possible to create "private overrides" where only code in that environment would use the override. It might be useful for sandboxing, but might not be sufficient.
Cool idea. Since the VM just cares about the identity of Symbols, we can have the same selector twice in one method dictionary. Each environment would send only the one from its own Symbol table.
IIRC the implementation of Selector (might be Symbol?) in David Simmons' AOS and S# systems is effectively two-level. A Selector is on object with two inst vars, one being its defining environment and the other being the selector's unique string (Symbol?). The latter is what we think of as a Symbol right now, so any two Selector (Symbol?) objects with the same sequence of characters have the same underlying unique string (Symbol?). Selectors are the keys in method dictionaries and the message selectors in compiled methods (and presumably are used in superclass names, but here I'm not familiar enough). David had some complex mechanism whereby selectors could match based on having the same underlying character sequence and choosing the shortest distances between their environments. This sounds complex, but the idea of boxing a Symbol so that there's a reference to its environment looks to me to be a useful one.
One could imagine using only boxed selectors for messages defined in a particular environment. This makes introspecting easy. A Symbol's environment would be the root environment; a Selector's would be e.g. that of its environment inst var.
Note that the VM doesn't (and shouldn't) care what objects are used for selectors; SmallIntegers can be used e.g. to save space.
Just 2¢
I want to stress, though, that this is *not* part of the current proposal—it's just some ruminating about what the next experiment might be, someday.
Yep.
- Bert -