I continue to be pleasantly surprised at how well LLVM works. Working with it is certainly a treat.
As an example, tonight I implemented structure types (i.e. aggregate types that are passed as values, not references) in my front end, and I wrote up this little unit test:
struct Vector {
var x:int;
var y:int;
var z:int;
def Vector(x:int, y:int, z:int) {
self.x = x;
self.y = y;
self.z = z;
}
def Vector() {
self.x = 0;
self.y = 0;
self.z = 0;
}
}
[EntryPoint]
def main(args:String) {
var v0:Vector = Vector();
assert(v0.x == 0);
assert(v0.y == 0);
assert(v0.z == 0);
let v1 = Vector(2, 3, 4);
assert(v1.x == 2);
assert(v1.y == 3);
assert(v1.z == 4);
v0 = v1;
assert(v0.x == 2);
assert(v0.y == 3);
assert(v0.z == 4);
}
After making a few tweaks to my code generator, it passed all of the tests...which was surprising enough. But then I turned on optimization -- and lo and behold, it converted every one of those asserts to "assert(1)", and completely eliminated everything else! If it had been able to inline the asserts (which I am still working on), it would have eliminated the body of main entirely.
Now that's the kind of optimization I like to see
-- Talin