use crate::clause_types::*;
use crate::instructions::*;
+use crate::machine::MachineState;
use crate::machine::machine_indices::*;
+// TODO: remove this, replace with just 'Code'.
#[derive(Debug)]
pub struct CodeRepo {
pub(super) code: Code,
}
impl CodeRepo {
- #[inline]
- pub(super) fn new() -> Self {
- CodeRepo { code: Code::new() }
- }
-
- #[inline]
- pub(super) fn lookup_local_instr<'a>(&'a self, p: LocalCodePtr) -> RefOrOwned<'a, Line> {
- match p {
- LocalCodePtr::Halt => {
- // exit with the interrupt exit code.
- std::process::exit(1);
- }
- LocalCodePtr::DirEntry(p) => RefOrOwned::Borrowed(&self.code[p as usize]),
- LocalCodePtr::IndexingBuf(p, o, i) => match &self.code[p] {
- &Line::IndexingCode(ref indexing_lines) => match &indexing_lines[o] {
- &IndexingLine::IndexedChoice(ref indexed_choice_instrs) => {
- RefOrOwned::Owned(Line::IndexedChoice(indexed_choice_instrs[i]))
- }
- &IndexingLine::DynamicIndexedChoice(ref indexed_choice_instrs) => {
- RefOrOwned::Owned(Line::DynamicIndexedChoice(indexed_choice_instrs[i]))
- }
- _ => {
- unreachable!()
- }
- },
- _ => {
- unreachable!()
- }
- },
- }
- }
-
- pub(super) fn lookup_instr<'a>(
- &'a self,
- last_call: bool,
- p: &CodePtr,
- ) -> Option<RefOrOwned<'a, Line>> {
+ pub(super) fn lookup_instr<'a>(&'a self, machine_st: &MachineState, p: &CodePtr) -> Option<RefOrOwned<'a, Line>> {
match p {
&CodePtr::Local(local) => {
- return Some(self.lookup_local_instr(local));
+ return Some(self.lookup_local_instr(machine_st, local));
}
&CodePtr::REPL(..) => None,
&CodePtr::BuiltInClause(ref built_in, _) => {
ClauseType::BuiltIn(built_in.clone()),
built_in.arity(),
0,
- last_call
+ machine_st.last_call
);
Some(RefOrOwned::Owned(call_clause))
}
&CodePtr::CallN(arity, _, last_call) => {
let call_clause = call_clause!(ClauseType::CallN, arity, 0, last_call);
-
Some(RefOrOwned::Owned(call_clause))
}
&CodePtr::VerifyAttrInterrupt(p) => Some(RefOrOwned::Borrowed(&self.code[p])),
}
}
- pub(super) fn find_living_dynamic_else(
- &self,
- mut p: usize,
- cc: usize,
- ) -> Option<(usize, usize)> {
+ #[inline]
+ pub(super) fn lookup_local_instr<'a>(&'a self, machine_st: &MachineState, p: LocalCodePtr) -> RefOrOwned<'a, Line> {
+ match p {
+ LocalCodePtr::Halt => {
+ // exit with the interrupt exit code.
+ std::process::exit(1);
+ }
+ LocalCodePtr::DirEntry(p) => match &self.code[p] {
+ &Line::IndexingCode(ref indexing_lines) => {
+ match &indexing_lines[machine_st.oip as usize] {
+ &IndexingLine::IndexedChoice(ref indexed_choice_instrs) => {
+ RefOrOwned::Owned(Line::IndexedChoice(indexed_choice_instrs[machine_st.iip as usize]))
+ }
+ &IndexingLine::DynamicIndexedChoice(ref indexed_choice_instrs) => {
+ RefOrOwned::Owned(Line::DynamicIndexedChoice(indexed_choice_instrs[machine_st.iip as usize]))
+ }
+ _ => {
+ RefOrOwned::Borrowed(&self.code[p as usize])
+ }
+ }
+ }
+ _ => RefOrOwned::Borrowed(&self.code[p as usize]),
+ }
+ }
+ }
+}
+
+impl MachineState {
+ pub(super) fn find_living_dynamic_else(&self, code: &Code, mut p: usize) -> Option<(usize, usize)> {
loop {
- match &self.code[p] {
+ match &code[p] {
&Line::Choice(ChoiceInstruction::DynamicElse(
birth,
death,
NextOrFail::Next(i),
)) => {
- if birth < cc && Death::Finite(cc) <= death {
+ if birth < self.cc && Death::Finite(self.cc) <= death {
return Some((p, i));
} else if i > 0 {
p += i;
death,
NextOrFail::Fail(_),
)) => {
- if birth < cc && Death::Finite(cc) <= death {
+ if birth < self.cc && Death::Finite(self.cc) <= death {
return Some((p, 0));
} else {
return None;
death,
NextOrFail::Next(i),
)) => {
- if birth < cc && Death::Finite(cc) <= death {
+ if birth < self.cc && Death::Finite(self.cc) <= death {
return Some((p, i));
} else if i > 0 {
p += i;
death,
NextOrFail::Fail(_),
)) => {
- if birth < cc && Death::Finite(cc) <= death {
+ if birth < self.cc && Death::Finite(self.cc) <= death {
return Some((p, 0));
} else {
return None;
}
}
- pub(super) fn find_living_dynamic(
- &self,
- p: LocalCodePtr,
- cc: usize,
- ) -> Option<(usize, usize, usize, bool)> {
- let (p, oi, mut ii) = match p {
- LocalCodePtr::IndexingBuf(p, oi, ii) => (p, oi, ii),
- _ => unreachable!(),
- };
+ pub(super) fn find_living_dynamic(&self, code: &Code, oi: u32, mut ii: u32) -> Option<(usize, u32, u32, bool)> {
+ let p = self.p.local().abs_loc();
- let indexed_choice_instrs = match &self.code[p] {
- Line::IndexingCode(ref indexing_code) => match &indexing_code[oi] {
+ let indexed_choice_instrs = match &code[p] {
+ Line::IndexingCode(ref indexing_code) => match &indexing_code[oi as usize] {
IndexingLine::DynamicIndexedChoice(ref indexed_choice_instrs) => {
indexed_choice_instrs
}
};
loop {
- match &indexed_choice_instrs.get(ii) {
- Some(&offset) => match &self.code[p + offset - 1] {
+ match &indexed_choice_instrs.get(ii as usize) {
+ Some(&offset) => match &code[p + offset - 1] {
&Line::Choice(ChoiceInstruction::DynamicInternalElse(
birth,
death,
next_or_fail,
)) => {
- if birth < cc && Death::Finite(cc) <= death {
+ if birth < self.cc && Death::Finite(self.cc) <= death {
return Some((offset, oi, ii, next_or_fail.is_next()));
} else {
ii += 1;
}
}
}
+
+impl CodeRepo {
+ #[inline]
+ pub(super) fn new() -> Self {
+ CodeRepo { code: Code::new() }
+ }
+}
pub enum LocalCodePtr {
DirEntry(usize), // offset
Halt,
- IndexingBuf(usize, usize, usize), // DirEntry offset, first internal offset, second internal offset
- // TopLevel(usize, usize), // chunk_num, offset
+ // IndexingBuf(usize, usize, usize), // DirEntry offset, first internal offset, second internal offset
+ // TopLevel(usize, usize), // chunk_num, offset
+}
+
+impl MachineState {
+ pub(crate) fn is_reset_cont_marker(&self, code_repo: &CodeRepo, p: LocalCodePtr) -> bool {
+ match code_repo.lookup_instr(self, &CodePtr::Local(p)) {
+ Some(line) => match line.as_ref() {
+ Line::Control(ControlInstruction::CallClause(ref ct, ..)) => {
+ if let ClauseType::System(SystemClauseType::ResetContinuationMarker) = *ct {
+ return true;
+ }
+ }
+ _ => {}
+ },
+ None => {}
+ }
+
+ false
+ }
}
impl LocalCodePtr {
pub fn abs_loc(&self) -> usize {
match self {
LocalCodePtr::DirEntry(ref p) => *p,
- LocalCodePtr::IndexingBuf(ref p, ..) => *p,
+ // LocalCodePtr::IndexingBuf(ref p, ..) => *p,
LocalCodePtr::Halt => unreachable!(),
}
}
- pub(crate) fn is_reset_cont_marker(&self, code_repo: &CodeRepo, last_call: bool) -> bool {
- match code_repo.lookup_instr(last_call, &CodePtr::Local(*self)) {
- Some(line) => match line.as_ref() {
- Line::Control(ControlInstruction::CallClause(ref ct, ..)) => {
- if let ClauseType::System(SystemClauseType::ResetContinuationMarker) = *ct {
- return true;
- }
- }
- _ => {}
- },
- None => {}
- }
-
- false
- }
-
pub(crate) fn as_functor(&self) -> MachineStub {
match self {
LocalCodePtr::DirEntry(p) => {
LocalCodePtr::Halt => {
functor!(atom!("halt"))
}
+ /*
LocalCodePtr::IndexingBuf(p, o, i) => {
functor!(
atom!("indexed_buf"),
[fixnum(*p), fixnum(*o), fixnum(*i)]
)
}
+ */
}
}
}
match self {
LocalCodePtr::DirEntry(p) => LocalCodePtr::DirEntry(p + rhs),
LocalCodePtr::Halt => unreachable!(),
- LocalCodePtr::IndexingBuf(p, o, i) => LocalCodePtr::IndexingBuf(p, o, i + rhs),
+ // LocalCodePtr::IndexingBuf(p, o, i) => LocalCodePtr::IndexingBuf(p, o, i + rhs),
}
}
}
match self {
LocalCodePtr::DirEntry(p) => p.checked_sub(rhs).map(LocalCodePtr::DirEntry),
LocalCodePtr::Halt => unreachable!(),
- LocalCodePtr::IndexingBuf(p, o, i) => i
- .checked_sub(rhs)
- .map(|r| LocalCodePtr::IndexingBuf(p, o, r)),
+ // LocalCodePtr::IndexingBuf(p, o, i) => i
+ // .checked_sub(rhs)
+ // .map(|r| LocalCodePtr::IndexingBuf(p, o, r)),
}
}
}
fn sub_assign(&mut self, rhs: usize) {
match self {
LocalCodePtr::DirEntry(ref mut p) => *p -= rhs,
- LocalCodePtr::Halt | LocalCodePtr::IndexingBuf(..) => unreachable!(),
+ LocalCodePtr::Halt => unreachable!() // | LocalCodePtr::IndexingBuf(..) => unreachable!(),
}
}
}
#[inline]
fn add_assign(&mut self, rhs: usize) {
match self {
- &mut LocalCodePtr::DirEntry(ref mut i)
- | &mut LocalCodePtr::IndexingBuf(_, _, ref mut i) => *i += rhs,
+ &mut LocalCodePtr::DirEntry(ref mut i) => *i += rhs,
+ // | &mut LocalCodePtr::IndexingBuf(_, _, ref mut i) => *i += rhs,
&mut LocalCodePtr::Halt => unreachable!(),
}
}
pub(super) pdl: Vec<HeapCellValue>,
pub(super) s: HeapPtr,
pub(super) p: CodePtr,
+ pub(super) oip: u32, // first internal code ptr
+ pub(super) iip : u32, // second internal code ptr
pub(super) b: usize,
pub(super) b0: usize,
pub(super) e: usize,
pub(super) ball: Ball,
pub(super) lifted_heap: Heap,
pub(super) interms: Vec<Number>, // intermediate numbers.
- pub(super) last_call: bool,
+ pub(super) last_call: bool, // TODO: REMOVE THIS.
pub(crate) flags: MachineFlags,
pub(crate) cc: usize,
pub(crate) global_clock: usize,
global_variables: &mut GlobalVarDir,
) -> CallResult {
let b = machine_st.b;
- let n = machine_st
- .stack
- .index_or_frame(b)
- .prelude
- .univ_prelude
- .num_cells;
-
- for i in 1..n + 1 {
- machine_st.registers[i] = machine_st.stack[stack_loc!(OrFrame, b, i - 1)];
+ let or_frame = machine_st.stack.index_or_frame_mut(b);
+ let n = or_frame.prelude.univ_prelude.num_cells;
+
+ for i in 0..n {
+ machine_st.registers[i + 1] = or_frame[i];
}
machine_st.num_of_args = n;
- machine_st.e = machine_st.stack.index_or_frame(b).prelude.e;
- machine_st.cp = machine_st.stack.index_or_frame(b).prelude.cp;
+ machine_st.e = or_frame.prelude.e;
+ machine_st.cp = or_frame.prelude.cp;
- machine_st.stack.index_or_frame_mut(b).prelude.bp = machine_st.p.local() + offset;
+ or_frame.prelude.bp = machine_st.p.local() + offset;
- let old_tr = machine_st.stack.index_or_frame(b).prelude.tr;
+ let old_tr = or_frame.prelude.tr;
let curr_tr = machine_st.tr;
+ let target_h = or_frame.prelude.h;
- machine_st.unwind_trail(old_tr, curr_tr, global_variables);
- machine_st.tr = machine_st.stack.index_or_frame(b).prelude.tr;
-
- machine_st.trail.truncate(machine_st.tr);
- machine_st
- .heap
- .truncate(machine_st.stack.index_or_frame(b).prelude.h);
+ machine_st.tr = or_frame.prelude.tr;
machine_st.attr_var_init.reset();
machine_st.hb = machine_st.heap.len();
machine_st.p += 1;
+ machine_st.unwind_trail(old_tr, curr_tr, global_variables);
+
+ machine_st.trail.truncate(machine_st.tr);
+ machine_st.heap.truncate(target_h);
+
Ok(())
}
global_variables: &mut GlobalVarDir,
) -> CallResult {
let b = machine_st.b;
- let n = machine_st
- .stack
- .index_or_frame(b)
- .prelude
- .univ_prelude
- .num_cells;
-
- for i in 1..n + 1 {
- machine_st.registers[i] = machine_st.stack.index_or_frame(b)[i - 1];
+ let or_frame = machine_st.stack.index_or_frame_mut(b);
+ let n = or_frame.prelude.univ_prelude.num_cells;
+
+ for i in 0..n {
+ machine_st.registers[i+1] = or_frame[i];
}
machine_st.num_of_args = n;
- machine_st.e = machine_st.stack.index_or_frame(b).prelude.e;
- machine_st.cp = machine_st.stack.index_or_frame(b).prelude.cp;
+ machine_st.e = or_frame.prelude.e;
+ machine_st.cp = or_frame.prelude.cp;
- machine_st.stack.index_or_frame_mut(b).prelude.bp = machine_st.p.local() + 1;
+ // WAS: or_frame.prelude.bp = machine_st.p.local() + 1;
+ or_frame.prelude.biip += 1;
- let old_tr = machine_st.stack.index_or_frame(b).prelude.tr;
+ let old_tr = or_frame.prelude.tr;
let curr_tr = machine_st.tr;
+ let target_h = or_frame.prelude.h;
+
+ machine_st.tr = or_frame.prelude.tr;
+ machine_st.attr_var_init.reset();
machine_st.unwind_trail(old_tr, curr_tr, global_variables);
- machine_st.tr = machine_st.stack.index_or_frame(b).prelude.tr;
machine_st.trail.truncate(machine_st.tr);
- machine_st
- .heap
- .truncate(machine_st.stack.index_or_frame(b).prelude.h);
+ machine_st.heap.truncate(target_h);
- machine_st.attr_var_init.reset();
machine_st.hb = machine_st.heap.len();
machine_st.p = CodePtr::Local(dir_entry!(machine_st.p.local().abs_loc() + offset));
+ machine_st.oip = 0;
+ machine_st.iip = 0;
+
Ok(())
}
global_variables: &mut GlobalVarDir,
) -> CallResult {
let b = machine_st.b;
- let n = machine_st
- .stack
- .index_or_frame(b)
- .prelude
- .univ_prelude
- .num_cells;
-
- for i in 1..n + 1 {
- machine_st.registers[i] = machine_st.stack[stack_loc!(OrFrame, b, i - 1)];
+ let or_frame = machine_st.stack.index_or_frame(b);
+ let n = or_frame.prelude.univ_prelude.num_cells;
+
+ for i in 0..n {
+ machine_st.registers[i+1] = or_frame[i];
}
machine_st.num_of_args = n;
- machine_st.e = machine_st.stack.index_or_frame(b).prelude.e;
- machine_st.cp = machine_st.stack.index_or_frame(b).prelude.cp;
+ machine_st.e = or_frame.prelude.e;
+ machine_st.cp = or_frame.prelude.cp;
- let old_tr = machine_st.stack.index_or_frame(b).prelude.tr;
+ let old_tr = or_frame.prelude.tr;
let curr_tr = machine_st.tr;
+ let target_h = or_frame.prelude.h;
+
+ machine_st.tr = or_frame.prelude.tr;
+
+ machine_st.attr_var_init.reset();
+ machine_st.b = or_frame.prelude.b;
machine_st.unwind_trail(old_tr, curr_tr, global_variables);
- machine_st.tr = machine_st.stack.index_or_frame(b).prelude.tr;
machine_st.trail.truncate(machine_st.tr);
- machine_st
- .heap
- .truncate(machine_st.stack.index_or_frame(b).prelude.h);
-
- machine_st.attr_var_init.reset();
- machine_st.b = machine_st.stack.index_or_frame(b).prelude.b;
machine_st.stack.truncate(b);
+ machine_st.heap.truncate(target_h);
machine_st.hb = machine_st.heap.len();
machine_st.p = CodePtr::Local(dir_entry!(machine_st.p.local().abs_loc() + offset));
+ machine_st.oip = 0;
+ machine_st.iip = 0;
+
Ok(())
}
global_variables: &mut GlobalVarDir,
) -> CallResult {
let b = machine_st.b;
- let n = machine_st
- .stack
- .index_or_frame(b)
- .prelude
- .univ_prelude
- .num_cells;
-
- for i in 1..n + 1 {
- machine_st.registers[i] = machine_st.stack[stack_loc!(OrFrame, b, i - 1)];
+ let or_frame = machine_st.stack.index_or_frame(b);
+ let n = or_frame.prelude.univ_prelude.num_cells;
+
+ for i in 0..n {
+ machine_st.registers[i+1] = or_frame[i];
}
machine_st.num_of_args = n;
- machine_st.e = machine_st.stack.index_or_frame(b).prelude.e;
- machine_st.cp = machine_st.stack.index_or_frame(b).prelude.cp;
+ machine_st.e = or_frame.prelude.e;
+ machine_st.cp = or_frame.prelude.cp;
- let old_tr = machine_st.stack.index_or_frame(b).prelude.tr;
+ let old_tr = or_frame.prelude.tr;
let curr_tr = machine_st.tr;
+ let target_h = or_frame.prelude.h;
+
+ machine_st.tr = or_frame.prelude.tr;
+
+ machine_st.attr_var_init.reset();
+ machine_st.b = or_frame.prelude.b;
machine_st.unwind_trail(old_tr, curr_tr, global_variables);
- machine_st.tr = machine_st.stack.index_or_frame(b).prelude.tr;
machine_st.trail.truncate(machine_st.tr);
- machine_st
- .heap
- .truncate(machine_st.stack.index_or_frame(b).prelude.h);
-
- machine_st.attr_var_init.reset();
- machine_st.b = machine_st.stack.index_or_frame(b).prelude.b;
machine_st.stack.truncate(b);
+ machine_st.heap.truncate(target_h);
machine_st.hb = machine_st.heap.len();
machine_st.p += 1;
}
}
-// the ordinary, heap term copier, used by duplicate_term.
impl<'a> CopierTarget for CopyTerm<'a> {
#[inline(always)]
fn threshold(&self) -> usize {
}
}
-// the ordinary, heap term copier, used by duplicate_term.
impl<'a> CopierTarget for CopyBallTerm<'a> {
fn threshold(&self) -> usize {
self.heap_boundary + self.stub.len()
pdl: Vec::with_capacity(1024),
s: HeapPtr::default(),
p: CodePtr::default(),
+ oip: 0,
+ iip: 0,
b: 0,
b0: 0,
e: 0,
None => unreachable!(),
}
}
- TrailEntryTag::TrailedAttachedValue => {
- }
+ TrailEntryTag::TrailedAttachedValue => {
+ }
}
}
}
}
&IndexingLine::IndexedChoice(_) => {
if let LocalCodePtr::DirEntry(p) = self.p.local() {
- self.p = CodePtr::Local(LocalCodePtr::IndexingBuf(p, index, 0));
+ self.p = CodePtr::Local(LocalCodePtr::DirEntry(p));
+ self.oip = index as u32;
+ self.iip = 0;
} else {
unreachable!()
}
self.dynamic_mode = FirstOrNext::First;
if let LocalCodePtr::DirEntry(p) = self.p.local() {
- self.p = CodePtr::Local(LocalCodePtr::IndexingBuf(p, index, 0));
+ self.p = CodePtr::Local(LocalCodePtr::DirEntry(p));
+ self.oip = index as u32;
+ self.iip = 0;
} else {
unreachable!()
}
) {
let p = self.p.local();
- match code_repo.find_living_dynamic(p, self.cc) {
+ match self.find_living_dynamic(&code_repo.code, self.oip, self.iip) {
Some((offset, oi, ii, is_next_clause)) => {
- self.p = CodePtr::Local(LocalCodePtr::IndexingBuf(p.abs_loc(), oi, ii));
+ self.p = CodePtr::Local(LocalCodePtr::DirEntry(p.abs_loc()));
+ self.oip = oi;
+ self.iip = ii;
match self.dynamic_mode {
FirstOrNext::First if !is_next_clause => {
// there's a leading DynamicElse that sets self.cc.
// self.cc = self.global_clock;
- match code_repo.find_living_dynamic(
- LocalCodePtr::IndexingBuf(p.abs_loc(), oi, ii + 1),
- self.cc,
- ) {
+ // see that there is a following dynamic_else
+ // clause so we avoid generating a choice
+ // point in case there isn't.
+ match self.find_living_dynamic(&code_repo.code, oi, ii + 1) {
Some(_) => {
self.registers[self.num_of_args + 1] =
fixnum_as_cell!(Fixnum::build_with(self.cc as i64));
- self.num_of_args += 1;
+
+ self.num_of_args += 2;
self.execute_indexed_choice_instr(
&IndexedChoiceInstruction::Try(offset),
global_variables,
);
- self.num_of_args -= 1;
+ self.num_of_args -= 2;
}
None => {
- self.p =
- CodePtr::Local(LocalCodePtr::DirEntry(p.abs_loc() + offset));
+ self.p = CodePtr::Local(LocalCodePtr::DirEntry(p.abs_loc() + offset));
+ self.oip = 0;
+ self.iip = 0;
}
}
}
FirstOrNext::Next => {
+ let b = self.b;
let n = self
.stack
- .index_or_frame(self.b)
+ .index_or_frame(b)
.prelude
.univ_prelude
.num_cells;
- self.cc = cell_as_fixnum!(self.stack[n - 1]).get_num() as usize;
+ self.cc = cell_as_fixnum!(self.stack[stack_loc!(OrFrame, b, n-2)])
+ .get_num() as usize;
if is_next_clause {
- match code_repo.find_living_dynamic(
- LocalCodePtr::IndexingBuf(p.abs_loc(), oi, ii + 1),
- self.cc,
- ) {
+ match self.find_living_dynamic(&code_repo.code, self.oip, self.iip) {
Some(_) => {
try_or_fail!(
self,
- call_policy.retry(self, offset, global_variables,)
- )
+ call_policy.retry(self, offset, global_variables)
+ );
}
None => {
try_or_fail!(
self,
- call_policy.trust(self, offset, global_variables,)
+ call_policy.trust(self, offset, global_variables)
)
}
}
or_frame.prelude.e = self.e;
or_frame.prelude.cp = self.cp;
or_frame.prelude.b = self.b;
- or_frame.prelude.bp = self.p.local() + 1;
+ or_frame.prelude.bp = self.p.local(); // + 1; in self.iip now!
+ or_frame.prelude.boip = self.oip;
+ or_frame.prelude.biip = self.iip + 1;
or_frame.prelude.tr = self.tr;
or_frame.prelude.h = self.heap.len();
or_frame.prelude.b0 = self.b0;
self.b = b;
- for i in 1..n + 1 {
- self.stack.index_or_frame_mut(b)[i - 1] = self.registers[i];
+ for i in 0..n {
+ or_frame[i] = self.registers[i+1];
}
+ /*
+ self.iip += 1;
+
+ let oip_b = self.oip.to_ne_bytes();
+ let iip_b = self.iip.to_ne_bytes();
+
+ or_frame[n] = HeapCellValue::from_bytes(
+ [oip_b[0], oip_b[1], oip_b[2], oip_b[3],
+ iip_b[0], iip_b[1], iip_b[2], iip_b[3]],
+ );
+ */
+
self.hb = self.heap.len();
self.p = CodePtr::Local(dir_entry!(self.p.local().abs_loc() + offset));
+
+ self.oip = 0;
+ self.iip = 0;
}
&IndexedChoiceInstruction::Retry(l) => {
try_or_fail!(self, call_policy.retry(self, l, global_variables));
let p = self.p.local().abs_loc();
- match code_repo.find_living_dynamic_else(p, self.cc) {
+ match self.find_living_dynamic_else(&code_repo.code, p) {
Some((p, next_i)) => {
self.p = CodePtr::Local(LocalCodePtr::DirEntry(p));
FirstOrNext::First => {
self.cc = self.global_clock;
- match code_repo.find_living_dynamic_else(p + next_i, self.cc) {
+ match self.find_living_dynamic_else(&code_repo.code, p + next_i) {
Some(_) => {
self.registers[self.num_of_args + 1] =
fixnum_as_cell!(Fixnum::build_with(self.cc as i64));
.univ_prelude
.num_cells;
- self.cc = cell_as_fixnum!(self.stack.index_or_frame(self.b)[n - 1])
+ self.cc = cell_as_fixnum!(self.stack[stack_loc!(OrFrame, self.b, n-1)])
.get_num() as usize;
if next_i > 0 {
- match code_repo.find_living_dynamic_else(p + next_i, self.cc) {
+ match self.find_living_dynamic_else(&code_repo.code, p + next_i) {
Some(_) => {
try_or_fail!(
self,
&ChoiceInstruction::DynamicInternalElse(..) => {
let p = self.p.local().abs_loc();
- match code_repo.find_living_dynamic_else(p, self.cc) {
+ match self.find_living_dynamic_else(&code_repo.code, p) {
Some((p, next_i)) => {
self.p = CodePtr::Local(LocalCodePtr::DirEntry(p));
self.p = CodePtr::Local(LocalCodePtr::DirEntry(p + 1));
}
FirstOrNext::First => {
- match code_repo.find_living_dynamic_else(p + next_i, self.cc) {
+ match self.find_living_dynamic_else(&code_repo.code, p + next_i) {
Some(_) => {
self.registers[self.num_of_args + 1] =
fixnum_as_cell!(Fixnum::build_with(self.cc as i64));
.univ_prelude
.num_cells;
- self.cc = cell_as_fixnum!(self.stack.index_or_frame(self.b)[n - 1])
+ self.cc = cell_as_fixnum!(self.stack[stack_loc!(OrFrame, self.b, n-1)])
.get_num() as usize;
if next_i > 0 {
- match code_repo.find_living_dynamic_else(p + next_i, self.cc) {
+ match self.find_living_dynamic_else(&code_repo.code, p + next_i) {
Some(_) => {
try_or_fail!(
self,
None => {
try_or_fail!(
self,
- call_policy.trust_me(self, global_variables,)
+ call_policy.trust_me(self, global_variables)
)
}
}
} else {
try_or_fail!(
self,
- call_policy.trust_me(self, global_variables,)
+ call_policy.trust_me(self, global_variables)
)
}
}
or_frame.prelude.cp = self.cp;
or_frame.prelude.b = self.b;
or_frame.prelude.bp = self.p.local() + offset;
+ or_frame.prelude.boip = 0;
+ or_frame.prelude.biip = 0;
or_frame.prelude.tr = self.tr;
or_frame.prelude.h = self.heap.len();
or_frame.prelude.b0 = self.b0;
user_input: &mut Stream,
user_output: &mut Stream,
) {
- let instr = match code_repo.lookup_instr(self.last_call, &self.p) {
+ let instr = match code_repo.lookup_instr(self, &self.p) {
Some(instr) => instr,
None => return,
};
fn backtrack(&mut self) {
let b = self.b;
+ let or_frame = self.stack.index_or_frame(b);
- self.b0 = self.stack.index_or_frame(b).prelude.b0;
- self.p = CodePtr::Local(self.stack.index_or_frame(b).prelude.bp);
+ self.b0 = or_frame.prelude.b0;
+ self.p = CodePtr::Local(or_frame.prelude.bp);
+
+ self.oip = or_frame.prelude.boip;
+ self.iip = or_frame.prelude.biip;
self.pdl.clear();
self.fail = false;
fn check_machine_index(&mut self, code_repo: &CodeRepo) -> bool {
match self.p {
- CodePtr::Local(LocalCodePtr::DirEntry(p)) |
- CodePtr::Local(LocalCodePtr::IndexingBuf(p, ..))
+ CodePtr::Local(LocalCodePtr::DirEntry(p))
if p < code_repo.code.len() => {}
CodePtr::Local(LocalCodePtr::Halt) | CodePtr::REPL(..) => {
return false;
user_output: &mut Stream,
) -> bool {
loop {
- let instr = match code_repo.lookup_instr(self.last_call, &self.p) {
+ let instr = match code_repo.lookup_instr(self, &self.p) {
Some(instr) => {
if instr.as_ref().is_head_instr() {
instr
let instigating_p = CodePtr::Local(self.attr_var_init.instigating_p);
let instigating_instr = code_repo
- .lookup_instr(false, &instigating_p)
+ .lookup_instr(self, &instigating_p)
.unwrap();
if !instigating_instr.as_ref().is_head_instr() {
pub(crate) cp: LocalCodePtr,
pub(crate) b: usize,
pub(crate) bp: LocalCodePtr,
+ pub(crate) boip: u32,
+ pub(crate) biip: u32,
pub(crate) tr: usize,
pub(crate) h: usize,
pub(crate) b0: usize,
let p_functor = self.store(self.deref(self.registers[2]));
let p = to_local_code_ptr(&self.heap, p_functor).unwrap();
- let num_cells = match code_repo.lookup_instr(self.last_call, &CodePtr::Local(p)) {
+ let num_cells = match code_repo.lookup_instr(self, &CodePtr::Local(p)) {
Some(line) => {
let perm_vars = match line.as_ref() {
Line::Control(ref ctrl_instr) => ctrl_instr.perm_vars(),
}
};
- if p.is_reset_cont_marker(code_repo, self.last_call) {
+ if self.is_reset_cont_marker(&code_repo, p) {
return return_from_clause!(self.last_call, self);
}
let mut cp = self.cp;
while e > 0 {
- if cp.is_reset_cont_marker(code_repo, self.last_call) {
+ if self.is_reset_cont_marker(code_repo, cp) {
self.e = e;
self.p = CodePtr::Local(cp + 1); // skip the reset marker.
match self {
LocalCodePtr::DirEntry(p) => write!(f, "LocalCodePtr::DirEntry({})", p),
LocalCodePtr::Halt => write!(f, "LocalCodePtr::Halt"),
- LocalCodePtr::IndexingBuf(p, o, i) => {
- write!(f, "LocalCodePtr::IndexingBuf({}, {}, {})", p, o, i)
- }
+ // LocalCodePtr::IndexingBuf(p, o, i) => {
+ // write!(f, "LocalCodePtr::IndexingBuf({}, {}, {})", p, o, i)
+ // }
}
}
}