CCodeGenerator (newbie) questions

Raab, Andreas Andreas.Raab at disney.com
Sun Jan 16 02:11:02 UTC 2000


> Another question if I may: what are the rules for getting a function 
> call translated inline. I've looked the examples, and I use 'self: 
> inline: true' but no inline translation occurs.

There are a number of rules for it. First, you have to declare it as

	self inline: true.

which has to occur on the top level of the method (e.g., you should write it
as the first statement). Then, no code containing 'self cCode:' or special
local variable declarations (e.g., 'self var:#blabla declareC:'...') will be
inlined (since the inliner can't see if there are any side effects). Other
than this, your method should be perfectly inlineable. There are also some
tricks one can use to make inlining possible (in particular with respect to
variable declarations). As an example, a method like

MyPlugin>>myString: charPointer at: index put: value
	self inline: true.
	self var: #charPointer declareC:'char *charPointer'.
	self var: #value declareC:'char value'
	charPointer at: index put: value.

would not be inlined due to the restrictions above. But it is possible to
rewrite this method as

MyPlugin>>myString: charPointer at: index put: value
	self inline: true.
	(self cCoerce: charPointer to: '(char*)')
		at: index
		put: (self cCoerce: value to: 'char')

So that now variable declarations are necessary. Another (little known)
effect about inlining is that 'functional methods' (e.g., methods that
contain a single statement) will always be inlined, which allows to rewrite
the above as

MyPlugin>>myString: charPointer at: index put: value
	^(self cCoerce: charPointer to: '(char*)')
		at: index
		put: (self cCoerce: value to: 'char')

And this method *will* get inlined.

  Andreas





More information about the Squeak-dev mailing list