]> Repositorios git - scryer-prolog.git/commitdiff
tidying up
authorMark Thom <[email protected]>
Sun, 9 Apr 2017 18:23:54 +0000 (12:23 -0600)
committerMark Thom <[email protected]>
Sun, 9 Apr 2017 18:23:54 +0000 (12:23 -0600)
Cargo.lock
src/prolog/codegen.rs

index 133eaf7a9fbb2940dd0776c242fd3ea68a7ca10c..71e9dd19b0f4a5d6f05eeb8361e813622c56fac4 100644 (file)
@@ -1,6 +1,6 @@
 [root]
 name = "rusty-wam"
-version = "0.5.10"
+version = "0.5.11"
 dependencies = [
  "lalrpop 0.12.5 (registry+https://github.com/rust-lang/crates.io-index)",
  "lalrpop-util 0.12.5 (registry+https://github.com/rust-lang/crates.io-index)",
index 16a5d3dddbfb23230eb416b107c586a54241b793..b6d868f9e1c472c563b1b20ab884d7f20433ac27 100644 (file)
@@ -411,6 +411,39 @@ impl CodeOffsets {
         }
     }
 
+
+    fn switch_on_str_offset_from(str_loc: IntIndex, prelude_len: usize, con_loc: IntIndex)
+                                 -> usize
+    {
+        match str_loc {
+            IntIndex::External(o) => o + prelude_len + 1,
+            IntIndex::Fail => 0,
+            IntIndex::Internal(_) => match con_loc {
+                IntIndex::Internal(_) => 2,
+                _ => 1
+            }
+        }
+    }
+
+    fn switch_on_con_offset_from(con_loc: IntIndex, prelude_len: usize) -> usize
+    {
+        match con_loc {
+            IntIndex::External(offset) => offset + prelude_len + 1,
+            IntIndex::Fail => 0,
+            IntIndex::Internal(offset) => offset,
+        }
+    }
+
+    fn switch_on_lst_offset_from(lst_loc: IntIndex, prelude_len: usize, lst_offset: usize)
+                                 -> usize
+    {
+        match lst_loc {
+            IntIndex::External(o) => o + prelude_len + 1,
+            IntIndex::Fail => 0,
+            IntIndex::Internal(_) => prelude_len - lst_offset + 1
+        }        
+    }
+    
     fn add_indices(self, code: &mut Code, mut code_body: Code)
     {
         if self.no_indices() {
@@ -420,11 +453,11 @@ impl CodeOffsets {
 
         let mut prelude = VecDeque::new();
 
-        let lst_step = Self::switch_on_list(self.lists, &mut prelude);
+        let lst_loc = Self::switch_on_list(self.lists, &mut prelude);
         let lst_offset = prelude.len();
 
-        let str_step = Self::switch_on_structure(self.structures, &mut prelude);
-        let con_step = Self::switch_on_constant(self.constants, &mut prelude);
+        let str_loc = Self::switch_on_structure(self.structures, &mut prelude);
+        let con_loc = Self::switch_on_constant(self.constants, &mut prelude);
 
         let prelude_length = prelude.len();
 
@@ -437,30 +470,15 @@ impl CodeOffsets {
                 _ => {}
             }
         }
-
-        let str_step = match str_step {
-            IntIndex::External(o) => o + prelude.len() + 1,
-            IntIndex::Fail => 0,
-            IntIndex::Internal(_) => match con_step {
-                IntIndex::Internal(_) => 2,
-                _ => 1
-            }
-        };
-        let con_step = match con_step {
-            IntIndex::External(offset) => offset + prelude.len() + 1,
-            IntIndex::Fail => 0,
-            IntIndex::Internal(offset) => offset,
-        };
-        let lst_step = match lst_step {
-            IntIndex::External(o) => o + prelude.len() + 1,
-            IntIndex::Fail => 0,
-            IntIndex::Internal(_) => prelude.len() - lst_offset + 1
-        };
-
+                
+        let str_loc = Self::switch_on_str_offset_from(str_loc, prelude.len(), con_loc);
+        let con_loc = Self::switch_on_con_offset_from(con_loc, prelude.len());
+        let lst_loc = Self::switch_on_lst_offset_from(lst_loc, prelude.len(), lst_offset);
+        
         let switch_instr = IndexingInstruction::SwitchOnTerm(prelude.len() + 1,
-                                                             con_step,
-                                                             lst_step,
-                                                             str_step);
+                                                             con_loc,
+                                                             lst_loc,
+                                                             str_loc);
 
         prelude.push_front(Line::from(switch_instr));