'From Cuis 2.3 of 22 March 2010 [latest update: #472] on 24 March 2010 at 10:09:18 pm'!
"Change Set:		RemoveBlockContextStuff
Date:			24 March 2010
Author:			Juan Vuletich

<your descriptive text goes here>"
BlockContext becomeUncompact!


!BlockContext commentStamp: 'jmv 3/24/2010 22:07' prior: 0!
Replaced almost everywhere by BlockClosure!


!ClassBuilder methodsFor: 'private' stamp: 'jmv 3/24/2010 21:53'!
tooDangerousClasses
	"Return a list of class names which will not be modified in the public interface"
	^#(
		"Object will break immediately"
		ProtoObject Object
		"Contexts and their superclasses"
		InstructionStream ContextPart MethodContext BlockClosure
		"Superclasses of basic collections"
		Collection SequenceableCollection ArrayedCollection
		"Collections known to the VM"
		Array Bitmap String Symbol ByteArray CompiledMethod TranslatedMethod
		"Basic Numbers"
		Magnitude Number SmallInteger Float
		"Misc other"
		LookupKey Association Link Point Rectangle Behavior PositionableStream UndefinedObject
	)
! !


!SystemDictionary methodsFor: 'special objects' stamp: 'jmv 3/24/2010 21:56'!
recreateSpecialObjectsArray
	"Smalltalk recreateSpecialObjectsArray"
	"The Special Objects Array is an array of object pointers used
	by the
	Squeak virtual machine. Its contents are critical and
	unchecked, so don't even think of playing here unless you
	know what you are doing."
	| newArray |
	newArray _ Array new: 50.
	"Nil false and true get used throughout the interpreter"
	newArray at: 1 put: nil.
	newArray at: 2 put: false.
	newArray at: 3 put: true.
	"This association holds the active process (a ProcessScheduler)"
	newArray at: 4 put: (self associationAt: #Processor).
	"Numerous classes below used for type checking and instantiation"
	newArray at: 5 put: Bitmap.
	newArray at: 6 put: SmallInteger.
	newArray at: 7 put: String.
	newArray at: 8 put: Array.
	newArray at: 9 put: Smalltalk.
	newArray at: 10 put: Float.
	newArray at: 11 put: MethodContext.
	newArray at: 12 put: nil.
	newArray at: 13 put: Point.
	newArray at: 14 put: LargePositiveInteger.
	newArray at: 15 put: Display.
	newArray at: 16 put: Message.
	newArray at: 17 put: CompiledMethod.
	newArray at: 18 put: (self specialObjectsArray at: 18).
	"(low space Semaphore)"
	newArray at: 19 put: Semaphore.
	newArray at: 20 put: Character.
	newArray at: 21 put: #doesNotUnderstand:.
	newArray at: 22 put: #cannotReturn:.
	newArray at: 23 put: nil.
	"An array of the 32 selectors that are compiled as special bytecodes,
	 paired alternately with the number of arguments each takes."
	newArray at: 24 put: #(	#+ 1 #- 1 #< 1 #> 1 #<= 1 #>= 1 #= 1 #~= 1
							#* 1 #/ 1 #\\ 1 #@ 1 #bitShift: 1 #// 1 #bitAnd: 1 #bitOr: 1
							#at: 1 #at:put: 2 #size 0 #next 0 #nextPut: 1 #atEnd 0 #== 1 #class 0
							#blockCopy: 1 #value 0 #value: 1 #do: 1 #new 0 #new: 1 #x 0 #y 0 ).
	"An array of the 255 Characters in ascii order."
	newArray at: 25 put: ((0 to: 255) collect: [:ascii | Character value: ascii]).
	newArray at: 26 put: #mustBeBoolean.
	newArray at: 27 put: ByteArray.
	newArray at: 28 put: Process.
	"An array of up to 31 classes whose instances will have compact headers"
	newArray at: 29 put: self compactClassesArray.
	newArray at: 30 put: (self specialObjectsArray at: 30).
	"(delay Semaphore)"
	newArray at: 31 put: (self specialObjectsArray at: 31).
	"(user interrupt Semaphore)"
	"Prototype instances that can be copied for fast initialization"
	newArray at: 32 put: (Float new: 2).
	newArray at: 33 put: (LargePositiveInteger new: 4).
	newArray at: 34 put: Point new.
	newArray at: 35 put: #cannotInterpret:.
	"Note: This must be fixed once we start using context prototypes (yeah, right)"
	"(MethodContext new: CompiledMethod fullFrameSize)."
	newArray at: 36 put: (self specialObjectsArray at: 36). "Is the prototype MethodContext (unused by the VM)"
	newArray at: 37 put: BlockClosure.
	"(BlockContext new: CompiledMethod fullFrameSize)."
	newArray at: 38 put: (self specialObjectsArray at: 38). "Is the prototype BlockContext (unused by the VM)"
	newArray at: 39 put: (self specialObjectsArray at: 39).	"preserve external semaphores"
	"array of objects referred to by external code"
	newArray at: 40 put: PseudoContext.
	newArray at: 41 put: TranslatedMethod.
	"finalization Semaphore"
	newArray at: 42 put: ((self specialObjectsArray at: 42) ifNil: [Semaphore new]).
	newArray at: 43 put: LargeNegativeInteger.
	"External objects for callout.
	 Note: Written so that one can actually completely remove the FFI."
	newArray at: 44 put: (self at: #ExternalAddress ifAbsent: nil).
	newArray at: 45 put: (self at: #ExternalStructure ifAbsent: nil).
	newArray at: 46 put: (self at: #ExternalData ifAbsent: nil).
	newArray at: 47 put: (self at: #ExternalFunction ifAbsent: nil).
	newArray at: 48 put: (self at: #ExternalLibrary ifAbsent: nil).
	newArray at: 49 put: #aboutToReturn:through:.
	newArray at: 50 put: #run:with:in:.
	"Now replace the interpreter's reference in one atomic operation"
	self specialObjectsArray become: newArray! !


!Utilities class methodsFor: 'closure support' stamp: 'jmv 3/24/2010 21:57'!
initializeClosures	"Utilities initializeClosures"
	"Eliminate the prototype BlockContext from the specialObjectsArray.  The VM doesn't use it. This paves the way for removing BlockCOntext altogether and merging ContextPart and MethodContext into e.g. Context."
	(Smalltalk specialObjectsArray at: 38) class name == #BlockContext 
		ifTrue:[Smalltalk specialObjectsArray at: 38 put: nil].
	"Remove unused class vars from CompiledMethod since we can't redefine its class definition directly. Add the new BlockClosure to the specialObjectsArray"
	(#(	BlockNodeCache MethodProperties SpecialConstants) 
			intersection: CompiledMethod classPool keys asSet) 
				do:[:classVarName| CompiledMethod removeClassVarName: classVarName].
	Smalltalk recreateSpecialObjectsArray.
	"Recompile methods in ContextPart, superclasses and subclasses that access inst vars"
	ContextPart withAllSuperclasses, ContextPart allSubclasses asArray do:[:class|
		class instSize > 0 ifTrue:[
			class allInstVarNames do:[:ivn|
				(class whichSelectorsAccess: ivn) do:[:sel| class recompile: sel]]]]! !

!Utilities class methodsFor: 'closure support' stamp: 'jmv 3/24/2010 22:00'!
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'].
	Smalltalk at: #BlockContext ifPresent: [ :bc |
		contexts _ bc allInstances.
		contexts ifNotEmpty: [
			contexts inspect. 
			self inform: 'There are left-over BlockContexts'.
			^self ]].
	unboundMethods isEmpty ifTrue:[
		self inform:'Congratulations - The bootstrap is now complete.'.
	]! !

BlockContext removeSelector: #aboutToReturn:through:!
BlockContext removeSelector: #activeHome!
BlockContext removeSelector: #argumentCount!
BlockContext removeSelector: #asContext!
BlockContext removeSelector: #assert!
BlockContext removeSelector: #bench!
BlockContext removeSelector: #blockReturnTop!
BlockContext removeSelector: #caller!
BlockContext removeSelector: #cannotReturn:!
BlockContext removeSelector: #closureHome!
BlockContext removeSelector: #contextForLocalVariables!
BlockContext removeSelector: #copyForSaving!
BlockContext removeSelector: #copyTo:blocks:!
BlockContext removeSelector: #decompile!
BlockContext removeSelector: #decompileString!
BlockContext removeSelector: #durationToRun!
BlockContext removeSelector: #endPC!
BlockContext removeSelector: #ensure:!
BlockContext removeSelector: #fork!
BlockContext removeSelector: #forkAndWait!
BlockContext removeSelector: #forkAt:!
BlockContext removeSelector: #forkAt:named:!
BlockContext removeSelector: #forkNamed:!
BlockContext removeSelector: #fullPrintOn:!
BlockContext removeSelector: #grabProcessor!
BlockContext removeSelector: #grabProcessorFor:onTimeout:!
BlockContext removeSelector: #grabProcessorOnlyFor:!
BlockContext removeSelector: #hasInstVarRef!
BlockContext removeSelector: #hasMethodReturn!
BlockContext removeSelector: #hideFromDebugger!
BlockContext removeSelector: #home!
BlockContext removeSelector: #ifCurtailed:!
BlockContext removeSelector: #ifError:!
BlockContext removeSelector: #instVarAt:put:!
BlockContext removeSelector: #isBlock!
BlockContext removeSelector: #isExecutingBlock!
BlockContext removeSelector: #method!
BlockContext removeSelector: #methodReturnContext!
BlockContext removeSelector: #myEnv!
BlockContext removeSelector: #newProcess!
BlockContext removeSelector: #newProcessWith:!
BlockContext removeSelector: #numArgs!
BlockContext removeSelector: #on:do:!
BlockContext removeSelector: #onDNU:do:!
BlockContext removeSelector: #printOn:!
BlockContext removeSelector: #printOnStream:!
BlockContext removeSelector: #privHome:!
BlockContext removeSelector: #privRefresh!
BlockContext removeSelector: #pushArgs:from:!
BlockContext removeSelector: #receiver!
BlockContext removeSelector: #reentrant!
BlockContext removeSelector: #repeat!
BlockContext removeSelector: #repeatWithGCIf:!
BlockContext removeSelector: #startpc!
BlockContext removeSelector: #stepToSendOrReturn!
BlockContext removeSelector: #tempAt:!
BlockContext removeSelector: #tempAt:put:!
BlockContext removeSelector: #timeToRun!
BlockContext removeSelector: #value!
BlockContext removeSelector: #value:!
BlockContext removeSelector: #value:value:!
BlockContext removeSelector: #value:value:value:!
BlockContext removeSelector: #value:value:value:value:!
BlockContext removeSelector: #valueAt:!
BlockContext removeSelector: #valueError!
BlockContext removeSelector: #valueSupplyingAnswer:!
BlockContext removeSelector: #valueSupplyingAnswers:!
BlockContext removeSelector: #valueSuppressingAllMessages!
BlockContext removeSelector: #valueSuppressingMessages:!
BlockContext removeSelector: #valueSuppressingMessages:supplyingAnswers:!
BlockContext removeSelector: #valueUninterruptably!
BlockContext removeSelector: #valueUnpreemptively!
BlockContext removeSelector: #valueWithArguments:!
BlockContext removeSelector: #valueWithEnoughArguments:!
BlockContext removeSelector: #valueWithExit!
BlockContext removeSelector: #valueWithPossibleArgs:!
BlockContext removeSelector: #valueWithPossibleArgument:!
BlockContext removeSelector: #valueWithRequestor:!
BlockContext removeSelector: #valueWithin:onTimeout:!
BlockContext removeSelector: #whileFalse!
BlockContext removeSelector: #whileFalse:!
BlockContext removeSelector: #whileTrue!
BlockContext removeSelector: #whileTrue:!

!BlockContext reorganize!
('initialize-release' home:startpc:nargs:)
!

"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."
Smalltalk recreateSpecialObjectsArray!

