let state = match term {
&Term::AnonVar =>
return Err(ArithmeticError::InvalidTerm),
- &Term::Clause(_, _, ref terms) =>
+ &Term::Clause(_, _, ref terms, _) =>
TermIterState::Clause(0, ClauseType::Root, terms),
&Term::Constant(ref cell, ref cons) =>
TermIterState::Constant(Level::Shallow, cell, cons),
self.interm.push(ArithmeticTerm::Reg(r));
},
- TermRef::Clause(ClauseType::Deep(_, _, name), terms) => {
+ TermRef::Clause(ClauseType::Deep(_, _, name, _), terms) => {
code.push(Line::Arithmetic(self.instr_from_clause(&*name, terms)?));
},
TermRef::Clause(ClauseType::Root, terms) => {
pub enum Term {
AnonVar,
- Clause(Cell<RegType>, Rc<Atom>, Vec<Box<Term>>),
+ Clause(Cell<RegType>, Rc<Atom>, Vec<Box<Term>>, Option<Fixity>),
Cons(Cell<RegType>, Box<Term>, Box<Term>),
Constant(Cell<RegType>, Constant),
Var(Cell<VarReg>, Rc<Var>)
pub enum ClauseType<'a> {
CallN,
Catch,
- Deep(Level, &'a Cell<RegType>, &'a Rc<Atom>),
+ Deep(Level, &'a Cell<RegType>, &'a Rc<Atom>, Option<Fixity>),
Is,
Root,
Throw,
impl<'a> ClauseType<'a> {
pub fn level_of_subterms(self) -> Level {
match self {
- ClauseType::Deep(_, _, _) => Level::Deep,
+ ClauseType::Deep(..) => Level::Deep,
_ => Level::Shallow
}
}
pub fn level(self) -> Level {
match self {
TermRef::AnonVar(lvl)
- | TermRef::Cons(lvl, _, _, _)
- | TermRef::Constant(lvl, _, _)
- | TermRef::Var(lvl, _, _) => lvl,
- TermRef::Clause(ClauseType::Deep(lvl, _, _), _) => lvl,
+ | TermRef::Cons(lvl, ..)
+ | TermRef::Constant(lvl, ..)
+ | TermRef::Var(lvl, ..) => lvl,
+ TermRef::Clause(ClauseType::Deep(lvl, ..), ..) => lvl,
_ => Level::Shallow
}
}
pub enum FactInstruction {
GetConstant(Level, Constant, RegType),
GetList(Level, RegType),
- GetStructure(Level, Rc<Atom>, usize, RegType),
+ GetStructure(Level, Rc<Atom>, usize, RegType, Option<Fixity>),
GetValue(RegType, usize),
GetVariable(RegType, usize),
UnifyConstant(Constant),
GetVariable(RegType, usize),
PutConstant(Level, Constant, RegType),
PutList(Level, RegType),
- PutStructure(Level, Rc<Atom>, usize, RegType),
+ PutStructure(Level, Rc<Atom>, usize, RegType, Option<Fixity>),
PutUnsafeValue(usize, usize),
PutValue(RegType, usize),
PutVariable(RegType, usize),
#[derive(Clone, PartialEq)]
pub enum HeapCellValue {
Addr(Addr),
- NamedStr(usize, Rc<Atom>), // arity, name.
+ NamedStr(usize, Rc<Atom>, Option<Fixity>), // arity, name.
}
impl HeapCellValue {
pub fn as_addr(&self, focus: usize) -> Addr {
match self {
&HeapCellValue::Addr(ref a) => a.clone(),
- &HeapCellValue::NamedStr(_, _) => Addr::Str(focus)
+ &HeapCellValue::NamedStr(_, _, _) => Addr::Str(focus)
}
}
}
impl Term {
pub fn first_arg(&self) -> Option<&Term> {
match self {
- &Term::Clause(_, _, ref terms) =>
+ &Term::Clause(_, _, ref terms, _) =>
terms.first().map(|bt| bt.as_ref()),
_ => None
}
pub fn is_callable(&self) -> bool {
match self {
- &Term::Clause(_, _, _) | &Term::Constant(_, Constant::Atom(_)) =>
+ &Term::Clause(..) | &Term::Constant(_, Constant::Atom(_)) =>
true,
_ => false
}
pub fn name(&self) -> Option<Rc<Atom>> {
match self {
&Term::Constant(_, Constant::Atom(ref atom))
- | &Term::Clause(_, ref atom, _) => Some(atom.clone()),
+ | &Term::Clause(_, ref atom, ..) => Some(atom.clone()),
_ => None
}
}
pub fn arity(&self) -> usize {
match self {
- &Term::Clause(_, _, ref child_terms) => child_terms.len(),
+ &Term::Clause(_, _, ref child_terms, ..) => child_terms.len(),
_ => 0
}
}
match term {
&Term::AnonVar =>
TermIterState::AnonVar(lvl),
- &Term::Clause(ref cell, ref atom, ref child_terms) =>
- TermIterState::Clause(0, ClauseType::Deep(lvl, cell, atom), child_terms),
+ &Term::Clause(ref cell, ref atom, ref child_terms, fixity) =>
+ TermIterState::Clause(0, ClauseType::Deep(lvl, cell, atom, fixity), child_terms),
&Term::Cons(ref cell, ref head, ref tail) =>
TermIterState::InitialCons(lvl, cell, head.as_ref(), tail.as_ref()),
&Term::Constant(ref cell, ref constant) =>
trust!(10),
try_me_else!(4),
fact![get_constant!(Constant::from("!"), temp_v!(1)),
- get_structure!(String::from(","), 2, temp_v!(2)),
+ get_structure!(String::from(","), 2, temp_v!(2), Some(infix!())),
unify_variable!(temp_v!(1)),
unify_variable!(temp_v!(2))],
set_cp!(temp_v!(3)),
execute_n!(1),
retry_me_else!(8),
allocate!(3),
- fact![get_structure!(String::from(","), 2, temp_v!(2)),
+ fact![get_structure!(String::from(","), 2, temp_v!(2), Some(infix!())),
unify_variable!(perm_v!(2)),
unify_variable!(perm_v!(1)),
get_var_in_fact!(perm_v!(3), 3)],
indexed_try!(3),
trust!(5),
try_me_else!(3),
- fact![get_structure!(String::from("->"), 2, temp_v!(1)),
+ fact![get_structure!(String::from("->"), 2, temp_v!(1), Some(infix!())),
unify_variable!(temp_v!(1)),
unify_variable!(temp_v!(2))],
goto!(139, 3),
trust_me!(),
- fact![get_structure!(String::from("->"), 2, temp_v!(1)),
+ fact![get_structure!(String::from("->"), 2, temp_v!(1), Some(infix!())),
unify_void!(2)],
query![put_value!(temp_v!(2), 1)],
neck_cut!(),
put_structure!(Level::Shallow,
String::from("type_error"),
1,
- temp_v!(1)),
+ temp_v!(1),
+ None),
set_constant!(Constant::Atom(rc_atom!("integer_expected")))],
goto!(59, 1), // goto throw/1.
try_me_else!(5), // arg_/3, 173.
self.marker.mark_anon_var(Level::Deep, target),
&Term::AnonVar =>
Self::add_or_increment_void_instr(target),
- &Term::Cons(ref cell, _, _) | &Term::Clause(ref cell, _, _) => {
+ &Term::Cons(ref cell, _, _) | &Term::Clause(ref cell, _, _, _) => {
self.marker.mark_non_var(Level::Deep, term_loc, cell, target);
target.push(Target::clause_arg_to_instr(cell.get()));
},
where Target: CompilationTarget<'a>
{
match ct {
- ClauseType::Deep(lvl, cell, atom) => {
+ ClauseType::Deep(lvl, cell, atom, fixity) => {
self.marker.mark_non_var(lvl, term_loc, cell, target);
- target.push(Target::to_structure(lvl, atom.clone(), terms.len(), cell.get()));
+ target.push(Target::to_structure(lvl, atom.clone(), terms.len(),
+ cell.get(), fixity));
for subterm in terms {
self.subterm_to_instr(subterm.as_ref(), term_loc, is_exposed, target);
let call = ControlInstruction::Call(atom.clone(), 0, pvs);
code.push(Line::Control(call));
},
- &QueryTerm::Term(Term::Clause(_, ref atom, ref terms)) => {
+ &QueryTerm::Term(Term::Clause(_, ref atom, ref terms, _)) => {
let call = ControlInstruction::Call(atom.clone(), terms.len(), pvs);
code.push(Line::Control(call));
},
},
&InlinedQueryTerm::IsAtomic(ref inner_term) =>
match inner_term[0].as_ref() {
- &Term::AnonVar | &Term::Clause(_, _, _) | &Term::Cons(_, _, _) => {
+ &Term::AnonVar | &Term::Clause(..) | &Term::Cons(..) => {
code.push(fail!());
},
- &Term::Constant(_, _) => {
+ &Term::Constant(..) => {
code.push(succeed!());
},
&Term::Var(ref vr, ref name) => {
},
&InlinedQueryTerm::IsVar(ref inner_term) =>
match inner_term[0].as_ref() {
- &Term::Constant(_, _) | &Term::Clause(_, _, _) | &Term::Cons(_, _, _) => {
+ &Term::Constant(..) | &Term::Clause(..) | &Term::Cons(..) => {
code.push(fail!());
},
&Term::AnonVar => {
self.compile_seq_prelude(&conjunct_info, &mut code);
if let &QueryTerm::Term(ref term) = p0 {
- if let &Term::Clause(_, _, _) = term {
+ if let &Term::Clause(..) = term {
let iter = FactInstruction::iter(term);
let fact = self.compile_target(iter, GenContext::Head, false);
let mut code = Vec::new();
- if let &Term::Clause(_, _, _) = term {
+ if let &Term::Clause(..) = term {
let iter = FactInstruction::iter(term);
let mut compiled_fact = self.compile_target(iter, GenContext::Head, false);
while scan < self.threshold() {
match self[scan].clone() {
- HeapCellValue::NamedStr(_, _) =>
+ HeapCellValue::NamedStr(_, _, _) =>
scan += 1,
HeapCellValue::Addr(a) =>
match a.clone() {
},
Addr::Str(s) => {
match self[s].clone() {
- HeapCellValue::NamedStr(arity, name) => {
+ HeapCellValue::NamedStr(arity, name, fixity) => {
let threshold = self.threshold();
self[scan] = HeapCellValue::Addr(Addr::Str(threshold));
self[s] = HeapCellValue::Addr(Addr::Str(threshold));
trail.push((Ref::HeapCell(s),
- HeapCellValue::NamedStr(arity, name.clone())));
+ HeapCellValue::NamedStr(arity, name.clone(), fixity)));
- self.push(HeapCellValue::NamedStr(arity, name));
+ self.push(HeapCellValue::NamedStr(arity, name, fixity));
for i in 0 .. arity {
let hcv = self[s + 1 + i].clone();
fn follow_heap(&mut self, h: usize) -> Addr
{
match &self.machine_st.heap[h] {
- &HeapCellValue::NamedStr(arity, _) => {
+ &HeapCellValue::NamedStr(arity, _, _) => {
for idx in (1 .. arity + 1).rev() {
self.state_stack.push(Ref::HeapCell(h + idx));
}
use prolog::ast::*;
-use prolog::builtins::*;
use prolog::heap_iter::*;
use std::cell::Cell;
// this can be overloaded to handle special cases, falling back on the default of
// format_struct when convenient.
- fn format_clause(&self, arity: usize, name: Rc<Atom>, state_stack: &mut Vec<TokenOrRedirect>);
+ fn format_clause(&self, usize, Rc<Atom>, Option<Fixity>, &mut Vec<TokenOrRedirect>);
}
// the 'classic' display corresponding to the display predicate.
pub struct DisplayFormatter {}
impl HeapCellValueFormatter for DisplayFormatter {
- fn format_clause(&self, arity: usize, name: Rc<Atom>, state_stack: &mut Vec<TokenOrRedirect>)
+ fn format_clause(&self, arity: usize, name: Rc<Atom>, _: Option<Fixity>,
+ state_stack: &mut Vec<TokenOrRedirect>)
{
self.format_struct(arity, name, state_stack);
}
}
-pub struct TermFormatter<'a> {
- op_dir: &'a OpDir
-}
-
-impl<'a> TermFormatter<'a> {
- pub fn new(op_dir: &'a OpDir) -> Self {
- TermFormatter { op_dir }
- }
-}
+pub struct TermFormatter {}
-impl<'a> HeapCellValueFormatter for TermFormatter<'a> {
- fn format_clause(&self, arity: usize, name: Rc<Atom>, state_stack: &mut Vec<TokenOrRedirect>) {
- if arity == 1 {
- match self.op_dir.get(&(name.clone(), Fixity::Post)) {
- Some(_) => {
+impl HeapCellValueFormatter for TermFormatter {
+ fn format_clause(&self, arity: usize, name: Rc<Atom>, fixity: Option<Fixity>,
+ state_stack: &mut Vec<TokenOrRedirect>)
+ {
+ if let Some(fixity) = fixity {
+ match fixity {
+ Fixity::Post => {
state_stack.push(TokenOrRedirect::Atom(name));
state_stack.push(TokenOrRedirect::Space);
state_stack.push(TokenOrRedirect::Redirect);
},
- None => match self.op_dir.get(&(name.clone(), Fixity::Pre)) {
- Some(_) => {
- state_stack.push(TokenOrRedirect::Redirect);
- state_stack.push(TokenOrRedirect::Space);
- state_stack.push(TokenOrRedirect::Atom(name));
- },
- None => self.format_struct(arity, name, state_stack)
- }
- }
- } else if arity == 2 {
- match self.op_dir.get(&(name.clone(), Fixity::In)) {
- Some(_) => {
+ Fixity::Pre => {
+ state_stack.push(TokenOrRedirect::Redirect);
+ state_stack.push(TokenOrRedirect::Space);
+ state_stack.push(TokenOrRedirect::Atom(name));
+ },
+ Fixity::In => {
state_stack.push(TokenOrRedirect::Redirect);
state_stack.push(TokenOrRedirect::Space);
state_stack.push(TokenOrRedirect::Atom(name));
state_stack.push(TokenOrRedirect::Space);
state_stack.push(TokenOrRedirect::Redirect);
- },
- None => self.format_struct(arity, name, state_stack)
- };
+ }
+ }
} else {
self.format_struct(arity, name, state_stack);
}
fn handle_heap_term(&mut self, heap_val: HeapCellValue, result: &mut String) {
match heap_val {
- HeapCellValue::NamedStr(arity, name) =>
- self.formatter.format_clause(arity, name, &mut self.state_stack),
+ HeapCellValue::NamedStr(arity, name, fixity) =>
+ self.formatter.format_clause(arity, name, fixity, &mut self.state_stack),
HeapCellValue::Addr(Addr::Con(Constant::EmptyList)) =>
if !Self::at_cdr(result, "") {
*result += "[]";
pub fn index_term(&mut self, first_arg: &Term, index: usize)
{
match first_arg {
- &Term::Clause(_, ref name, ref terms) => {
+ &Term::Clause(_, ref name, ref terms, _) => {
let code = self.structures.entry((name.clone(), terms.len()))
.or_insert(Vec::new());
let is_initial_index = code.is_empty();
code.push(Self::add_index(is_initial_index, index));
},
- &Term::Cons(_, _, _) => {
+ &Term::Cons(..) => {
let is_initial_index = self.lists.is_empty();
self.lists.push(Self::add_index(is_initial_index, index));
},
write!(f, "get_list A{}", r.reg_num()),
&FactInstruction::GetList(Level::Deep, ref r) =>
write!(f, "get_list {}", r),
- &FactInstruction::GetStructure(Level::Deep, ref name, ref arity, ref r) =>
+ &FactInstruction::GetStructure(Level::Deep, ref name, ref arity, ref r, _) =>
write!(f, "get_structure {}/{}, {}", name, arity, r),
- &FactInstruction::GetStructure(Level::Shallow, ref name, ref arity, ref r) =>
+ &FactInstruction::GetStructure(Level::Shallow, ref name, ref arity, ref r, _) =>
write!(f, "get_structure {}/{}, A{}", name, arity, r.reg_num()),
&FactInstruction::GetValue(ref x, ref a) =>
write!(f, "get_value {}, A{}", x, a),
write!(f, "put_list A{}", r.reg_num()),
&QueryInstruction::PutList(Level::Deep, ref r) =>
write!(f, "put_list {}", r),
- &QueryInstruction::PutStructure(Level::Deep, ref name, ref arity, ref r) =>
+ &QueryInstruction::PutStructure(Level::Deep, ref name, ref arity, ref r, _) =>
write!(f, "put_structure {}/{}, {}", name, arity, r),
- &QueryInstruction::PutStructure(Level::Shallow, ref name, ref arity, ref r) =>
+ &QueryInstruction::PutStructure(Level::Shallow, ref name, ref arity, ref r, _) =>
write!(f, "put_structure {}/{}, A{}", name, arity, r.reg_num()),
&QueryInstruction::PutUnsafeValue(y, a) =>
write!(f, "put_unsafe_value Y{}, A{}", y, a),
let state = match term {
&Term::AnonVar =>
return QueryIterator { state_stack: vec![] },
- &Term::Clause(_, _, ref terms) =>
+ &Term::Clause(.., ref terms, _) =>
TermIterState::Clause(0, ClauseType::Root, terms),
- &Term::Cons(_, _, _) =>
+ &Term::Cons(..) =>
return QueryIterator { state_stack: vec![] },
&Term::Constant(_, _) =>
return QueryIterator { state_stack: vec![] },
match ct {
ClauseType::CallN =>
self.push_subterm(Level::Shallow, child_terms[0].as_ref()),
- ClauseType::Deep(_, _, _) =>
+ ClauseType::Deep(..) =>
return Some(TermRef::Clause(ct, child_terms)),
_ =>
return None
let states = match term {
&Term::AnonVar =>
vec![TermIterState::AnonVar(Level::Shallow)],
- &Term::Clause(_, _, ref terms) =>
+ &Term::Clause(.., ref terms, _) =>
vec![TermIterState::Clause(0, ClauseType::Root, terms)],
&Term::Cons(ref cell, ref head, ref tail) =>
vec![TermIterState::InitialCons(Level::Shallow,
}
match ct {
- ClauseType::Deep(_, _, _) =>
+ ClauseType::Deep(..) =>
return Some(TermRef::Clause(ct, child_terms)),
_ =>
continue
let r1 = &self.heap[a1];
let r2 = &self.heap[a2];
- if let &HeapCellValue::NamedStr(n1, ref f1) = r1 {
- if let &HeapCellValue::NamedStr(n2, ref f2) = r2 {
+ if let &HeapCellValue::NamedStr(n1, ref f1, _) = r1 {
+ if let &HeapCellValue::NamedStr(n2, ref f2, _) = r2 {
if n1 == n2 && *f1 == *f2 {
for i in 1 .. n1 + 1 {
pdl.push(Addr::HeapCell(a1 + i));
_ => self.fail = true
};
},
- &FactInstruction::GetStructure(_, ref name, arity, reg) => {
+ &FactInstruction::GetStructure(_, ref name, arity, reg, fixity) => {
let addr = self.deref(self[reg].clone());
match self.store(addr.clone()) {
Addr::Str(a) => {
let result = &self.heap[a];
- if let &HeapCellValue::NamedStr(narity, ref str) = result {
+ if let &HeapCellValue::NamedStr(narity, ref str, _) = result {
if narity == arity && *name == *str {
self.s = a + 1;
self.mode = MachineMode::Read;
let h = self.heap.h;
self.heap.push(HeapCellValue::Addr(Addr::Str(h + 1)));
- self.heap.push(HeapCellValue::NamedStr(arity, name.clone()));
+ self.heap.push(HeapCellValue::NamedStr(arity, name.clone(), fixity));
self.bind(addr.as_var().unwrap(), Addr::HeapCell(h));
let offset = match addr {
Addr::Str(s) => {
- if let &HeapCellValue::NamedStr(arity, ref name) = &self.heap[s] {
+ if let &HeapCellValue::NamedStr(arity, ref name, _) = &self.heap[s] {
match hm.get(&(name.clone(), arity)) {
Some(offset) => *offset,
_ => 0
self[reg] = Addr::Con(constant.clone()),
&QueryInstruction::PutList(_, reg) =>
self[reg] = Addr::Lis(self.heap.h),
- &QueryInstruction::PutStructure(_, ref name, arity, reg) => {
+ &QueryInstruction::PutStructure(_, ref name, arity, reg, fixity) => {
let h = self.heap.h;
- self.heap.push(HeapCellValue::NamedStr(arity, name.clone()));
+ self.heap.push(HeapCellValue::NamedStr(arity, name.clone(), fixity));
self[reg] = Addr::Str(h);
},
&QueryInstruction::PutUnsafeValue(n, arg) => {
Addr::Str(a) => {
let result = self.heap[a].clone();
- if let HeapCellValue::NamedStr(narity, name) = result {
+ if let HeapCellValue::NamedStr(narity, name, _) = result {
if narity + arity > 63 {
self.throw_exception(functor!("representation_error",
1,
if let Addr::Str(o) = a2 {
match self.heap[o].clone() {
- HeapCellValue::NamedStr(arity, _) =>
+ HeapCellValue::NamedStr(arity, _, _) =>
match i.to_usize() {
Some(i) if 1 <= i && i <= arity => {
let a3 = self[temp_v!(3)].clone();
match a1.clone() {
Addr::Str(o) =>
match self.heap[o].clone() {
- HeapCellValue::NamedStr(arity, name) => {
+ HeapCellValue::NamedStr(arity, name, _) => {
let name = Addr::Con(Constant::Atom(name)); // A2
let arity = Addr::Con(Constant::Number(rc_integer!(arity)));
}
};
- self.heap.push(HeapCellValue::NamedStr(arity, name));
+ self.heap.push(HeapCellValue::NamedStr(arity, name, None));
for _ in 0 .. arity {
let h = self.heap.h;
pub fn add_fact<'a>(&mut self, fact: &Term, mut code: Code) -> EvalSession<'a>
{
match fact {
- &Term::Clause(_, ref name, _) | &Term::Constant(_, Constant::Atom(ref name)) => {
+ &Term::Clause(_, ref name, ..) | &Term::Constant(_, Constant::Atom(ref name)) => {
let p = self.code.len();
let arity = fact.arity();
pub fn add_rule<'a>(&mut self, rule: &Rule, mut code: Code) -> EvalSession<'a>
{
match &rule.head.0 {
- &QueryTerm::Term(Term::Clause(_, ref name, _))
+ &QueryTerm::Term(Term::Clause(_, ref name, ..))
| &QueryTerm::Term(Term::Constant(_, Constant::Atom(ref name))) => {
let p = self.code.len();
let arity = rule.head.0.arity();
fn print_var(&self, r: Ref) -> String
{
- let disp = TermFormatter::new(&self.op_dir);
+ let disp = TermFormatter {};
let iter = HeapCellIterator::new(&self.ms, r);
let mut printer = HeapCellPrinter::new(iter, disp);
macro_rules! functor {
($name:expr, $len:expr, [$($args:expr),*]) => {{
if $len > 0 {
- vec![ HeapCellValue::NamedStr($len, Rc::new(String::from($name))), $($args),* ]
+ vec![ HeapCellValue::NamedStr($len, Rc::new(String::from($name)), None), $($args),* ]
} else {
vec![ atom!($name) ]
}
}
macro_rules! put_structure {
- ($lvl:expr, $name:expr, $arity:expr, $r:expr) => (
- QueryInstruction::PutStructure($lvl, Rc::new($name), $arity, $r)
+ ($lvl:expr, $name:expr, $arity:expr, $r:expr, $fix:expr) => (
+ QueryInstruction::PutStructure($lvl, Rc::new($name), $arity, $r, $fix)
)
}
}
macro_rules! get_structure {
- ($atom:expr, $arity:expr, $r:expr) => (
- FactInstruction::GetStructure(Level::Shallow, Rc::new($atom), $arity, $r)
+ ($atom:expr, $arity:expr, $r:expr, $fix:expr) => (
+ FactInstruction::GetStructure(Level::Shallow, Rc::new($atom), $arity, $r, $fix)
)
}
Rc::new(String::from($e))
)
}
+
+macro_rules! infix {
+ () => (
+ Fixity::In
+ )
+}
-Subproject commit 171e1f6d6ff8ef5b916cc57062958295a1203895
+Subproject commit 159f82cd836192cc1970187b67b2fb44ef7e6c68
use std::cell::RefCell;
use std::collections::HashSet;
-use std::hash::Hash;
-use std::ops::Deref;
+use std::fmt;
+use std::hash::{Hash, Hasher};
+use std::ops::{Deref, DerefMut};
use std::rc::Rc;
pub type TabledData<T> = HashSet<Rc<T>>;
-#[derive(Clone, PartialEq, Eq, Hash)]
+#[derive(Clone, PartialEq, Eq)]
pub struct TabledRc<T: Hash + Eq> {
atom: Rc<T>,
table: Rc<RefCell<TabledData<T>>>
}
+impl<T: Hash + Eq> Hash for TabledRc<T> {
+ fn hash<H: Hasher>(&self, state: &mut H)
+ {
+ self.atom.hash(state)
+ }
+}
+
impl<T: Hash + Eq> TabledRc<T> {
- pub fn new(atom: T, table: Rc<RefCell<TabledData<T>>>) -> Self {
+ pub fn new(atom: T, table: Rc<RefCell<TabledData<T>>>) -> Self {
TabledRc { atom: Rc::new(atom), table }
}
}
impl<T: Hash + Eq> Drop for TabledRc<T> {
fn drop(&mut self) {
if Rc::strong_count(&self.atom) == 2 {
- let table = *self.table.borrow_mut();
- table.remove(&self.atom);
+ let mut table = self.table.borrow_mut();
+ table.deref_mut().remove(&self.atom);
}
}
}
&*self.atom
}
}
+
+impl<T: Hash + Eq + fmt::Display> fmt::Display for TabledRc<T> {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "{}", &*self.atom)
+ }
+}
fn to_constant(Level, Constant, RegType) -> Self;
fn to_list(Level, RegType) -> Self;
- fn to_structure(Level, Rc<Atom>, usize, RegType) -> Self;
+ fn to_structure(Level, Rc<Atom>, usize, RegType, Option<Fixity>) -> Self;
fn to_void(usize) -> Self;
fn is_void_instr(&self) -> bool;
FactInstruction::GetConstant(lvl, constant, reg)
}
- fn to_structure(lvl: Level, atom: Rc<Atom>, arity: usize, reg: RegType) -> Self {
- FactInstruction::GetStructure(lvl, atom, arity, reg)
+ fn to_structure(lvl: Level, atom: Rc<Atom>, arity: usize, reg: RegType, fixity: Option<Fixity>)
+ -> Self
+ {
+ FactInstruction::GetStructure(lvl, atom, arity, reg, fixity)
}
fn to_list(lvl: Level, reg: RegType) -> Self {
term.post_order_iter()
}
- fn to_structure(lvl: Level, atom: Rc<Atom>, arity: usize, reg: RegType) -> Self {
- QueryInstruction::PutStructure(lvl, atom, arity, reg)
+ fn to_structure(lvl: Level, atom: Rc<Atom>, arity: usize, reg: RegType, fixity: Option<Fixity>)
+ -> Self
+ {
+ QueryInstruction::PutStructure(lvl, atom, arity, reg, fixity)
}
fn to_constant(lvl: Level, constant: Constant, reg: RegType) -> Self {