]> Repositorios git - scryer-prolog.git/commitdiff
count single character atoms as characters when generating first argument indices
authorMark Thom <[email protected]>
Sat, 7 Mar 2020 04:19:53 +0000 (21:19 -0700)
committerMark Thom <[email protected]>
Sat, 7 Mar 2020 04:19:53 +0000 (21:19 -0700)
src/prolog/indexing.rs
src/prolog/machine/machine_state_impl.rs

index 032087338553bf23688faa75b0b44c53f3e4c9ab..fe694d19ea1ca3b0fde98c8c9a25e4df3f27b3d8 100644 (file)
@@ -74,6 +74,15 @@ impl CodeOffsets {
                 code.push(Self::add_index(is_initial_index, index));
             }
             &Term::Constant(_, ref constant) => {
+                if let Constant::Atom(ref name, _) = constant {
+                    if !name.as_str().is_empty() && name.as_str().chars().skip(1).next().is_none() {
+                        let c = name.as_str().chars().next().unwrap();
+                        let code = self.constants.entry(Constant::Char(c)).or_insert(vec![]);
+                        
+                        code.push(Self::add_index(code.is_empty(), index));
+                    }
+                }
+                
                 let code = self.constants.entry(constant.clone()).or_insert(Vec::new());
 
                 let is_initial_index = code.is_empty();
index 10468a368967c8b5b3cb651500ea6962631f9b7c..fec480458e39ec21ba67e1083907c5419d6b8229 100644 (file)
@@ -1806,7 +1806,7 @@ impl MachineState {
                 let a1 = self.registers[1].clone();
                 let addr = self.store(self.deref(a1));
 
-                let offset = match addr {
+                let offset = match addr {                    
                     Addr::Con(constant) => match hm.get(&constant) {
                         Some(offset) => *offset,
                         _ => 0,