fix conformity errors

This commit is contained in:
Mark Thom
2019-04-04 22:51:00 -06:00
parent 546aeea479
commit 3912a4772d
17 changed files with 150 additions and 150 deletions

View File

@@ -14,7 +14,7 @@ cfg-if = "0.1.7"
downcast = "0.10.0"
num = "0.2"
ordered-float = "0.5.0"
prolog_parser = "0.8.14"
prolog_parser = "0.8.15"
readline_rs_compat = { version = "0.1.7", optional = true }
ref_thread_local = "0.0.0"

View File

@@ -28,8 +28,8 @@ impl<'a> ArithInstructionIterator<'a> {
let state = match term {
&Term::AnonVar =>
return Err(ArithmeticError::InvalidTerm),
&Term::Clause(ref cell, ref name, ref terms, fixity) =>
match ClauseType::from(name.clone(), terms.len(), fixity) {
&Term::Clause(ref cell, ref name, ref terms, ref fixity) =>
match ClauseType::from(name.clone(), terms.len(), fixity.clone()) {
ct @ ClauseType::Named(..) | ct @ ClauseType::Op(..) =>
Ok(TermIterState::Clause(Level::Shallow, 0, cell, ct, terms)),
_ => Err(ArithmeticError::InvalidOp)

View File

@@ -1,6 +1,5 @@
use prolog_parser::ast::*;
use prolog::forms::OpDecl;
use prolog::machine::machine_indices::*;
use ref_thread_local::RefThreadLocal;
@@ -403,7 +402,7 @@ pub enum ClauseType {
Hook(CompileTimeHook),
Inlined(InlinedClauseType),
Named(ClauseName, usize, CodeIndex), // name, arity, index.
Op(OpDecl, CodeIndex),
Op(ClauseName, SharedOpDesc, CodeIndex),
System(SystemClauseType)
}
@@ -454,16 +453,16 @@ impl BuiltInClauseType {
}
impl ClauseType {
pub fn spec(&self) -> Option<(usize, Specifier)> {
pub fn spec(&self) -> Option<SharedOpDesc> {
match self {
&ClauseType::Op(ref op_decl, _) =>
Some((op_decl.0, op_decl.1)),
&ClauseType::Op(_, ref spec, _) =>
Some(spec.clone()),
&ClauseType::Inlined(InlinedClauseType::CompareNumber(..))
| &ClauseType::BuiltIn(BuiltInClauseType::Is(..))
| &ClauseType::BuiltIn(BuiltInClauseType::CompareTerm(_))
| &ClauseType::BuiltIn(BuiltInClauseType::NotEq)
| &ClauseType::BuiltIn(BuiltInClauseType::Eq) =>
Some((700, XFX)),
Some(SharedOpDesc::new(700, XFX)),
_ => None
}
}
@@ -474,21 +473,20 @@ impl ClauseType {
&ClauseType::BuiltIn(ref built_in) => built_in.name(),
&ClauseType::Hook(ref hook) => hook.name(),
&ClauseType::Inlined(ref inlined) => clause_name!(inlined.name()),
&ClauseType::Op(ref op_decl, ..) => op_decl.name(),
&ClauseType::Op(ref name, ..) => name.clone(),
&ClauseType::Named(ref name, ..) => name.clone(),
&ClauseType::System(ref system) => system.name(),
}
}
pub fn from(name: ClauseName, arity: usize, spec: Option<(usize, Specifier)>) -> Self {
pub fn from(name: ClauseName, arity: usize, spec: Option<SharedOpDesc>) -> Self {
CLAUSE_TYPE_FORMS.borrow().get(&(name.as_str(), arity)).cloned()
.unwrap_or_else(||
SystemClauseType::from(name.as_str(), arity)
.map(ClauseType::System)
.unwrap_or_else(||
if let Some(spec) = spec {
let op_decl = OpDecl(spec.0, spec.1, name);
ClauseType::Op(op_decl, CodeIndex::default())
ClauseType::Op(name, spec, CodeIndex::default())
} else if name.as_str() == "call" {
ClauseType::CallN
} else {

View File

@@ -177,30 +177,31 @@ impl OpDecl {
self.2.clone()
}
pub fn arity(&self) -> usize {
let spec = self.1;
if (spec | XFX != 0) || (spec | XFY != 0) || (spec | YFX != 0) {
2
} else {
1
}
}
#[inline]
pub fn remove(&self, op_dir: &mut OpDir) {
self.insert_into_op_dir(clause_name!(""), op_dir, 0);
}
fn insert_into_op_dir(&self, module: ClauseName, op_dir: &mut OpDir, prec: usize)
{
let (spec, name) = (self.1, self.2.clone());
if is_prefix!(spec) {
op_dir.remove(&(name.clone(), Fixity::Pre));
let fixity = match spec {
XFY | XFX | YFX => Fixity::In,
XF | YF => Fixity::Post,
FX | FY => Fixity::Pre,
_ => return
};
match op_dir.get(&(name.clone(), fixity)) {
Some(cell) => {
cell.shared_op_desc().set(prec, spec);
return;
}
None => {}
}
if is_infix!(spec) {
op_dir.remove(&(name.clone(), Fixity::In));
}
if is_postfix!(spec) {
op_dir.remove(&(name, Fixity::Post));
}
op_dir.insert((name, fixity), OpDirValue::new(spec, prec, module));
}
pub fn submit(&self, module: ClauseName, existing_desc: Option<OpDesc>, op_dir: &mut OpDir)
@@ -213,7 +214,7 @@ impl OpDecl {
if desc.post > 0 {
return Err(SessionError::OpIsInfixAndPostFix(name));
}
};
}
}
if is_postfix!(spec) {
@@ -221,23 +222,10 @@ impl OpDecl {
if desc.inf > 0 {
return Err(SessionError::OpIsInfixAndPostFix(name));
}
};
}
}
match spec {
XFY | XFX | YFX => {
op_dir.insert((name.clone(), Fixity::In), (spec, prec, module.clone()));
},
XF | YF => {
op_dir.insert((name.clone(), Fixity::Post), (spec, prec, module.clone()));
},
FX | FY => {
op_dir.insert((name.clone(), Fixity::Pre), (spec, prec, module.clone()));
},
_ => {}
};
Ok(())
Ok(self.insert_into_op_dir(module, op_dir, prec))
}
}

View File

@@ -17,8 +17,8 @@ use std::rc::Rc;
/* contains the location, name, precision and Specifier of the parent op. */
#[derive(Clone)]
pub enum DirectedOp {
Left(ClauseName, (usize, Specifier)),
Right(ClauseName, (usize, Specifier)),
Left(ClauseName, SharedOpDesc),
Right(ClauseName, SharedOpDesc)
}
impl DirectedOp {
@@ -33,22 +33,33 @@ impl DirectedOp {
#[inline]
fn is_negative_sign(&self) -> bool {
match self {
&DirectedOp::Left(ref name, (_, spec)) | &DirectedOp::Right(ref name, (_, spec)) =>
name.as_str() == "-" && is_prefix!(spec)
&DirectedOp::Left(ref name, ref cell) | &DirectedOp::Right(ref name, ref cell) =>
name.as_str() == "-" && is_prefix!(cell.assoc())
}
}
}
fn needs_bracketing(child_spec: (usize, Specifier), op: &DirectedOp) -> bool
fn needs_bracketing(child_spec: &SharedOpDesc, op: &DirectedOp) -> bool
{
match op {
&DirectedOp::Left(_, (priority, spec)) => {
&DirectedOp::Left(ref name, ref cell) => {
let (priority, spec) = cell.get();
if name.as_str() == "-" {
let child_assoc = child_spec.assoc();
if is_prefix!(spec) && (is_postfix!(child_assoc) || is_infix!(child_assoc)) {
return true;
}
}
let is_strict_right = is_yfx!(spec) || is_xfx!(spec) || is_fx!(spec);
child_spec.0 > priority || (child_spec.0 == priority && is_strict_right)
child_spec.prec() > priority || (child_spec.prec() == priority && is_strict_right)
},
&DirectedOp::Right(_, (priority, spec)) => {
&DirectedOp::Right(_, ref cell) => {
let (priority, spec) = cell.get();
let is_strict_left = is_xfx!(spec) || is_xfy!(spec) || is_xf!(spec);
child_spec.0 > priority || (child_spec.0 == priority && is_strict_left)
child_spec.prec() > priority || (child_spec.prec() == priority && is_strict_left)
}
}
}
@@ -66,19 +77,19 @@ impl<'a> HCPreOrderIterator<'a> {
None => return false
};
let mut parent_spec = DirectedOp::Left(clause_name!("-"), (200, FY));
let mut parent_spec = DirectedOp::Left(clause_name!("-"), SharedOpDesc::new(200, FY));
loop {
match self.machine_st.store(self.machine_st.deref(addr)) {
Addr::Str(s) =>
match &self.machine_st.heap[s] {
&HeapCellValue::NamedStr(_, ref name, Some(spec))
if is_postfix!(spec.1) || is_infix!(spec.1) =>
&HeapCellValue::NamedStr(_, ref name, Some(ref spec))
if is_postfix!(spec.assoc()) || is_infix!(spec.assoc()) =>
if needs_bracketing(spec, &parent_spec) {
return false;
} else {
addr = Addr::HeapCell(s+1);
parent_spec = DirectedOp::Right(name.clone(), spec);
parent_spec = DirectedOp::Right(name.clone(), spec.clone());
},
_ =>
return false
@@ -95,7 +106,7 @@ impl<'a> HCPreOrderIterator<'a> {
#[derive(Clone)]
pub enum TokenOrRedirect {
Atom(ClauseName),
Op(ClauseName, (usize, Specifier)),
Op(ClauseName, SharedOpDesc),
NumberedVar(String),
CompositeRedirect(DirectedOp),
FunctorRedirect,
@@ -259,7 +270,7 @@ fn continues_with_append(atom: &str, op: &str) -> bool {
if alpha_char!(ac) {
alpha_numeric_char!(oc)
} else if graphic_token_char!(ac) {
graphic_char!(oc)
graphic_token_char!(oc)
} else if variable_indicator_char!(ac) {
alpha_numeric_char!(oc)
} else if capital_letter_char!(ac) {
@@ -354,7 +365,7 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter>
{
let mut printer = Self::new(machine_st, output);
printer.toplevel_spec = Some(DirectedOp::Right(clause_name!("="), (700, XFX)));
printer.toplevel_spec = Some(DirectedOp::Right(clause_name!("="), SharedOpDesc::new(700, XFX)));
printer.heap_locs = reverse_heap_locs(machine_st, heap_locs);
printer
@@ -375,25 +386,25 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter>
}
// TODO: create a DirectedOp factory method. Use it here, and above.
fn enqueue_op(&mut self, ct: ClauseType, spec: (usize, Specifier)) {
if is_postfix!(spec.1) {
let right_directed_op = DirectedOp::Right(ct.name(), spec);
fn enqueue_op(&mut self, ct: ClauseType, spec: SharedOpDesc) {
if is_postfix!(spec.assoc()) {
let right_directed_op = DirectedOp::Right(ct.name(), spec.clone());
self.state_stack.push(TokenOrRedirect::Op(ct.name(), spec));
self.state_stack.push(TokenOrRedirect::CompositeRedirect(right_directed_op));
} else if is_prefix!(spec.1) {
} else if is_prefix!(spec.assoc()) {
if ct.name().as_str() == "-" {
self.format_negated_operand();
self.format_negated_operand(spec);
return;
}
let left_directed_op = DirectedOp::Left(ct.name(), spec);
let left_directed_op = DirectedOp::Left(ct.name(), spec.clone());
self.state_stack.push(TokenOrRedirect::CompositeRedirect(left_directed_op));
self.state_stack.push(TokenOrRedirect::Op(ct.name(), spec));
} else { // if is_infix!(spec.1)
let left_directed_op = DirectedOp::Left(ct.name(), spec);
let right_directed_op = DirectedOp::Right(ct.name(), spec);
} else { // if is_infix!(spec.assoc())
let left_directed_op = DirectedOp::Left(ct.name(), spec.clone());
let right_directed_op = DirectedOp::Right(ct.name(), spec.clone());
self.state_stack.push(TokenOrRedirect::CompositeRedirect(left_directed_op));
self.state_stack.push(TokenOrRedirect::Op(ct.name(), spec));
@@ -416,10 +427,10 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter>
self.state_stack.push(TokenOrRedirect::Atom(name));
}
fn format_negated_operand(&mut self)
fn format_negated_operand(&mut self, spec: SharedOpDesc)
{
let op = DirectedOp::Left(clause_name!("-"), (200, FY));
let op = DirectedOp::Left(clause_name!("-"), spec);
self.state_stack.push(TokenOrRedirect::CompositeRedirect(op));
self.state_stack.push(TokenOrRedirect::Space);
self.state_stack.push(TokenOrRedirect::Atom(clause_name!("-")));
@@ -452,10 +463,17 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter>
if self.format_numbered_vars(iter) {
return;
}
}
}
if let Some(spec) = ct.spec() {
if !self.ignore_ops {
if "." == ct.name().as_str() && is_infix!(spec.assoc()) {
if !self.ignore_ops {
self.push_list();
return;
}
}
if !self.ignore_ops && spec.prec() > 0 {
return self.enqueue_op(ct, spec);
}
}
@@ -628,10 +646,10 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter>
if self.outputter.ends_with(&format!(" {}", op.as_str())) {
self.push_char(' ');
}
self.push_char('(');
}
self.print_atom(atom);
if op.is_some() {
@@ -715,12 +733,12 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter>
};
match heap_val {
HeapCellValue::NamedStr(arity, ref name, Some(spec)) => {
HeapCellValue::NamedStr(arity, name, Some(spec)) => {
let add_brackets = if !self.ignore_ops {
add_brackets || if let Some(ref op) = &op {
needs_bracketing(spec, op)
needs_bracketing(&spec, op)
} else {
is_functor_redirect && spec.0 >= 1000
is_functor_redirect && spec.prec() >= 1000
}
} else {
false

View File

@@ -45,10 +45,9 @@ impl<'a> TermIterState<'a> {
match term {
&Term::AnonVar =>
TermIterState::AnonVar(lvl),
&Term::Clause(ref cell, ref name, ref subterms, spec) => {
&Term::Clause(ref cell, ref name, ref subterms, ref spec) => {
let ct = if let Some(spec) = spec {
let op_decl = OpDecl(spec.0, spec.1, name.clone());
ClauseType::Op(op_decl, CodeIndex::default())
ClauseType::Op(name.clone(), spec.clone(), CodeIndex::default())
} else {
ClauseType::Named(name.clone(), subterms.len(), CodeIndex::default())
};
@@ -86,9 +85,9 @@ impl<'a> QueryIterator<'a> {
let state = match term {
&Term::AnonVar =>
return QueryIterator { state_stack: vec![] },
&Term::Clause(ref r, ref name, ref terms, fixity) =>
&Term::Clause(ref r, ref name, ref terms, ref fixity) =>
TermIterState::Clause(Level::Root, 0, r,
ClauseType::from(name.clone(), terms.len(), fixity),
ClauseType::from(name.clone(), terms.len(), fixity.clone()),
terms),
&Term::Cons(..) =>
return QueryIterator { state_stack: vec![] },
@@ -200,8 +199,8 @@ impl<'a> FactIterator<'a> {
let states = match term {
&Term::AnonVar =>
vec![TermIterState::AnonVar(Level::Root)],
&Term::Clause(ref cell, ref name, ref terms, fixity) => {
let ct = ClauseType::from(name.clone(), terms.len(), fixity);
&Term::Clause(ref cell, ref name, ref terms, ref fixity) => {
let ct = ClauseType::from(name.clone(), terms.len(), fixity.clone());
vec![TermIterState::Clause(Level::Root, 0, cell, ct, terms)]
},
&Term::Cons(ref cell, ref head, ref tail) =>

View File

@@ -395,8 +395,8 @@ impl ListingCompiler {
if ct_name == &name && arity == ct_arity => {
*idx = self_idx.clone();
},
&mut ClauseType::Op(ref op_decl, ref mut idx)
if op_decl.name() == name && op_decl.arity() == arity => {
&mut ClauseType::Op(ref op_name, ref shared_op_desc, ref mut idx)
if op_name == &name && shared_op_desc.arity() == arity => {
*idx = self_idx.clone();
},
_ => {}
@@ -553,14 +553,11 @@ impl ListingCompiler {
Declaration::NonCountedBacktracking(name, arity) =>
Ok(self.add_non_counted_bt_flag(name, arity)),
Declaration::Op(op_decl) => {
let existing_desc = {
let comp_ops = composite_op!(self.module.is_some(), &wam_indices.op_dir,
&mut indices.op_dir);
let spec = get_desc(op_decl.name(), composite_op!(self.module.is_some(),
&wam_indices.op_dir,
&mut indices.op_dir));
get_desc(op_decl.name(), comp_ops)
};
op_decl.submit(self.get_module_name(), existing_desc, &mut indices.op_dir)
op_decl.submit(self.get_module_name(), spec, &mut indices.op_dir)
},
Declaration::UseModule(name) =>
self.use_module(name, code_repo, flags, wam_indices, indices),
@@ -579,10 +576,10 @@ impl ListingCompiler {
}
}
fn process_and_commit_decl<'a, R: Read>(&mut self, decl: Declaration,
worker: &mut TopLevelBatchWorker<'a, R>,
indices: &mut IndexStore, flags: MachineFlags)
-> Result<(), SessionError>
fn process_and_commit_decl<R: Read>(&mut self, decl: Declaration,
worker: &mut TopLevelBatchWorker<R>,
indices: &mut IndexStore, flags: MachineFlags)
-> Result<(), SessionError>
{
match &decl {
&Declaration::Dynamic(ref name, arity) => {

View File

@@ -149,7 +149,7 @@ impl<T: CopierTarget> CopyTermState<T> {
self.target[addr] = HeapCellValue::Addr(Addr::Str(threshold));
self.trail.push((Ref::HeapCell(addr),
HeapCellValue::NamedStr(arity, name.clone(), fixity)));
HeapCellValue::NamedStr(arity, name.clone(), fixity.clone())));
self.target.push(HeapCellValue::NamedStr(arity, name, fixity));

View File

@@ -22,7 +22,7 @@ pub(super) struct MachineError {
impl MachineError {
pub(super) fn functor_stub(name: ClauseName, arity: usize) -> MachineStub {
let name = HeapCellValue::Addr(Addr::Con(Constant::Atom(name, None)));
functor!("/", 2, [name, heap_integer!(arity)], (400, YFX))
functor!("/", 2, [name, heap_integer!(arity)], SharedOpDesc::new(400, YFX))
}
pub(super) fn evaluation_error(eval_error: EvalError) -> Self {
@@ -47,8 +47,8 @@ impl MachineError {
stub.append(&mut functor!("/", 2, [HeapCellValue::Addr(Addr::HeapCell(h + 2 + 3)),
heap_integer!(arity)],
(400, YFX)));
stub.append(&mut functor!(":", 2, [mod_name, name], (600, XFY)));
SharedOpDesc::new(400, YFX)));
stub.append(&mut functor!(":", 2, [mod_name, name], SharedOpDesc::new(600, XFY)));
MachineError { stub, from: ErrorProvenance::Constructed }
}

View File

@@ -14,8 +14,8 @@ use std::rc::Rc;
#[derive(Clone, PartialEq, Eq, Hash)]
pub enum DBRef {
BuiltInPred(ClauseName, usize, Option<(usize, Specifier)>),
NamedPred(ClauseName, usize, Option<(usize, Specifier)>)
BuiltInPred(ClauseName, usize, Option<SharedOpDesc>),
NamedPred(ClauseName, usize, Option<SharedOpDesc>)
}
#[derive(Clone, PartialEq, Eq, Hash)]
@@ -163,7 +163,7 @@ impl From<Ref> for TrailRef {
#[derive(Clone, PartialEq)]
pub enum HeapCellValue {
Addr(Addr),
NamedStr(usize, ClauseName, Option<(usize, Specifier)>), // arity, name, precedence/Specifier if it has one.
NamedStr(usize, ClauseName, Option<SharedOpDesc>), // arity, name, precedence/Specifier if it has one.
}
impl HeapCellValue {
@@ -411,7 +411,7 @@ pub struct IndexStore {
impl IndexStore {
pub fn predicate_exists(&self, name: ClauseName, module: ClauseName, arity: usize,
op_spec: Option<(usize, Specifier)>)
op_spec: Option<SharedOpDesc>)
-> bool
{
match self.modules.get(&module) {
@@ -419,8 +419,8 @@ impl IndexStore {
match ClauseType::from(name, arity, op_spec) {
ClauseType::Named(name, arity, _) =>
module.code_dir.contains_key(&(name, arity)),
ClauseType::Op(op_decl, ..) =>
module.code_dir.contains_key(&(op_decl.name(), op_decl.arity())),
ClauseType::Op(name, spec, ..) =>
module.code_dir.contains_key(&(name, spec.arity())),
_ =>
true
},
@@ -428,8 +428,8 @@ impl IndexStore {
match ClauseType::from(name, arity, op_spec) {
ClauseType::Named(name, arity, _) =>
self.code_dir.contains_key(&(name, arity)),
ClauseType::Op(op_decl, ..) =>
self.code_dir.contains_key(&(op_decl.name(), op_decl.arity())),
ClauseType::Op(name, spec, ..) =>
self.code_dir.contains_key(&(name, spec.arity())),
_ =>
true
}

View File

@@ -538,11 +538,11 @@ pub(crate) trait CallPolicy: Any {
let c = match machine_st.compare_term_test(&a2, &a3) {
Ordering::Greater => Addr::Con(Constant::Atom(clause_name!(">"),
Some((700, XFX)))),
Some(SharedOpDesc::new(700, XFX)))),
Ordering::Equal => Addr::Con(Constant::Atom(clause_name!("="),
Some((700, XFX)))),
Some(SharedOpDesc::new(700, XFX)))),
Ordering::Less => Addr::Con(Constant::Atom(clause_name!("<"),
Some((700, XFX))))
Some(SharedOpDesc::new(700, XFX))))
};
machine_st.unify(a1, c);

View File

@@ -1023,7 +1023,7 @@ impl MachineState {
self.interms[t - 1] = try_or_fail!(self, self.pow(n1, n2));
self.p += 1;
},
},
&ArithmeticInstruction::RDiv(ref a1, ref a2, t) => {
let stub = MachineError::functor_stub(clause_name!("(rdiv)"), 2);
@@ -2002,7 +2002,7 @@ impl MachineState {
}
fn try_functor_compound_case(&mut self, name: ClauseName, arity: usize,
spec: Option<(usize, Specifier)>)
spec: Option<SharedOpDesc>)
{
let name = Addr::Con(Constant::Atom(name, spec));
let arity = Addr::Con(integer!(arity));
@@ -2164,9 +2164,10 @@ impl MachineState {
HeapCellValue::NamedStr(2, ref name, Some(_))
if *name == clause_name!("-") =>
Ok(Addr::HeapCell(s+1)),
_ => Err(self.error_form(MachineError::type_error(ValidType::Pair,
self.heap[s].as_addr(s)),
stub))
_ =>
Err(self.error_form(MachineError::type_error(ValidType::Pair,
self.heap[s].as_addr(s)),
stub))
},
a => Err(self.error_form(MachineError::type_error(ValidType::Pair, a), stub))
}
@@ -2389,7 +2390,7 @@ impl MachineState {
self.p = CodePtr::Local(self.cp);
}
},
&ClauseType::Named(ref name, _, ref idx) | &ClauseType::Op(OpDecl(.., ref name), ref idx) =>
&ClauseType::Named(ref name, _, ref idx) | &ClauseType::Op(ref name, _, ref idx) =>
try_or_fail!(self, call_policy.context_call(self, name.clone(), arity, idx.clone(),
indices)),
&ClauseType::System(ref ct) =>

View File

@@ -274,13 +274,7 @@ impl Machine {
#[inline]
pub fn add_batched_ops(&mut self, op_dir: OpDir) {
for ((name, fixity), info) in op_dir {
if info.1 == 0 {
self.indices.op_dir.remove(&(name, fixity));
} else {
self.indices.op_dir.insert((name, fixity), info);
}
}
self.indices.op_dir.extend(op_dir.into_iter());
}
#[inline]

View File

@@ -71,6 +71,11 @@ pub trait SubModuleUser
fn insert_dir_entry(&mut self, ClauseName, usize, CodeIndex);
fn get_op_module_name(&mut self, name: ClauseName, fixity: Fixity) -> Option<ClauseName>
{
self.op_dir().get(&(name, fixity)).map(|op_val| op_val.owning_module())
}
fn remove_module(&mut self, mod_name: ClauseName, module: &Module)
{
for (name, arity) in module.module_decl.exports.iter().cloned() {
@@ -86,21 +91,21 @@ pub trait SubModuleUser
// remove or respecify ops.
if arity == 2 {
if let Some((_, _, mod_name)) = self.op_dir().get(&(name.clone(), Fixity::In)).cloned()
if let Some(mod_name) = self.get_op_module_name(name.clone(), Fixity::In)
{
if mod_name == module.module_decl.name {
self.op_dir().remove(&(name.clone(), Fixity::In));
}
}
} else if arity == 1 {
if let Some((_, _, mod_name)) = self.op_dir().get(&(name.clone(), Fixity::Pre)).cloned()
if let Some(mod_name) = self.get_op_module_name(name.clone(), Fixity::Pre)
{
if mod_name == module.module_decl.name {
self.op_dir().remove(&(name.clone(), Fixity::Pre));
}
}
if let Some((_, _, mod_name)) = self.op_dir().get(&(name.clone(), Fixity::Post)).cloned()
if let Some(mod_name) = self.get_op_module_name(name.clone(), Fixity::Post)
{
if mod_name == module.module_decl.name {
self.op_dir().remove(&(name.clone(), Fixity::Post));

View File

@@ -570,8 +570,8 @@ impl MachineState {
}
},
&SystemClauseType::OpDeclaration => {
let priority = self[temp_v!(1)].clone();
let specifier = self[temp_v!(2)].clone();
let priority = self[temp_v!(1)].clone();
let specifier = self[temp_v!(2)].clone();
let op = self[temp_v!(3)].clone();
let priority = match self.store(self.deref(priority)) {
@@ -599,8 +599,8 @@ impl MachineState {
if op_decl.0 == 0 {
Ok(op_decl.remove(&mut indices.op_dir))
} else {
let desc = get_desc(op_decl.name(), composite_op!(&indices.op_dir));
op_decl.submit(module, desc, &mut indices.op_dir)
let spec = get_desc(op_decl.name(), composite_op!(&indices.op_dir));
op_decl.submit(module, spec, &mut indices.op_dir)
}
});

View File

@@ -58,16 +58,16 @@ impl<'a, 'b> CompositeIndices<'a, 'b>
}
}
fn get_clause_type(&mut self, name: ClauseName, arity: usize, spec: Option<(usize, Specifier)>) -> ClauseType
fn get_clause_type(&mut self, name: ClauseName, arity: usize, spec: Option<SharedOpDesc>) -> ClauseType
{
match ClauseType::from(name, arity, spec) {
ClauseType::Named(name, arity, _) => {
let idx = self.get_code_index(name.clone(), arity);
ClauseType::Named(name, arity, idx.clone())
},
ClauseType::Op(op_decl, _) => {
let idx = self.get_code_index(op_decl.2.clone(), arity);
ClauseType::Op(op_decl, idx.clone())
ClauseType::Op(name, spec, _) => {
let idx = self.get_code_index(name.clone(), arity);
ClauseType::Op(name, spec, idx.clone())
},
ct => ct
}
@@ -741,8 +741,8 @@ impl RelationWorker {
self.dynamic_clauses.extend(other.dynamic_clauses.into_iter());
}
fn expand_queue_contents<'a, R>(&mut self, term_stream: &mut TermStream<'a, R>, op_dir: &OpDir)
-> Result<(), SessionError>
fn expand_queue_contents<R>(&mut self, term_stream: &mut TermStream<R>, op_dir: &OpDir)
-> Result<(), SessionError>
where R: Read
{
let mut machine_st = MachineState::new();
@@ -762,8 +762,8 @@ impl RelationWorker {
}
}
fn term_to_toplevel<'a, R>(term_stream: &mut TermStream<'a, R>, code_dir: &mut CodeDir, term: Term)
-> Result<(TopLevel, RelationWorker), ParserError>
fn term_to_toplevel<R>(term_stream: &mut TermStream<R>, code_dir: &mut CodeDir, term: Term)
-> Result<(TopLevel, RelationWorker), ParserError>
where R: Read
{
let mut rel_worker = RelationWorker::new();

View File

@@ -135,7 +135,7 @@ impl fmt::Display for ClauseType {
&ClauseType::System(SystemClauseType::SetCutPoint(r)) =>
write!(f, "$set_cp({})", r),
&ClauseType::Named(ref name, _, ref idx)
| &ClauseType::Op(OpDecl(.., ref name), ref idx) =>
| &ClauseType::Op(ref name, _, ref idx) =>
{
let idx = idx.0.borrow();
write!(f, "{}:{}/{}", idx.1, name, idx.0)
@@ -150,9 +150,9 @@ impl fmt::Display for HeapCellValue {
match self {
&HeapCellValue::Addr(ref addr) =>
write!(f, "{}", addr),
&HeapCellValue::NamedStr(arity, ref name, Some((priority, spec))) =>
&HeapCellValue::NamedStr(arity, ref name, Some(ref cell)) =>
write!(f, "{}/{} (op, priority: {}, spec: {})", name.as_str(), arity,
priority, spec),
cell.prec(), cell.assoc()),
&HeapCellValue::NamedStr(arity, ref name, None) =>
write!(f, "{}/{}", name.as_str(), arity)
}