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

View File

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