add proceed to close out inlined atomic and var
This commit is contained in:
@@ -214,6 +214,10 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator<'a, TermMarker>
|
||||
},
|
||||
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));
|
||||
@@ -252,6 +256,14 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator<'a, TermMarker>
|
||||
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()
|
||||
};
|
||||
|
||||
@@ -288,8 +300,8 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator<'a, TermMarker>
|
||||
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.
|
||||
},
|
||||
@@ -299,14 +311,15 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator<'a, TermMarker>
|
||||
&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.
|
||||
},
|
||||
@@ -316,6 +329,7 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator<'a, TermMarker>
|
||||
&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));
|
||||
@@ -441,9 +455,7 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator<'a, TermMarker>
|
||||
code.push(Line::Fact(compiled_fact));
|
||||
}
|
||||
|
||||
let proceed = Line::Control(ControlInstruction::Proceed);
|
||||
|
||||
code.push(proceed);
|
||||
code.push(proceed!());
|
||||
code
|
||||
}
|
||||
|
||||
|
||||
@@ -124,6 +124,44 @@ impl fmt::Display for IndexedChoiceInstruction {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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 {
|
||||
@@ -202,7 +240,8 @@ pub fn print_code(code: &Code) {
|
||||
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) =>
|
||||
|
||||
Reference in New Issue
Block a user