[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

@ -263,7 +263,7 @@ fn assert_eval_ok(tree: &SyntaxTree, lines: &Lines, expected: &str) {
let semantics = Semantics::new(tree, lines);
let module = compile(&semantics);
let mut context = Context::new(module);
let mut context = Context::new(module.clone());
context.init().expect("Unable to initialize module");
match eval_export_fn(&mut context, "test", &[]) {
@ -278,7 +278,24 @@ fn assert_eval_ok(tree: &SyntaxTree, lines: &Lines, expected: &str) {
);
}
Err(e) => {
semantic_panic!(&semantics, None, "error occurred while running: {:?}", e);
semantics.dump_compiler_state(None);
let mut actual = String::new();
let _ = dump_module(&mut actual, &module);
eprintln!("{actual}");
for frame in e.stack.iter() {
eprintln!("{:?}", frame.func());
eprint!(" (");
for arg in frame.args().iter() {
eprint!("{:?},", arg);
}
eprintln!(") @ {}", frame.pc());
}
eprintln!();
panic!("error occurred while running: {:?}", e.code);
}
}
}

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
// |