The Inbox: Environments-cwp.41.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Inbox: Environments-cwp.41.mcz

commits-2
A new version of Environments was added to project The Inbox:
http://source.squeak.org/inbox/Environments-cwp.41.mcz

==================== Summary ====================

Name: Environments-cwp.41
Author: cwp
Time: 1 January 2014, 1:10:00.935 pm
UUID: 773b58d5-3b62-45ef-9176-c6e5b6a5dddb
Ancestors: Environments-ul.40

Rewrite import/export to be eager, rather than lazy. (step 1 of 3)

=============== Diff against Environments-ul.40 ===============

Item was added:
+ ----- Method: Binding>>source (in category 'as yet unclassified') -----
+ source
+ ^ self!

Item was changed:
  Object subclass: #BindingPolicy
+ instanceVariableNames: 'namespace policy next environment addSelector removeSelector'
- instanceVariableNames: 'namespace policy next'
  classVariableNames: ''
  poolDictionaries: ''
  category: 'Environments-Policies'!

Item was added:
+ ----- Method: BindingPolicy class>>environment:policy:addSelector:removeSelector: (in category 'as yet unclassified') -----
+ environment: anEnvironment policy: aNamePolicy addSelector: addSelector removeSelector: removeSelector
+ ^ self basicNew
+ initializeWithEnvironment: anEnvironment
+ policy: aNamePolicy
+ addSelector: addSelector
+ removeSelector: removeSelector!

Item was added:
+ ----- Method: BindingPolicy>>binding:addedTo:notify: (in category 'events') -----
+ binding: aBinding addedTo: anEnvironment notify: anObject
+ environment == anEnvironment ifTrue:
+ [policy name: aBinding key do:
+ [:name || binding |
+ binding := aBinding asBinding: name.
+ anObject perform: addSelector with: binding]].
+ !

Item was added:
+ ----- Method: BindingPolicy>>binding:removedFrom:notify: (in category 'events') -----
+ binding: aBinding removedFrom: anEnvironment notify: anObject
+ environment == anEnvironment ifTrue:
+ [policy name: aBinding key do:
+ [:name || binding |
+ binding := aBinding asBinding: name.
+ anObject perform: removeSelector with: binding]].
+ !

Item was added:
+ ----- Method: BindingPolicy>>initializeWithEnvironment:policy:addSelector:removeSelector: (in category 'initialize-release') -----
+ initializeWithEnvironment: anEnvironment
+ policy: aNamePolicy
+ addSelector: aSelector
+ removeSelector: rSelector
+ self initialize.
+ environment := anEnvironment.
+ policy := aNamePolicy.
+ addSelector := aSelector.
+ removeSelector := rSelector!

Item was changed:
  Object subclass: #Environment
+ instanceVariableNames: 'info imports exports declarations references public undeclared bindings policies observers'
- instanceVariableNames: 'info imports exports declarations references public undeclared'
  classVariableNames: 'Default Instances'
  poolDictionaries: ''
  category: 'Environments-Core'!
 
  !Environment commentStamp: 'cmm 12/20/2013 14:10' prior: 0!
  I am a context for compiling methods. I maintain the namespace of classes and global variables that are visible to the methods compiled within me.
 
  I have the following instance variables:
 
  info <EnvironmentInfo>
  Metadata about me and the code I contain.
 
  imports <Import>
  Rules for importing globals from other environments.
 
  exports <Export>
  Rules for exposing globals to other environments.
 
  declarations <IdentityDictionary>
  Bindings for globals that have been declared inside me.
 
  references      <IdentityDictionary>
  Bindings for globals that are used by methods compiled inside me.
 
  public <IdentityDictionary>
  Bindings for classes that have been declared inside me, and which satisfy the export rules contain in 'exports'.
 
  undeclared      <Dictionary>
  Bindings for globals that are used by methods compiled inside me, but which aren't present in 'references' and couldn't be found via the rules in 'imports'.!

Item was added:
+ ----- Method: Environment>>addAllBindings (in category 'updating') -----
+ addAllBindings
+ declarations associationsDo:
+ [:ea | self binding: ea addedTo: self]!

Item was added:
+ ----- Method: Environment>>addObserver: (in category 'accessing') -----
+ addObserver: anObject
+ observers add: anObject!

Item was added:
+ ----- Method: Environment>>bind:to: (in category 'binding') -----
+ bind: aSymbol to: anObject
+ | binding newBinding |
+ newBinding := aSymbol => anObject.
+
+ binding := declarations associationAt: aSymbol ifAbsent: [nil].
+ binding ifNotNil:
+ [binding class == newBinding class
+ ifTrue: [binding value: anObject]
+ ifFalse: [binding becomeForward: newBinding].
+ ^anObject].
+
+ binding := undeclared associationAt: aSymbol ifAbsent: [nil].
+ binding
+        ifNil: [binding := newBinding]
+        ifNotNil:
+ [undeclared removeKey: aSymbol.
+ binding class == newBinding class
+ ifTrue: [binding value: anObject]
+ ifFalse: [binding becomeForward: newBinding]].
+
+ declarations add: binding.
+ self binding: binding addedTo: self.
+ ^anObject
+ !

Item was added:
+ ----- Method: Environment>>binding:addedTo: (in category 'updating') -----
+ binding: aBinding addedTo: anEnvironment
+ policies do:
+ [:ea | ea binding: aBinding addedTo: anEnvironment notify: self]!

Item was added:
+ ----- Method: Environment>>binding:removedFrom: (in category 'updating') -----
+ binding: aBinding removedFrom: anEnvironment
+ policies do:
+ [:ea | ea binding: aBinding removedFrom: anEnvironment notify: self]!

Item was added:
+ ----- Method: Environment>>declarationOf: (in category 'binding') -----
+ declarationOf: aSymbol
+ ^ declarations bindingOf: aSymbol!

Item was added:
+ ----- Method: Environment>>hideBinding: (in category 'binding') -----
+ hideBinding: aBinding
+ bindings removeKey: aBinding key!

Item was changed:
  ----- Method: Environment>>migrate (in category 'initialize-release') -----
  migrate
+ | newDeclarations source dest index policy |
+ bindings := IdentityDictionary new.
+ newDeclarations := IdentityDictionary new.
+ source := Array new: declarations size.
+ dest := Array new: declarations size.
+ index := 1.
+ declarations associationsDo:
+ [:ea || binding |
+ binding := ea key => ea value.
+ source at: index put: ea.
+ dest at: index put: binding.
+ newDeclarations add: binding.
+ bindings add: binding.
+ index := index + 1].
+ declarations := newDeclarations.
+ source elementsForwardIdentityTo: dest.
+
+ policy := BindingPolicy
+ environment: self
+ policy: AllNamePolicy new
+ addSelector: #showBinding:
+ removeSelector: #hideBinding:.
+ policies := Array with: policy.
+
+ observers := IdentitySet new..
+ !
- declarations := declarations.
- references := references.!

Item was added:
+ ----- Method: Environment>>notifyObserversOfBindingAdded: (in category 'updating') -----
+ notifyObserversOfBindingAdded: aBinding
+ observers do: [:ea | ea binding: aBinding addedTo: self]!

Item was added:
+ ----- Method: Environment>>notifyObserversOfBindingRemoved: (in category 'updating') -----
+ notifyObserversOfBindingRemoved: aBinding
+ observers do: [:ea | ea binding: aBinding removedFrom: self]!

Item was added:
+ ----- Method: Environment>>purgeUndeclared (in category 'binding') -----
+ purgeUndeclared
+ undeclared removeUnreferencedKeys!

Item was added:
+ ----- Method: Environment>>removeObserver: (in category 'accessing') -----
+ removeObserver: anObject
+ observers remove: anObject!

Item was added:
+ ----- Method: Environment>>showBinding: (in category 'binding') -----
+ showBinding: aBinding
+ | binding |
+ binding := undeclared associationAt: aBinding key ifAbsent: [nil].
+ binding ifNotNil:
+ [undeclared removeKey: binding key.
+ binding becomeForward: aBinding].
+
+ binding := bindings associationAt: aBinding key ifAbsent: [nil].
+ binding ifNotNil:
+ [bindings removeKey: binding key].
+
+ bindings add: aBinding.!

Item was added:
+ ----- Method: Environment>>undeclare: (in category 'binding') -----
+ undeclare: aSymbol
+ ^ undeclared add: aSymbol => nil!

Item was changed:
  (PackageInfo named: 'Environments') postscript: '"below, add code to be run after the loading of this package"
 
+ Smalltalk globals migrate.
- | allAliases toBeRecompiled undesirableAliases |
-
- "Collect the CompiledMethods pointing to an Alias"
- allAliases := Alias allInstances.
- toBeRecompiled := CompiledMethod allInstances select: [:c | c isInstalled and: [allAliases anySatisfy: [:a | c pointsTo: a]]].
-
- "Collect the Aliases pointing to some class binding in the same Environment with same name"
- undesirableAliases := (Smalltalk globals instVarNamed: ''references'') associations select: [:e |
- e class = Alias and: [e key = e source key
- and: [(Smalltalk globals instVarNamed: ''declarations'') associations includes: e source]]].
-
- "Replace the undesirable Aliases with their source binding"
- undesirableAliases do: [:a | a becomeForward: a source].
-
- "Rehash the references because they pointed to those Aliases - hope there''s nothing else to rehash"
- (Smalltalk globals instVarNamed: ''references'') rehash.
-
- "Recompile the CompiledMethod that used to point to an Alias, because the bytecodes do change"
- Symbol rehash.
- toBeRecompiled do: [:c | c methodClass recompile: c selector].
-
- allAliases := toBeRecompiled := undesirableAliases := nil.
- Smalltalk garbageCollect.
- Alias allInstances size.
  '!