[fine] Static methods I guess

This commit is contained in:
John Doty 2024-01-25 06:44:53 -08:00
parent bc57978dda
commit 19e57db724
6 changed files with 111 additions and 51 deletions

View file

@ -285,9 +285,10 @@ fn assert_eval_ok(tree: &SyntaxTree, lines: &Lines, expected: &str) {
eprintln!("{actual}");
eprintln!("Backtrace:");
for frame in e.stack.iter() {
eprintln!("{:?}", frame.func());
eprint!(" (");
let func = frame.func();
eprint!(" {} (", func.name());
for arg in frame.args().iter() {
eprint!("{:?},", arg);
}

View file

@ -2,9 +2,9 @@ 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
@ -23,19 +23,19 @@ fun test() -> f64 {
};
let pt = line.start;
let z = line.start.x + pt.square_length();// + Point::something_static();
let z = line.start.x + pt.square_length() + Point.something_static();
z
}
// @no-errors
// @eval: Float(585.0)
// @eval: Float(597.0)
// @compiles-to:
// | function << module >> (0 args, 0 locals):
// | strings (0):
// | code (2):
// | 0: PushNothing
// | 1: Return
// | function Point (5 args, 0 locals):
// | function Point (6 args, 0 locals):
// | strings (1):
// | 0: Point
// | code (5):
@ -55,7 +55,7 @@ fun test() -> f64 {
// | 4: Return
// | function test (0 args, 3 locals):
// | strings (0):
// | code (24):
// | code (27):
// | 0: PushFloat(99.0)
// | 1: PushFloat(999.0)
// | 2: LoadFunction(1)
@ -77,9 +77,12 @@ fun test() -> f64 {
// | 18: LoadFunction(4)
// | 19: Call(1)
// | 20: FloatAdd
// | 21: StoreLocal(2)
// | 22: LoadLocal(2)
// | 23: Return
// | 21: LoadFunction(5)
// | 22: Call(0)
// | 23: FloatAdd
// | 24: StoreLocal(2)
// | 25: LoadLocal(2)
// | 26: Return
// | function square_length (1 args, 0 locals):
// | strings (0):
// | code (12):
@ -95,4 +98,9 @@ fun test() -> f64 {
// | 9: FloatMultiply
// | 10: FloatAdd
// | 11: Return
// | function something_static (0 args, 0 locals):
// | strings (0):
// | code (2):
// | 0: PushFloat(12.0)
// | 1: Return
// |

View file

@ -5,4 +5,4 @@ fun test() -> f64 {
}
// @expect-errors:
// | 4:2: Foo is a class, not a value (did you mean to create a new instance with 'new'?)
// | 4:6: cannot apply binary operator '+' to expressions of type 'class Foo' (on the left) and 'f64' (on the right)

View file

@ -18,7 +18,7 @@ fun test() {
// @expect-errors:
// | 7:12: missing an initializer for field y
// | 8:12: missing an initializer for field x
// | 9:41: class Point does not have a field named z
// | 9:41: Point instance does not have a field named z
// | 10:32: field x is of type f64, but this expression generates a string
// | 12:32: cannot find value x here
// | 15:31: field x is of type f64, but this expression generates a string