mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-31 09:07:21 +00:00
Qualified lookups return params
This commit is contained in:
parent
96e2d32fa6
commit
9d26adb228
6 changed files with 112 additions and 42 deletions
|
@ -622,6 +622,22 @@ impl ModuleIds {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct LookedupSymbol {
|
||||
pub symbol: Symbol,
|
||||
pub params: Option<Symbol>,
|
||||
}
|
||||
|
||||
impl LookedupSymbol {
|
||||
pub fn new(symbol: Symbol, params: Option<Symbol>) -> Self {
|
||||
Self { symbol, params }
|
||||
}
|
||||
|
||||
pub fn no_params(symbol: Symbol) -> Self {
|
||||
Self::new(symbol, None)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ScopeModules {
|
||||
modules: VecMap<ModuleName, ModuleId>,
|
||||
|
@ -629,6 +645,22 @@ pub struct ScopeModules {
|
|||
params: Vec<Option<Symbol>>,
|
||||
}
|
||||
|
||||
pub struct LookedupModule {
|
||||
pub id: ModuleId,
|
||||
pub params: Option<Symbol>,
|
||||
}
|
||||
|
||||
impl LookedupModule {
|
||||
pub fn into_symbol(&self, symbol: Symbol) -> LookedupSymbol {
|
||||
debug_assert_eq!(symbol.module_id(), self.id);
|
||||
|
||||
LookedupSymbol {
|
||||
symbol,
|
||||
params: self.params,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum ScopeModuleSource {
|
||||
Builtin,
|
||||
|
@ -637,12 +669,22 @@ pub enum ScopeModuleSource {
|
|||
}
|
||||
|
||||
impl ScopeModules {
|
||||
pub fn get_id(&self, module_name: &ModuleName) -> Option<ModuleId> {
|
||||
self.modules.get(module_name).copied()
|
||||
pub fn lookup(&self, module_name: &ModuleName) -> Option<LookedupModule> {
|
||||
self.modules
|
||||
.get_with_index(module_name)
|
||||
.map(|(index, module_id)| LookedupModule {
|
||||
id: *module_id,
|
||||
params: self.params.get(index).copied().unwrap(),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn has_id(&self, module_id: ModuleId) -> bool {
|
||||
self.sources.contains_key(&module_id)
|
||||
pub fn lookup_by_id(&self, module_id: &ModuleId) -> Option<LookedupModule> {
|
||||
self.modules
|
||||
.get_index_by_value(module_id)
|
||||
.map(|index| LookedupModule {
|
||||
id: *module_id,
|
||||
params: self.params.get(index).copied().unwrap(),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn available_names(&self) -> impl Iterator<Item = &ModuleName> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue