Add mandatory return type for MIR Function
This commit is contained in:
parent
0932af2e3b
commit
12dc457b99
@ -1,7 +1,7 @@
|
||||
use crate::ast::*;
|
||||
use crate::{
|
||||
lexer::Token,
|
||||
token_stream::{Error, TokenRange, TokenStream},
|
||||
token_stream::{Error, TokenStream},
|
||||
};
|
||||
|
||||
pub trait Parse
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::{
|
||||
ast,
|
||||
ast::{self, TypeKind},
|
||||
mir::{self, StmtKind, VariableReference},
|
||||
};
|
||||
|
||||
@ -176,6 +176,10 @@ impl ast::Module {
|
||||
|
||||
let def = mir::FunctionDefinition {
|
||||
name: signature.name.clone(),
|
||||
return_type: signature
|
||||
.return_type
|
||||
.map(|r| r.0.into())
|
||||
.unwrap_or(mir::TypeKind::Void),
|
||||
parameters: signature
|
||||
.args
|
||||
.iter()
|
||||
|
@ -20,7 +20,6 @@ impl mir::Module {
|
||||
let mut functions = HashMap::new();
|
||||
|
||||
for function in &self.functions {
|
||||
let ret_type = function.return_type().unwrap().get_type();
|
||||
let param_types: Vec<Type> = function
|
||||
.parameters
|
||||
.iter()
|
||||
@ -29,9 +28,9 @@ impl mir::Module {
|
||||
|
||||
let func = match &function.kind {
|
||||
mir::FunctionDefinitionKind::Local(_, _) => {
|
||||
module.function(&function.name, ret_type, param_types)
|
||||
module.function(&function.name, function.return_type.get_type(), param_types)
|
||||
}
|
||||
mir::FunctionDefinitionKind::Extern(_) => todo!(),
|
||||
mir::FunctionDefinitionKind::Extern => todo!(),
|
||||
};
|
||||
functions.insert(function.name.clone(), func);
|
||||
}
|
||||
@ -62,7 +61,7 @@ impl mir::Module {
|
||||
scope.block.terminate(TerminatorKind::Ret(ret)).unwrap();
|
||||
}
|
||||
}
|
||||
mir::FunctionDefinitionKind::Extern(_) => {}
|
||||
mir::FunctionDefinitionKind::Extern => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -114,6 +114,7 @@ pub struct FunctionCall {
|
||||
#[derive(Debug)]
|
||||
pub struct FunctionDefinition {
|
||||
pub name: String,
|
||||
pub return_type: TypeKind,
|
||||
pub parameters: Vec<(String, TypeKind)>,
|
||||
pub kind: FunctionDefinitionKind,
|
||||
}
|
||||
@ -122,8 +123,7 @@ pub struct FunctionDefinition {
|
||||
pub enum FunctionDefinitionKind {
|
||||
/// Actual definition block and surrounding signature range
|
||||
Local(Block, Metadata),
|
||||
/// Return Type
|
||||
Extern(TypeKind),
|
||||
Extern,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -64,11 +64,11 @@ impl ReturnType for FunctionCall {
|
||||
}
|
||||
}
|
||||
|
||||
impl ReturnType for FunctionDefinition {
|
||||
fn return_type(&self) -> Result<TypeKind, ReturnTypeOther> {
|
||||
match &self.kind {
|
||||
FunctionDefinitionKind::Local(block, _) => block.return_type(),
|
||||
FunctionDefinitionKind::Extern(type_kind) => Ok(type_kind.clone()),
|
||||
}
|
||||
}
|
||||
}
|
||||
// impl ReturnType for FunctionDefinition {
|
||||
// fn return_type(&self) -> Result<TypeKind, ReturnTypeOther> {
|
||||
// match &self.kind {
|
||||
// FunctionDefinitionKind::Local(block, _) => block.return_type(),
|
||||
// FunctionDefinitionKind::Extern(type_kind) => Ok(type_kind.clone()),
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
Loading…
Reference in New Issue
Block a user