]> Repositorios git - scryer-prolog.git/commitdiff
use existing bindings in compile_is (#1545)
authorMark Thom <[email protected]>
Mon, 14 Nov 2022 05:58:00 +0000 (22:58 -0700)
committerMark Thom <[email protected]>
Tue, 15 Nov 2022 03:58:07 +0000 (20:58 -0700)
src/arithmetic.rs
src/codegen.rs

index 172af5bb19ac9e158df7da167e8fb72efaafdd24..0cbb1eabdaf6a0c7757f6d0f1d73bb8ed72be2ad 100644 (file)
@@ -67,19 +67,6 @@ impl<'a> ArithInstructionIterator<'a> {
             Term::Clause(cell, name, terms) => {
                 TermIterState::Clause(Level::Shallow, 0, cell, *name, terms)
             }
-            /* match ClauseType::from(*name, terms.len()) {
-                ct @ ClauseType::Named(..) => {
-                    Ok(TermIterState::Clause(Level::Shallow, 0, cell, ct, terms))
-                }
-                ct @ ClauseType::Inlined(InlinedClauseType::IsFloat(_)) => {
-                    // let ct = ClauseType::Named(1, atom!("float"), CodeIndex::default());
-                    Ok(TermIterState::Clause(Level::Shallow, 0, cell, ct, terms))
-                }
-                _ => Err(ArithmeticError::NonEvaluableFunctor(
-                    Literal::Atom(*name),
-                    terms.len(),
-                )),
-            }?,*/
             Term::Literal(cell, cons) => TermIterState::Literal(Level::Shallow, cell, cons),
             Term::Cons(..) | Term::PartialString(..) | Term::CompleteString(..) => {
                 return Err(ArithmeticError::NonEvaluableFunctor(
@@ -320,8 +307,7 @@ impl<'a> ArithmeticEvaluator<'a> {
         src: &'a Term,
         term_loc: GenContext,
         arg: usize,
-    ) -> Result<ArithCont, ArithmeticError>
-    {
+    ) -> Result<ArithCont, ArithmeticError> {
         let mut code = vec![];
         let mut iter = src.iter()?;
 
@@ -338,15 +324,19 @@ impl<'a> ArithmeticEvaluator<'a> {
                             &mut code,
                         )
                     } else if term_loc.is_last() || cell.get().norm().reg_num() == 0 {
-                        self.marker.mark_var::<QueryInstruction>(
-                            name.clone(),
-                            lvl,
-                            cell,
-                            term_loc,
-                            &mut code,
-                        );
-
-                        self.marker.get_binding(&name).unwrap()
+                        if let Some(r) = self.marker.get_binding(&name) {
+                            r
+                        } else {
+                            self.marker.mark_var::<QueryInstruction>(
+                                name.clone(),
+                                lvl,
+                                cell,
+                                term_loc,
+                                &mut code,
+                            );
+
+                            self.marker.get_binding(&name).unwrap()
+                        }
                     } else {
                         cell.get().norm()
                     };
index 6abed278fc1b48bbe4ee9742d0118cd1d5c9eed3..6f7223360c610c0258b14a28aecfae8eb69f6bc7 100644 (file)
@@ -747,7 +747,7 @@ impl<'b> CodeGenerator<'b> {
     ) -> Result<(), CompilationError> {
         macro_rules! compile_expr {
             ($self:expr, $terms:expr, $term_loc:expr, $code:expr) => ({
-                let (acode, at) = $self.compile_arith_expr(&$terms[1], 1, $term_loc, 2)?;
+                let (acode, at) = $self.compile_arith_expr($terms, 1, $term_loc, 2)?;
                 $code.extend(acode.into_iter());
                 at
             });
@@ -765,7 +765,7 @@ impl<'b> CodeGenerator<'b> {
                     code,
                 );
 
-                compile_expr!(self, terms, term_loc, code)
+                compile_expr!(self, &terms[1], term_loc, code)
             }
             &Term::Literal(_, c @ Literal::Integer(_) |
                               c @ Literal::Float(_) |
@@ -775,7 +775,7 @@ impl<'b> CodeGenerator<'b> {
                 code.push(instr!("put_constant", Level::Shallow, v, temp_v!(1)));
 
                 self.marker.advance_arg();
-                compile_expr!(self, terms, term_loc, code)
+                compile_expr!(self, &terms[1], term_loc, code)
             }
             _ => {
                 code.push(instr!("$fail", 0));