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