From 5f7abda22d92181f669cae2b0ebe2d26bb4c6ed6 Mon Sep 17 00:00:00 2001 From: Mark Thom Date: Tue, 16 Mar 2021 13:47:30 -0600 Subject: [PATCH] remove operators declared at user-level from files when reloading --- src/forms.rs | 13 +++++ src/machine/load_state.rs | 19 +++++++ src/machine/loader.rs | 19 +++++-- src/machine/machine_indices.rs | 90 ++++++++++++++-------------------- 4 files changed, 85 insertions(+), 56 deletions(-) diff --git a/src/forms.rs b/src/forms.rs index 3d07ec8a..1f0affc7 100644 --- a/src/forms.rs +++ b/src/forms.rs @@ -453,6 +453,19 @@ impl Module { listing_src, } } + + pub(crate) fn new_in_situ(module_decl: ModuleDecl) -> Self { + Module { + module_decl, + code_dir: CodeDir::new(), + op_dir: OpDir::new(), + meta_predicates: MetaPredicateDir::new(), + is_impromptu_module: false, + extensible_predicates: ExtensiblePredicates::new(), + local_extensible_predicates: LocalExtensiblePredicates::new(), + listing_src: ListingSource::DynamicallyGenerated, + } + } } #[derive(Debug, Clone)] diff --git a/src/machine/load_state.rs b/src/machine/load_state.rs index c51328ff..d0754936 100644 --- a/src/machine/load_state.rs +++ b/src/machine/load_state.rs @@ -718,6 +718,16 @@ impl<'a> LoadState<'a> { pub(super) fn add_op_decl(&mut self, op_decl: &OpDecl) { match &self.compilation_target { CompilationTarget::User => { + if let Some(filename) = self.listing_src_file_name() { + match self.wam.indices.modules.get_mut(&filename) { + Some(ref mut module) => { + op_decl.insert_into_op_dir(&mut module.op_dir); + } + None => { + } + } + } + add_op_decl( &mut self.retraction_info, &self.compilation_target, @@ -949,6 +959,15 @@ impl<'a> LoadState<'a> { } if &self.compilation_target == compilation_target { + if let CompilationTarget::User = &self.compilation_target { + match (key.0.as_str(), key.1) { + ("term_expansion", 2) | ("goal_expansion", 2) => { + continue; + } + _ => {} + } + } + let skeleton_opt = self.wam.indices.remove_predicate_skeleton( compilation_target, &key, diff --git a/src/machine/loader.rs b/src/machine/loader.rs index 7c1c76ad..8d31b47a 100644 --- a/src/machine/loader.rs +++ b/src/machine/loader.rs @@ -1474,16 +1474,29 @@ impl Machine { exports: vec![], }; - if !loader.load_state.wam.indices.modules.contains_key(&module_decl.name) { - let module_name = module_decl.name.clone(); - let module = Module::new(module_decl, ListingSource::DynamicallyGenerated); + let module_name = module_decl.name.clone(); + if !loader.load_state.wam.indices.modules.contains_key(&module_decl.name) { + let module = Module::new_in_situ(module_decl); loader.load_state.wam.indices.modules.insert(module_name, module); } else { loader.load_state.reset_in_situ_module( module_decl.clone(), &ListingSource::DynamicallyGenerated, ); + + match loader.load_state.wam.indices.modules.get_mut(&module_name) { + Some(module) => { + for (key, value) in module.op_dir.drain(0 ..) { + let (prec, spec) = value.shared_op_desc().get(); + let mut op_decl = OpDecl::new(prec, spec, key.0); + + op_decl.remove(&mut loader.load_state.wam.indices.op_dir); + } + } + None => { + } + } } } diff --git a/src/machine/machine_indices.rs b/src/machine/machine_indices.rs index 90593d8f..f01cbeee 100644 --- a/src/machine/machine_indices.rs +++ b/src/machine/machine_indices.rs @@ -702,7 +702,7 @@ impl IndexStore { key: &PredicateKey, ) -> Option<&mut PredicateSkeleton> { match (key.0.as_str(), key.1) { - ("term_expansion", 2) => self.extensible_predicates.get_mut(key), +// ("term_expansion", 2) => self.extensible_predicates.get_mut(key), _ => match compilation_target { CompilationTarget::User => self.extensible_predicates.get_mut(key), CompilationTarget::Module(ref module_name) => { @@ -722,24 +722,19 @@ impl IndexStore { local_compilation_target: CompilationTarget, key: PredicateKey, ) -> Option<&mut PredicateSkeleton> { - match (key.0.as_str(), key.1) { - ("term_expansion", 2) => self + match src_compilation_target { + CompilationTarget::User => self .local_extensible_predicates .get_mut(&(local_compilation_target, key)), - _ => match src_compilation_target { - CompilationTarget::User => self - .local_extensible_predicates - .get_mut(&(local_compilation_target, key)), - CompilationTarget::Module(ref module_name) => { - if let Some(module) = self.modules.get_mut(module_name) { - module - .local_extensible_predicates - .get_mut(&(local_compilation_target, key)) - } else { - None - } + CompilationTarget::Module(ref module_name) => { + if let Some(module) = self.modules.get_mut(module_name) { + module + .local_extensible_predicates + .get_mut(&(local_compilation_target, key)) + } else { + None } - }, + } } } @@ -749,24 +744,19 @@ impl IndexStore { local_compilation_target: CompilationTarget, key: PredicateKey, ) -> Option<&PredicateSkeleton> { - match (key.0.as_str(), key.1) { - ("term_expansion", 2) => self + match src_compilation_target { + CompilationTarget::User => self .local_extensible_predicates .get(&(local_compilation_target, key)), - _ => match src_compilation_target { - CompilationTarget::User => self - .local_extensible_predicates - .get(&(local_compilation_target, key)), - CompilationTarget::Module(ref module_name) => { - if let Some(module) = self.modules.get(module_name) { - module - .local_extensible_predicates - .get(&(local_compilation_target, key)) - } else { - None - } + CompilationTarget::Module(ref module_name) => { + if let Some(module) = self.modules.get(module_name) { + module + .local_extensible_predicates + .get(&(local_compilation_target, key)) + } else { + None } - }, + } } } @@ -775,18 +765,15 @@ impl IndexStore { compilation_target: &CompilationTarget, key: &PredicateKey, ) -> Option<&PredicateSkeleton> { - match (key.0.as_str(), key.1) { - ("term_expansion", 2) => self.extensible_predicates.get(key), - _ => match compilation_target { - CompilationTarget::User => self.extensible_predicates.get(key), - CompilationTarget::Module(ref module_name) => { - if let Some(module) = self.modules.get(module_name) { - module.extensible_predicates.get(key) - } else { - None - } + match compilation_target { + CompilationTarget::User => self.extensible_predicates.get(key), + CompilationTarget::Module(ref module_name) => { + if let Some(module) = self.modules.get(module_name) { + module.extensible_predicates.get(key) + } else { + None } - }, + } } } @@ -795,18 +782,15 @@ impl IndexStore { compilation_target: &CompilationTarget, key: &PredicateKey, ) -> Option { - match (key.0.as_str(), key.1) { - ("term_expansion", 2) => self.extensible_predicates.remove(key), - _ => match compilation_target { - CompilationTarget::User => self.extensible_predicates.remove(key), - CompilationTarget::Module(ref module_name) => { - if let Some(module) = self.modules.get_mut(module_name) { - module.extensible_predicates.remove(key) - } else { - None - } + match compilation_target { + CompilationTarget::User => self.extensible_predicates.remove(key), + CompilationTarget::Module(ref module_name) => { + if let Some(module) = self.modules.get_mut(module_name) { + module.extensible_predicates.remove(key) + } else { + None } - }, + } } } -- 2.54.0