Add ScopeTypes to Pass

This commit is contained in:
Sofia 2025-07-15 22:11:38 +03:00
parent b012a46e91
commit e13b6349f0
2 changed files with 15 additions and 1 deletions

View File

@ -330,7 +330,7 @@ pub struct TypeDefinition {
#[derive(Debug)]
pub enum TypeDefinitionKind {
Struct(Vec<(String, Type)>),
Struct(Vec<(String, TypeKind)>),
}
#[derive(Debug)]

View File

@ -109,6 +109,7 @@ impl<T: Clone + std::fmt::Debug> Storage<T> {
pub struct Scope {
pub function_returns: Storage<ScopeFunction>,
pub variables: Storage<ScopeVariable>,
pub types: Storage<ScopeTypedefKind>,
/// Hard Return type of this scope, if inside a function
pub return_type_hint: Option<TypeKind>,
}
@ -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<T: Pass>(&mut self, pass: &mut T, state: &mut State<T::TError>, 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