Thanks for the suggestions! I'll order some of these books.
However, while they arrive, could someone give me a hint how to do
scalar replacement in a transformer:
// Given this method
def compute(v1: Vector2) = { val v2 = v1 + 2f; v2 }
// I want it to transform it to this
def compute(v1: Vector2) = {
val v2$x = v1.x + 2f
val v2$y = v2.y + 2f
Vector2(v2$x, v2$y)
}
// Nevermind that in this particular case there is no performance
improvement
In a transformer if I match on ValDef(...) I can do the replacement, but
what should I return?
I must return a single tree, but I have two trees that need to replace
the first one.
Maybe I should do this with a different method, not with the tree
transformer class?
Or perhaps I should create a new tree subtype that is eliminated in a
next phase?
Sorry if these are dumb questions :)
Erkki
Erkki Lindpere wrote:
> Can anyone recommend a good book or online resource on compilers that
> would help understand the Scala compiler?
>
> I want to create a plug-in that does vector math optimizations*, but
> I've never studied compilers and many things in the compiler seem
> really foreign to me.
>
> * I think scalar replacement is what it's called -- given the type
> Vector2(x: Float, y: Float) { /* operations */ }, I want to replace
> 1) local variables:
> val v = new Vector2(1f, 2f) --> val v$x = 1f; val v$y = 2f
> 2) any operations on Vectors with operations on Floats
> 3) any escaping vectors with new Vector2(v$x, v$y) -- most of the time
> they will not escape
>
> Or should I just wait until JIT can do this better? :)
>
> Erkki
>