transition to reference counted constants

This commit is contained in:
Mark Thom
2018-01-09 22:38:17 -07:00
parent 9b225a0a56
commit 848068c734
10 changed files with 215 additions and 220 deletions

View File

@@ -2,6 +2,7 @@ use prolog::ast::*;
use prolog::fixtures::*;
use std::cmp::{min, max};
use std::rc::Rc;
use std::vec::Vec;
pub struct ArithExprIterator<'a> {
@@ -170,10 +171,8 @@ impl<'a> ArithmeticEvaluator<'a> {
fn push_constant(&mut self, c: &Constant) -> Result<(), ArithmeticError> {
match c {
&Constant::Float(fl) =>
self.interm.push(ArithmeticTerm::Float(fl)),
&Constant::Integer(ref bi) =>
self.interm.push(ArithmeticTerm::Integer(bi.clone())),
&Constant::Number(ref n) =>
self.interm.push(ArithmeticTerm::Number(n.clone())),
_ =>
return Err(ArithmeticError::InvalidAtom),
}
@@ -202,11 +201,11 @@ impl<'a> ArithmeticEvaluator<'a> {
self.interm.push(ArithmeticTerm::Reg(r));
},
TermRef::Clause(ClauseType::Deep(_, _, name), terms) => {
code.push(Line::Arithmetic(self.instr_from_clause(name, terms)?));
code.push(Line::Arithmetic(self.instr_from_clause(&*name, terms)?));
},
TermRef::Clause(ClauseType::Root, terms) => {
let name = term.name().unwrap();
code.push(Line::Arithmetic(self.instr_from_clause(name, terms)?));
code.push(Line::Arithmetic(self.instr_from_clause(&*name, terms)?));
},
_ =>
return Err(ArithmeticError::InvalidTerm)