Hi list, consider this code:
c := Compiler compile: 'meth "bla" ^ 2'. Here, c will be set to the symbol #meth. And Compiler will be added a new method "meth". This is of course counter-intuitive, but it's kind of wired into the system. Behavior>compile: does certainly more than compile. It compiles the code and adds it to itself, then returns the methodName as a symbol. Without mirrors, it's hard to do it right, though. Also, there's an easy method to add a method to a class, but no easy method to get a CompiledMethod object. I don't want to strongly advocate for my change, I just want to offer it. Here's what I did in my system: I changed Compiler>compile: to do the following: class side: compile: aString onClass: aClass ^ self new compiledMethodFor: aString onClass: aClass instance side: compiledMethodFor: textOrStream onClass: aClass | methodNode method | class := aClass. self from: textOrStream class: class context: nil notifying: nil. methodNode := self translate: sourceStream noPattern: false ifFail: [^self error: 'Compilation failed']. method := methodNode generate: #(0 0 0 0). self interactive ifTrue: [method := method copyWithTempsFromMethodNode: methodNode]. ^method This has its own problem, like: compile: suddenly has different semantics on Compiler than anywhere else. Best might be renaming Behavior>compile: to something more intuitive. Like #compileFromAndAdd:. Cheers, Niko _______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project