re: #73
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "scryer-prolog"
|
||||
version = "0.8.24"
|
||||
version = "0.8.25"
|
||||
authors = ["Mark Thom <markjordanthom@gmail.com>"]
|
||||
repository = "https://github.com/mthom/scryer-prolog"
|
||||
description = "A modern Prolog implementation written mostly in Rust."
|
||||
@@ -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.4"
|
||||
prolog_parser = "0.8.5"
|
||||
readline_rs_compat = { version = "0.1.7", optional = true }
|
||||
ref_thread_local = "0.0.0"
|
||||
|
||||
|
||||
@@ -181,11 +181,7 @@ impl HCValueOutputter for PrinterOutputter {
|
||||
|
||||
#[inline]
|
||||
fn is_numbered_var(ct: &ClauseType, arity: usize) -> bool {
|
||||
arity == 1 && if let &ClauseType::Named(ref name, ..) = ct {
|
||||
name.as_str() == "$VAR"
|
||||
} else {
|
||||
false
|
||||
}
|
||||
arity == 1 && ct.name().as_str() == "$VAR"
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -435,26 +431,40 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter>
|
||||
self.state_stack.push(TokenOrRedirect::LeftCurly);
|
||||
}
|
||||
|
||||
fn format_numbered_vars(&mut self, iter: &mut HCPreOrderIterator) -> bool
|
||||
{
|
||||
let addr = iter.stack().last().cloned().unwrap();
|
||||
|
||||
// 7.10.4
|
||||
if let Some(var) = iter.machine_st().numbervar(&self.numbervars_offset, addr) {
|
||||
iter.stack().pop();
|
||||
self.state_stack.push(TokenOrRedirect::NumberedVar(var));
|
||||
return true;
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
fn format_clause(&mut self, iter: &mut HCPreOrderIterator, arity: usize, ct: ClauseType)
|
||||
{
|
||||
if let Some(spec) = ct.spec() {
|
||||
if self.numbervars && is_numbered_var(&ct, arity) {
|
||||
if self.format_numbered_vars(iter) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if !self.ignore_ops {
|
||||
return self.enqueue_op(ct, spec);
|
||||
}
|
||||
} else if self.numbervars && is_numbered_var(&ct, arity) {
|
||||
let addr = iter.stack().last().cloned().unwrap();
|
||||
|
||||
// 7.10.4
|
||||
if let Some(var) = iter.machine_st().numbervar(&self.numbervars_offset, addr) {
|
||||
iter.stack().pop();
|
||||
self.state_stack.push(TokenOrRedirect::NumberedVar(var));
|
||||
if self.format_numbered_vars(iter) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
match (ct.name().as_str(), arity) {
|
||||
("-", 1) => self.format_negated_operand(),
|
||||
("{}", 1) => self.format_curly_braces(),
|
||||
("{}", 1) if !self.ignore_ops => self.format_curly_braces(),
|
||||
_ => self.format_struct(arity, ct.name())
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1747,7 +1747,7 @@ impl MachineState {
|
||||
(HeapCellValue::Addr(Addr::Lis(_)), HeapCellValue::Addr(Addr::Lis(_))) =>
|
||||
continue,
|
||||
(HeapCellValue::Addr(Addr::Lis(_)), HeapCellValue::NamedStr(ar, n, _))
|
||||
| (HeapCellValue::NamedStr(ar, n, _), HeapCellValue::Addr(Addr::Lis(_))) =>
|
||||
| (HeapCellValue::NamedStr(ar, n, _), HeapCellValue::Addr(Addr::Lis(_))) =>
|
||||
if ar == 2 && n.as_str() == "." {
|
||||
continue;
|
||||
} else if ar < 2 {
|
||||
@@ -1932,12 +1932,12 @@ impl MachineState {
|
||||
match name {
|
||||
Addr::Con(_) if arity == 0 =>
|
||||
self.unify(a1, name),
|
||||
Addr::Con(Constant::Atom(name, _)) => {
|
||||
Addr::Con(Constant::Atom(name, spec)) => {
|
||||
let f_a = if name.as_str() == "." && arity == 2 {
|
||||
Addr::Lis(self.heap.h)
|
||||
} else {
|
||||
let h = self.heap.h;
|
||||
self.heap.push(HeapCellValue::NamedStr(arity as usize, name, None));
|
||||
self.heap.push(HeapCellValue::NamedStr(arity as usize, name, spec));
|
||||
Addr::Str(h)
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user