From c0e5447ddd00dc327b789829ea567efa6a0a1b57 Mon Sep 17 00:00:00 2001 From: mlokr Date: Sat, 20 Jul 2024 18:52:24 +0200 Subject: [PATCH] fixed nasty wrong scope bug --- "f\033" | 519 ++++++++++++++++++++++++++++++++++++++++ hblang/README.md | 5 +- hblang/src/codegen.rs | 10 +- hblang/text-prj/main.hb | 6 +- hblang/text-prj/pkg.hb | 14 ++ 5 files changed, 550 insertions(+), 4 deletions(-) create mode 100644 "f\033" diff --git "a/f\033" "b/f\033" new file mode 100644 index 00000000..364829dd --- /dev/null +++ "b/f\033" @@ -0,0 +1,519 @@ +───────┬─────────────────────────────────────────────────────────────────────────────────────── + │ STDIN +───────┼─────────────────────────────────────────────────────────────────────────────────────── + 1 │  Compiling hblang v0.1.0 (/home/mlokis/personal/rust/holey-bytes/hblang) + 2 │  Finished `test` profile [unoptimized + debuginfo] target(s) in 0.53s + 3 │  Running unittests src/lib.rs (target/debug/deps/hblang-f17d24a239ab5c0e) + 4 │ + 5 │ running 28 tests + 6 │ test codegen::tests::arithmetic ... ok + 7 │ test codegen::tests::comments ... ok + 8 │ test codegen::tests::different_types ... ok + 9 │ test codegen::tests::arrays ... ok + 10 │ test codegen::tests::functions ... ok + 11 │ test codegen::tests::generic_functions ... ok + 12 │ test codegen::tests::variables ... ok + 13 │ test codegen::tests::c_strings ... ok + 14 │ test codegen::tests::loops ... ok + 15 │ test codegen::tests::pointers ... ok + 16 │ test parser::test::comments ... ok + 17 │ test codegen::tests::struct_operators ... ok + 18 │ test codegen::tests::structs ... ok + 19 │ test parser::test::some_ordinary_fild_per_lin_struct ... ok + 20 │ test parser::test::some_ordinary_code ... ok + 21 │ test codegen::tests::directives ... ok + 22 │ test parser::test::code_block ... ok + 23 │ test parser::test::some_arg_per_line_code ... ok + 24 │ test parser::test::some_ordinary_struct ... ok + 25 │ test test::task_queue_sanity ... ok + 26 │ test codegen::tests::generic_types ... ok + 27 │ test codegen::tests::if_statements ... ok + 28 │ test codegen::tests::struct_patterns ... ok + 29 │ test codegen::tests::global_variables ... ok + 30 │ test codegen::tests::comptime_pointers ... FAILED + 31 │ test codegen::tests::struct_return_from_module_function ... FAILED + 32 │ test codegen::tests::fb_driver ... ok + 33 │ test lexer::test::test_smh ... ok + 34 │ + 35 │ failures: + 36 │ + 37 │ ---- codegen::tests::comptime_pointers stdout ---- + 38 │ Dbg: stack_ptr: 7ee366800010 + 39 │ Dbg: 00000000: jal: 1f0000000000 + 40 │ Dbg: 00000007: tx:  + 41 │ Dbg: find_or_declare:  + 42 │ [hblang/src/codegen.rs:2925:9] lit_name = "" + 43 │ Dbg: eval + 44 │ Dbg: 00000000: addi64: fefe0000000000000000 + 45 │ Dbg: 0000000b: st: 1ffe00000000000000000000 + 46 │ Dbg: 00000018: li64: 010d00000000000000 + 47 │ Dbg: 00000022: jmp: 00000000 + 48 │ Dbg: 00000000: addi64: fefe0000000000000000 + 49 │ Dbg: 0000000b: st: 1ffe00000000000000000000 + 50 │ Dbg: 00000027: ld: 1ffe00000000000000000800 + 51 │ Dbg: 00000034: addi64: fefe0800000000000000 + 52 │ Dbg: 0000003f: tx:  + 53 │ Dbg: 64 0 + 54 │ Dbg: read-typed: 7ee3580116b0 u8 "addi64" + 55 │ Dbg: read-typed: 7ee3580116b1 hbvm::vmrun::>::binary_ +  │ op_imm::OpsRRImm "fefef8ffffffffffffff" + 56 │ Dbg: read-typed: 7ee3580116bb u8 "st" + 57 │ Dbg: read-typed: 7ee3580116bc hbbytecode::ops::OpsRRAH "1ffe00000000000000000800" + 58 │ Dbg: store: 7ee366800008 "0000000000000000" + 59 │ Dbg: read-typed: 7ee3580116c8 u8 "li64" + 60 │ Dbg: read-typed: 7ee3580116c9 hbbytecode::ops::OpsRD "010d00000000000000" + 61 │ Dbg: read-typed: 7ee3580116d2 u8 "jmp" + 62 │ Dbg: read-typed: 7ee3580116d3 hbbytecode::ops::OpsO "05000000" + 63 │ Dbg: read-typed: 7ee3580116d7 u8 "ld" + 64 │ Dbg: read-typed: 7ee3580116d8 hbbytecode::ops::OpsRRAH "1ffe00000000000000000800" + 65 │ Dbg: load: 7ee366800008 "0000000000000000" + 66 │ Dbg: read-typed: 7ee3580116e4 u8 "addi64" + 67 │ Dbg: read-typed: 7ee3580116e5 hbvm::vmrun::>::binary_ +  │ op_imm::OpsRRImm "fefe0800000000000000" + 68 │ Dbg: read-typed: 7ee3580116ef u8 "tx" + 69 │ Dbg: eval-end + 70 │ Dbg: fn: main + 71 │ Dbg: 00000008: addi64: fefe0000000000000000 + 72 │ Dbg: 00000013: st: 1ffe00000000000000000000 + 73 │ Dbg: fn-args + 74 │ Dbg: fn-body + 75 │ Dbg: eval + 76 │ Dbg: 00000008: addi64: fefe0000000000000000 + 77 │ Dbg: 00000013: st: 1ffe00000000000000000000 + 78 │ Dbg: 00000020: cp: 2001 + 79 │ Dbg: 00000023: li64: 210700000000000000 + 80 │ Dbg: 0000002d: st: 212000000000000000000800 + 81 │ Dbg: 0000003a: jmp: 00000000 + 82 │ Dbg: 00000000: addi64: fefe0000000000000000 + 83 │ Dbg: 0000000b: st: 1ffe00000000000000000000 + 84 │ Dbg: 0000003f: ld: 1ffe00000000000000001800 + 85 │ Dbg: 0000004c: addi64: fefe1800000000000000 + 86 │ Dbg: 00000057: tx:  + 87 │ Dbg: 00000058: cp: 0120 + 88 │ Dbg: 91 8 + 89 │ Dbg: read-typed: 7ee3580127b8 u8 "addi64" + 90 │ Dbg: read-typed: 7ee3580127b9 hbvm::vmrun::>::binary_ +  │ op_imm::OpsRRImm "fefee8ffffffffffffff" + 91 │ Dbg: read-typed: 7ee3580127c3 u8 "st" + 92 │ Dbg: read-typed: 7ee3580127c4 hbbytecode::ops::OpsRRAH "1ffe00000000000000001800" + 93 │ Dbg: store: 7ee366800000 "000000000000000000000000000000000000000000000000" + 94 │ Dbg: read-typed: 7ee3580127d0 u8 "cp" + 95 │ Dbg: read-typed: 7ee3580127d1 hbbytecode::ops::OpsRR "2001" + 96 │ Dbg: read-typed: 7ee3580127d3 u8 "li64" + 97 │ Dbg: read-typed: 7ee3580127d4 hbbytecode::ops::OpsRD "210700000000000000" + 98 │ Dbg: read-typed: 7ee3580127dd u8 "st" + 99 │ Dbg: read-typed: 7ee3580127de hbbytecode::ops::OpsRRAH "212000000000000000000800" + 100 │ Dbg: store: 7ee366800010 "0000000000000007" + 101 │ Dbg: read-typed: 7ee3580127ea u8 "jmp" + 102 │ Dbg: read-typed: 7ee3580127eb hbbytecode::ops::OpsO "05000000" + 103 │ Dbg: read-typed: 7ee3580127ef u8 "ld" + 104 │ Dbg: read-typed: 7ee3580127f0 hbbytecode::ops::OpsRRAH "1ffe00000000000000001800" + 105 │ Dbg: load: 7ee366800000 "000000000000000700000000000000000000000000000000" + 106 │ Dbg: read-typed: 7ee3580127fc u8 "addi64" + 107 │ Dbg: read-typed: 7ee3580127fd hbvm::vmrun::>::binary_ +  │ op_imm::OpsRRImm "fefe1800000000000000" + 108 │ Dbg: read-typed: 7ee358012807 u8 "tx" + 109 │ Dbg: eval-end + 110 │ Dbg: call modify + 111 │ Dbg: eval + 112 │ Dbg: 00000008: addi64: fefe0000000000000000 + 113 │ Dbg: 00000013: st: 1ffe00000000000000000000 + 114 │ Dbg: find_or_declare: modify + 115 │ [hblang/src/codegen.rs:2925:9] lit_name = "modify" + 116 │ Dbg: 00000020: li64: 010100006000000000 + 117 │ Dbg: 0000002a: jmp: 00000000 + 118 │ Dbg: 00000000: addi64: fefe0000000000000000 + 119 │ Dbg: 0000000b: st: 1ffe00000000000000000000 + 120 │ Dbg: 0000002f: ld: 1ffe00000000000000000800 + 121 │ Dbg: 0000003c: addi64: fefe0800000000000000 + 122 │ Dbg: 00000047: tx:  + 123 │ Dbg: 72 8 + 124 │ Dbg: read-typed: 7ee3580127b8 u8 "addi64" + 125 │ Dbg: read-typed: 7ee3580127b9 hbvm::vmrun::>::binary_ +  │ op_imm::OpsRRImm "fefef8ffffffffffffff" + 126 │ Dbg: read-typed: 7ee3580127c3 u8 "st" + 127 │ Dbg: read-typed: 7ee3580127c4 hbbytecode::ops::OpsRRAH "1ffe00000000000000000800" + 128 │ Dbg: store: 7ee366800010 "0000000000000000" + 129 │ Dbg: read-typed: 7ee3580127d0 u8 "li64" + 130 │ Dbg: read-typed: 7ee3580127d1 hbbytecode::ops::OpsRD "010100006000000000" + 131 │ Dbg: read-typed: 7ee3580127da u8 "jmp" + 132 │ Dbg: read-typed: 7ee3580127db hbbytecode::ops::OpsO "05000000" + 133 │ Dbg: read-typed: 7ee3580127df u8 "ld" + 134 │ Dbg: read-typed: 7ee3580127e0 hbbytecode::ops::OpsRRAH "1ffe00000000000000000800" + 135 │ Dbg: load: 7ee366800010 "0000000000000000" + 136 │ Dbg: read-typed: 7ee3580127ec u8 "addi64" + 137 │ Dbg: read-typed: 7ee3580127ed hbvm::vmrun::>::binary_ +  │ op_imm::OpsRRImm "fefe0800000000000000" + 138 │ Dbg: read-typed: 7ee3580127f7 u8 "tx" + 139 │ Dbg: eval-end + 140 │ Dbg: eval + 141 │ Dbg: 00000008: addi64: fefe0000000000000000 + 142 │ Dbg: 00000013: st: 1ffe00000000000000000000 + 143 │ Dbg: eval + 144 │ Dbg: 00000008: addi64: fefe0000000000000000 + 145 │ Dbg: 00000013: st: 1ffe00000000000000000000 + 146 │ Dbg: 00000020: li64: 010d00000000000000 + 147 │ Dbg: 0000002a: jmp: 00000000 + 148 │ Dbg: 00000000: addi64: fefe0000000000000000 + 149 │ Dbg: 0000000b: st: 1ffe00000000000000000000 + 150 │ Dbg: 0000002f: ld: 1ffe00000000000000000800 + 151 │ Dbg: 0000003c: addi64: fefe0800000000000000 + 152 │ Dbg: 00000047: tx:  + 153 │ Dbg: 72 8 + 154 │ Dbg: read-typed: 7ee3580127b8 u8 "addi64" + 155 │ Dbg: read-typed: 7ee3580127b9 hbvm::vmrun::>::binary_ +  │ op_imm::OpsRRImm "fefef8ffffffffffffff" + 156 │ Dbg: read-typed: 7ee3580127c3 u8 "st" + 157 │ Dbg: read-typed: 7ee3580127c4 hbbytecode::ops::OpsRRAH "1ffe00000000000000000800" + 158 │ Dbg: store: 7ee366800010 "0000000000000000" + 159 │ Dbg: read-typed: 7ee3580127d0 u8 "li64" + 160 │ Dbg: read-typed: 7ee3580127d1 hbbytecode::ops::OpsRD "010d00000000000000" + 161 │ Dbg: read-typed: 7ee3580127da u8 "jmp" + 162 │ Dbg: read-typed: 7ee3580127db hbbytecode::ops::OpsO "05000000" + 163 │ Dbg: read-typed: 7ee3580127df u8 "ld" + 164 │ Dbg: read-typed: 7ee3580127e0 hbbytecode::ops::OpsRRAH "1ffe00000000000000000800" + 165 │ Dbg: load: 7ee366800010 "0000000000000000" + 166 │ Dbg: read-typed: 7ee3580127ec u8 "addi64" + 167 │ Dbg: read-typed: 7ee3580127ed hbvm::vmrun::>::binary_ +  │ op_imm::OpsRRImm "fefe0800000000000000" + 168 │ Dbg: read-typed: 7ee3580127f7 u8 "tx" + 169 │ Dbg: eval-end + 170 │ Dbg: 00000020: li64: 010000004000000000 + 171 │ Dbg: 0000002a: jmp: 00000000 + 172 │ Dbg: 00000000: addi64: fefe0000000000000000 + 173 │ Dbg: 0000000b: st: 1ffe00000000000000000000 + 174 │ Dbg: 0000002f: ld: 1ffe00000000000000000800 + 175 │ Dbg: 0000003c: addi64: fefe0800000000000000 + 176 │ Dbg: 00000047: tx:  + 177 │ Dbg: 72 8 + 178 │ Dbg: read-typed: 7ee3580127b8 u8 "addi64" + 179 │ Dbg: read-typed: 7ee3580127b9 hbvm::vmrun::>::binary_ +  │ op_imm::OpsRRImm "fefef8ffffffffffffff" + 180 │ Dbg: read-typed: 7ee3580127c3 u8 "st" + 181 │ Dbg: read-typed: 7ee3580127c4 hbbytecode::ops::OpsRRAH "1ffe00000000000000000800" + 182 │ Dbg: store: 7ee366800010 "0000000000000000" + 183 │ Dbg: read-typed: 7ee3580127d0 u8 "li64" + 184 │ Dbg: read-typed: 7ee3580127d1 hbbytecode::ops::OpsRD "010000004000000000" + 185 │ Dbg: read-typed: 7ee3580127da u8 "jmp" + 186 │ Dbg: read-typed: 7ee3580127db hbbytecode::ops::OpsO "05000000" + 187 │ Dbg: read-typed: 7ee3580127df u8 "ld" + 188 │ Dbg: read-typed: 7ee3580127e0 hbbytecode::ops::OpsRRAH "1ffe00000000000000000800" + 189 │ Dbg: load: 7ee366800010 "0000000000000000" + 190 │ Dbg: read-typed: 7ee3580127ec u8 "addi64" + 191 │ Dbg: read-typed: 7ee3580127ed hbvm::vmrun::>::binary_ +  │ op_imm::OpsRRImm "fefe0800000000000000" + 192 │ Dbg: read-typed: 7ee3580127f7 u8 "tx" + 193 │ Dbg: eval-end + 194 │ Dbg: arg: ^int + 195 │ thread 'codegen::tests::comptime_pointers' panicked at hblang/src/codegen.rs:1823:29: + 196 │ assertion `left == right` failed: TODO: we dont support anything except type generics + 197 │  left: Id(1073741824) + 198 │  right: Id(4) + 199 │ stack backtrace: + 200 │  0: rust_begin_unwind + 201 │  at /rustc/20ae37c18df95f9246c019b04957d23b4164bf7a/library/std/src/panick +  │ ing.rs:661:5 + 202 │  1: core::panicking::panic_fmt + 203 │  at /rustc/20ae37c18df95f9246c019b04957d23b4164bf7a/library/core/src/panic +  │ king.rs:74:14 + 204 │  2: core::panicking::assert_failed_inner + 205 │  at /rustc/20ae37c18df95f9246c019b04957d23b4164bf7a/library/core/src/panic +  │ king.rs:405:23 + 206 │  3: core::panicking::assert_failed + 207 │  at /rustc/20ae37c18df95f9246c019b04957d23b4164bf7a/library/core/src/panic +  │ king.rs:365:5 + 208 │  4: hblang::codegen::Codegen::expr_ctx + 209 │  at ./src/codegen.rs:1823:29 + 210 │  5: hblang::codegen::Codegen::expr + 211 │  at ./src/codegen.rs:1363:9 + 212 │  6: hblang::codegen::Codegen::expr_ctx + 213 │  at ./src/codegen.rs:1954:21 + 214 │  7: hblang::codegen::Codegen::expr + 215 │  at ./src/codegen.rs:1363:9 + 216 │  8: hblang::codegen::Codegen::handle_task + 217 │  at ./src/codegen.rs:2578:12 + 218 │  9: hblang::codegen::Codegen::complete_call_graph_low + 219 │  at ./src/codegen.rs:2506:13 + 220 │  10: hblang::codegen::Codegen::generate + 221 │  at ./src/codegen.rs:1351:9 + 222 │  11: hblang::codegen::tests::generate + 223 │  at ./src/codegen.rs:3261:9 + 224 │  12: hblang::run_test + 225 │  at ./src/lib.rs:497:5 + 226 │  13: hblang::codegen::tests::comptime_pointers + 227 │  at ./src/lib.rs:33:13 + 228 │  14: hblang::codegen::tests::comptime_pointers::{{closure}} + 229 │  at ./src/lib.rs:32:19 + 230 │  15: core::ops::function::FnOnce::call_once + 231 │  at /rustc/20ae37c18df95f9246c019b04957d23b4164bf7a/library/core/src/ops/f +  │ unction.rs:250:5 + 232 │  16: core::ops::function::FnOnce::call_once + 233 │  at /rustc/20ae37c18df95f9246c019b04957d23b4164bf7a/library/core/src/ops/f +  │ unction.rs:250:5 + 234 │ note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace +  │ . + 235 │ Inf: dropping chunk of size: 944 + 236 │ Dbg: deallocating full chunk + 237 │ + 238 │ ---- codegen::tests::struct_return_from_module_function stdout ---- + 239 │ Inf: dropping chunk of size: 888 + 240 │ Dbg: deallocating full chunk + 241 │ Dbg: stack_ptr: 7ee33c221550 + 242 │ Dbg: 00000000: jal: 1f0000000000 + 243 │ Dbg: 00000007: tx:  + 244 │ Dbg: find_or_declare:  + 245 │ [hblang/src/codegen.rs:2925:9] lit_name = "" + 246 │ Dbg: eval + 247 │ Dbg: 00000000: addi64: fefe0000000000000000 + 248 │ Dbg: 0000000b: st: 1ffe00000000000000000000 + 249 │ Dbg: 00000018: li64: 010d00000000000000 + 250 │ Dbg: 00000022: jmp: 00000000 + 251 │ Dbg: 00000000: addi64: fefe0000000000000000 + 252 │ Dbg: 0000000b: st: 1ffe00000000000000000000 + 253 │ Dbg: 00000027: ld: 1ffe00000000000000000800 + 254 │ Dbg: 00000034: addi64: fefe0800000000000000 + 255 │ Dbg: 0000003f: tx:  + 256 │ Dbg: 64 0 + 257 │ Dbg: read-typed: 7ee33c221930 u8 "addi64" + 258 │ Dbg: read-typed: 7ee33c221931 hbvm::vmrun::>::binary_ +  │ op_imm::OpsRRImm "fefef8ffffffffffffff" + 259 │ Dbg: read-typed: 7ee33c22193b u8 "st" + 260 │ Dbg: read-typed: 7ee33c22193c hbbytecode::ops::OpsRRAH "1ffe00000000000000000800" + 261 │ Dbg: store: 7ee33c221548 "0000000000000000" + 262 │ Dbg: read-typed: 7ee33c221948 u8 "li64" + 263 │ Dbg: read-typed: 7ee33c221949 hbbytecode::ops::OpsRD "010d00000000000000" + 264 │ Dbg: read-typed: 7ee33c221952 u8 "jmp" + 265 │ Dbg: read-typed: 7ee33c221953 hbbytecode::ops::OpsO "05000000" + 266 │ Dbg: read-typed: 7ee33c221957 u8 "ld" + 267 │ Dbg: read-typed: 7ee33c221958 hbbytecode::ops::OpsRRAH "1ffe00000000000000000800" + 268 │ Dbg: load: 7ee33c221548 "0000000000000000" + 269 │ Dbg: read-typed: 7ee33c221964 u8 "addi64" + 270 │ Dbg: read-typed: 7ee33c221965 hbvm::vmrun::>::binary_ +  │ op_imm::OpsRRImm "fefe0800000000000000" + 271 │ Dbg: read-typed: 7ee33c22196f u8 "tx" + 272 │ Dbg: eval-end + 273 │ Dbg: fn: main + 274 │ Dbg: 00000008: addi64: fefe0000000000000000 + 275 │ Dbg: 00000013: st: 1ffe00000000000000000000 + 276 │ Dbg: fn-args + 277 │ Dbg: fn-body + 278 │ Dbg: 00000020: li64: 200700000000000000 + 279 │ Dbg: 7 - bar.foo().x + 280 │ Dbg: call bar.foo + 281 │ Dbg: eval + 282 │ Dbg: 00000008: addi64: fefe0000000000000000 + 283 │ Dbg: 00000013: st: 1ffe00000000000000000000 + 284 │ Dbg: find_or_declare: bar + 285 │ [hblang/src/codegen.rs:2925:9] lit_name = "bar" + 286 │ Dbg: eval + 287 │ Dbg: 00000008: addi64: fefe0000000000000000 + 288 │ Dbg: 00000013: st: 1ffe00000000000000000000 + 289 │ Dbg: 00000020: cp: 2001 + 290 │ Dbg: 00000023: li64: 21010000a000000000 + 291 │ Dbg: 0000002d: st: 212000000000000000000400 + 292 │ Dbg: 00000000: addi64: fefe0000000000000000 + 293 │ Dbg: 0000000b: st: 1ffe00000000000000000000 + 294 │ Dbg: 0000003e: ld: 1ffe00000000000000001800 + 295 │ Dbg: 0000004b: addi64: fefe1800000000000000 + 296 │ Dbg: 00000056: tx:  + 297 │ Dbg: 87 12 + 298 │ Dbg: read-typed: 7ee33c22210c u8 "addi64" + 299 │ Dbg: read-typed: 7ee33c22210d hbvm::vmrun::>::binary_ +  │ op_imm::OpsRRImm "fefee8ffffffffffffff" + 300 │ Dbg: read-typed: 7ee33c222117 u8 "st" + 301 │ Dbg: read-typed: 7ee33c222118 hbbytecode::ops::OpsRRAH "1ffe00000000000000001800" + 302 │ Dbg: store: 7ee33c221538 "000000000000000000000000000000000000000000000000" + 303 │ Dbg: read-typed: 7ee33c222124 u8 "cp" + 304 │ Dbg: read-typed: 7ee33c222125 hbbytecode::ops::OpsRR "2001" + 305 │ Dbg: read-typed: 7ee33c222127 u8 "li64" + 306 │ Dbg: read-typed: 7ee33c222128 hbbytecode::ops::OpsRD "21010000a000000000" + 307 │ Dbg: read-typed: 7ee33c222131 u8 "st" + 308 │ Dbg: read-typed: 7ee33c222132 hbbytecode::ops::OpsRRAH "212000000000000000000400" + 309 │ Dbg: store: 7ee33c222108 "a0000001" + 310 │ Dbg: read-typed: 7ee33c22213e u8 "ld" + 311 │ Dbg: read-typed: 7ee33c22213f hbbytecode::ops::OpsRRAH "1ffe00000000000000001800" + 312 │ Dbg: load: 7ee33c221538 "000000000000000000000000000000000000000000000000" + 313 │ Dbg: read-typed: 7ee33c22214b u8 "addi64" + 314 │ Dbg: read-typed: 7ee33c22214c hbvm::vmrun::>::binary_ +  │ op_imm::OpsRRImm "fefe1800000000000000" + 315 │ Dbg: read-typed: 7ee33c222156 u8 "tx" + 316 │ Dbg: eval-end + 317 │ Dbg: 1 + 318 │ Dbg: 00000024: lra: 200000000000 + 319 │ Dbg: eval + 320 │ Dbg: 0000000c: addi64: fefe0000000000000000 + 321 │ Dbg: 00000017: st: 1ffe00000000000000000000 + 322 │ Dbg: 1 + 323 │ Dbg: 00000024: lra: 200000000000 + 324 │ Dbg: 0000002b: cp: 0100 + 325 │ Dbg: 0000002e: ld: 012000000000000000000400 + 326 │ Dbg: 0000003b: jmp: 00000000 + 327 │ Dbg: reloc: Reloc { offset: 24, sub_offset: 3, width: 4, shifted: false } 0 52 12 12 + 328 │ Dbg: reloc: Reloc { offset: 24, sub_offset: 3, width: 4, shifted: false } 12 64 0 0 + 329 │ Dbg: 00000000: addi64: fefe0000000000000000 + 330 │ Dbg: 0000000b: st: 1ffe00000000000000000000 + 331 │ Dbg: 00000040: ld: 1ffe00000000000000001000 + 332 │ Dbg: 0000004d: addi64: fefe1000000000000000 + 333 │ Dbg: 00000058: tx:  + 334 │ Dbg: 89 12 + 335 │ Dbg: read-typed: 7ee33c22210c u8 "addi64" + 336 │ Dbg: read-typed: 7ee33c22210d hbvm::vmrun::>::binary_ +  │ op_imm::OpsRRImm "fefef0ffffffffffffff" + 337 │ Dbg: read-typed: 7ee33c222117 u8 "st" + 338 │ Dbg: read-typed: 7ee33c222118 hbbytecode::ops::OpsRRAH "1ffe00000000000000001000" + 339 │ Dbg: store: 7ee33c221540 "00000000000000000000000000000000" + 340 │ Dbg: read-typed: 7ee33c222124 u8 "lra" + 341 │ Dbg: read-typed: 7ee33c222125 hbbytecode::ops::OpsRRO "2000e4ffffff" + 342 │ Dbg: read-typed: 7ee33c22212b u8 "cp" + 343 │ Dbg: read-typed: 7ee33c22212c hbbytecode::ops::OpsRR "0100" + 344 │ Dbg: read-typed: 7ee33c22212e u8 "ld" + 345 │ Dbg: read-typed: 7ee33c22212f hbbytecode::ops::OpsRRAH "012000000000000000000400" + 346 │ Dbg: load: 7ee33c222108 "a0000001" + 347 │ Dbg: read-typed: 7ee33c22213b u8 "jmp" + 348 │ Dbg: read-typed: 7ee33c22213c hbbytecode::ops::OpsO "05000000" + 349 │ Dbg: read-typed: 7ee33c222140 u8 "ld" + 350 │ Dbg: read-typed: 7ee33c222141 hbbytecode::ops::OpsRRAH "1ffe00000000000000001000" + 351 │ Dbg: load: 7ee33c221540 "00000000000000000000000000000000" + 352 │ Dbg: read-typed: 7ee33c22214d u8 "addi64" + 353 │ Dbg: read-typed: 7ee33c22214e hbvm::vmrun::>::binary_ +  │ op_imm::OpsRRImm "fefe1000000000000000" + 354 │ Dbg: read-typed: 7ee33c222158 u8 "tx" + 355 │ Dbg: eval-end + 356 │ Dbg: find_or_declare:  + 357 │ [hblang/src/codegen.rs:2925:9] lit_name = "" + 358 │ Dbg: eval + 359 │ Dbg: 0000000c: addi64: fefe0000000000000000 + 360 │ Dbg: 00000017: st: 1ffe00000000000000000000 + 361 │ Dbg: 1 + 362 │ Dbg: 00000024: lra: 200000000000 + 363 │ Dbg: 0000002b: cp: 0100 + 364 │ Dbg: 0000002e: ld: 012000000000000000000400 + 365 │ Dbg: 0000003b: jmp: 00000000 + 366 │ Dbg: reloc: Reloc { offset: 24, sub_offset: 3, width: 4, shifted: false } 0 52 12 12 + 367 │ Dbg: reloc: Reloc { offset: 24, sub_offset: 3, width: 4, shifted: false } 12 64 0 0 + 368 │ Dbg: 00000000: addi64: fefe0000000000000000 + 369 │ Dbg: 0000000b: st: 1ffe00000000000000000000 + 370 │ Dbg: 00000040: ld: 1ffe00000000000000001000 + 371 │ Dbg: 0000004d: addi64: fefe1000000000000000 + 372 │ Dbg: 00000058: tx:  + 373 │ Dbg: 89 12 + 374 │ Dbg: read-typed: 7ee33c22210c u8 "addi64" + 375 │ Dbg: read-typed: 7ee33c22210d hbvm::vmrun::>::binary_ +  │ op_imm::OpsRRImm "fefef0ffffffffffffff" + 376 │ Dbg: read-typed: 7ee33c222117 u8 "st" + 377 │ Dbg: read-typed: 7ee33c222118 hbbytecode::ops::OpsRRAH "1ffe00000000000000001000" + 378 │ Dbg: store: 7ee33c221540 "00000000000000000000000000000000" + 379 │ Dbg: read-typed: 7ee33c222124 u8 "lra" + 380 │ Dbg: read-typed: 7ee33c222125 hbbytecode::ops::OpsRRO "2000e4ffffff" + 381 │ Dbg: read-typed: 7ee33c22212b u8 "cp" + 382 │ Dbg: read-typed: 7ee33c22212c hbbytecode::ops::OpsRR "0100" + 383 │ Dbg: read-typed: 7ee33c22212e u8 "ld" + 384 │ Dbg: read-typed: 7ee33c22212f hbbytecode::ops::OpsRRAH "012000000000000000000400" + 385 │ Dbg: load: 7ee33c222108 "a0000001" + 386 │ Dbg: read-typed: 7ee33c22213b u8 "jmp" + 387 │ Dbg: read-typed: 7ee33c22213c hbbytecode::ops::OpsO "05000000" + 388 │ Dbg: read-typed: 7ee33c222140 u8 "ld" + 389 │ Dbg: read-typed: 7ee33c222141 hbbytecode::ops::OpsRRAH "1ffe00000000000000001000" + 390 │ Dbg: load: 7ee33c221540 "00000000000000000000000000000000" + 391 │ Dbg: read-typed: 7ee33c22214d u8 "addi64" + 392 │ Dbg: read-typed: 7ee33c22214e hbvm::vmrun::>::binary_ +  │ op_imm::OpsRRImm "fefe1000000000000000" + 393 │ Dbg: read-typed: 7ee33c222158 u8 "tx" + 394 │ Dbg: eval-end + 395 │ Dbg: 00000024: li64: 010100006000000000 + 396 │ Dbg: 0000002e: jmp: 00000000 + 397 │ Dbg: fn: foo + 398 │ Dbg: 0000000c: addi64: fefe0000000000000000 + 399 │ Dbg: 00000017: st: 1ffe00000000000000000000 + 400 │ Dbg: fn-args + 401 │ thread 'codegen::tests::struct_return_from_module_function' panicked at hblang/src/cod +  │ egen.rs:995:19: + 402 │ not implemented: size_of: Module(1) + 403 │ stack backtrace: + 404 │  0: rust_begin_unwind + 405 │  at /rustc/20ae37c18df95f9246c019b04957d23b4164bf7a/library/std/src/panick +  │ ing.rs:661:5 + 406 │  1: core::panicking::panic_fmt + 407 │  at /rustc/20ae37c18df95f9246c019b04957d23b4164bf7a/library/core/src/panic +  │ king.rs:74:14 + 408 │  2: hblang::codegen::Types::size_of + 409 │  at ./src/codegen.rs:995:19 + 410 │  3: hblang::codegen::Types::parama + 411 │  at ./src/codegen.rs:910:43 + 412 │  4: hblang::codegen::Codegen::handle_task + 413 │  at ./src/codegen.rs:2557:26 + 414 │  5: hblang::codegen::Codegen::complete_call_graph_low + 415 │  at ./src/codegen.rs:2506:13 + 416 │  6: hblang::codegen::Codegen::complete_call_graph + 417 │  at ./src/codegen.rs:2495:9 + 418 │  7: hblang::codegen::Codegen::eval_const_low::{{closure}} + 419 │  at ./src/codegen.rs:2213:25 + 420 │  8: hblang::codegen::Codegen::ct_eval + 421 │  at ./src/codegen.rs:3064:19 + 422 │  9: hblang::codegen::Codegen::eval_const_low + 423 │  at ./src/codegen.rs:2197:19 + 424 │  10: hblang::codegen::Codegen::eval_const + 425 │  at ./src/codegen.rs:2185:9 + 426 │  11: hblang::codegen::Codegen::ty + 427 │  at ./src/codegen.rs:2849:22 + 428 │  12: hblang::codegen::Codegen::expr_ctx + 429 │  at ./src/codegen.rs:1795:31 + 430 │  13: hblang::codegen::Codegen::expr + 431 │  at ./src/codegen.rs:1363:9 + 432 │  14: hblang::codegen::Codegen::expr_ctx + 433 │  at ./src/codegen.rs:1705:31 + 434 │  15: hblang::codegen::Codegen::expr_ctx + 435 │  at ./src/codegen.rs:2083:29 + 436 │  16: hblang::codegen::Codegen::expr + 437 │  at ./src/codegen.rs:1363:9 + 438 │  17: hblang::codegen::Codegen::expr_ctx + 439 │  at ./src/codegen.rs:2065:28 + 440 │  18: hblang::codegen::Codegen::expr + 441 │  at ./src/codegen.rs:1363:9 + 442 │  19: hblang::codegen::Codegen::expr_ctx + 443 │  at ./src/codegen.rs:2065:28 + 444 │  20: hblang::codegen::Codegen::expr_ctx + 445 │  at ./src/codegen.rs:1942:30 + 446 │  21: hblang::codegen::Codegen::expr + 447 │  at ./src/codegen.rs:1363:9 + 448 │  22: hblang::codegen::Codegen::expr_ctx + 449 │  at ./src/codegen.rs:1954:21 + 450 │  23: hblang::codegen::Codegen::expr + 451 │  at ./src/codegen.rs:1363:9 + 452 │  24: hblang::codegen::Codegen::handle_task + 453 │  at ./src/codegen.rs:2578:12 + 454 │  25: hblang::codegen::Codegen::complete_call_graph_low + 455 │  at ./src/codegen.rs:2506:13 + 456 │  26: hblang::codegen::Codegen::generate + 457 │  at ./src/codegen.rs:1351:9 + 458 │  27: hblang::codegen::tests::generate + 459 │  at ./src/codegen.rs:3261:9 + 460 │  28: hblang::run_test + 461 │  at ./src/lib.rs:497:5 + 462 │  29: hblang::codegen::tests::struct_return_from_module_function + 463 │  at ./src/lib.rs:33:13 + 464 │  30: hblang::codegen::tests::struct_return_from_module_function::{{closure}} + 465 │  at ./src/lib.rs:32:19 + 466 │  31: core::ops::function::FnOnce::call_once + 467 │  at /rustc/20ae37c18df95f9246c019b04957d23b4164bf7a/library/core/src/ops/f +  │ unction.rs:250:5 + 468 │  32: core::ops::function::FnOnce::call_once + 469 │  at /rustc/20ae37c18df95f9246c019b04957d23b4164bf7a/library/core/src/ops/f +  │ unction.rs:250:5 + 470 │ note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace +  │ . + 471 │ Inf: dropping chunk of size: 888 + 472 │ Dbg: deallocating full chunk + 473 │ Inf: dropping chunk of size: 752 + 474 │ Dbg: deallocating full chunk + 475 │ + 476 │ + 477 │ failures: + 478 │  codegen::tests::comptime_pointers + 479 │  codegen::tests::struct_return_from_module_function + 480 │ + 481 │ test result: FAILED. 26 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out; finis +  │ hed in 0.22s + 482 │ + 483 │ error: test failed, to rerun pass `-p hblang --lib` +───────┴─────────────────────────────────────────────────────────────────────────────────────── diff --git a/hblang/README.md b/hblang/README.md index 2796a173..d4381a74 100644 --- a/hblang/README.md +++ b/hblang/README.md @@ -510,7 +510,10 @@ main := fn(): int { // in module: bar.hb -foo := fn(): struct {x: int, y: u32, z: u32} { + +foo := fn(): Foo { return .{x: 3, y: 2, z: 2} } + +Foo := struct {x: int, y: u32, z: u32} ``` diff --git a/hblang/src/codegen.rs b/hblang/src/codegen.rs index 7868fb51..325efb7b 100644 --- a/hblang/src/codegen.rs +++ b/hblang/src/codegen.rs @@ -2648,6 +2648,7 @@ impl Codegen { assert_eq!(offset, 0, "TODO"); if reg.is_ref() { let new_reg = self.ci.regs.allocate(); + debug_assert_ne!(reg.get(), 0); self.output.emit(cp(new_reg.get(), reg.get())); reg = new_reg; } @@ -2750,6 +2751,7 @@ impl Codegen { } (lpat!(false, src, 0, None), lpat!(false, dst, 0, None)) => { if src != dst { + debug_assert_ne!(src.get(), 0); self.output.emit(cp(dst.get(), src.get())); } } @@ -2912,7 +2914,7 @@ impl Codegen { name: Result, lit_name: &str, ) -> ty::Kind { - log::dbg!("find_or_declare: {lit_name}"); + log::dbg!("find_or_declare: {lit_name} {file}"); let f = self.files[file as usize].clone(); let Some((expr, ident)) = f.find_decl(name) else { match name { @@ -2922,6 +2924,8 @@ impl Codegen { } }; + log::dbg!("foo: {expr}"); + if let Some(existing) = self.tys.syms.get(&SymKey { file, ident }) { if let ty::Kind::Func(id) = existing.expand() && let func = &mut self.tys.funcs[id as usize] @@ -2934,6 +2938,7 @@ impl Codegen { return existing.expand(); } + let prev_file = std::mem::replace(&mut self.ci.file, file); let sym = match expr { Expr::BinOp { left: &Expr::Ident { .. }, @@ -2959,7 +2964,9 @@ impl Codegen { self.tasks.push(Some(FTask { file, id })); let args = self.pack_args(pos, arg_base); + log::dbg!("eval ret"); let ret = self.ty(ret); + Some(Sig { args, ret }) }, expr: ExprRef::new(expr), @@ -2992,6 +2999,7 @@ impl Codegen { } e => unimplemented!("{e:#?}"), }; + self.ci.file = prev_file; self.tys.syms.insert(SymKey { ident, file }, sym.compress()); sym } diff --git a/hblang/text-prj/main.hb b/hblang/text-prj/main.hb index f91a4ea4..e6522988 100644 --- a/hblang/text-prj/main.hb +++ b/hblang/text-prj/main.hb @@ -1,9 +1,11 @@ foo := 0; -.{global, fib} := @use("pkg.hb") +.{global, fib, Structa, create_window, WindowID} := @use("pkg.hb") main := fn(a: int): int { g := global - return fib(g) + win := create_window() + + return fib(g + Structa.(0, 0).foo) } diff --git a/hblang/text-prj/pkg.hb b/hblang/text-prj/pkg.hb index 0e27000d..7348fa0b 100644 --- a/hblang/text-prj/pkg.hb +++ b/hblang/text-prj/pkg.hb @@ -1,5 +1,19 @@ global := 10 +Structa := struct { + foo: int, + goo: int, +} + +create_window := fn(): WindowID { + return WindowID.(1, 2) +} + +WindowID := struct { + host_id: int, + window_id: int, +} + fib := fn(n: int): int { return n + 1 }