thisCompiler special variable

Stephen Pair spair at advantive.com
Thu May 18 06:58:20 UTC 2000


I've always wanted a way of specifying compile time directives in method
source.  I just had a thought that it might be nice to expose a new special
variable called "thisCompiler" (or maybe thisParser?).

Then we could write code like:

someMethod

	thisCompiler ifDebug: [
		self printDebugInfoInTranscript.
	].
	self doSomething.

- or -

someMethod

	^thisCompiler valueNow: [
		IdentityDictionary new
			at: 'US' put: 'United States';
			at: 'UK' put: 'United Kingdom';
			yourself
	].

- or even -

someMethod

	thisCompiler primitive: 'primname' module: 'modulename'.
	self primitiveFailed.

---

In the #ifDebug: case you could set or reset a compiler flag for debugging,
then re-compile all senders of #ifDebug: to yield compiled methods with
either the debug code embedded, or ignored.  The second case is an
alternative to special syntax that other dialects introduce (dolphin allows
##() to denote evaluation at compile time).  Also, (but less importantly) it
could be used to eliminate the special syntax for primitive declarations.

I haven't really thought through the idea, but at first glance it seems like
it would be very useful.  I might take a stab at it if people think it's a
good idea.  Thoughts?

- Stephen





More information about the Squeak-dev mailing list