@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "scryer-prolog"
|
||||
version = "0.8.52"
|
||||
version = "0.8.53"
|
||||
authors = ["Mark Thom <markjordanthom@gmail.com>"]
|
||||
repository = "https://github.com/mthom/scryer-prolog"
|
||||
description = "A modern Prolog implementation written mostly in Rust."
|
||||
|
||||
@@ -438,7 +438,7 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter>
|
||||
} else { // if is_infix!(spec.assoc())
|
||||
match ct.name().as_str() {
|
||||
"|" => {
|
||||
self.format_infix_op_with_space(ct.name(), spec);
|
||||
self.format_bar_separator_op_with_space(ct.name(), spec);
|
||||
return;
|
||||
},
|
||||
_ => {}
|
||||
@@ -477,13 +477,12 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter>
|
||||
self.state_stack.push(TokenOrRedirect::Atom(name));
|
||||
}
|
||||
|
||||
fn format_infix_op_with_space(&mut self, name: ClauseName, spec: SharedOpDesc)
|
||||
fn format_bar_separator_op_with_space(&mut self, name: ClauseName, spec: SharedOpDesc)
|
||||
{
|
||||
let left_directed_op = DirectedOp::Left(name.clone(), spec.clone());
|
||||
let right_directed_op = DirectedOp::Right(name.clone(), spec.clone());
|
||||
|
||||
self.state_stack.push(TokenOrRedirect::CompositeRedirect(left_directed_op));
|
||||
// self.state_stack.push(TokenOrRedirect::Op(name.clone(), spec));
|
||||
self.state_stack.push(TokenOrRedirect::HeadTailSeparator);
|
||||
self.state_stack.push(TokenOrRedirect::CompositeRedirect(right_directed_op));
|
||||
}
|
||||
@@ -516,7 +515,7 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter>
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if let Some(spec) = ct.spec() {
|
||||
if "." == ct.name().as_str() && is_infix!(spec.assoc()) {
|
||||
if !self.ignore_ops {
|
||||
|
||||
@@ -123,7 +123,6 @@ fn compile_query(terms: Vec<QueryTerm>, queue: VecDeque<TopLevel>, flags: Machin
|
||||
let mut code = try!(cg.compile_query(&terms));
|
||||
|
||||
compile_appendix(&mut code, &queue, false, flags)?;
|
||||
|
||||
Ok((code, cg.take_vars()))
|
||||
}
|
||||
|
||||
|
||||
@@ -615,7 +615,7 @@ pub(crate) trait CallPolicy: Any {
|
||||
return_from_clause!(machine_st.last_call, machine_st)
|
||||
},
|
||||
&BuiltInClauseType::Functor => {
|
||||
machine_st.try_functor()?;
|
||||
machine_st.try_functor(&indices.op_dir)?;
|
||||
return_from_clause!(machine_st.last_call, machine_st)
|
||||
},
|
||||
&BuiltInClauseType::NotEq => {
|
||||
|
||||
@@ -191,7 +191,7 @@ impl MachineState {
|
||||
-> Outputter
|
||||
where Outputter: HCValueOutputter
|
||||
{
|
||||
let orig_len = output.len();
|
||||
let orig_len = output.len();
|
||||
|
||||
output.begin_new_var();
|
||||
|
||||
@@ -2027,7 +2027,7 @@ impl MachineState {
|
||||
self.try_functor_unify_components(name, arity);
|
||||
}
|
||||
|
||||
pub(super) fn try_functor(&mut self) -> CallResult {
|
||||
pub(super) fn try_functor(&mut self, op_dir: &OpDir) -> CallResult {
|
||||
let stub = MachineError::functor_stub(clause_name!("functor"), 3);
|
||||
let a1 = self.store(self.deref(self[temp_v!(1)].clone()));
|
||||
|
||||
@@ -2042,8 +2042,11 @@ impl MachineState {
|
||||
self.try_functor_compound_case(name, arity, spec),
|
||||
_ => self.fail = true
|
||||
},
|
||||
Addr::Lis(_) =>
|
||||
self.try_functor_compound_case(clause_name!("."), 2, None),
|
||||
Addr::Lis(_) => {
|
||||
let shared_op_desc = op_dir.get(&(clause_name!("."), Fixity::In))
|
||||
.map(|val| val.0.clone());
|
||||
self.try_functor_compound_case(clause_name!("."), 2, shared_op_desc)
|
||||
},
|
||||
Addr::AttrVar(..) | Addr::HeapCell(_) | Addr::StackCell(..) => {
|
||||
let name = self.store(self.deref(self[temp_v!(2)].clone()));
|
||||
let arity = self.store(self.deref(self[temp_v!(3)].clone()));
|
||||
|
||||
@@ -208,13 +208,13 @@ impl Machine {
|
||||
compile_user_module(self, parsing_stream(ASSOC.as_bytes()));
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[cfg(test)]
|
||||
pub fn reset(&mut self) {
|
||||
self.prolog_stream = readline::input_stream();
|
||||
self.policies.cut_policy = Box::new(DefaultCutPolicy {});
|
||||
self.machine_st.reset();
|
||||
}
|
||||
|
||||
|
||||
pub fn run_toplevel(&mut self) {
|
||||
self.machine_st.p = CodePtr::Local(LocalCodePtr::DirEntry(self.toplevel_idx));
|
||||
self.run_query(&AllocVarDict::new(), &mut HeapVarDict::new());
|
||||
@@ -413,7 +413,7 @@ impl Machine {
|
||||
};
|
||||
}
|
||||
|
||||
let term_output = self.machine_st.print_with_locs(term, &var_dict);
|
||||
let term_output = self.machine_st.print_query(term, &var_dict);
|
||||
term_output.result()
|
||||
},
|
||||
Err(err_stub) => {
|
||||
@@ -496,7 +496,7 @@ impl Machine {
|
||||
EvalSession::QueryFailure => {
|
||||
write!(raw_stdout, "false.\r\n").unwrap();
|
||||
raw_stdout.flush().unwrap();
|
||||
|
||||
|
||||
self.machine_st.absorb_snapshot(snapshot);
|
||||
return;
|
||||
},
|
||||
@@ -525,10 +525,10 @@ impl Machine {
|
||||
EvalSession::QueryFailure =>
|
||||
if self.machine_st.ball.stub.len() > 0 {
|
||||
let ball = self.machine_st.ball.take();
|
||||
|
||||
|
||||
self.machine_st.absorb_snapshot(snapshot);
|
||||
self.machine_st.ball = ball;
|
||||
|
||||
|
||||
let stub = self.machine_st.copy_and_align_ball();
|
||||
self.machine_st.throw_exception(stub);
|
||||
|
||||
@@ -654,6 +654,23 @@ impl Machine {
|
||||
|
||||
|
||||
impl MachineState {
|
||||
fn print_query(&self, addr: Addr, var_dict: &HeapVarDict) -> PrinterOutputter
|
||||
{
|
||||
let output = PrinterOutputter::new();
|
||||
let mut printer = HCPrinter::from_heap_locs(&self, output, var_dict);
|
||||
|
||||
printer.quoted = true;
|
||||
printer.numbervars = false;
|
||||
printer.drop_toplevel_spec();
|
||||
|
||||
printer.see_all_locs();
|
||||
|
||||
let mut output = printer.print(addr);
|
||||
|
||||
output.push_char('.');
|
||||
output
|
||||
}
|
||||
|
||||
fn execute_instr(&mut self, indices: &mut IndexStore, policies: &mut MachinePolicies,
|
||||
code_repo: &CodeRepo, prolog_stream: &mut PrologStream)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user