fixed tests

This commit is contained in:
pca006132 2021-09-22 17:26:19 +08:00
parent 084efe92af
commit 7d48883583
2 changed files with 21 additions and 2 deletions

View File

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

View File

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