From 5d563527fd1992a8168675716c6547b03503006d Mon Sep 17 00:00:00 2001 From: SimonFJ20 Date: Wed, 28 Aug 2024 21:49:04 +0200 Subject: [PATCH] delete unused --- src/sym.rs | 125 ---------------------------------------------------- src/util.rs | 36 --------------- 2 files changed, 161 deletions(-) delete mode 100644 src/sym.rs delete mode 100644 src/util.rs diff --git a/src/sym.rs b/src/sym.rs deleted file mode 100644 index 9ae9168..0000000 --- a/src/sym.rs +++ /dev/null @@ -1,125 +0,0 @@ -#![allow(unused_variables)] -use std::collections::HashMap; - -use rand::random; - -use crate::checked::Type; - -#[derive(Clone, PartialEq, Debug)] -pub struct Sym { - pub id: u64, - pub uid: u64, - pub typ: Type, -} - -#[derive(Debug)] -pub struct Syms { - tables: Vec, - current_id: usize, -} - -impl Syms { - pub fn new() -> Self { - Self { - tables: vec![SymTable::new()], - current_id: 0, - } - } - - pub fn enter_scope(&mut self) { - let new_id = self.tables.len(); - self.tables.push(SymTable::from(self.current_id)); - self.current_id = new_id; - } - - pub fn leave_scope(&mut self) -> Result<(), ()> { - let parent = self.tables[self.current_id].parent.ok_or(())?; - self.current_id = parent; - Ok(()) - } - - pub fn get(&self, id: u64) -> Option<&Sym> { - self.get_rec(self.current_id, id) - } - - fn get_rec(&self, table_id: usize, id: u64) -> Option<&Sym> { - if let Some(sym) = self.tables[table_id].get(id) { - return Some(sym); - } - if let Some(parent_id) = self.tables[table_id].parent { - return self.get_rec(parent_id, id); - }; - None - } - - pub fn defined_locally(&self, id: u64) -> bool { - self.tables[self.current_id].defined(id) - } - - pub fn define(&mut self, id: u64, typ: Type) { - self.tables[self.current_id].define(id, typ); - } - - pub fn table_id(&self) -> usize { - self.current_id - } - - pub fn view(&self, table_id: usize) -> SymView { - SymView { - syms: self, - current_id: table_id, - } - } -} - -pub struct SymView<'a> { - syms: &'a Syms, - current_id: usize, -} - -impl<'a> SymView<'a> { - pub fn get(&self, id: u64) -> Option<&Sym> { - self.syms.get_rec(self.current_id, id) - } -} - -#[derive(Debug)] -struct SymTable { - map: HashMap, - parent: Option, -} - -impl SymTable { - pub fn new() -> Self { - Self { - map: HashMap::new(), - parent: None, - } - } - - pub fn from(parent: usize) -> Self { - Self { - map: HashMap::new(), - parent: Some(parent), - } - } - - pub fn defined(&self, id: u64) -> bool { - self.map.contains_key(&id) - } - - pub fn get(&self, id: u64) -> Option<&Sym> { - self.map.get(&id) - } - - pub fn define(&mut self, id: u64, typ: Type) { - self.map.insert( - id, - Sym { - id, - uid: random(), - typ, - }, - ); - } -} diff --git a/src/util.rs b/src/util.rs deleted file mode 100644 index 7bcec60..0000000 --- a/src/util.rs +++ /dev/null @@ -1,36 +0,0 @@ -use std::hash::{DefaultHasher, Hash, Hasher}; - -pub fn hash(value: H) -> u64 { - let mut hasher = DefaultHasher::new(); - value.hash(&mut hasher); - hasher.finish() -} -enum Duplicate { - None(std::collections::HashMap), - Found(T), -} - -pub trait Itertewls -where - Self: Iterator + Sized, -{ - fn find_first_duplicate(self) -> Option; -} - -impl Itertewls for I -where - I: Iterator + Sized, - Item: std::cmp::PartialEq + Clone, -{ - fn find_first_duplicate(mut self) -> Option { - self.try_fold(Vec::new(), |mut used, item| { - if used.contains(&item) { - Err(item) - } else { - used.push(item); - Ok(used) - } - }) - .err() - } -}