]> Repositorios git - scryer-prolog.git/commitdiff
remove Term impl
authorMark Thom <[email protected]>
Mon, 31 Oct 2016 02:32:13 +0000 (20:32 -0600)
committerMark Thom <[email protected]>
Mon, 31 Oct 2016 02:32:13 +0000 (20:32 -0600)
src/l0/ast.rs
src/l0/codegen.rs

index fddc3965ec8a5d24b3152790a12c6443b992b7c5..f88af86f18ab00a5a77d06af5d63caf6ed93500a 100644 (file)
@@ -17,24 +17,6 @@ pub enum Term {
     Var(Var)
 }
 
-impl Term {
-    pub fn name(&self) -> &Atom {
-        match self {
-            &Term::Atom(ref atom) => atom,
-            &Term::Var(ref var)   => var,
-            &Term::Clause(ref atom, _) => atom
-        }
-    }
-
-    pub fn is_variable(&self) -> bool {
-        if let &Term::Var(_) = self {
-            return true;
-        }
-
-        return false;
-    }
-}
-
 #[derive(Clone)]
 pub enum MachineInstruction {
     GetStructure(Atom, usize, usize),
index f813c4fc05802711f7e6914f79a5de4b602f0849..c5a643bd9995ece0c68772dedf4a4090f90299f8 100644 (file)
@@ -60,10 +60,12 @@ pub fn compile_query<'a>(t: &'a Term) -> Program
                 let mut counter : usize = max_reg_used; // r + 1;
 
                 for t in terms {
-                    if t.is_variable() && !variable_allocs.contains_key(t.name()) {
-                        counter += 1;
-                        variable_allocs.insert(t.name(), (counter, false));
-                    } else if !t.is_variable() {
+                    if let &Term::Var(ref var) = t.as_ref() {
+                        if !variable_allocs.contains_key(var) {
+                            counter += 1;
+                            variable_allocs.insert(var, (counter, false));
+                        }
+                    } else {
                         counter += 1;
                     }
                 }
@@ -71,7 +73,7 @@ pub fn compile_query<'a>(t: &'a Term) -> Program
                 max_reg_used = counter;
 
                 for t in terms.iter().rev() {
-                    if t.is_variable() {
+                    if let &Term::Var(_) = t.as_ref() {
                         counter -= 1;
                         continue;
                     }
@@ -142,13 +144,15 @@ pub fn compile_fact<'a>(t: &'a Term) -> Program {
                 let mut counter : usize = reg;
 
                 for t in terms {
-                    if t.is_variable() && !variable_allocs.contains_key(t.name()) {
-                        variable_allocs.insert(t.name(), counter);
-                        fact.push(MachineInstruction::UnifyVariable(counter));
-                        counter += 1;
-                    } else if t.is_variable() {
-                        let r = variable_allocs.get(t.name()).unwrap();
-                        fact.push(MachineInstruction::UnifyValue(*r));
+                    if let &Term::Var(ref var) = t.as_ref() {
+                        if !variable_allocs.contains_key(var) {
+                            variable_allocs.insert(var, counter);
+                            fact.push(MachineInstruction::UnifyVariable(counter));
+                            counter += 1;
+                        } else {
+                            let r = variable_allocs.get(var).unwrap();
+                            fact.push(MachineInstruction::UnifyValue(*r));
+                        }
                     } else {
                         fact.push(MachineInstruction::UnifyVariable(counter));
                         queue.push_back((counter, t));