From cbe6f98dff9960e6b070173f35cf54434b0262f6 Mon Sep 17 00:00:00 2001 From: mlokr Date: Sun, 1 Sep 2024 23:14:48 +0200 Subject: [PATCH] maybe fixed --- hblang/README.md | 48 +++++++++++++++++-- hblang/src/codegen.rs | 7 +-- ...ts_comptime_function_from_another_file.txt | 3 ++ 3 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 hblang/tests/codegen_tests_comptime_function_from_another_file.txt diff --git a/hblang/README.md b/hblang/README.md index cd2e4ba..7252607 100644 --- a/hblang/README.md +++ b/hblang/README.md @@ -456,17 +456,20 @@ main := fn(): int { #### comptime_min_reg_leak ```hb +a := @use("math.hb").min(100, 50) + +main := fn(): int { + return a +} + +// in module: math.hb + SIZEOF_INT := 32 SHIFT := SIZEOF_INT - 1 min := fn(a: int, b: int): int { c := a - b return b + (c & c >> SHIFT) } -a := min(100, 50) - -main := fn(): int { - return a -} ``` #### different_types @@ -574,3 +577,38 @@ main := fn(): int { return 1 } ``` + +#### structs_in_registers +```hb +ColorBGRA := struct {b: u8, g: u8, r: u8, a: u8} +MAGENTA := ColorBGRA.{b: 205, g: 0, r: 205, a: 255} + +main := fn(): int { + color := MAGENTA + return color.r +} +``` + +#### comptime_function_from_another_file +```hb +stn := @use("stn.hb") + +CONST_A := 100 +CONST_B := 50 +a := stn.math.min(CONST_A, CONST_B) + +main := fn(): int { + return a +} + +// in module: stn.hb +math := @use("math.hb") + +// in module: math.hb +SIZEOF_INT := 32 +SHIFT := SIZEOF_INT - 1 +min := fn(a: int, b: int): int { + c := a - b + return b + (c & c >> SHIFT) +} +``` diff --git a/hblang/src/codegen.rs b/hblang/src/codegen.rs index a6afeef..54376d1 100644 --- a/hblang/src/codegen.rs +++ b/hblang/src/codegen.rs @@ -1852,7 +1852,7 @@ impl Codegen { self.tasks.push(Some(FTask { // FIXME: this will fuck us - file: self.ci.file, + file: fuc.file, id: func_id as _, })); @@ -2929,7 +2929,7 @@ impl Codegen { match name { Ok(_) => self.report(pos, format_args!("undefined indentifier: {lit_name}")), Err("main") => self.report(pos, format_args!("missing main function: {f}")), - Err(name) => unimplemented!("somehow we did not handle: {name:?}"), + Err(name) => self.report(pos, format_args!("undefined indentifier: {name}")), } }; @@ -3353,6 +3353,7 @@ mod tests { sort_something_viredly => README; hex_octal_binary_literals => README; comptime_min_reg_leak => README; - + // structs_in_registers => README; + comptime_function_from_another_file => README; } } diff --git a/hblang/tests/codegen_tests_comptime_function_from_another_file.txt b/hblang/tests/codegen_tests_comptime_function_from_another_file.txt new file mode 100644 index 0000000..18abd15 --- /dev/null +++ b/hblang/tests/codegen_tests_comptime_function_from_another_file.txt @@ -0,0 +1,3 @@ +code size: 255 +ret: 50 +status: Ok(())