fixing generic function inlining

This commit is contained in:
Jakub Doka 2024-10-12 22:29:52 +02:00
parent 9e65f3949d
commit 6d7e726066
No known key found for this signature in database
GPG key ID: C6E9A89936B8C143
2 changed files with 23 additions and 7 deletions

View file

@ -905,6 +905,7 @@ impl Codegen {
let scope = self.ci.vars.len(); let scope = self.ci.vars.len();
let sig = self.compute_signature(&mut func, func_ast.pos(), args)?; 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"); 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) { for (arg, carg) in args.iter().zip(cargs) {
let ty = self.tys.ins.args[sig_args.next().unwrap()]; let ty = self.tys.ins.args[sig_args.next().unwrap()];
let sym = parser::find_symbol(&ast.symbols, carg.id); let sym = parser::find_symbol(&ast.symbols, carg.id);
if sym.flags & idfl::COMPTIME != 0 { let loc = match sym.flags & idfl::COMPTIME != 0 {
sig_args.next().unwrap(); true => Loc::ty(self.tys.ins.args[sig_args.next().unwrap()]),
continue; false => self.expr_ctx(arg, Ctx::default().with_ty(ty))?.loc,
} };
debug_assert_ne!(ty, ty::Id::TYPE);
let loc = self.expr_ctx(arg, Ctx::default().with_ty(ty))?.loc;
self.ci.vars.push(Variable { id: carg.id, value: Value { ty, loc } }); self.ci.vars.push(Variable { id: carg.id, value: Value { ty, loc } });
} }

View file

@ -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(())