* `atomic/1`
* `call/N` (1 <= N <= 63)
* `catch/3`
+* `display/1`
* `duplicate_term/2`
* `false/0`
* `functor/3`
pub enum QueryTerm {
Arg(Vec<Box<Term>>),
CallN(Vec<Box<Term>>),
- Catch(Vec<Box<Term>>),
+ Catch(Vec<Box<Term>>),
Cut,
+ Display(Vec<Box<Term>>),
Functor(Vec<Box<Term>>),
Inlined(InlinedQueryTerm),
Is(Vec<Box<Term>>),
&QueryTerm::Arg(_) => 3,
&QueryTerm::Catch(_) => 3,
&QueryTerm::Throw(_) => 1,
+ &QueryTerm::Display(_) => 1,
&QueryTerm::Functor(_) => 3,
&QueryTerm::Inlined(ref term) => term.arity(),
&QueryTerm::Is(_) => 2,
CatchCall,
CatchExecute,
Deallocate,
+ DisplayCall,
+ DisplayExecute,
Execute(Rc<Atom>, usize),
ExecuteN(usize),
FunctorCall,
&ControlInstruction::Call(_, _, _) => true,
&ControlInstruction::CatchCall => true,
&ControlInstruction::CatchExecute => true,
+ &ControlInstruction::DisplayCall => true,
+ &ControlInstruction::DisplayExecute => true,
&ControlInstruction::Execute(_, _) => true,
&ControlInstruction::CallN(_) => true,
&ControlInstruction::ExecuteN(_) => true,
},
&QueryTerm::Catch(_) =>
code.push(Line::Control(ControlInstruction::CatchCall)),
+ &QueryTerm::Display(_) =>
+ code.push(Line::Control(ControlInstruction::DisplayCall)),
&QueryTerm::Functor(_) =>
code.push(Line::Control(ControlInstruction::FunctorCall)),
&QueryTerm::Inlined(_) =>
*ctrl = ControlInstruction::Execute(name, arity),
ControlInstruction::CallN(arity) =>
*ctrl = ControlInstruction::ExecuteN(arity),
+ ControlInstruction::DisplayCall =>
+ *ctrl = ControlInstruction::DisplayExecute,
ControlInstruction::FunctorCall =>
*ctrl = ControlInstruction::FunctorExecute,
ControlInstruction::CatchCall =>
pub struct DisplayFormatter {}
impl HeapCellValueFormatter for DisplayFormatter {
- fn format_clause(&self, arity: usize, name: Rc<Atom>, _: Option<Fixity>,
+ fn format_clause(&self, arity: usize, name: Rc<Atom>, fixity: Option<Fixity>,
state_stack: &mut Vec<TokenOrRedirect>)
{
- self.format_struct(arity, name, state_stack);
+ if fixity.is_some() {
+ let mut new_name = String::from("'");
+ new_name += name.as_ref();
+ new_name += "'";
+
+ let name = Rc::new(new_name);
+ self.format_struct(arity, name, state_stack);
+ } else {
+ self.format_struct(arity, name, state_stack);
+ }
}
}
&ControlInstruction::CatchCall =>
write!(f, "call_catch"),
&ControlInstruction::CatchExecute =>
- write!(f, "execute_catch"),
+ write!(f, "execute_catch"),
+ &ControlInstruction::DisplayCall =>
+ write!(f, "call_display"),
+ &ControlInstruction::DisplayExecute =>
+ write!(f, "execute_display"),
&ControlInstruction::ExecuteN(arity) =>
write!(f, "execute_N {}", arity),
&ControlInstruction::FunctorCall =>
- write!(f, "functor_call"),
+ write!(f, "call_functor"),
&ControlInstruction::FunctorExecute =>
- write!(f, "functor_execute"),
+ write!(f, "execute_functor"),
&ControlInstruction::Deallocate =>
write!(f, "deallocate"),
&ControlInstruction::Execute(ref name, arity) =>
let state = TermIterState::Clause(0, ClauseType::Catch, terms);
QueryIterator { state_stack: vec![state] }
},
+ &QueryTerm::Display(ref terms) => {
+ let state = TermIterState::Clause(0, ClauseType::Root, terms);
+ QueryIterator { state_stack: vec![state] }
+ },
&QueryTerm::Arg(ref terms)
| &QueryTerm::Functor(ref terms) => {
let state = TermIterState::Clause(0, ClauseType::Root, terms);
arity = child_terms.len();
break;
},
+ &QueryTerm::Display(_) => {
+ result.push(term);
+ arity = 1;
+ break;
+ },
&QueryTerm::Arg(_)
| &QueryTerm::Functor(_) => {
result.push(term);
use prolog::ast::*;
use prolog::builtins::*;
use prolog::copier::*;
+use prolog::heap_iter::*;
+use prolog::heap_print::*;
use prolog::num::{Integer, ToPrimitive, Zero};
use prolog::num::bigint::{BigInt, BigUint};
use prolog::num::rational::Ratio;
self.trail(r1);
}
+
+ fn print_var<Fmt>(&self, r: Ref, fmt: Fmt) -> String
+ where Fmt: HeapCellValueFormatter
+ {
+ let iter = HeapCellIterator::new(&self, r);
+ let mut printer = HeapCellPrinter::new(iter, fmt);
+
+ printer.print()
+ }
+ pub(super) fn print_term<Fmt>(&self, addr: &Addr, fmt: Fmt) -> String
+ where Fmt: HeapCellValueFormatter
+ {
+ match addr {
+ &Addr::Con(ref c) =>
+ format!("{}", c),
+ &Addr::Lis(h) | &Addr::HeapCell(h) | &Addr::Str(h) =>
+ self.print_var(Ref::HeapCell(h), fmt),
+ &Addr::StackCell(fr, sc) =>
+ self.print_var(Ref::StackCell(fr, sc), fmt)
+ }
+ }
+
fn unify(&mut self, a1: Addr, a2: Addr) {
let mut pdl = vec![a1, a2];
self.p += 1;
},
+ &ControlInstruction::DisplayCall => {
+ let result = self.print_term(&self[temp_v!(1)], DisplayFormatter {});
+ println!("{}", result);
+
+ self.p += 1;
+ },
+ &ControlInstruction::DisplayExecute => {
+ let result = self.print_term(&self[temp_v!(1)], DisplayFormatter {});
+ println!("{}", result);
+
+ self.p = self.cp;
+ },
&ControlInstruction::Execute(ref name, arity) =>
self.try_execute_predicate(code_dir, name.clone(), arity),
&ControlInstruction::ExecuteN(arity) =>
use prolog::ast::*;
use prolog::builtins::*;
use prolog::codegen::*;
-use prolog::heap_iter::*;
use prolog::heap_print::*;
use prolog::fixtures::*;
let h = self.ms.heap.h;
self.ms.copy_and_align_ball_to_heap();
- EvalSession::QueryFailureWithException(self.print_term(&Addr::HeapCell(h)))
+ let msg = self.ms.print_term(&Addr::HeapCell(h), TermFormatter {});
+
+ EvalSession::QueryFailureWithException(msg)
} else {
EvalSession::QueryFailure
}
}
}
- fn print_var(&self, r: Ref) -> String
- {
- let disp = TermFormatter {};
- let iter = HeapCellIterator::new(&self.ms, r);
-
- let mut printer = HeapCellPrinter::new(iter, disp);
-
- printer.print()
- }
-
- fn print_term(&self, addr: &Addr) -> String
- {
- match addr {
- &Addr::Con(ref c) =>
- format!("{}", c),
- &Addr::Lis(h) | &Addr::HeapCell(h) | &Addr::Str(h) =>
- self.print_var(Ref::HeapCell(h)),
- &Addr::StackCell(fr, sc) =>
- self.print_var(Ref::StackCell(fr, sc))
- }
- }
-
pub fn heap_view(&self, var_dir: &HeapVarDict) -> String {
let mut result = String::new();
result += var.as_str();
result += " = ";
- result += self.print_term(addr).as_str();
+ result += self.ms.print_term(addr, TermFormatter {}).as_str();
}
result
-Subproject commit 159f82cd836192cc1970187b67b2fb44ef7e6c68
+Subproject commit d2d6cd53af484607b89f3a979f51db66b3710c84