From: Mark Thom Date: Thu, 11 Feb 2021 22:38:16 +0000 (-0700) Subject: offset SwitchOnTerm's Internal indices only if the proper instructions were emitted X-Git-Tag: v0.9.0~150^2~57 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=170a71bd029e3a21d311c0fba9a2c45fc9e29022;p=scryer-prolog.git offset SwitchOnTerm's Internal indices only if the proper instructions were emitted --- diff --git a/src/indexing.rs b/src/indexing.rs index 90f1b2b3..6e1cdc85 100644 --- a/src/indexing.rs +++ b/src/indexing.rs @@ -848,7 +848,7 @@ fn second_level_index( } fn switch_on( - instr_fn: impl Fn(IndexMap) -> IndexingInstruction, + mut instr_fn: impl FnMut(IndexMap) -> IndexingInstruction, index: IndexMap>, prelude: &mut SliceDeque, ) -> IndexingCodePtr { @@ -1083,31 +1083,40 @@ impl CodeOffsets { let mut prelude = sdeq![]; + let mut emitted_switch_on_structure = false; + let mut emitted_switch_on_constant = false; + let mut lst_loc = switch_on_list(self.lists, &mut prelude); let mut str_loc = switch_on( - IndexingInstruction::SwitchOnStructure, + |index| { + emitted_switch_on_structure = true; + IndexingInstruction::SwitchOnStructure(index) + }, self.structures, &mut prelude, ); let con_loc = switch_on( - IndexingInstruction::SwitchOnConstant, + |index| { + emitted_switch_on_constant = true; + IndexingInstruction::SwitchOnConstant(index) + }, self.constants, &mut prelude, ); match &mut str_loc { IndexingCodePtr::Internal(ref mut i) => { - *i += con_loc.is_internal() as usize; + *i += emitted_switch_on_constant as usize; // con_loc.is_internal() as usize; } _ => {} }; match &mut lst_loc { IndexingCodePtr::Internal(ref mut i) => { - *i += con_loc.is_internal() as usize; - *i += str_loc.is_internal() as usize; + *i += emitted_switch_on_constant as usize; // con_loc.is_internal() as usize; + *i += emitted_switch_on_structure as usize; // str_loc.is_internal() as usize; } _ => {} };