[Vm-dev] change to struct foo {} fum declaration

David T. Lewis lewis at mail.msen.com
Fri Dec 3 05:07:54 UTC 2010

On Thu, Dec 02, 2010 at 03:54:30PM -0800, Andreas Raab wrote:
> On 12/2/2010 3:33 PM, David T. Lewis wrote:
> >>>So, I want to change the default definition of fum variable (to "static 
> >>>struct foo").
> >>>What do you think?
> While you're at it, could you *please* give these variables reasonable 
> names? I mean 'struct foo fum'? WTF?


Esteban was asking if it is OK to change the declaration from "struct foo"
to "static struct foo", and the answer is yes, he should proceed with
that change (or I'll commit it to VMMaker if Esteban prefers to handle
it that way).

With respect to changing the names to something less whimsical, that's
a fair point. However, it effects two classes and a dozen methods in
VMMaker, as well as the external gnuify.awk script that has to be in
sync with these. Given that we have two significant branches of VMMaker
and two branches of the platform sources in need of convergence, this
may not be a good time to introduce additional changes that require 
coordination. Can we do it a few months from now?

Change set attached, but I vote for waiting until next year to apply it.


-------------- next part --------------
'From Squeak3.11alpha of 1 December 2010 [latest update: #10731] on 2 December 2010 at 10:49:48 pm'!
"Change Set:		FeFiFooFum-dtl
Date:			2 December 2010
Author:			David T. Lewis

Change the fe fi fo(o) fum naming convention to something a bit more somber in tone."!

Object subclass: #TMethod
	instanceVariableNames: 'selector returnType args locals declarations primitive parseTree labels possibleSideEffectsCache complete export static sharedLabel sharedCase comment definingClass globalStructureBuildMethodHasLocalVars canAsmLabel mustAsmLabel properties cascadeVariableNumber'
	classVariableNames: 'CaseStatements'
	poolDictionaries: ''
	category: 'VMMaker-Translation to C'!

!CCodeGeneratorGlobalStructure methodsFor: 'C code generator' stamp: 'dtl 12/2/2010 22:44'!
emitCVariablesOn: aStream
	"Store the global variable declarations on the given stream.
	break logic into vars for structure and vars for non-structure"
	| varString structure nonstruct target |

	structure := WriteStream on: (String new: 32768).
	nonstruct := WriteStream on: (String new: 32768).
	aStream nextPutAll: '/*** Variables ***/'; cr.
	structure nextPutAll: 'static struct localVars {'; cr.
	self buildSortedVariablesCollection do: [ :var |
		varString := var asString.
		target := (self placeInStructure: var) 
			ifTrue: [structure]
			ifFalse: [nonstruct].
		(self isGeneratingPluginCode) ifTrue:[
			varString = 'interpreterProxy' ifTrue:[
				"quite special..."
				aStream cr; nextPutAll: '#ifdef SQUEAK_BUILTIN_PLUGIN'.
				aStream cr; nextPutAll: 'extern'.
				aStream cr; nextPutAll: '#endif'; cr.
			] ifFalse:[aStream nextPutAll:'static '].
		(variableDeclarations includesKey: varString) ifTrue: [
			target nextPutAll: (variableDeclarations at: varString), ';'; cr.
		] ifFalse: [
			"default variable declaration"
			target nextPutAll: 'sqInt ', varString, ';'; cr.
	structure nextPutAll: ' } localVars;';cr.

	"if the machine needs the interpVars structure defining locally, do it now"
	localStructDef ifTrue:[structure nextPutAll: 'struct localVars * interpVars = &localVars;';cr;cr].

	aStream nextPutAll: structure contents.
	aStream nextPutAll: nonstruct contents.
	aStream cr.! !

!CCodeGeneratorGlobalStructure methodsFor: 'C code generator' stamp: 'dtl 12/2/2010 22:44'!
emitStructureInitFunctionOn: aStream 
	"For the VM using a global struct for most of the global vars (useful for ARM and PPC so far), append the initGlobalStructure() function"
		nextPutAll: 'void initGlobalStructure(void) {interpVars = &localVars;}';
		cr! !

!CCodeGeneratorGlobalStructure methodsFor: 'C code generator' stamp: 'dtl 12/2/2010 22:49'!
returnPrefixFromVariable: aName
	^((self globalsAsSet includes: aName) and: [self placeInStructure: aName])
		ifTrue: ['interpVars->',aName]
		ifFalse: [aName]! !

!TMethod methodsFor: 'accessing' stamp: 'dtl 12/2/2010 22:25'!
	^globalStructureBuildMethodHasLocalVars! !

!TMethod methodsFor: 'accessing' stamp: 'dtl 12/2/2010 22:24'!
globalStructureBuildMethodHasLocalVars: number
	globalStructureBuildMethodHasLocalVars := number! !

!TMethod methodsFor: 'accessing' stamp: 'dtl 12/2/2010 22:26'!
referencesGlobalStructIncrementBy: value
	globalStructureBuildMethodHasLocalVars := globalStructureBuildMethodHasLocalVars + value.! !

!TMethod methodsFor: 'accessing' stamp: 'dtl 12/2/2010 22:26'!
	globalStructureBuildMethodHasLocalVars := 0! !

!TMethod methodsFor: 'C code generation' stamp: 'dtl 12/2/2010 22:44'!
emitGlobalStructReferenceOn: aStream
	"Add a reference to the globals struct if needed"

	(self globalStructureBuildMethodHasLocalVars > 1)
		ifTrue: [aStream nextPutAll: 'register struct localVars * interpVars = &localVars;'; cr].
! !

!TMethod methodsFor: 'initialization' stamp: 'dtl 12/2/2010 22:26'!
setSelector: sel definingClass: class args: argList locals: localList block: aBlockNode primitive: aNumber properties: methodProperties comment: aComment
	"Initialize this method using the given information."

	selector := sel.
	definingClass := class.
	returnType := #sqInt. 	 "assume return type is long for now"
	args := argList asOrderedCollection collect: [:arg | arg key].
	locals := (localList asSortedCollection: [:a :b| a key < b key]) collect: [:arg | arg key].
	declarations := Dictionary new.
	"self addTypeForSelf." "<- Cog feature to be added later"
	primitive := aNumber.
	properties := methodProperties.
	comment := aComment.
	parseTree := aBlockNode asTranslatorNodeIn: self.
	labels := OrderedCollection new.
	complete := false.  "set to true when all possible inlining has been done"
	export := self extractExportDirective.
	static := self extractStaticDirective.
	canAsmLabel := self extractLabelDirective.
	self extractSharedCase.
	self removeFinalSelfReturn.	"must preceed recordDeclarations because this may set returnType"
	self recordDeclarations.
	globalStructureBuildMethodHasLocalVars := 0! !

TMethod removeSelector: #globalStructureBuildMethodHasFoo!
TMethod removeSelector: #globalStructureBuildMethodHasFoo:!

More information about the Vm-dev mailing list