it runs! gets the wrong answer, but runs!
This commit is contained in:
@@ -482,7 +482,7 @@ impl<M: Module> Backend<M> {
|
||||
let (arguments, _argument_types): (Vec<_>, Vec<_>) = args
|
||||
.into_iter()
|
||||
.map(|x| self.compile_value_or_ref(x, variables, builder))
|
||||
.collect::<Result<Vec<(_,_)>,BackendError>>()?
|
||||
.collect::<Result<Vec<(_, _)>, BackendError>>()?
|
||||
.into_iter()
|
||||
.unzip();
|
||||
|
||||
@@ -491,20 +491,29 @@ impl<M: Module> Backend<M> {
|
||||
panic!("Can't use a value for a function")
|
||||
}
|
||||
|
||||
ValueOrRef::Ref(_, result_type, name) => match self.defined_functions.get(&name) {
|
||||
None => panic!("Couldn't find function {} to call", name),
|
||||
Some(function) => {
|
||||
let func_ref = self.module.declare_func_in_func(*function, builder.func);
|
||||
let call = builder.ins().call(func_ref, &arguments);
|
||||
let results = builder.inst_results(call);
|
||||
|
||||
match results {
|
||||
[] => Ok((builder.ins().iconst(types::I64, 0), ConstantType::Void)),
|
||||
[result] => match result_type {
|
||||
Type::Primitive(ct) => Ok((*result, ct.into())),
|
||||
Type::Function(_, _) => panic!("return value is a function?"),
|
||||
ValueOrRef::Ref(_, result_type, name) => {
|
||||
match self.defined_functions.get(&name) {
|
||||
None => panic!("Couldn't find function {} to call", name),
|
||||
Some(function) => {
|
||||
let func_ref =
|
||||
self.module.declare_func_in_func(*function, builder.func);
|
||||
let call = builder.ins().call(func_ref, &arguments);
|
||||
let results = builder.inst_results(call);
|
||||
|
||||
match results {
|
||||
[] => Ok((
|
||||
builder.ins().iconst(types::I64, 0),
|
||||
ConstantType::Void,
|
||||
)),
|
||||
[result] => match result_type {
|
||||
Type::Primitive(ct) => Ok((*result, ct.into())),
|
||||
Type::Function(_, rt) => match *rt {
|
||||
Type::Function(_, _) => panic!("function returns a function?"),
|
||||
Type::Primitive(ct) => Ok((*result, ct.into())),
|
||||
}
|
||||
},
|
||||
_ => panic!("don't support multi-value returns yet"),
|
||||
}
|
||||
_ => panic!("don't support multi-value returns yet"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user