From 7d48883583f829e4bf29f9600c4643d7ad70a484 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Wed, 22 Sep 2021 17:26:19 +0800 Subject: [PATCH] fixed tests --- nac3core/src/codegen/test.rs | 4 ++-- nac3core/src/typecheck/type_inferencer/mod.rs | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/nac3core/src/codegen/test.rs b/nac3core/src/codegen/test.rs index 1173b97e..86e55aae 100644 --- a/nac3core/src/codegen/test.rs +++ b/nac3core/src/codegen/test.rs @@ -328,14 +328,14 @@ fn test_simple_call() { body: ; preds = %init %load = load i32, i32* %a, align 4 - %call = call i32 @foo_0(i32 %load) + %call = call i32 @foo.0(i32 %load) store i32 %call, i32* %a, align 4 %load1 = load i32, i32* %a, align 4 %mul = mul i32 %load1, 2 ret i32 %mul } - define i32 @foo_0(i32 %0) { + define i32 @foo.0(i32 %0) { init: %a = alloca i32, align 4 store i32 %0, i32* %a, align 4 diff --git a/nac3core/src/typecheck/type_inferencer/mod.rs b/nac3core/src/typecheck/type_inferencer/mod.rs index 4301e696..7d322d62 100644 --- a/nac3core/src/typecheck/type_inferencer/mod.rs +++ b/nac3core/src/typecheck/type_inferencer/mod.rs @@ -248,9 +248,17 @@ impl<'a> Inferencer<'a> { if let TypeEnum::TFunc(sign) = &*self.unifier.get_ty(*ty) { let sign = sign.borrow(); if sign.vars.is_empty() { + let call = self.unifier.add_call(Call { + posargs: params, + kwargs: HashMap::new(), + ret: sign.ret, + fun: RefCell::new(None), + }); + let call = self.unifier.add_ty(TypeEnum::TCall(vec![call].into())); if let Some(ret) = ret { self.unifier.unify(sign.ret, ret).unwrap(); } + self.constrain(call, *ty, &location)?; return Ok(sign.ret); } } @@ -483,6 +491,17 @@ impl<'a> Inferencer<'a> { if let TypeEnum::TFunc(sign) = &*self.unifier.get_ty(func.custom.unwrap()) { let sign = sign.borrow(); if sign.vars.is_empty() { + let call = self.unifier.add_call(Call { + posargs: args.iter().map(|v| v.custom.unwrap()).collect(), + kwargs: keywords + .iter() + .map(|v| (v.node.arg.as_ref().unwrap().clone(), v.custom.unwrap())) + .collect(), + fun: RefCell::new(None), + ret: sign.ret, + }); + let call = self.unifier.add_ty(TypeEnum::TCall(vec![call].into())); + self.unify(func.custom.unwrap(), call, &func.location)?; return Ok(Located { location, custom: Some(sign.ret),