},
QueryTermRef::Catch(_) =>
compiled_query.push(Line::Control(ControlInstruction::CatchCall)),
+ QueryTermRef::IsAtomic(_) =>
+ compiled_query.push(proceed!()),
+ QueryTermRef::IsVar(_) =>
+ compiled_query.push(proceed!()),
QueryTermRef::Term(&Term::Constant(_, Constant::Atom(ref atom))) => {
let call = ControlInstruction::Call(atom.clone(), 0, pvs);
compiled_query.push(Line::Control(call));
if let &mut Line::Control(ref mut ctrl) = code.last_mut().unwrap() {
*ctrl = ControlInstruction::ThrowExecute;
},
+ QueryTermRef::IsAtomic(_) => {
+ dealloc_index = code.len();
+ code.push(proceed!());
+ },
+ QueryTermRef::IsVar(_) => {
+ dealloc_index = code.len();
+ code.push(proceed!());
+ },
_ => dealloc_index = code.len()
};
Line::Cut(CutInstruction::Cut(Terminal::Terminal))
});
},
- &QueryTermRef::IsAtomic(term) =>
- match term {
+ &QueryTermRef::IsAtomic(inner_term) =>
+ match inner_term {
&Term::AnonVar | &Term::Clause(_, _, _) | &Term::Cons(_, _, _) => {
code.push(fail!()); //goto!(61, 0)); // goto false/0.
},
&Term::Var(ref vr, ref name) => {
let mut target = Vec::new();
+ self.marker.advance(term_loc, *term); // reset self.marker.arg_c to 1.
self.marker.mark_var(name, Level::Shallow, vr, term_loc, &mut target);
code.push(Line::Query(target));
code.push(is_atomic!(vr.get().norm()));
}
},
- &QueryTermRef::IsVar(term) =>
- match term {
+ &QueryTermRef::IsVar(inner_term) =>
+ match inner_term {
&Term::Constant(_, _) | &Term::Clause(_, _, _) | &Term::Cons(_, _, _) => {
code.push(fail!()); //goto!(61, 0)); // goto false/0.
},
&Term::Var(ref vr, ref name) => {
let mut target = Vec::new();
+ self.marker.advance(term_loc, *term); // reset self.marker.arg_c to 1.
self.marker.mark_var(name, Level::Shallow, vr, term_loc, &mut target);
code.push(Line::Query(target));
code.push(Line::Fact(compiled_fact));
}
- let proceed = Line::Control(ControlInstruction::Proceed);
-
- code.push(proceed);
+ code.push(proceed!());
code
}
}
}
+
+impl fmt::Display for BuiltInInstruction {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ match self {
+ &BuiltInInstruction::CleanUpBlock =>
+ write!(f, "clean_up_block"),
+ &BuiltInInstruction::DuplicateTerm =>
+ write!(f, "duplicate_term X1"),
+ &BuiltInInstruction::EraseBall =>
+ write!(f, "erase_ball"),
+ &BuiltInInstruction::Fail =>
+ write!(f, "false"),
+ &BuiltInInstruction::GetBall =>
+ write!(f, "get_ball X1"),
+ &BuiltInInstruction::GetCurrentBlock =>
+ write!(f, "get_current_block X1"),
+ &BuiltInInstruction::InstallNewBlock =>
+ write!(f, "install_new_block"),
+ &BuiltInInstruction::InternalCallN =>
+ write!(f, "internal_call_N"),
+ &BuiltInInstruction::IsAtomic(r) =>
+ write!(f, "is_atomic {}", r),
+ &BuiltInInstruction::IsVar(r) =>
+ write!(f, "is_var {}", r),
+ &BuiltInInstruction::ResetBlock =>
+ write!(f, "reset_block"),
+ &BuiltInInstruction::SetBall =>
+ write!(f, "set_ball"),
+ &BuiltInInstruction::Succeed =>
+ write!(f, "true"),
+ &BuiltInInstruction::Unify =>
+ write!(f, "unify"),
+ &BuiltInInstruction::UnwindStack =>
+ write!(f, "unwind_stack")
+ }
+ }
+}
+
impl fmt::Display for ChoiceInstruction {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
for fact_instr in fact {
println!("{}", fact_instr);
},
- &Line::BuiltIn(_) => {},
+ &Line::BuiltIn(ref instr) =>
+ println!("{}", instr),
&Line::Cut(ref cut) =>
println!("{}", cut),
&Line::Choice(ref choice) =>