From 6d7e726066109e8b08f049bbc4684bba2a2eb88a Mon Sep 17 00:00:00 2001 From: Jakub Doka Date: Sat, 12 Oct 2024 22:29:52 +0200 Subject: [PATCH] fixing generic function inlining --- lang/src/codegen.rs | 12 +++++------- ...codegen_tests_inlined_generic_functions.txt | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/lang/src/codegen.rs b/lang/src/codegen.rs index 17aaa9d..b51419e 100644 --- a/lang/src/codegen.rs +++ b/lang/src/codegen.rs @@ -905,6 +905,7 @@ impl Codegen { let scope = self.ci.vars.len(); let sig = self.compute_signature(&mut func, func_ast.pos(), args)?; + self.ci.vars.truncate(scope); self.assert_arg_count(expr.pos(), args.len(), cargs.len(), "inline function call"); @@ -912,13 +913,10 @@ impl Codegen { for (arg, carg) in args.iter().zip(cargs) { let ty = self.tys.ins.args[sig_args.next().unwrap()]; let sym = parser::find_symbol(&ast.symbols, carg.id); - if sym.flags & idfl::COMPTIME != 0 { - sig_args.next().unwrap(); - continue; - } - - debug_assert_ne!(ty, ty::Id::TYPE); - let loc = self.expr_ctx(arg, Ctx::default().with_ty(ty))?.loc; + let loc = match sym.flags & idfl::COMPTIME != 0 { + true => Loc::ty(self.tys.ins.args[sig_args.next().unwrap()]), + false => self.expr_ctx(arg, Ctx::default().with_ty(ty))?.loc, + }; self.ci.vars.push(Variable { id: carg.id, value: Value { ty, loc } }); } diff --git a/lang/tests/codegen_tests_inlined_generic_functions.txt b/lang/tests/codegen_tests_inlined_generic_functions.txt index e69de29..dd97ece 100644 --- a/lang/tests/codegen_tests_inlined_generic_functions.txt +++ b/lang/tests/codegen_tests_inlined_generic_functions.txt @@ -0,0 +1,18 @@ +main: + ADDI64 r254, r254, -32d + ST r31, r254, 0a, 32h + LI64 r32, 10d + NEG r32, r32 + CP r33, r32 + LI64 r34, 8d + ADDI64 r34, r34, -1d + SRS64 r33, r33, r34 + CP r34, r32 + XOR r34, r34, r33 + SUB64 r1, r34, r33 + LD r31, r254, 0a, 32h + ADDI64 r254, r254, 32d + JALA r0, r31, 0a +code size: 119 +ret: 10 +status: Ok(())