remove GetLevelAndUnify and replace it with GetCutPoint
This commit is contained in:
@@ -639,8 +639,6 @@ enum InstructionTemplate {
|
|||||||
Cut(RegType),
|
Cut(RegType),
|
||||||
#[strum_discriminants(strum(props(Arity = "1", Name = "get_level")))]
|
#[strum_discriminants(strum(props(Arity = "1", Name = "get_level")))]
|
||||||
GetLevel(RegType),
|
GetLevel(RegType),
|
||||||
#[strum_discriminants(strum(props(Arity = "1", Name = "get_level_and_unify")))]
|
|
||||||
GetLevelAndUnify(RegType),
|
|
||||||
#[strum_discriminants(strum(props(Arity = "0", Name = "neck_cut")))]
|
#[strum_discriminants(strum(props(Arity = "0", Name = "neck_cut")))]
|
||||||
NeckCut,
|
NeckCut,
|
||||||
// choice instruction
|
// choice instruction
|
||||||
@@ -1298,10 +1296,6 @@ fn generate_instruction_preface() -> TokenStream {
|
|||||||
let rt_stub = reg_type_into_functor(r);
|
let rt_stub = reg_type_into_functor(r);
|
||||||
functor!(atom!("get_level"), [str(h, 0)], [rt_stub])
|
functor!(atom!("get_level"), [str(h, 0)], [rt_stub])
|
||||||
}
|
}
|
||||||
&Instruction::GetLevelAndUnify(r) => {
|
|
||||||
let rt_stub = reg_type_into_functor(r);
|
|
||||||
functor!(atom!("get_level_and_unify"), [str(h, 0)], [rt_stub])
|
|
||||||
}
|
|
||||||
&Instruction::NeckCut => {
|
&Instruction::NeckCut => {
|
||||||
functor!(atom!("neck_cut"))
|
functor!(atom!("neck_cut"))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -840,25 +840,6 @@ impl<'b> CodeGenerator<'b> {
|
|||||||
code.push(instr!("$set_cp", cell.get().norm(), 0));
|
code.push(instr!("$set_cp", cell.get().norm(), 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compile_get_level_and_unify(
|
|
||||||
&mut self,
|
|
||||||
code: &mut Code,
|
|
||||||
cell: &Cell<VarReg>,
|
|
||||||
var: Var,
|
|
||||||
term_loc: GenContext,
|
|
||||||
) {
|
|
||||||
let mut target = Code::new();
|
|
||||||
|
|
||||||
self.marker.reset_arg(1);
|
|
||||||
self.marker.mark_var::<QueryInstruction>(var, Level::Shallow, cell, term_loc, &mut target);
|
|
||||||
|
|
||||||
if !target.is_empty() {
|
|
||||||
code.extend(target.into_iter());
|
|
||||||
}
|
|
||||||
|
|
||||||
code.push(instr!("get_level_and_unify", cell.get().norm()));
|
|
||||||
}
|
|
||||||
|
|
||||||
fn compile_seq<'a>(
|
fn compile_seq<'a>(
|
||||||
&mut self,
|
&mut self,
|
||||||
iter: ChunkedIterator<'a>,
|
iter: ChunkedIterator<'a>,
|
||||||
@@ -874,9 +855,6 @@ impl<'b> CodeGenerator<'b> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
match *term {
|
match *term {
|
||||||
&QueryTerm::GetLevelAndUnify(ref cell, ref var) => {
|
|
||||||
self.compile_get_level_and_unify(code, cell, var.clone(), term_loc)
|
|
||||||
}
|
|
||||||
&QueryTerm::UnblockedCut(ref cell) => self.compile_unblocked_cut(code, cell),
|
&QueryTerm::UnblockedCut(ref cell) => self.compile_unblocked_cut(code, cell),
|
||||||
&QueryTerm::BlockedCut => code.push(if chunk_num == 0 {
|
&QueryTerm::BlockedCut => code.push(if chunk_num == 0 {
|
||||||
Instruction::NeckCut
|
Instruction::NeckCut
|
||||||
|
|||||||
@@ -105,7 +105,6 @@ pub enum QueryTerm {
|
|||||||
Not(Vec<QueryTerm>),
|
Not(Vec<QueryTerm>),
|
||||||
IfThen(Vec<QueryTerm>, Vec<QueryTerm>),
|
IfThen(Vec<QueryTerm>, Vec<QueryTerm>),
|
||||||
Branch(Vec<Vec<QueryTerm>>),
|
Branch(Vec<Vec<QueryTerm>>),
|
||||||
GetLevelAndUnify(Cell<VarReg>, Var),
|
|
||||||
ChunkTypeBoundary(ChunkType),
|
ChunkTypeBoundary(ChunkType),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,7 +121,7 @@ impl QueryTerm {
|
|||||||
&QueryTerm::Clause(_, _, ref subterms, ..) => subterms.len(),
|
&QueryTerm::Clause(_, _, ref subterms, ..) => subterms.len(),
|
||||||
&QueryTerm::Cut | &QueryTerm::Branch(_) => 0,
|
&QueryTerm::Cut | &QueryTerm::Branch(_) => 0,
|
||||||
&QueryTerm::IfThen(..) => 2,
|
&QueryTerm::IfThen(..) => 2,
|
||||||
&QueryTerm::Not(_) | &QueryTerm::GetLevelAndUnify(..) => 1,
|
&QueryTerm::Not(_) => 1,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -173,10 +173,6 @@ impl<'a> QueryIterator<'a> {
|
|||||||
&QueryTerm::Cut => {
|
&QueryTerm::Cut => {
|
||||||
self.state_stack.push(TermIterState::Cut(lvl));
|
self.state_stack.push(TermIterState::Cut(lvl));
|
||||||
}
|
}
|
||||||
&QueryTerm::GetLevelAndUnify(ref cell, ref var) => {
|
|
||||||
// TODO: get rid of it if possible. or! specialized TermIterState variant.
|
|
||||||
self.state_stack.push(TermIterState::Var(lvl, cell, VarPtr::from(var)));
|
|
||||||
}
|
|
||||||
&QueryTerm::Not(ref terms) => {
|
&QueryTerm::Not(ref terms) => {
|
||||||
self.state_stack.push(TermIterState::Fail(lvl));
|
self.state_stack.push(TermIterState::Fail(lvl));
|
||||||
self.state_stack.push(TermIterState::Cut(lvl));
|
self.state_stack.push(TermIterState::Cut(lvl));
|
||||||
@@ -521,11 +517,6 @@ impl<'a> ChunkedIterator<'a> {
|
|||||||
ChunkedTerm::BodyTerm(&QueryTerm::Cut) => {
|
ChunkedTerm::BodyTerm(&QueryTerm::Cut) => {
|
||||||
result.push(term);
|
result.push(term);
|
||||||
}
|
}
|
||||||
ChunkedTerm::BodyTerm(&QueryTerm::GetLevelAndUnify(..)) => {
|
|
||||||
result.push(term);
|
|
||||||
arity = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
ChunkedTerm::BodyTerm(&QueryTerm::Clause(_, ClauseType::Inlined(_), ..)) => {
|
ChunkedTerm::BodyTerm(&QueryTerm::Clause(_, ClauseType::Inlined(_), ..)) => {
|
||||||
result.push(term);
|
result.push(term);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ scc_helper(_, _, _) :-
|
|||||||
|
|
||||||
run_cleaners_with_handling :-
|
run_cleaners_with_handling :-
|
||||||
'$get_scc_cleaner'(C),
|
'$get_scc_cleaner'(C),
|
||||||
'$get_level'(B),
|
'$get_cp'(B),
|
||||||
catch(C, _, true),
|
catch(C, _, true),
|
||||||
'$set_cp_by_default'(B),
|
'$set_cp_by_default'(B),
|
||||||
run_cleaners_with_handling.
|
run_cleaners_with_handling.
|
||||||
@@ -186,7 +186,7 @@ run_cleaners_with_handling :-
|
|||||||
|
|
||||||
run_cleaners_without_handling(Cp) :-
|
run_cleaners_without_handling(Cp) :-
|
||||||
'$get_scc_cleaner'(C),
|
'$get_scc_cleaner'(C),
|
||||||
'$get_level'(B),
|
'$get_cp'(B),
|
||||||
call(C),
|
call(C),
|
||||||
'$set_cp_by_default'(B),
|
'$set_cp_by_default'(B),
|
||||||
run_cleaners_without_handling(Cp).
|
run_cleaners_without_handling(Cp).
|
||||||
@@ -258,7 +258,7 @@ call_with_inference_limit(_, _, R, Bb, B) :-
|
|||||||
'$remove_inference_counter'(B, _),
|
'$remove_inference_counter'(B, _),
|
||||||
( '$get_ball'(Ball),
|
( '$get_ball'(Ball),
|
||||||
'$push_ball_stack',
|
'$push_ball_stack',
|
||||||
'$get_level'(Cp),
|
'$get_cp'(Cp),
|
||||||
'$set_cp_by_default'(Cp)
|
'$set_cp_by_default'(Cp)
|
||||||
; '$remove_call_policy_check'(B),
|
; '$remove_call_policy_check'(B),
|
||||||
'$fail'
|
'$fail'
|
||||||
|
|||||||
@@ -566,7 +566,7 @@ impl VariableClassifier {
|
|||||||
|
|
||||||
let build_stack_len = build_stack.len();
|
let build_stack_len = build_stack.len();
|
||||||
|
|
||||||
// TODO: insert GetLevelAndUnify between
|
// TODO: insert GetCutPoint between
|
||||||
// the two traversal states and detect
|
// the two traversal states and detect
|
||||||
// that as a chunk boundary in
|
// that as a chunk boundary in
|
||||||
// insert_set_last_chunk_type ??
|
// insert_set_last_chunk_type ??
|
||||||
@@ -587,22 +587,6 @@ impl VariableClassifier {
|
|||||||
state_stack.push(TraversalState::BuildNot(build_stack_len));
|
state_stack.push(TraversalState::BuildNot(build_stack_len));
|
||||||
state_stack.push(TraversalState::Term(terms[0]));
|
state_stack.push(TraversalState::Term(terms[0]));
|
||||||
}
|
}
|
||||||
Term::Clause(_, atom!("$get_level"), terms) if terms.len() == 1 => {
|
|
||||||
state_stack.push(TraversalState::IncrChunkNum);
|
|
||||||
|
|
||||||
// TODO: need to classify this variable?
|
|
||||||
// what is the difference between $get_cp and this exactly?
|
|
||||||
if let Term::Var(_, ref var) = &terms[0] {
|
|
||||||
build_stack.push(
|
|
||||||
QueryTerm::GetLevelAndUnify(
|
|
||||||
Cell::default(),
|
|
||||||
var.clone(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return Err(CompilationError::InadmissibleQueryTerm);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Term::Clause(_, atom!(":"), mut terms) if terms.len() == 2 => {
|
Term::Clause(_, atom!(":"), mut terms) if terms.len() == 2 => {
|
||||||
let term_loc = chunk_type.to_gen_context(self.current_chunk_num);
|
let term_loc = chunk_type.to_gen_context(self.current_chunk_num);
|
||||||
|
|
||||||
|
|||||||
@@ -1152,17 +1152,6 @@ impl Machine {
|
|||||||
self.machine_st[r] = fixnum_as_cell!(Fixnum::build_with(b0 as i64));
|
self.machine_st[r] = fixnum_as_cell!(Fixnum::build_with(b0 as i64));
|
||||||
self.machine_st.p += 1;
|
self.machine_st.p += 1;
|
||||||
}
|
}
|
||||||
&Instruction::GetLevelAndUnify(r) => {
|
|
||||||
// let b0 = self.machine_st[perm_v!(1)];
|
|
||||||
let b0 = cell_as_fixnum!(
|
|
||||||
self.machine_st.stack[stack_loc!(AndFrame, self.machine_st.e, 1)]
|
|
||||||
);
|
|
||||||
let a = self.machine_st.store(self.machine_st.deref(self.machine_st[r]));
|
|
||||||
|
|
||||||
// unify_fn!(&mut self.machine_st, a, b0);
|
|
||||||
self.machine_st.unify_fixnum(b0, a);
|
|
||||||
step_or_fail!(self, self.machine_st.p += 1);
|
|
||||||
}
|
|
||||||
&Instruction::Cut(r) => {
|
&Instruction::Cut(r) => {
|
||||||
let value = self.machine_st[r];
|
let value = self.machine_st[r];
|
||||||
self.machine_st.cut_body(value);
|
self.machine_st.cut_body(value);
|
||||||
|
|||||||
Reference in New Issue
Block a user