diff --git a/reid/src/mir/mod.rs b/reid/src/mir/mod.rs index 61666eb..37d1f75 100644 --- a/reid/src/mir/mod.rs +++ b/reid/src/mir/mod.rs @@ -330,7 +330,7 @@ pub struct TypeDefinition { #[derive(Debug)] pub enum TypeDefinitionKind { - Struct(Vec<(String, Type)>), + Struct(Vec<(String, TypeKind)>), } #[derive(Debug)] diff --git a/reid/src/mir/pass.rs b/reid/src/mir/pass.rs index b0a1cf1..d78fde5 100644 --- a/reid/src/mir/pass.rs +++ b/reid/src/mir/pass.rs @@ -109,6 +109,7 @@ impl Storage { pub struct Scope { pub function_returns: Storage, pub variables: Storage, + pub types: Storage, /// Hard Return type of this scope, if inside a function pub return_type_hint: Option, } @@ -125,11 +126,17 @@ pub struct ScopeVariable { pub mutable: bool, } +#[derive(Clone, Debug)] +pub enum ScopeTypedefKind { + Struct(Vec<(String, TypeKind)>), +} + impl Scope { pub fn inner(&self) -> Scope { Scope { function_returns: self.function_returns.clone(), variables: self.variables.clone(), + types: self.types.clone(), return_type_hint: self.return_type_hint.clone(), } } @@ -218,6 +225,13 @@ impl Context { impl Module { fn pass(&mut self, pass: &mut T, state: &mut State, scope: &mut Scope) { + for typedef in &self.typedefs { + let kind = match &typedef.kind { + TypeDefinitionKind::Struct(fields) => ScopeTypedefKind::Struct(fields.clone()), + }; + scope.types.set(typedef.name.clone(), kind).ok(); + } + for function in &self.functions { scope .function_returns