getting closer

This commit is contained in:
2025-05-04 14:21:27 -04:00
parent 6583d47ef8
commit 9368d6dcd0
16 changed files with 423 additions and 327 deletions
+13 -69
View File
@@ -1,4 +1,4 @@
use super::{Type, UInstrInst, UInstruction};
use super::{FnInst, ResErr, StructInst, Type, UInstrInst, UInstruction};
use crate::{
common::FileSpan,
ir::{Len, ID},
@@ -7,57 +7,9 @@ use std::{collections::HashMap, fmt::Debug};
pub type NamePath = Vec<String>;
// "effective" (externally visible) kinds
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum KindTy {
Type,
Var,
Struct,
Fn,
}
impl KindTy {
pub fn str(&self) -> &'static str {
match self {
KindTy::Type => "type",
KindTy::Var => "variable",
KindTy::Fn => "function",
KindTy::Struct => "struct",
}
}
}
pub trait Kind {
fn ty() -> KindTy;
}
impl Kind for UFunc {
fn ty() -> KindTy {
KindTy::Fn
}
}
impl Kind for UVar {
fn ty() -> KindTy {
KindTy::Var
}
}
impl Kind for UStruct {
fn ty() -> KindTy {
KindTy::Struct
}
}
impl Kind for Type {
fn ty() -> KindTy {
KindTy::Type
}
}
pub type FnID = ID<UFunc>;
pub type VarID = ID<UVar>;
pub type VarInstID = ID<VarInst>;
pub type IdentID = ID<UIdent>;
pub type TypeID = ID<Type>;
pub type GenericID = ID<UGeneric>;
pub type StructID = ID<UStruct>;
@@ -99,31 +51,33 @@ pub struct UVar {
pub origin: Origin,
pub ty: TypeID,
pub parent: Option<VarID>,
pub children: Vec<VarID>,
pub children: HashMap<String, VarID>,
}
/// these are more like "expressions", need to find good name
/// eg. a::b::c::<T,U>.d.e
#[derive(Clone, Debug)]
pub struct VarInst {
pub status: VarStatus,
pub struct UIdent {
pub status: IdentStatus,
pub origin: Origin,
}
#[derive(Clone, Debug)]
pub enum VarStatus {
pub enum IdentStatus {
Var(VarID),
Struct(StructID, Vec<TypeID>),
Struct(StructInst),
Fn(FnInst),
Type(TypeID),
Unres {
path: ModPath,
name: String,
mem: MemberID,
gargs: Vec<TypeID>,
fields: Vec<MemberID>,
},
Partial {
v: VarID,
PartialVar {
id: VarID,
fields: Vec<MemberID>,
},
Failed(ResErr),
Cooked,
}
@@ -209,13 +163,3 @@ impl<'a> Iterator for InstrIter<'a> {
}
}
impl VarInst {
pub fn id(&self) -> Option<VarID> {
match &self.status {
VarStatus::Var(id) => Some(*id),
VarStatus::Unres { .. } => None,
VarStatus::Partial { .. } => None,
VarStatus::Cooked => None,
}
}
}