Skip to content

Commit

Permalink
zesterer pointed a sword at me and demanded i make one bucket per ite…
Browse files Browse the repository at this point in the history
…m type
  • Loading branch information
Lokathor committed Dec 3, 2024
1 parent 9942e1c commit 59d9779
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/ast/data/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ use super::*;

#[derive(Debug, Clone)]
pub enum Item {
Function(FileSpanned<Function>),
Const(FileSpanned<Const>),
Function(FileSpanned<Function>),
Static(FileSpanned<Static>),
ItemError,
}
impl Item {
pub fn get_name(&self) -> Option<StrID> {
match self {
Item::Function(fs_function) => Some(fs_function.name._payload),
Item::Const(fs_const) => Some(fs_const.name._payload),
Item::Function(fs_function) => Some(fs_function.name._payload),
Item::Static(fs_static) => Some(fs_static.name._payload),
Item::ItemError => None,
}
Expand Down
13 changes: 11 additions & 2 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ pub mod parsing;

#[derive(Debug, Clone, Default)]
pub struct Ast {
pub items: BTreeMap<StrID, FileSpanned<Item>>,
pub consts: BTreeMap<StrID, FileSpanned<Const>>,
pub functions: BTreeMap<StrID, FileSpanned<Function>>,
pub statics: BTreeMap<StrID, FileSpanned<Static>>,
}
impl Ast {
pub fn from_items(
items: Vec<FileSpanned<Item>>, err_bucket: &mut Vec<YagError>,
) -> Self {
// Note(Lokathor): Currently all items are in a single namespace, so here we
// verify that we don't define the same identifier more than once.
let mut everything_map: BTreeMap<StrID, Vec<FileSpanned<Item>>> =
BTreeMap::new();
for item in items {
Expand All @@ -27,7 +31,12 @@ impl Ast {
} else {
let definition = definitions.pop().unwrap();
let name = definition.get_name().unwrap();
assert!(out.items.insert(name, definition).is_none());
match definition._payload {
Item::Function(f) => assert!(out.functions.insert(name, f).is_none()),
Item::Const(c) => assert!(out.consts.insert(name, c).is_none()),
Item::Static(s) => assert!(out.statics.insert(name, s).is_none()),
Item::ItemError => unimplemented!(),
};
}
}
out
Expand Down

0 comments on commit 59d9779

Please sign in to comment.