<?xml version="1.0"?><st-source><!-- Name: ObjVLisp-ForStudentDbIdentifier: scgStoreDbTrace: 7930PackageName: ObjVLisp-ForStudentParcel: #('ObjVLisp-ForStudent')PrintStringCache: (1.0,bergel)Date: 6:51:43 am September 16, 2003 --><time-stamp>From VisualWorks® NonCommercial, Release 7 of March 21, 2003 on September 16, 2003 at 6:51:43 am</time-stamp><do-it>(Dialog confirm: 'You are filing-in a Parcel source file!\\While this is possible it will not have\the same effect as loading the parcel.\None of the Parcel''s prerequisites will\be loaded and none of its load actions\will be performed.\\Are you sure you want to file-in?' withCRs) ifFalse: [self error: 'Parcel file-in abandoned.  Choose terminate or close.']</do-it><class><name>ObjTest</name><environment>Smalltalk</environment><super>XProgramming.SUnit.TestCase</super><private>false</private><indexed-type>none</indexed-type><inst-vars>objectClass aPoint coloredPointClass pointClass classClass aColoredPoint </inst-vars><class-inst-vars></class-inst-vars><imports></imports><category>ObjVLispApp</category><attributes><package>ObjVLisp-ForStudent</package></attributes></class><class><name>Obj</name><environment>Smalltalk</environment><super>Core.Array</super><private>false</private><indexed-type>objects</indexed-type><inst-vars></inst-vars><class-inst-vars>definedObjClasses </class-inst-vars><imports></imports><category>ObjVLispApp</category><attributes><package>ObjVLisp-ForStudent</package></attributes></class><class><name>ObjTestBootstrap</name><environment>Smalltalk</environment><super>XProgramming.SUnit.TestCase</super><private>false</private><indexed-type>none</indexed-type><inst-vars></inst-vars><class-inst-vars></class-inst-vars><imports></imports><category>ObjVLispApp</category><attributes><package>ObjVLisp-ForStudent</package></attributes></class><class><name>ObjClassInspector</name><environment>Smalltalk</environment><super>Tools.Inspector</super><private>false</private><indexed-type>none</indexed-type><inst-vars></inst-vars><class-inst-vars></class-inst-vars><imports></imports><category>ObjVLispApp</category><attributes><package>ObjVLisp-ForStudent</package></attributes></class><comment><class-id>ObjClassInspector</class-id><body>ObjClassInspector is special inspector to help inspecting ObjClass</body></comment><shared-variable><name>MethodFoundIn</name><environment>Obj</environment><private>false</private><constant>false</constant><category>As yet unclassified</category><attributes><package>ObjVLisp-ForStudent</package></attributes></shared-variable><shared-variable><name>ClassesImplementingLookupMethod</name><environment>Obj</environment><private>false</private><constant>false</constant><category>As yet unclassified</category><attributes><package>ObjVLisp-ForStudent</package></attributes></shared-variable><methods><class-id>ObjTest</class-id> <category>setup</category><body package="ObjVLisp-ForStudent">assembleClassClass	classClass := Obj new: 6.	classClass at: classClass offsetForName put: #ObjClass.	classClass at: classClass offsetForClass put: #ObjClass.	classClass at: classClass offsetForIVs		put: #(#class #name #superclass #iv #keywords #methodDict).	classClass at: classClass offsetForKeywords		put: #(#name: #superclass: #iv: #keywords: #methodDict:).	classClass at: classClass offsetForSuperclass put: #ObjObject.	classClass at: classClass offsetForMethodDict		put: (IdentityDictionary new).	Obj declareClass: classClass</body><body package="ObjVLisp-ForStudent">assembleColoredInstance	aColoredPoint := Obj new: 4.	aColoredPoint at: 1 put: #ObjColoredPoint.	aColoredPoint at: 2 put: 10.	aColoredPoint at: 3 put: 15.	aColoredPoint at: 3 put: #blue</body><body package="ObjVLisp-ForStudent">assembleColoredPointClass	coloredPointClass := Obj new: 6.	coloredPointClass at: pointClass offsetForName put: #ObjColoredPoint.	coloredPointClass at: pointClass offsetForClass put: #ObjClass.	coloredPointClass at: pointClass offsetForIVs put: #(#color).	coloredPointClass at: pointClass offsetForSuperclass put: #ObjPoint.	coloredPointClass at: pointClass offsetForMethodDict		put: (IdentityDictionary new).	Obj declareClass: coloredPointClass.	(coloredPointClass at: coloredPointClass offsetForMethodDict) at: #print		put: 			[:objself | 			Transcript show: 'I''am a colored point';				cr].	(coloredPointClass at: coloredPointClass offsetForMethodDict) at: #foo		put: 			[:objself | 			(objself unarySuper: #foo) + (objself unarySuper: #foo)			].	(coloredPointClass at: coloredPointClass offsetForMethodDict) at: #bar		put: 			[:objself | 			(objself unarySuper: #bar) + (objself unarySuper: #bar)			].</body><body package="ObjVLisp-ForStudent">assembleObjectClass	objectClass := Obj new: 6.	objectClass at: objectClass offsetForName put: #ObjObject.	objectClass at: objectClass offsetForClass put: #ObjClass.	objectClass at: objectClass offsetForIVs put: #(#class).	objectClass at: objectClass offsetForKeywords put: #().	objectClass at: objectClass offsetForSuperclass put: #ObjObject.	objectClass at: objectClass offsetForMethodDict		put: (IdentityDictionary new).	Obj declareClass: objectClass.	objectClass addMethod: #print		withBody: 			[:objself | 			Transcript show: 'I''am an Object';				cr].	objectClass addMethod: #error		withBody: 			[:object :selector | 			Transcript show: 'Error: selector ' , selector asString , 'not understood';				cr].	objectClass addMethod: #getIV		withBody: [:object :iv | object valueOfInstanceVariable: iv].	objectClass addMethod: #setIV		withBody: 			[:object :iv :val | 			object at: (object offsetFromObjectOfInstanceVariable: iv) put: val].	objectClass addMethod: #bar		withBody:			[:objself | 			5].</body><body package="ObjVLisp-ForStudent">assemblePointClass	| cl |	cl := Obj giveClassNamed: #ObjClass.	pointClass := Obj new: (cl at: cl offsetForIVs) size.	pointClass at: pointClass offsetForName put: #ObjPoint.	pointClass at: pointClass offsetForClass put: #ObjClass.	pointClass at: pointClass offsetForIVs put: #(#class #x #y).	pointClass at: pointClass offsetForKeywords put: #(#x: #y:).	pointClass at: pointClass offsetForSuperclass put: #ObjObject.	pointClass at: pointClass offsetForMethodDict		put: (IdentityDictionary new).	Obj declareClass: pointClass.	pointClass addMethod: #x		withBody: [:objself | objself valueOfInstanceVariable: #x].	pointClass addMethod: #print		withBody: 			[:objself | 			Transcript show: 'I''am a Point';				cr].		pointClass addMethod: #foo		withBody: 			[:objself | 			Transcript show: 'ObjPoint&gt;&gt;foo';cr.			5			]</body><body package="ObjVLisp-ForStudent">assemblePointInstance	aPoint := Obj new: 3.	aPoint at: 1 put: #ObjPoint.	aPoint at: 2 put: 10.	aPoint at: 3 put: 15</body><body package="ObjVLisp-ForStudent">setUp	"self new setUp"	Obj initialize.	self assembleClassClass.	self assemblePointClass.	self assembleObjectClass.	self assembleColoredPointClass.	self assemblePointInstance.	self assembleColoredInstance.	Obj initializeStack</body></methods><methods><class-id>ObjTest</class-id> <category>tests</category><body package="ObjVLisp-ForStudent">testAllocate	"(self  selector: #testAllocate) run"	| newInstance testInstance |	testInstance := Obj new: 3.	testInstance at: 1 put: #ObjPoint.	newInstance := pointClass allocateAnInstance.	self assert: (newInstance = testInstance).	self assert: (newInstance objClass = pointClass)</body><body package="ObjVLisp-ForStudent">testClassAccess	"(self  selector: #testClassAccess) run"		self assert: (aPoint objClass = pointClass)</body><body package="ObjVLisp-ForStudent">testInitialize	"(self  selector: #testInitialize) run"	| newInstance testInstance |	newInstance := pointClass allocateAnInstance.	testInstance := Obj new: 3.	testInstance at: 1 put: #ObjPoint.	testInstance at: 2 put: 1.	testInstance at: 3 put: 2.	newInstance initializeUsing: #(#y: 2 #z: 3 #t: 55 #x: 1).	self assert: (newInstance = testInstance)</body><body package="ObjVLisp-ForStudent">testInstanceVariableInheritance	"(self  selector: #testInstanceVariableInheritance) run"	self assert: 			((Obj new computeNewIVFrom: #(#a #b #c #d) asOrderedCollection				with: #(#a #z #b #t) asOrderedCollection)					= #(#a #b #c #d #z #t) asOrderedCollection).	self assert: 			((Obj new computeNewIVFrom: #() asOrderedCollection				with: #(#a #z #b #t) asOrderedCollection)					= #(#a #z #b #t) asOrderedCollection).	self assert: 			((Obj new computeNewIVFrom: #(#a #z #b #t) asOrderedCollection				with: #() asOrderedCollection)					= #(#a #z #b #t) asOrderedCollection)</body><body package="ObjVLisp-ForStudent">testIVOffset	"(self  selector: #testIVOffset) run"	self assert: ((pointClass offsetFromClassOfInstanceVariable: #x ) = 2).	self assert: ((pointClass offsetFromClassOfInstanceVariable: #lulu ) = 0)</body><body package="ObjVLisp-ForStudent">testIVOffsetAndValue	"(self  selector: #testIVOffsetAndValue) run"	self assert: ((aPoint offsetFromObjectOfInstanceVariable: #x ) = 2).	self assert: ((aPoint valueOfInstanceVariable: #x ) = 10)</body><body package="ObjVLisp-ForStudent">testKeywords	"(self  selector: #testKeywords) run"	| dummyObject |	dummyObject := Obj new.	self assert: 			((dummyObject generateKeywords: #(#titi #toto #lulu))				= #(#titi: #toto: #lulu:)).	self assert: 			((dummyObject keywordValue: #x				getFrom: #(#toto 33 #x 23)				ifAbsent: 2) = 23).	self assert: 			((dummyObject keywordValue: #x				getFrom: #(#toto 23)				ifAbsent: 2) = 2).	self assert: 			((dummyObject returnValuesFrom: #(#x 22 #y 35) followingSchema: #(#y #yy #x #y))				= #(35 nil 22 35))</body><body package="ObjVLisp-ForStudent">testMethodLookup	"(self  selector: #testMethodLookup) run"	pointClass lookup: #x for: aPoint.	self assert: ( pointClass methodFoundIn = pointClass ).	Obj initializeStack.	coloredPointClass lookup: #print for: aPoint.	self assert: ( coloredPointClass classToLookForSuperSend = pointClass).	Obj initializeStack.	coloredPointClass lookup: #x for: aPoint.	self assert:  (coloredPointClass methodFoundIn = pointClass)	"we cannot test the error for the moment because ObjObject does exist	at that time"</body><body package="ObjVLisp-ForStudent">testMethodManagment	"(self  selector: #testMethodManagment) run"	self assert: (pointClass doesUnderstand: #x).	self assert: (pointClass doesUnderstand: #xx) not.	pointClass addMethod: #xx		withBody: [:objself | objself valueOfInstanceVariable: #x ].	self assert: (((pointClass bodyOfMethod: #xx) value: aPoint) = 10).	self assert: (pointClass doesUnderstand: #xx).	pointClass removeMethod: #xx.	self assert: (pointClass doesUnderstand: #xx) not.	self assert: (((pointClass bodyOfMethod: #x) value: aPoint) = 10)</body><body package="ObjVLisp-ForStudent">testMethodSelfSend	"(self  selector: #testMethodSelfSend) run"	self assert: ((aPoint unarySend: #x) = 10).	self assert: ((aPoint binarySend: #getIV with: #x) = 10).	aPoint send: #setIV withArguments: #(y 22).	self assert: ((aPoint binarySend: #getIV with: #y) = 22)</body><body package="ObjVLisp-ForStudent">testMethodSuperCall	"(self  selector: #testMethodSuperCall) run"	self assert: ((aPoint unarySend: #foo) = 5).	self assert: ((aColoredPoint unarySend: #foo) = 10).</body><body package="ObjVLisp-ForStudent">testMethodSuperCallOverBigHierarchy	"(self  selector: #testMethodSuperCallOverBigHierarchy) run"	self assert: (aPoint unarySend: #bar) = 5.	self assert: (aColoredPoint unarySend: #bar) = 10.</body><body package="ObjVLisp-ForStudent">testPrimitiveStructure	"(self selector: #testPrimitiveStructure) run"	self assert: (pointClass objClassId = #ObjClass).	self assert: ((pointClass objName ) = #ObjPoint).	self assert: ((pointClass objSuperclassId ) = #ObjObject).	self assert: ((pointClass objIVs) = #(#class #x #y)).	self assert: ((pointClass objKeywords) = #(#x: #y:)).	self assert: ((pointClass objMethodDict) = nil) not</body></methods><methods><class-id>ObjTest class</class-id> <category>run</category><body package="ObjVLisp-ForStudent">allTestCases	"self allTestCases"	| result |	result := OrderedCollection new.	result add: (self selector: #testAllocate).	result add: (self selector: #testClassAccess).	result add: (self selector: #testIVOffset).	result add: (self selector: #testIVOffsetAndValue).	result add: (self selector: #testKeywords).	result add: (self selector: #testPrimitiveStructure).	"result add: (self selector: #testMethodLookup)."	result add: (self selector: #testMethodManagment).	result add: (self selector: #testMethodSelfSend).	^result</body><body package="ObjVLisp-ForStudent">runAll	"self runAll"	| test |	test := TestSuite named: 'Complete ObL Test Suite'.	test addTestCases: self allTestCases.	^test run</body></methods><methods><class-id>Obj</class-id> <category>method management</category><body package="ObjVLisp-ForStudent">addMethod: aSelector withBody: aBlock 	"Define a method with selector &lt;aSelector&gt; and a body &lt;aBlock&gt; in the receiver.	If a method with the same selector already existed, the new definition will erase it.	self is an objClass"	self  objMethodDict at: aSelector put: aBlock.	^self</body><body package="ObjVLisp-ForStudent">bodyOfMethod: aSelector 	"Return the method associated with the selector &lt;aSelector&gt; in the receiver.	Return nil if the selector is not defined.  self is an objClass"	^self objMethodDict at: aSelector ifAbsent: [nil]</body><body package="ObjVLisp-ForStudent">doesUnderstand: aSelector 	"Tell if the receiver has a method having &lt;aSelector&gt; as selector. self is anObjClass"	^self objMethodDict keys includes: aSelector</body><body package="ObjVLisp-ForStudent">removeMethod: aSelector	"Remove the method with aSelector &lt;aSymbol&gt; in the receiver. 	self is an objClass"	self objMethodDict removeKey: aSelector ifAbsent: [].	^self</body></methods><methods><class-id>Obj</class-id> <category>basic class operations</category><body package="ObjVLisp-ForStudent">computeAndSetKeywords	"Compute the keywords of a given class.  As the class of an object should not be changed.	 the keywords should note contain the keyword class. self is anObjClass"	self objKeywords: (self generateKeywords: (self objIVs copyWithout: #class))</body></methods><methods><class-id>Obj</class-id> <category>debugging</category><body package="ObjVLisp-ForStudent">debug	"(self giveClassNamed: #ObjClass) debug"	"(self giveClassNamed: #ObjSet) debug"	"ObjExtension new debug"	"|aPt|	aPt := ObjExtension new: 3.	aPt at: 1 put: #ObjPoint.	aPt debug"	"|aPt|	aPt := ObjExtension new: 3.	aPt at: 1 put: #ObjPoint3.	aPt debug"	ObjClassInspector openOn: self</body></methods><methods><class-id>Obj</class-id> <category>keyword management</category><body package="ObjVLisp-ForStudent">generateKeywords: anArray 	"Returns an array containing the keywords made from the collection of Symbol passed as argument"	"self new generateKeywords: #(titi toto lulu) "	^anArray collect: [:e | (e , ':') asSymbol]</body><body package="ObjVLisp-ForStudent">keywordValue: aSymbol getFrom: anArray ifAbsent: aDefaultValue 	"precondition: ((length anArray) mod 2) = 0 	returns the value associated with the keyword represented by aSymbol 	in the initarg list represented by anArray."	"self new keywordValue: #titi getFrom: #(toto 12 titi 23) ifAbsent: 2"	"self new keywordValue: #titi getFrom: #(toto 23) ifAbsent: 2"	| i |	i := anArray indexOf: aSymbol ifAbsent: nil.	^i isNil 		ifTrue: [aDefaultValue] 		ifFalse: [anArray at: i + 1]</body><body package="ObjVLisp-ForStudent">returnValuesFrom: anInitargArray followingSchema: anArrayOfKeywords 	"Return the values associated with the keys. The extracted values are taken from &lt;anInitargArray&gt; 	and the return values are extracted according to the schema defined by the collection of keys &lt;anArrayOfKeywords&gt;"	"self new returnValuesFrom: #(lulu 22  titi 35)  followingSchema: #(titi toto lulu titi)  #(35 nil 22 35)"	^anArrayOfKeywords collect: 			[:e | 			self keywordValue: e				getFrom: anInitargArray 				ifAbsent: nil]</body></methods><methods><class-id>Obj</class-id> <category>instance initialization</category><body package="ObjVLisp-ForStudent">initializeUsing: anAlternatedArray 	"Returns the receiver an ObjObject initialized according to the directives given by anAlternateArray"	| ivValues |	ivValues := self  returnValuesFrom: anAlternatedArray				followingSchema: self objClass objKeywords.	^ivValues startingAt: 1		replaceElementsIn: self		from: 2		to: ivValues size + 1</body></methods><methods><class-id>Obj</class-id> <category>iv management</category><body package="ObjVLisp-ForStudent">numberOfIVs	"Returns the number of instance variables of the class an ObjClass"	^self objIVs size</body><body package="ObjVLisp-ForStudent">offsetFromClassOfInstanceVariable: aSymbol 	"Returns the index of the instance variable named aSymbol for an class anObjClass.	Returns 0 if the aSymbol is not present in the instance variable lists of anObjClass"</body><body package="ObjVLisp-ForStudent">offsetFromObjectOfInstanceVariable: aSymbol	"Returns the offset of the instance variable named aSymbol in the object anObjObject.	If aSymbol is not an instance variable is not an instance variable of the object raise an error"</body><body package="ObjVLisp-ForStudent">valueOfInstanceVariable: aSymbol 	^self at: (self offsetFromObjectOfInstanceVariable: aSymbol)</body></methods><methods><class-id>Obj</class-id> <category>object structure primitive</category><body package="ObjVLisp-ForStudent">objClass	"Returns the ObjClass object of the object and not its internal identification. Differs from classId  which is a primitive 	to access the structure representing a class"</body><body package="ObjVLisp-ForStudent">objClassId	"Returns the identifier that identifies the class of the object. In this implementation we chose to use the class name as identifier"	^self at: self offsetForClass</body><body package="ObjVLisp-ForStudent">objClassId: anObjClassId	"Set the identifier that identifies the class of the object."		self at: self offsetForClass put: anObjClassId</body></methods><methods><class-id>Obj</class-id> <category>object structure offset</category><body package="ObjVLisp-ForStudent">offsetForClass	^1</body></methods><methods><class-id>Obj</class-id> <category>class structure offset</category><body package="ObjVLisp-ForStudent">offsetForIVs	^4</body><body package="ObjVLisp-ForStudent">offsetForKeywords	^5</body><body package="ObjVLisp-ForStudent">offsetForMethodDict	^6</body><body package="ObjVLisp-ForStudent">offsetForName	^2</body><body package="ObjVLisp-ForStudent">offsetForSuperclass	^3</body></methods><methods><class-id>Obj</class-id> <category>printing</category><body package="ObjVLisp-ForStudent">printOn: aStream	aStream nextPutAll: 'an Obj object: '.		super printOn: aStream</body></methods><methods><class-id>Obj</class-id> <category>method lookup</category><body package="ObjVLisp-ForStudent">classToLookForSuperSend	"^self class giveClassNamed: MethodFoundIn objSuperclassId"	^ self class giveClassNamed: (ClassesImplementingLookupMethod last objSuperclassId)</body><body package="ObjVLisp-ForStudent">lookup: selector for: anObjObject 	"look for the method named &lt;selector&gt; starting in the receiver. 	The lookup is done for a message sent to &lt;anObjObject&gt;. self is an objClass"		^(self doesUnderstand: selector)		ifTrue: 			[ClassesImplementingLookupMethod addLast: self.	"we mark the class for the super"			self bodyOfMethod: selector]		ifFalse: 			[self objName = #ObjObject				ifFalse: 					[					(Obj giveClassNamed: self objSuperclassId) lookup: selector for: anObjObject.					]				ifTrue: [anObjObject binarySend: #error with: selector]]</body></methods><methods><class-id>Obj</class-id> <category>for tests</category><body package="ObjVLisp-ForStudent">methodFoundIn	^ClassesImplementingLookupMethod last</body></methods><methods><class-id>Obj</class-id> <category>iv inheritance</category><body package="ObjVLisp-ForStudent">computeNewIVFrom: superIVOrdCol with: localIVOrdCol	"Returns an ordered collection that is the union without duplicate of ivOfSuper and ivOrderedCollection.	Important the order of the instance variable is conserved"</body><body package="ObjVLisp-ForStudent">computeNewIVFromClass: anObjClass with: ivOrderedCollection 	"Obj new computeNewIVFromClass: #(#C #C #O #(a b c d))									with:#(a z b t) asOrderedCollection"	"Obj  new computeNewIVFromClass: nil									with:#(a z b t) asOrderedCollection"	| ivs |	^anObjClass isNil		ifTrue: [ivOrderedCollection]		ifFalse: 			[ivs := anObjClass objIVs asOrderedCollection copy.			ivOrderedCollection do: [:e | (ivs includes: e) ifFalse: [ivs add: e]].			ivs]</body></methods><methods><class-id>Obj</class-id> <category>class structure primitive</category><body package="ObjVLisp-ForStudent">objIVs	"Get the list of instance variable names of anObjClass"</body><body package="ObjVLisp-ForStudent">objIVs: anOrderedCollection 	"Set the list of instance variable names of anObjClass"</body><body package="ObjVLisp-ForStudent">objKeywords	"Returns the keyword list of an ObjClass"</body><body package="ObjVLisp-ForStudent">objKeywords: anOrderedCollection	"Sets the list of keywords of an ObjClass. Note that this method is just an accessor and does not compute the actual list of keywords"</body><body package="ObjVLisp-ForStudent">objMethodDict	"Returns the method dictionary of an ObjClass"</body><body package="ObjVLisp-ForStudent">objMethodDict: aDictionary 	"Sets the method dictionary of an ObjClass"</body><body package="ObjVLisp-ForStudent">objName	"Returns the name of an ObjClass"</body><body package="ObjVLisp-ForStudent">objName: aName 	"Set the name of an ObjClass"</body><body package="ObjVLisp-ForStudent">objSuperclassId	"Returns the superclass id of anObjClass"</body><body package="ObjVLisp-ForStudent">objSuperclassId: anObjClassId	"Set the superclass id of anObjClass"</body></methods><methods><class-id>Obj</class-id> <category>message passing</category><body package="ObjVLisp-ForStudent">binarySend: selector with: argument 	"send the message whose selector is &lt;selector&gt; to the receiver. The arguments of the messages	are an  &lt;argument&gt;. The method is lookep up in the class of the receiver. 	self is an objObject or a objClass."</body><body package="ObjVLisp-ForStudent">binarySuper: selector with: argument 	"send the message whose selector is &lt;selector&gt; to the receiver. The arguments of the messages	are an  &lt;argument&gt;. The method is lookep up in the class of the receiver. 	self is an objObject or a objClass."</body><body package="ObjVLisp-ForStudent">send: selector withArguments: arguments 	"send the message whose selector is &lt;selector&gt; to the receiver. The arguments of the messages	are an array &lt;arguments&gt;. The method is lookep up in the class of the receiver. 	self is an objObject or a objClass."</body><body package="ObjVLisp-ForStudent">super: selector withArguments: arguments 	"Invoke an oveeriden method named &lt;selector&gt; with an array of arguments &lt;arguments&gt;. 	self is an objClass."</body><body package="ObjVLisp-ForStudent">unarySend: selector</body><body package="ObjVLisp-ForStudent">unarySuper: selector</body></methods><methods><class-id>Obj</class-id> <category>instance allocation</category><body package="ObjVLisp-ForStudent">allocateAnInstance	"Returns a newly created instance of self, an ObjClass. In this implementation the identifier of the object class is the name of the class. "</body></methods><methods><class-id>Obj class</class-id> <category>bootstrap objClass manually</category><body package="ObjVLisp-ForStudent">bootstrap	"self bootstrap"		self initialize.	self manuallyCreateObjClass.	self createObjObject.	self createObjClass.</body><body package="ObjVLisp-ForStudent">defineAllocateMethodIn: class</body><body package="ObjVLisp-ForStudent">defineManualInitializeMethodIn: class 	class addMethod: #initialize		withBody: 			[:aclass :initArray | 			| objsuperclass |			aclass initializeUsing: initArray.	"Initialize a class as an object. In the bootstrapped system will be done via super"			objsuperclass := Obj giveClassNamed: aclass objSuperclassId ifAbsent: [nil].			objsuperclass isNil				ifFalse: 					[aclass						objIVs: (aclass computeNewIVFrom: objsuperclass objIVs with: aclass objIVs)]				ifTrue: 					[aclass objIVs: (aclass computeNewIVFrom: #(#class) with: aclass objIVs)].			aclass				objKeywords: (aclass generateKeywords: (aclass objIVs copyWithout: #class)).			aclass objMethodDict: (IdentityDictionary new: 3).			Obj declareClass: aclass.			aclass]</body><body package="ObjVLisp-ForStudent">defineNewMethodIn: class</body><body package="ObjVLisp-ForStudent">manuallyCreateObjClass	"self manuallyCreateObjClass"</body><body package="ObjVLisp-ForStudent">manualObjClassStructure</body></methods><methods><class-id>Obj class</class-id> <category>global class repository management</category><body package="ObjVLisp-ForStudent">declareClass: anObjClass 	"To declare an ObjClass in the class repository"	| nameC |	nameC := anObjClass objName.	nameC isNil		ifFalse: [definedObjClasses at: nameC put: anObjClass]		ifTrue: [self error: 'The class does not have a name']</body><body package="ObjVLisp-ForStudent">giveClassNamed: aSymbol 	"Return the class defined in the class repository with the name aSymbol"	^ self giveClassNamed: aSymbol ifAbsent: [self error: ('The class ' , aSymbol printString , ' is not defined')]</body><body package="ObjVLisp-ForStudent">giveClassNamed: aSymbol ifAbsent: aBlock	^ definedObjClasses at: aSymbol ifAbsent: aBlock</body></methods><methods><class-id>Obj class</class-id> <category>tricks</category><body package="ObjVLisp-ForStudent">doesNotUnderstand: aMessage	"debugging &gt;&gt;&gt;"	InputState default shiftDown ifTrue:[ self halt ].		^ definedObjClasses at: aMessage selector</body></methods><methods><class-id>Obj class</class-id> <category>class management</category><body package="ObjVLisp-ForStudent">initializeStack	ClassesImplementingLookupMethod := OrderedCollection new</body></methods><methods><class-id>Obj class</class-id> <category>initialize</category><body package="ObjVLisp-ForStudent">initialize	"self initialize"	 	definedObjClasses := IdentityDictionary new.	definedObjClasses at: #ObjClass put: nil.	definedObjClasses at: #ObjObject put: nil.	self initializeStack</body></methods><methods><class-id>Obj class</class-id> <category>bootstrap objObject</category><body package="ObjVLisp-ForStudent">createObjObject</body><body package="ObjVLisp-ForStudent">objObjectStructure</body></methods><methods><class-id>Obj class</class-id> <category>bootstrap objClass</category><body package="ObjVLisp-ForStudent">createObjClass</body><body package="ObjVLisp-ForStudent">defineInitializeMethodIn: objClass</body><body package="ObjVLisp-ForStudent">objClassStructure</body></methods><methods><class-id>ObjTestBootstrap</class-id> <category>test creation ObjObject</category><body package="ObjVLisp-ForStudent">testCreateObjObjectInstanceMessage	"(self selector: #testCreateObjObjectInstanceMessage) run"	| pointClass objClass pointInstance |	Obj initialize.	Obj manuallyCreateObjClass.	Obj createObjObject.	objClass := Obj giveClassNamed: #ObjClass.	pointClass := objClass send: #new				withArguments: #(#(#name: #ObjPoint 								  #superclass: #ObjObject #iv: #(#x #y))).	pointInstance := pointClass send: #new withArguments: #(#()).	self assert: (pointInstance objClassId = #ObjPoint).	self assert: ((pointInstance binarySend: #getIV with: #x) = nil).	pointInstance send: #setIV withArguments: #(#x 25).	self assert: ((pointInstance binarySend: #getIV with: #x) = 25)</body><body package="ObjVLisp-ForStudent">testCreateObjObjectMessage	"(self selector: #testCreateObjObjectMessage) run"	| objObject |	Obj initialize.	Obj manuallyCreateObjClass.	Obj createObjObject.	objObject := Obj giveClassNamed: #ObjObject.	self assert: ((objObject unarySend: #class) = (Obj giveClassNamed: #ObjClass)).	self assert: ((objObject unarySend: #isClass) not).	self assert: ((objObject binarySend: #getIV with: #class) = #ObjClass)</body><body package="ObjVLisp-ForStudent">testCreateObjObjectStructure	"(self selector: #testCreateObjObjectStructure) run"	| objObject |	Obj initialize.	Obj manuallyCreateObjClass.	Obj createObjObject.	objObject := Obj giveClassNamed: #ObjObject.	self assert: (objObject objName = #ObjObject).	self assert: (objObject objClassId = #ObjClass).	self assert: (objObject objSuperclassId isNil).	self assert: (objObject objIVs asArray = #(#class)).	self assert: (objObject objKeywords asArray = #())</body></methods><methods><class-id>ObjTestBootstrap</class-id> <category>test ObjClass manual creation </category><body package="ObjVLisp-ForStudent">testManuallyCreateObjClassAllocate	"(self selector: #testManuallyCreateObjClassAllocate) run"	| objClass emptyClass |	Obj initialize.	Obj manuallyCreateObjClass.	objClass := Obj giveClassNamed: #ObjClass.	emptyClass := objClass unarySend: #allocate.	self assert: (emptyClass objClassId = #ObjClass).	self assert: (emptyClass objSuperclassId isNil).	self assert: (emptyClass objIVs isNil).	self assert: (emptyClass objKeywords isNil).	self assert: (emptyClass objMethodDict isNil).	self assert: (emptyClass objName isNil)</body><body package="ObjVLisp-ForStudent">testManuallyCreateObjClassStructure	"(self selector: #testManuallyCreateObjClassStructure) run"	| objClass |	Obj initialize.	Obj manuallyCreateObjClass.	objClass := Obj giveClassNamed: #ObjClass.	self assert: (objClass objName = #ObjClass).	self assert: (objClass objClassId = #ObjClass).	self assert: (objClass objClass == objClass).	self assert: (objClass objSuperclassId = #ObjObject).		"the fact that the created first class inherits form ObjObject is not necessary	because there is no super calls"	self assert: 			(objClass objIVs = #(#class #name #superclass #iv #keywords #methodDict)).	self assert: 			(objClass objKeywords = #(#name: #superclass: #iv: #keywords: #methodDict:))</body></methods><methods><class-id>ObjTestBootstrap</class-id> <category>test ObjClass creation</category><body package="ObjVLisp-ForStudent">testCreateObjClassMessage	"(self selector: #testCreateObjClassMessage) run"	| objClass |	Obj bootstrap.	objClass := Obj giveClassNamed: #ObjClass.	self assert: ((objClass unarySend: #class) = (Obj giveClassNamed: #ObjClass)).	self assert: (objClass unarySend: #isClass).	self assert: (objClass unarySend: #isMetaclass)</body><body package="ObjVLisp-ForStudent">testCreateObjClassStructure	"(self selector: #testCreateObjClassStructure) run"	| objClass |	Obj bootstrap.	objClass := Obj giveClassNamed: #ObjClass.	self assert: (objClass objName = #ObjClass).	self assert: (objClass objClassId = #ObjClass).	self assert: (objClass objSuperclassId = #ObjObject).	self assert: 			(objClass objIVs asArray			= #(#class #name #superclass #iv #keywords #methodDict)).	self assert: 			(objClass objKeywords asArray				= #(#name: #superclass: #iv: #keywords: #methodDict:))</body></methods><methods><class-id>ObjClassInspector</class-id> <category>field list</category><body package="ObjVLisp-ForStudent">fieldIndex	"Answer the offset corresponding to the currently selected field."	^ self listOfClassFields indexOf: field</body><body package="ObjVLisp-ForStudent">fieldList	"Answer an Array consisting of 'self' and the instance variable 	names of the inspected object. Up to 40 indices are given for 	variable length objects."	^ ((OrderedCollection with: 'self') addAll: self listOfClassFields ;yourself) asArray</body><body package="ObjVLisp-ForStudent">fieldValue	(field = 'self' or: [field == nil]) ifTrue: [^object].	^ object basicAt: self fieldIndex</body></methods><methods><class-id>ObjClassInspector</class-id> <category>private</category><body package="ObjVLisp-ForStudent">listOfClassFields	"object objClass objIVs"	| class |	^object size isZero		ifTrue: [#()]		ifFalse: 			[(object at: 1) isNil				ifTrue: [#()]				ifFalse: 					[class := Obj giveClassNamed: (object at: 1) ifAbsent: [nil].					class isNil						ifTrue: [#()]						ifFalse: 							[| iv |							iv := class at: 4.							iv isNil								ifTrue: [#(#class #name #superclass #iv #keywords #methods)]								ifFalse: [class at: 4]]]]</body></methods><initialize><class-id>Obj</class-id></initialize><do-it>"Imported Classes:"</do-it><do-it>self error: 'Attempting to file-in parcel imports.  Choose terminate or close'</do-it><class><name>Inspector</name><environment>Tools</environment><super>UI.ApplicationModel</super><private>false</private><indexed-type>none</indexed-type><inst-vars>object field fieldList properties history showAllFields </inst-vars><class-inst-vars></class-inst-vars><imports></imports><category>Tools-Inspector</category><attributes><package>Tools-Inspector</package></attributes></class><class><name>Array</name><environment>Core</environment><super>Core.ArrayedCollection</super><private>false</private><indexed-type>objects</indexed-type><inst-vars></inst-vars><class-inst-vars></class-inst-vars><imports></imports><category>Collections-Arrayed</category><attributes><package>Collections-Arrayed</package></attributes></class><class><name>TestCase</name><environment>XProgramming.SUnit</environment><super>Core.Object</super><private>false</private><indexed-type>none</indexed-type><inst-vars>testSelector </inst-vars><class-inst-vars></class-inst-vars><imports></imports><category>SUnit</category><attributes><package>SUnit</package></attributes></class></st-source>