[fine] Methods!

This commit is contained in:
John Doty 2024-01-24 09:03:45 -08:00
parent 2839b43f6d
commit 0c69758b11
5 changed files with 352 additions and 95 deletions

View file

@ -6,9 +6,9 @@ class Point {
// 12
// }
// fun square_length(self) -> f64 {
// self.x * self.x + self.y * self.y
// }
fun square_length(self) -> f64 {
self.x * self.x + self.y * self.y
}
}
class Line {
@ -18,24 +18,24 @@ class Line {
fun test() -> f64 {
let line = new Line {
start: new Point { x: 7, y: 23 },
start: new Point { y: 23, x: 7 },
end: new Point { x: 999, y: 99 },
};
let z = line.start.x;// + pt.square_length() + Point::something_static();
let pt = line.start;
let z = line.start.x + pt.square_length();// + Point::something_static();
z
}
/// @ignore WIP: Methods
// @no-errors
// @eval: Float(7.0)
// @eval: Float(585.0)
// @compiles-to:
// | function << module >> (0 args, 0 locals):
// | strings (0):
// | code (2):
// | 0: PushNothing
// | 1: Return
// | function Point (4 args, 0 locals):
// | function Point (5 args, 0 locals):
// | strings (1):
// | 0: Point
// | code (5):
@ -53,9 +53,9 @@ fun test() -> f64 {
// | 2: PushString(0)
// | 3: NewObject(2)
// | 4: Return
// | function test (0 args, 2 locals):
// | function test (0 args, 3 locals):
// | strings (0):
// | code (17):
// | code (24):
// | 0: PushFloat(99.0)
// | 1: PushFloat(999.0)
// | 2: LoadFunction(1)
@ -69,8 +69,30 @@ fun test() -> f64 {
// | 10: StoreLocal(0)
// | 11: LoadLocal(0)
// | 12: LoadSlot(0)
// | 13: LoadSlot(0)
// | 14: StoreLocal(1)
// | 15: LoadLocal(1)
// | 16: Return
// | 13: StoreLocal(1)
// | 14: LoadLocal(0)
// | 15: LoadSlot(0)
// | 16: LoadSlot(0)
// | 17: LoadLocal(1)
// | 18: LoadFunction(4)
// | 19: Call(1)
// | 20: FloatAdd
// | 21: StoreLocal(2)
// | 22: LoadLocal(2)
// | 23: 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
// |