[Vm-dev] Re: [Cog] Problems with generating code (initialization of options)

Igor Stasenko siguctua at gmail.com
Thu Jun 30 14:30:17 UTC 2011


I found the problem.
Its in #buildCodeGeneratorForInterpreter

i put a halt in
addPoolVarsFor: aClass
	"Add the pool variables for the given class to the code base as constants."

	(aClass sharedPools reject: [:pool| pools includes: pool]) do:
		[:pool |
		pools add: pool.
		pool bindingsDo: [:assoc | | val node |
			self halt.
			val := assoc value.
			node := (useSymbolicConstants and:[self isCLiteral: val])
						ifTrue:[TDefineNode new setName: assoc key asString value: assoc value]
						ifFalse:[TConstantNode new setValue: assoc value].
			constants at: assoc key asString put: node]].

and it triggered before the halt in:

ObjectMemory>>initializeWithOptions: optionsDictionary
	"ObjectMemory initializeWithOptions: Dictionary new"
self halt.
	self initBytesPerWord: (optionsDictionary at: #BytesPerWord ifAbsent: [4])..
    ...


The #initBytesPerWord: initializing VMBasicConstants pool vars.
But they are already added to codegenerator (with nil values) before
#initBytesPerWord: are sent.

This is because in #buildCodeGeneratorForInterpreter the
#addStructClass: adds given shared pool before it get initialized:

 ....
	(ChangeSet superclassOrder: structClasses asArray) do:
		[:structClass|
		structClass initialize.
a)>>>>		cg addStructClass: structClass].

	interpreterClasses do:
		[:ic|
		(ic respondsTo: #initializeWithOptions:)
b)>>>>			ifTrue: [ic initializeWithOptions: optionsDictionary]
			ifFalse: [ic initialize]].

	interpreterClasses do: [:ic| cg addClass: ic].
	^cg

apparently, for correct initialization (b) should precede (a) ,
because once you adding class to code generator it automatically sucks
all pools vars in, and converts them into TDefineNode before their
values are properly initialized.

Here the proposed fix (in attachment). I just split the #initialize
from adding to code generator.
So, initialization order will remain the same (first a struct classes
are initialized , and then interpreterClasses),
because i don't know if its important to initialize struct classes
before initializing interpreter class(es).



-- 
Best regards,
Igor Stasenko AKA sig.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: VMMaker-buildCodeGeneratorForInterpreter.st
Type: application/octet-stream
Size: 1555 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20110630/5cc923f0/VMMaker-buildCodeGeneratorForInterpreter.obj


More information about the Vm-dev mailing list