use existing bindings in compile_is (#1545)

This commit is contained in:
Mark Thom
2022-11-13 22:58:00 -07:00
parent d19a8d6b98
commit d16312a314
2 changed files with 16 additions and 26 deletions

View 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,
);
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()
self.marker.get_binding(&name).unwrap()
}
} else {
cell.get().norm()
};

View 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));