In 3.0, when using the new Compiler, there is now a new way to set options that
the compile
chain can act on (Opal takes care to hand them through all the stages).
For now, the there are two cases where we use options: controlling inlining and
to generate
long ivar access bytecodes even when short ones would be enough:
defaultOptions
^ #(
"by default we inline all optimized constructs"
+ optInlineIf
+ optInlineIfNil
+ optInlineAndOr
+ optInlineWhile
+ optInlineToDo
+ optInlineCase
- optIlineNone "to turn off all. Overrides the others"
- optLongIvarAccessBytecodes "special for Contexts"
)
There are two ways to set compiler options. One is per Class Hierarchy. For
example, in
InstructionStream class, there is this method:
compiler
^super compiler options: #(+ optLongIvarAccessBytecodes)
The other way to use it is with a pragma:
test
<compilerOptions: #(-optInlineIf)>
^1 < 2 ifTrue: [ 'Hello!' ]
The options API idea is taken from NativeBoost:
#( + option1 option2 - option3 ... )
each time the #+ is seen, the options which follow it will be subject for
inclusion
and, correspondingly, if #- seen, then they will be excluded.
By default, (if none of #+ or #- specified initially), all options are subject
for inclusion.
Like NativeBoost it uses #doesNotUnderstand, so e.g. if you want to have a flag
for your own
Compiler Plugin, just set it and query the compilationContext by sending the
flag symbol as
a message.
Next: AST Transformation Plugins… ready later this week.
Marcus