mirror of
https://forge.katzen.cafe/katzen-cafe/iowo.git
synced 2024-11-05 15:26:24 +01:00
refactor to common id types
This commit is contained in:
parent
c3db966765
commit
1acb5ef3cf
|
@ -30,12 +30,14 @@ impl EvalConfig {
|
|||
}
|
||||
}
|
||||
|
||||
pub type FileId = usize;
|
||||
|
||||
// this is also bad
|
||||
// need a better architecture for this
|
||||
pub struct Evaluator<'a> {
|
||||
curr_phase: EvalPhase,
|
||||
files: SimpleFiles<&'a str, String>,
|
||||
errors: HashMap<usize, Vec<Errors>>,
|
||||
errors: HashMap<FileId, Vec<Errors>>,
|
||||
cfg: EvalConfig,
|
||||
}
|
||||
|
||||
|
@ -75,7 +77,7 @@ impl<'a> Evaluator<'a> {
|
|||
pub fn next(mut self) {
|
||||
match self.curr_phase {
|
||||
EvalPhase::Lex => {
|
||||
todo!()
|
||||
unreachable!()
|
||||
}
|
||||
EvalPhase::Check(file_id, syntax) => {
|
||||
let r = check(&syntax);
|
||||
|
@ -129,7 +131,7 @@ impl<'a> Evaluator<'a> {
|
|||
|
||||
enum EvalPhase {
|
||||
Lex,
|
||||
Check(usize, Vec<PipelineElement>),
|
||||
BareTyped(usize, Vec<PipelineElement>),
|
||||
Check(FileId, Vec<PipelineElement>),
|
||||
BareTyped(FileId, Vec<PipelineElement>),
|
||||
Failed,
|
||||
}
|
||||
|
|
|
@ -2,12 +2,13 @@ use std::fmt::Debug;
|
|||
use std::fmt::Display;
|
||||
|
||||
use super::typedef::{InternalTypeDef, TypeDef};
|
||||
use super::CommandId;
|
||||
|
||||
use super::GlobalNamespace;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct Command<'a> {
|
||||
pub(super) id: usize,
|
||||
pub(super) id: CommandId,
|
||||
pub(super) namespace: &'a GlobalNamespace,
|
||||
}
|
||||
|
||||
|
@ -67,4 +68,5 @@ pub(super) struct InternalCommand {
|
|||
// gosh this is hacky
|
||||
pub(super) input: Option<InternalTypeDef>,
|
||||
pub(super) output: Option<InternalTypeDef>,
|
||||
// generic_ns: HashMap<String, Vec<usize>>,
|
||||
}
|
||||
|
|
|
@ -23,15 +23,17 @@ pub struct GlobalNamespace {
|
|||
data_namespace: RefCell<HashMap<String, DataNamespaceId>>,
|
||||
}
|
||||
|
||||
pub type TypeId = usize;
|
||||
pub type TraitId = usize;
|
||||
pub type CommandId = usize;
|
||||
|
||||
enum TypeNamespaceId {
|
||||
Types(usize),
|
||||
Traits(usize),
|
||||
Types(TypeId),
|
||||
Traits(TraitId),
|
||||
}
|
||||
|
||||
enum DataNamespaceId {
|
||||
Commands(usize),
|
||||
#[allow(dead_code, reason = "will be used later")]
|
||||
Globals(usize),
|
||||
Commands(CommandId),
|
||||
}
|
||||
|
||||
impl GlobalNamespace {
|
||||
|
@ -126,21 +128,21 @@ impl GlobalNamespace {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_type(&self, id: usize) -> Option<Type> {
|
||||
pub fn get_type(&self, id: TypeId) -> Option<Type> {
|
||||
(self.types.borrow().len() > id).then_some(Type {
|
||||
id,
|
||||
namespace: self,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn get_trait(&self, id: usize) -> Option<Trait> {
|
||||
pub fn get_trait(&self, id: TraitId) -> Option<Trait> {
|
||||
(self.traits.borrow().len() > id).then_some(Trait {
|
||||
id,
|
||||
namespace: self,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn get_command(&self, id: usize) -> Option<Command> {
|
||||
pub fn get_command(&self, id: CommandId) -> Option<Command> {
|
||||
(self.commands.borrow().len() > id).then_some(Command {
|
||||
id,
|
||||
namespace: self,
|
||||
|
|
|
@ -5,10 +5,12 @@ use std::fmt::Debug;
|
|||
use std::fmt::Display;
|
||||
|
||||
use super::GlobalNamespace;
|
||||
use super::TraitId;
|
||||
use super::TypeId;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct Trait<'a> {
|
||||
pub(super) id: usize,
|
||||
pub(super) id: TraitId,
|
||||
pub(super) namespace: &'a GlobalNamespace,
|
||||
}
|
||||
|
||||
|
@ -28,6 +30,6 @@ impl Debug for Trait<'_> {
|
|||
|
||||
pub(super) struct InternalTrait {
|
||||
// make resolution easier
|
||||
pub(super) types: RefCell<HashSet<usize>>,
|
||||
pub(super) types: RefCell<HashSet<TypeId>>,
|
||||
pub(super) name: String,
|
||||
}
|
||||
|
|
|
@ -7,10 +7,12 @@ use std::fmt::Display;
|
|||
use super::Trait;
|
||||
|
||||
use super::GlobalNamespace;
|
||||
use super::TraitId;
|
||||
use super::TypeId;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct Type<'a> {
|
||||
pub(super) id: usize,
|
||||
pub(super) id: TypeId,
|
||||
pub(super) namespace: &'a GlobalNamespace,
|
||||
}
|
||||
|
||||
|
@ -48,6 +50,6 @@ impl Debug for Type<'_> {
|
|||
}
|
||||
|
||||
pub(super) struct InternalType {
|
||||
pub(super) traits: RefCell<HashSet<usize>>,
|
||||
pub(super) traits: RefCell<HashSet<TraitId>>,
|
||||
pub(super) name: String,
|
||||
}
|
||||
|
|
10
src/typed.rs
10
src/typed.rs
|
@ -1,15 +1,9 @@
|
|||
use core::panic;
|
||||
use std::process::CommandEnvs;
|
||||
|
||||
use crate::{
|
||||
builtins::{TYPE_FLOAT, TYPE_INTEGER, TYPE_STRING},
|
||||
error::Errors,
|
||||
namespace::{
|
||||
command::{self, Command},
|
||||
r#type::Type,
|
||||
typedef::TypeDef,
|
||||
GlobalNamespace,
|
||||
},
|
||||
namespace::{command::Command, r#type::Type, typedef::TypeDef, GlobalNamespace},
|
||||
syntax::{CommandPart, CommandPartKind, PipelineElement, PipelineElementKind},
|
||||
Span,
|
||||
};
|
||||
|
@ -51,7 +45,7 @@ impl<'a> ExprKind<'a> {
|
|||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct CommandExpr<'a> {
|
||||
pub struct CommandExpr<'a> {
|
||||
command: Command<'a>,
|
||||
args: Vec<Expr<'a>>,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue