switch callable to interning too

main
NotAFile 2022-02-16 17:38:56 +01:00
parent 853021e4f8
commit 3f08a838d2
2 changed files with 9 additions and 4 deletions

View File

@ -4,7 +4,7 @@ use std::fmt::Write;
use super::parser; use super::parser;
use crate::rtlil; use crate::rtlil;
pub use callable::Callable; pub use callable::{Callable, CallableId};
pub use types::{Type, TypeStruct, TypingContext}; pub use types::{Type, TypeStruct, TypingContext};
mod callable; mod callable;
@ -64,7 +64,8 @@ impl Signal {
pub struct Context { pub struct Context {
/// map callable name to callable /// map callable name to callable
callables: BTreeMap<String, Callable>, callable_names: BTreeMap<String, CallableId>,
callables: BTreeMap<CallableId, Callable>,
/// type names /// type names
typenames: BTreeMap<String, Type>, typenames: BTreeMap<String, Type>,
types: TypingContext, types: TypingContext,
@ -92,6 +93,7 @@ impl Context {
let tcx = TypingContext::new(); let tcx = TypingContext::new();
Context { Context {
callables: BTreeMap::new(), callables: BTreeMap::new(),
callable_names: BTreeMap::new(),
signals: BTreeMap::new(), signals: BTreeMap::new(),
types: TypingContext::new(), types: TypingContext::new(),
typenames: [ typenames: [
@ -115,8 +117,8 @@ impl Context {
}) })
} }
fn try_get_callable(&self, callname: &str) -> Result<&Callable, CompileError> { fn try_get_callable(&self, callname: &str) -> Result<CallableId, CompileError> {
self.callables.get(callname).ok_or_else(|| { self.callable_names.get(callname).copied().ok_or_else(|| {
CompileError::new(CompileErrorKind::UndefinedReference(callname.to_owned())) CompileError::new(CompileErrorKind::UndefinedReference(callname.to_owned()))
}) })
} }

View File

@ -1,5 +1,8 @@
use super::types::Type; use super::types::Type;
#[derive(Copy, Clone, PartialEq)]
pub struct CallableId(u32);
pub struct Callable { pub struct Callable {
pub name: String, pub name: String,
pub args: Vec<(Option<String>, Type)>, pub args: Vec<(Option<String>, Type)>,