]> Repositorios git - scryer-prolog.git/commitdiff
install asserted predicates into modules from initialization directives (#222)
authorMark Thom <[email protected]>
Tue, 29 Oct 2019 06:06:51 +0000 (00:06 -0600)
committerMark Thom <[email protected]>
Tue, 29 Oct 2019 06:06:51 +0000 (00:06 -0600)
src/prolog/machine/compile.rs
src/prolog/machine/mod.rs

index 2881c21caa7addb5662e016ca43fa64afc4f93dc..36105baa9f38ba62f9ef370c567525b0a0443fad 100644 (file)
@@ -277,19 +277,19 @@ pub fn compile_term(wam: &mut Machine, packet: TopLevelPacket) -> EvalSession {
     }
 }
 
-fn update_module_indices(wam: &Machine, module_name: ClauseName, mut indices: IndexStore) {
-    match wam.indices.modules.get(&module_name) {
-        Some(module) => {
+fn update_module_indices(wam: &mut Machine, module_name: ClauseName, mut indices: IndexStore) {
+    match wam.indices.modules.get_mut(&module_name) {
+        Some(ref mut module) => {
             let code_dir = mem::replace(&mut indices.code_dir, CodeDir::new());
 
             // replace the "user" module src's in the indices with module_name.
             for (key, idx) in code_dir.iter() {
                 let p = idx.0.borrow().0;
-
-                match module.code_dir.get(&key) {
-                    Some(idx) => set_code_index!(idx, p, module_name.clone()),
-                    _ => {}
-                }
+                
+                let idx = CodeIndex::dynamic_undefined(module_name.clone());                
+                let idx = module.code_dir.entry(key.clone()).or_insert(idx);
+                
+                set_code_index!(idx, p, module_name.clone());
 
                 match wam.indices.code_dir.get(&key) {
                     Some(idx) => {
@@ -419,6 +419,7 @@ impl ClauseCodeGenerator {
         }
     }
 
+    // compiles the latest version of clause/2.
     fn generate_clause_code(
         &mut self,
         dynamic_clause_map: &DynamicClauseMap,
index dfd43ae257eba8ddc4013c9623f0a921e9c44cad..7a6823a05df317f34badf0f4792c5b62a60fc439 100644 (file)
@@ -184,7 +184,8 @@ impl Machine {
             Ok(p) => {
                 self.machine_st.attr_var_init.verify_attrs_loc = p;
             }
-            Err(_) => panic!("Machine::compile_special_forms() failed at VERIFY_ATTRS"),
+            Err(_) =>
+                panic!("Machine::compile_special_forms() failed at VERIFY_ATTRS"),
         }
 
         match compile_special_form(self, parsing_stream(PROJECT_ATTRS.as_bytes()), project_attrs_src)
@@ -192,7 +193,8 @@ impl Machine {
             Ok(p) => {
                 self.machine_st.attr_var_init.project_attrs_loc = p;
             }
-            Err(e) => panic!("Machine::compile_special_forms() failed at PROJECT_ATTRS: {}", e),
+            Err(e) =>
+                panic!("Machine::compile_special_forms() failed at PROJECT_ATTRS: {}", e),
         }
     }