Add some support for custom struct types in lib

This commit is contained in:
Sofia 2025-07-15 20:28:59 +03:00
parent 1acaa29a12
commit 0ec427252f
4 changed files with 28 additions and 1 deletions

View File

@ -38,6 +38,7 @@ Currently missing relevant features (TODOs) are:
- ~~Extern functions~~ (DONE)
- ~~Strings~~ (DONE)
- Loops
- Debug Information
### Why "Reid"

View File

@ -5,12 +5,15 @@ use std::{cell::RefCell, rc::Rc};
use crate::{
BlockData, ConstValue, FunctionData, Instr, InstructionData, ModuleData, TerminatorKind, Type,
util::match_types,
TypeData, util::match_types,
};
#[derive(Clone, Hash, Copy, PartialEq, Eq)]
pub struct ModuleValue(pub(crate) usize);
#[derive(Clone, Hash, Copy, PartialEq, Eq)]
pub struct TypeValue(pub(crate) ModuleValue, pub(crate) usize);
#[derive(Clone, Hash, Copy, PartialEq, Eq)]
pub struct FunctionValue(pub(crate) ModuleValue, pub(crate) usize);
@ -25,6 +28,13 @@ pub struct ModuleHolder {
pub(crate) value: ModuleValue,
pub(crate) data: ModuleData,
pub(crate) functions: Vec<FunctionHolder>,
pub(crate) types: Vec<TypeHolder>,
}
#[derive(Clone)]
pub struct TypeHolder {
pub(crate) value: TypeValue,
pub(crate) data: TypeData,
}
#[derive(Clone)]
@ -65,6 +75,7 @@ impl Builder {
value,
data,
functions: Vec::new(),
types: Vec::new(),
});
value
}

View File

@ -196,6 +196,10 @@ impl ModuleHolder {
context.context_ref,
);
for _ty in &self.types {
todo!("Do something with types!");
}
// Compile the contents
let mut functions = HashMap::new();

View File

@ -263,3 +263,14 @@ pub enum TerminatorKind {
Br(BlockValue),
CondBr(InstructionValue, BlockValue, BlockValue),
}
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
pub struct TypeData {
name: String,
kind: CustomTypeKind,
}
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
pub enum CustomTypeKind {
Struct(Vec<Type>),
}