Tuesday, December 15, 2009

What to keep in mind when playing with compilers in Pharo

If you play with the compiler in Pharo, here's an urgent hint: don't lock yourself out of your image! If you break the compiler, you want to have something to fall back to. So here's what you do.

The compiler for the system is whatever Behavior compilerClass returns, so change that method to read out a preference:

Behavior>compilerClass
"Answer a compiler class appropriate for source methods of this class."
|default|
default := Compiler.
^(Smalltalk classNamed: (Preferences valueOfPreference: #whichCompiler ifAbsent: [^ default]) ) ifNil: [default]


That's step 1. Second step is to create the preference, so you can read it out at all:

Preferences addTextPreference: #whichCompiler category: #compiler default: 'Compiler' balloonHelp: 'Compiler to be used throughout the system' .

That's it, you're set. Happy hacking!

3 comments:

  1. How often did you lock yourself out? :)

    ReplyDelete
  2. Last week at least 3 times … very annoying! This is how you get back after you lock yourself out: You commit via Monticello to just about anyhwere, then open the .mcz package, dispose of all the garbage in it except the .st file. That file you edit by hand to remove all implementations of compilerClass. And then you drag the file into Pharo. Now you DON'T click on "into new changeset," the topmost option, because that will execute the file in random order, and that will fail. Rather, you file in the entire file!

    ReplyDelete

Note: Only a member of this blog may post a comment.