'From Cuis 1.0 of 28 November 2009 [latest update: #337] on 2 January 2010 at 7:05:35 pm'!

!Utilities class methodsFor: 'closure support' stamp: 'jmv 1/2/2010 18:53'!
compileUsingClosures	"Utilities compileUsingClosures"
	"Recompile the system and do some minimal clean-ups"
	| classes compilationErrors |
	Preferences setPreference: #allowBlockArgumentAssignment toValue: false.
	compilationErrors := Set new.
	classes := Smalltalk forgetDoIts allClasses reject: [:c| c name == #GeniePlugin].

	'Recompiling The System' displayProgressAt: Sensor cursorPoint
		from: 0 to: classes size during:[:bar |
			classes withIndexDo:[:c :i|
				bar value: i.
				{ c. c class } do:[:b|
					"Transcript cr; print: b; endEntry."
					b selectors "asSortedCollection" do:[:s| 
						"Transcript cr; show: b asString, '>>', s."
						[b recompile: s from: b] on: Error do:[:ex|
							Transcript
								cr; nextPutAll: 'COMPILATION ERROR: ';
								print: b; nextPutAll: '>>'; nextPutAll: s; flush.
							compilationErrors add: (MethodReference class: b selector: s)]]]]].

	compilationErrors notEmpty ifTrue:[
		Smalltalk
			browseMessageList: compilationErrors asSortedCollection
			name: 'Compilation Errors']! !

!CompiledMethod class methodsFor: 'services' stamp: 'jmv 1/4/2010 10:16'!
unboundMethods
	| unboundMethods |
	unboundMethods := self allInstances select: [ :m |
		m methodClass isNil or: [ 
			m methodClass isBehavior not or: [
				m ~~ (m methodClass compiledMethodAt: m selector ifAbsent: nil)]]].
	unboundMethods := unboundMethods reject: [ :m | m selector asSymbol isDoIt ].
	^unboundMethods! !

!Utilities class methodsFor: 'closure support' stamp: 'jmv 1/3/2010 00:17'!
postRecompileCleanup	"Utilities postRecompileCleanup"
	"Cleanup after loading closure bootstrap"
	"Before doing this, please start a new UI process (for example, by hitting alt-period and closing the debugger)."
	| unboundMethods contexts |
	World removeAllKnownFailing.
	ProcessorScheduler startUp.
	WeakArray restartFinalizationProcess.
	MethodChangeRecord allInstancesDo:[:x| x noteNewMethod: nil].
	Undeclared removeUnreferencedKeys.
	Delay startTimerEventLoop.
	EventSensor install.
	WorldState allInstancesDo:[:ws| ws convertAlarms; convertStepList].
	Workspace allInstancesDo:[:ws| ws setBindings: nil].
	Smalltalk garbageCollect.
	Smalltalk
		at: #DebuggerMethodMap
		ifPresent: [ :dmm | dmm voidMapCache ].
	Smalltalk forgetDoIts.
	Smalltalk garbageCollect.
	unboundMethods := CompiledMethod unboundMethods.
	unboundMethods notEmpty ifTrue: [
		unboundMethods inspectWithLabel: 'Unbound Methods'].
	contexts := BlockContext allInstances.
	contexts ifNotEmpty:[contexts inspect. self inform: 'There are left-over BlockContexts'].
	(unboundMethods isEmpty and: [ contexts isEmpty ]) ifTrue:[
		self inform:'Congratulations - The bootstrap is now complete.'.
	]! !

"Postscript:
Leave the line above, and replace the rest of this comment by a useful one.
Executable statements should follow this comment, and should
be separated by periods, with no exclamation points (!!).
Be sure to put any further comments in double-quotes, like this one."
Utilities initializeClosures.
Utilities compileUsingClosures.!

