[fine] Improvements to classes
- Classes are defined lazily - Member access is via environment - Member access is just a binary expression with a weird environment - Slot loads look like variable loads now - Associativity in the parser (ugh)
This commit is contained in:
parent
0d48bfb113
commit
2839b43f6d
5 changed files with 286 additions and 123 deletions
|
|
@ -2,22 +2,31 @@ class Point {
|
|||
x: f64;
|
||||
y: f64;
|
||||
|
||||
fun something_static() -> f64 {
|
||||
12
|
||||
}
|
||||
// fun something_static() -> f64 {
|
||||
// 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 {
|
||||
start: Point;
|
||||
end: Point;
|
||||
}
|
||||
|
||||
fun test() -> f64 {
|
||||
let pt = new Point { x: 7, y: 23 };
|
||||
let z = pt.x + pt.square_length() + Point::something_static();
|
||||
let line = new Line {
|
||||
start: new Point { x: 7, y: 23 },
|
||||
end: new Point { x: 999, y: 99 },
|
||||
};
|
||||
|
||||
let z = line.start.x;// + pt.square_length() + Point::something_static();
|
||||
z
|
||||
}
|
||||
|
||||
// @ignore WIP: Methods
|
||||
/// @ignore WIP: Methods
|
||||
// @no-errors
|
||||
// @eval: Float(7.0)
|
||||
// @compiles-to:
|
||||
|
|
@ -35,17 +44,33 @@ fun test() -> f64 {
|
|||
// | 2: PushString(0)
|
||||
// | 3: NewObject(2)
|
||||
// | 4: Return
|
||||
// | function Line (4 args, 0 locals):
|
||||
// | strings (1):
|
||||
// | 0: Line
|
||||
// | code (5):
|
||||
// | 0: LoadArgument(1)
|
||||
// | 1: LoadArgument(0)
|
||||
// | 2: PushString(0)
|
||||
// | 3: NewObject(2)
|
||||
// | 4: Return
|
||||
// | function test (0 args, 2 locals):
|
||||
// | strings (0):
|
||||
// | code (10):
|
||||
// | 0: PushFloat(23.0)
|
||||
// | 1: PushFloat(7.0)
|
||||
// | code (17):
|
||||
// | 0: PushFloat(99.0)
|
||||
// | 1: PushFloat(999.0)
|
||||
// | 2: LoadFunction(1)
|
||||
// | 3: Call(2)
|
||||
// | 4: StoreLocal(0)
|
||||
// | 5: LoadLocal(0)
|
||||
// | 6: LoadSlot(0)
|
||||
// | 7: StoreLocal(1)
|
||||
// | 8: LoadLocal(1)
|
||||
// | 9: Return
|
||||
// | 4: PushFloat(23.0)
|
||||
// | 5: PushFloat(7.0)
|
||||
// | 6: LoadFunction(1)
|
||||
// | 7: Call(2)
|
||||
// | 8: LoadFunction(2)
|
||||
// | 9: Call(2)
|
||||
// | 10: StoreLocal(0)
|
||||
// | 11: LoadLocal(0)
|
||||
// | 12: LoadSlot(0)
|
||||
// | 13: LoadSlot(0)
|
||||
// | 14: StoreLocal(1)
|
||||
// | 15: LoadLocal(1)
|
||||
// | 16: Return
|
||||
// |
|
||||
|
|
|
|||
18
fine/tests/expression/errors/wild_member_access.fine
Normal file
18
fine/tests/expression/errors/wild_member_access.fine
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
class Foo {
|
||||
foo: f64;
|
||||
}
|
||||
|
||||
fun test() {
|
||||
let f = new Foo { foo: 12 };
|
||||
let z = f.{let y = 222; foo };
|
||||
}
|
||||
|
||||
// NOTE: The AST allows for generic expressions to the right of the dot.
|
||||
// We need to make sure things are parsed correctly.
|
||||
//
|
||||
// TODO: Better parser recovery will improve the specifics of the errors.
|
||||
// @expect-errors:
|
||||
// | 7:12: Error at '{': expected an expression
|
||||
// | 7:13: Error at 'let': expect ';' to end a let statement
|
||||
// | 7:26: cannot find value foo here
|
||||
// | 8:0: Error at '}': unbalanced '}'
|
||||
Loading…
Add table
Add a link
Reference in a new issue