fix '$get_clause_p' whose old implementation was broken by the introduction

of lookahead indexing
This commit is contained in:
Mark
2023-12-18 09:52:46 -07:00
parent 30f3818c66
commit b943afb7c7
2 changed files with 68 additions and 102 deletions

View File

@@ -925,8 +925,8 @@ impl Machine {
self.machine_st.hb = self.machine_st.heap.len(); self.machine_st.hb = self.machine_st.heap.len();
self.machine_st.oip = 0; // self.machine_st.oip = 0;
self.machine_st.iip = 0; // self.machine_st.iip = 0;
} }
self.machine_st.p += offset; self.machine_st.p += offset;
@@ -1010,8 +1010,8 @@ impl Machine {
self.machine_st.heap.truncate(target_h); self.machine_st.heap.truncate(target_h);
self.machine_st.oip = 0; // self.machine_st.oip = 0;
self.machine_st.iip = 0; // self.machine_st.iip = 0;
} else { } else {
self.trust_epilogue(offset); self.trust_epilogue(offset);
} }
@@ -1059,8 +1059,13 @@ impl Machine {
self.machine_st.stack.truncate(b); self.machine_st.stack.truncate(b);
self.machine_st.heap.truncate(target_h); self.machine_st.heap.truncate(target_h);
self.machine_st.oip = 0; // these registers don't need to be reset here and MUST NOT be
self.machine_st.iip = 0; // (nor in indexed_try to trust_epilogue)! oip could be reset
// without any adverse effects but iip is needed by
// get_clause_p to find the last executed clause/2 clause.
// self.machine_st.oip = 0;
// self.machine_st.iip = 0;
} }
#[inline(always)] #[inline(always)]

View File

@@ -1171,37 +1171,6 @@ impl Machine {
.get_predicate_skeleton(&compilation_target, &key) .get_predicate_skeleton(&compilation_target, &key)
.unwrap(); .unwrap();
if self.machine_st.b > self.machine_st.e {
let or_frame = self.machine_st.stack.index_or_frame(self.machine_st.b);
let bp = or_frame.prelude.bp;
match &self.code[bp] {
Instruction::IndexingCode(ref indexing_code) => {
match &indexing_code[or_frame.prelude.boip as usize] {
IndexingLine::IndexedChoice(ref indexed_choice) => {
let p = or_frame.prelude.biip as usize - 1;
match &indexed_choice[p] {
&IndexedChoiceInstruction::Try(offset)
| &IndexedChoiceInstruction::Retry(offset)
| &IndexedChoiceInstruction::DefaultRetry(offset) => {
let clause_clause_loc = skeleton.core.clause_clause_locs[p];
(clause_clause_loc, bp + offset)
}
&IndexedChoiceInstruction::Trust(_)
| &IndexedChoiceInstruction::DefaultTrust(_) => {
unreachable!()
}
}
}
_ => {
unreachable!()
}
}
}
_ => unreachable!(),
}
} else {
let module_name = match compilation_target { let module_name = match compilation_target {
CompilationTarget::User => atom!("builtins"), CompilationTarget::User => atom!("builtins"),
CompilationTarget::Module(target) => target, CompilationTarget::Module(target) => target,
@@ -1213,6 +1182,8 @@ impl Machine {
.and_then(|idx| idx.local()) .and_then(|idx| idx.local())
.unwrap(); .unwrap();
let p = self.machine_st.iip as usize;
macro_rules! extract_ptr { macro_rules! extract_ptr {
($ptr: expr) => { ($ptr: expr) => {
match $ptr { match $ptr {
@@ -1231,13 +1202,7 @@ impl Machine {
match &self.code[bp] { match &self.code[bp] {
Instruction::IndexingCode(ref indexing_code) => { Instruction::IndexingCode(ref indexing_code) => {
let indexing_code_ptr = match &indexing_code[0] { let indexing_code_ptr = match &indexing_code[0] {
&IndexingLine::Indexing(IndexingInstruction::SwitchOnTerm( &IndexingLine::Indexing(IndexingInstruction::SwitchOnTerm(_, _, c, _, s)) => {
_,
_,
c,
_,
s,
)) => {
if key.1 > 0 { if key.1 > 0 {
s s
} else { } else {
@@ -1264,19 +1229,15 @@ impl Machine {
match &indexing_code[boip] { match &indexing_code[boip] {
IndexingLine::IndexedChoice(indexed_choice) => { IndexingLine::IndexedChoice(indexed_choice) => {
return ( return (
skeleton.core.clause_clause_locs.back().cloned().unwrap(), skeleton.core.clause_clause_locs[p],
bp + indexed_choice.back().unwrap().offset(), bp + indexed_choice[p].offset(),
); );
} }
_ => unreachable!(), _ => unreachable!(),
} }
} }
_ => { _ => {
return ( return (skeleton.core.clause_clause_locs[p], bp);
skeleton.core.clause_clause_locs.back().cloned().unwrap(),
bp,
);
}
} }
} }
} }