This is simpler because we don't "discover" functions to compile as we go, we just compile all the ones we can find, and functions have pre-defined exports. This is good and useful to us as we can now refer to functions in different modules by known indices, but it *does* make me wonder what we're going to do for compiling generic specializations. The previous technique was better for that sort of thing. This is all predicated on the idea that I want to have partially-compiled modules, which I can't really say why I want it. If I'm happy to just compile things cross module in the same kind of space then it's much easier to go back to the function key way of working.
108 lines
2.3 KiB
Text
108 lines
2.3 KiB
Text
class Point {
|
|
x: f64;
|
|
y: f64;
|
|
|
|
fun something_static() -> f64 {
|
|
12
|
|
}
|
|
|
|
fun square_length(self) -> f64 {
|
|
self.x * self.x + self.y * self.y
|
|
}
|
|
}
|
|
|
|
class Line {
|
|
start: Point;
|
|
end: Point;
|
|
}
|
|
|
|
fun test() -> f64 {
|
|
let line = new Line {
|
|
start: new Point { y: 23, x: 7 },
|
|
end: new Point { x: 999, y: 99 },
|
|
};
|
|
|
|
let pt = line.start;
|
|
let z = line.start.x + pt.square_length() + Point.something_static();
|
|
z
|
|
}
|
|
|
|
// @no-errors
|
|
// @eval: Float(597.0)
|
|
// @compiles-to:
|
|
// | function something_static (0 args, 0 locals):
|
|
// | strings (0):
|
|
// | code (2):
|
|
// | 0: PushFloat(12.0)
|
|
// | 1: Return
|
|
// | function square_length (1 args, 0 locals):
|
|
// | strings (0):
|
|
// | code (12):
|
|
// | 0: LoadArgument(0)
|
|
// | 1: LoadSlot(0)
|
|
// | 2: LoadArgument(0)
|
|
// | 3: LoadSlot(0)
|
|
// | 4: FloatMultiply
|
|
// | 5: LoadArgument(0)
|
|
// | 6: LoadSlot(1)
|
|
// | 7: LoadArgument(0)
|
|
// | 8: LoadSlot(1)
|
|
// | 9: FloatMultiply
|
|
// | 10: FloatAdd
|
|
// | 11: Return
|
|
// | function Point (6 args, 0 locals):
|
|
// | strings (1):
|
|
// | 0: "Point"
|
|
// | code (6):
|
|
// | 0: LoadArgument(1)
|
|
// | 1: LoadArgument(0)
|
|
// | 2: PushString(0)
|
|
// | 3: PushInt(33)
|
|
// | 4: NewObject(2)
|
|
// | 5: Return
|
|
// | function Line (4 args, 0 locals):
|
|
// | strings (1):
|
|
// | 0: "Line"
|
|
// | code (6):
|
|
// | 0: LoadArgument(1)
|
|
// | 1: LoadArgument(0)
|
|
// | 2: PushString(0)
|
|
// | 3: PushInt(40)
|
|
// | 4: NewObject(2)
|
|
// | 5: Return
|
|
// | function test (0 args, 3 locals):
|
|
// | strings (0):
|
|
// | code (27):
|
|
// | 0: PushFloat(99.0)
|
|
// | 1: PushFloat(999.0)
|
|
// | 2: LoadFunction(2)
|
|
// | 3: Call(2)
|
|
// | 4: PushFloat(23.0)
|
|
// | 5: PushFloat(7.0)
|
|
// | 6: LoadFunction(2)
|
|
// | 7: Call(2)
|
|
// | 8: LoadFunction(3)
|
|
// | 9: Call(2)
|
|
// | 10: StoreLocal(0)
|
|
// | 11: LoadLocal(0)
|
|
// | 12: LoadSlot(0)
|
|
// | 13: StoreLocal(1)
|
|
// | 14: LoadLocal(0)
|
|
// | 15: LoadSlot(0)
|
|
// | 16: LoadSlot(0)
|
|
// | 17: LoadLocal(1)
|
|
// | 18: LoadFunction(1)
|
|
// | 19: Call(1)
|
|
// | 20: FloatAdd
|
|
// | 21: LoadFunction(0)
|
|
// | 22: Call(0)
|
|
// | 23: FloatAdd
|
|
// | 24: StoreLocal(2)
|
|
// | 25: LoadLocal(2)
|
|
// | 26: Return
|
|
// | function << module >> (0 args, 0 locals):
|
|
// | strings (0):
|
|
// | code (2):
|
|
// | 0: PushNothing
|
|
// | 1: Return
|
|
// |
|