corrections to dispatch loop

This commit is contained in:
Mark Thom
2025-11-27 21:03:22 -08:00
parent 4bd16b8a2e
commit 3b019fca1d
2 changed files with 112 additions and 172 deletions

View File

@@ -15,7 +15,6 @@ pub(super) struct AttrVarInitializer {
pub(super) bindings: Bindings, pub(super) bindings: Bindings,
pub(super) p: usize, pub(super) p: usize,
pub(super) cp: usize, pub(super) cp: usize,
// pub(super) instigating_p: usize,
pub(super) verify_attrs_loc: usize, pub(super) verify_attrs_loc: usize,
} }
@@ -116,7 +115,7 @@ impl MachineState {
let e = self.e; let e = self.e;
let and_frame = self.stack.index_and_frame_mut(e); let and_frame = self.stack.index_and_frame_mut(e);
for i in 1..arity + 1 { for i in 1..=arity {
and_frame[i] = self.registers[i]; and_frame[i] = self.registers[i];
} }

View File

@@ -599,7 +599,6 @@ impl MachineState {
#[inline(always)] #[inline(always)]
fn cos_instr(&mut self, a1: &ArithmeticTerm, t: usize) { fn cos_instr(&mut self, a1: &ArithmeticTerm, t: usize) {
let n1 = try_or_throw!(self, self.get_number(a1), return); let n1 = try_or_throw!(self, self.get_number(a1), return);
let value = Number::Float(OrderedFloat(try_or_throw_gen!(self, cos(n1)))); let value = Number::Float(OrderedFloat(try_or_throw_gen!(self, cos(n1))));
self.registers[t] = HeapCellValue::from((value, &mut self.arena)); self.registers[t] = HeapCellValue::from((value, &mut self.arena));
@@ -609,7 +608,6 @@ impl MachineState {
#[inline(always)] #[inline(always)]
fn sin_instr(&mut self, a1: &ArithmeticTerm, t: usize) { fn sin_instr(&mut self, a1: &ArithmeticTerm, t: usize) {
let n1 = try_or_throw!(self, self.get_number(a1), return); let n1 = try_or_throw!(self, self.get_number(a1), return);
let value = Number::Float(OrderedFloat(try_or_throw_gen!(self, sin(n1)))); let value = Number::Float(OrderedFloat(try_or_throw_gen!(self, sin(n1))));
self.registers[t] = HeapCellValue::from((value, &mut self.arena)); self.registers[t] = HeapCellValue::from((value, &mut self.arena));
@@ -619,7 +617,6 @@ impl MachineState {
#[inline(always)] #[inline(always)]
fn tan_instr(&mut self, a1: &ArithmeticTerm, t: usize) { fn tan_instr(&mut self, a1: &ArithmeticTerm, t: usize) {
let n1 = try_or_throw!(self, self.get_number(a1), return); let n1 = try_or_throw!(self, self.get_number(a1), return);
let value = Number::Float(OrderedFloat(try_or_throw_gen!(self, tan(n1)))); let value = Number::Float(OrderedFloat(try_or_throw_gen!(self, tan(n1))));
self.registers[t] = HeapCellValue::from((value, &mut self.arena)); self.registers[t] = HeapCellValue::from((value, &mut self.arena));
@@ -629,7 +626,6 @@ impl MachineState {
#[inline(always)] #[inline(always)]
fn sqrt_instr(&mut self, a1: &ArithmeticTerm, t: usize) { fn sqrt_instr(&mut self, a1: &ArithmeticTerm, t: usize) {
let n1 = try_or_throw!(self, self.get_number(a1), return); let n1 = try_or_throw!(self, self.get_number(a1), return);
let value = Number::Float(OrderedFloat(try_or_throw_gen!(self, sqrt(n1)))); let value = Number::Float(OrderedFloat(try_or_throw_gen!(self, sqrt(n1))));
self.registers[t] = HeapCellValue::from((value, &mut self.arena)); self.registers[t] = HeapCellValue::from((value, &mut self.arena));
@@ -639,7 +635,6 @@ impl MachineState {
#[inline(always)] #[inline(always)]
fn log_instr(&mut self, a1: &ArithmeticTerm, t: usize) { fn log_instr(&mut self, a1: &ArithmeticTerm, t: usize) {
let n1 = try_or_throw!(self, self.get_number(a1), return); let n1 = try_or_throw!(self, self.get_number(a1), return);
let value = Number::Float(OrderedFloat(try_or_throw_gen!(self, log(n1)))); let value = Number::Float(OrderedFloat(try_or_throw_gen!(self, log(n1))));
self.registers[t] = HeapCellValue::from((value, &mut self.arena)); self.registers[t] = HeapCellValue::from((value, &mut self.arena));
@@ -649,7 +644,6 @@ impl MachineState {
#[inline(always)] #[inline(always)]
fn exp_instr(&mut self, a1: &ArithmeticTerm, t: usize) { fn exp_instr(&mut self, a1: &ArithmeticTerm, t: usize) {
let n1 = try_or_throw!(self, self.get_number(a1), return); let n1 = try_or_throw!(self, self.get_number(a1), return);
let value = Number::Float(OrderedFloat(try_or_throw_gen!(self, exp(n1)))); let value = Number::Float(OrderedFloat(try_or_throw_gen!(self, exp(n1))));
self.registers[t] = HeapCellValue::from((value, &mut self.arena)); self.registers[t] = HeapCellValue::from((value, &mut self.arena));
@@ -659,7 +653,6 @@ impl MachineState {
#[inline(always)] #[inline(always)]
fn acos_instr(&mut self, a1: &ArithmeticTerm, t: usize) { fn acos_instr(&mut self, a1: &ArithmeticTerm, t: usize) {
let n1 = try_or_throw!(self, self.get_number(a1), return); let n1 = try_or_throw!(self, self.get_number(a1), return);
let value = Number::Float(OrderedFloat(try_or_throw_gen!(self, acos(n1)))); let value = Number::Float(OrderedFloat(try_or_throw_gen!(self, acos(n1))));
self.registers[t] = HeapCellValue::from((value, &mut self.arena)); self.registers[t] = HeapCellValue::from((value, &mut self.arena));
@@ -669,7 +662,6 @@ impl MachineState {
#[inline(always)] #[inline(always)]
fn asin_instr(&mut self, a1: &ArithmeticTerm, t: usize) { fn asin_instr(&mut self, a1: &ArithmeticTerm, t: usize) {
let n1 = try_or_throw!(self, self.get_number(a1), return); let n1 = try_or_throw!(self, self.get_number(a1), return);
let value = Number::Float(OrderedFloat(try_or_throw_gen!(self, asin(n1)))); let value = Number::Float(OrderedFloat(try_or_throw_gen!(self, asin(n1))));
self.registers[t] = HeapCellValue::from((value, &mut self.arena)); self.registers[t] = HeapCellValue::from((value, &mut self.arena));
@@ -679,7 +671,6 @@ impl MachineState {
#[inline(always)] #[inline(always)]
fn atan_instr(&mut self, a1: &ArithmeticTerm, t: usize) { fn atan_instr(&mut self, a1: &ArithmeticTerm, t: usize) {
let n1 = try_or_throw!(self, self.get_number(a1), return); let n1 = try_or_throw!(self, self.get_number(a1), return);
let value = Number::Float(OrderedFloat(try_or_throw_gen!(self, atan(n1)))); let value = Number::Float(OrderedFloat(try_or_throw_gen!(self, atan(n1))));
self.registers[t] = HeapCellValue::from((value, &mut self.arena)); self.registers[t] = HeapCellValue::from((value, &mut self.arena));
@@ -700,7 +691,6 @@ impl MachineState {
#[inline(always)] #[inline(always)]
fn float_instr(&mut self, a1: &ArithmeticTerm, t: usize) { fn float_instr(&mut self, a1: &ArithmeticTerm, t: usize) {
let n1 = try_or_throw!(self, self.get_number(a1), return); let n1 = try_or_throw!(self, self.get_number(a1), return);
let value = Number::Float(OrderedFloat(try_or_throw_gen!(self, float(n1)))); let value = Number::Float(OrderedFloat(try_or_throw_gen!(self, float(n1))));
self.registers[t] = HeapCellValue::from((value, &mut self.arena)); self.registers[t] = HeapCellValue::from((value, &mut self.arena));
@@ -719,7 +709,6 @@ impl MachineState {
#[inline(always)] #[inline(always)]
fn round_instr(&mut self, a1: &ArithmeticTerm, t: usize) { fn round_instr(&mut self, a1: &ArithmeticTerm, t: usize) {
let n1 = try_or_throw!(self, self.get_number(a1), return); let n1 = try_or_throw!(self, self.get_number(a1), return);
let value = try_or_throw_gen!(self, round(n1, &mut self.arena)); let value = try_or_throw_gen!(self, round(n1, &mut self.arena));
self.registers[t] = HeapCellValue::from((value, &mut self.arena)); self.registers[t] = HeapCellValue::from((value, &mut self.arena));
@@ -962,9 +951,6 @@ impl MachineState {
self.bind(r, char_as_cell!(c)); self.bind(r, char_as_cell!(c));
} else { } else {
self.fail = true; self.fail = true;
}
if self.fail {
break; break;
} }
@@ -1225,7 +1211,6 @@ impl MachineState {
#[inline(always)] #[inline(always)]
fn put_partial_string_instr(&mut self, string: &str, r: RegType) { fn put_partial_string_instr(&mut self, string: &str, r: RegType) {
self[r] = backtrack_on_resource_error!(self, self.heap.allocate_pstr(string), return); self[r] = backtrack_on_resource_error!(self, self.heap.allocate_pstr(string), return);
self.p += 1; self.p += 1;
} }
@@ -1567,59 +1552,6 @@ impl Machine {
&Instruction::BreakFromDispatchLoop => { &Instruction::BreakFromDispatchLoop => {
break 'outer; break 'outer;
} }
&Instruction::Add(ref a1, ref a2, t) => self.machine_st.add_instr(a1, a2, t),
&Instruction::Sub(ref a1, ref a2, t) => self.machine_st.sub_instr(a1, a2, t),
&Instruction::Mul(ref a1, ref a2, t) => self.machine_st.mul_instr(a1, a2, t),
&Instruction::Max(ref a1, ref a2, t) => self.machine_st.max_instr(a1, a2, t),
&Instruction::Min(ref a1, ref a2, t) => self.machine_st.min_instr(a1, a2, t),
&Instruction::IntPow(ref a1, ref a2, t) => {
self.machine_st.int_pow_instr(a1, a2, t)
}
&Instruction::Gcd(ref a1, ref a2, t) => self.machine_st.gcd_instr(a1, a2, t),
&Instruction::Pow(ref a1, ref a2, t) => self.machine_st.pow_instr(a1, a2, t),
&Instruction::RDiv(ref a1, ref a2, t) => self.machine_st.rdiv_instr(a1, a2, t),
&Instruction::IntFloorDiv(ref a1, ref a2, t) => {
self.machine_st.int_floor_div_instr(a1, a2, t)
}
&Instruction::IDiv(ref a1, ref a2, t) => self.machine_st.idiv_instr(a1, a2, t),
&Instruction::Abs(ref a1, t) => self.machine_st.abs_instr(a1, t),
&Instruction::Sign(ref a1, t) => self.machine_st.sign_instr(a1, t),
&Instruction::Neg(ref a1, t) => self.machine_st.neg_instr(a1, t),
&Instruction::BitwiseComplement(ref a1, t) => {
self.machine_st.bitwise_complement_instr(a1, t)
}
&Instruction::Div(ref a1, ref a2, t) => self.machine_st.div_instr(a1, a2, t),
&Instruction::Shr(ref a1, ref a2, t) => self.machine_st.shr_instr(a1, a2, t),
&Instruction::Shl(ref a1, ref a2, t) => self.machine_st.shl_instr(a1, a2, t),
&Instruction::Xor(ref a1, ref a2, t) => self.machine_st.xor_instr(a1, a2, t),
&Instruction::And(ref a1, ref a2, t) => self.machine_st.and_instr(a1, a2, t),
&Instruction::Or(ref a1, ref a2, t) => self.machine_st.or_instr(a1, a2, t),
&Instruction::Mod(ref a1, ref a2, t) => self.machine_st.mod_instr(a1, a2, t),
&Instruction::Rem(ref a1, ref a2, t) => self.machine_st.rem_instr(a1, a2, t),
&Instruction::Cos(ref a1, t) => self.machine_st.cos_instr(a1, t),
&Instruction::Sin(ref a1, t) => self.machine_st.sin_instr(a1, t),
&Instruction::Tan(ref a1, t) => self.machine_st.tan_instr(a1, t),
&Instruction::Sqrt(ref a1, t) => self.machine_st.sqrt_instr(a1, t),
&Instruction::Log(ref a1, t) => self.machine_st.log_instr(a1, t),
&Instruction::Exp(ref a1, t) => self.machine_st.exp_instr(a1, t),
&Instruction::ACos(ref a1, t) => self.machine_st.acos_instr(a1, t),
&Instruction::ASin(ref a1, t) => self.machine_st.asin_instr(a1, t),
&Instruction::ATan(ref a1, t) => self.machine_st.atan_instr(a1, t),
&Instruction::ATan2(ref a1, ref a2, t) => {
self.machine_st.atan2_instr(a1, a2, t)
}
&Instruction::Float(ref a1, t) => self.machine_st.float_instr(a1, t),
&Instruction::Truncate(ref a1, t) => self.machine_st.truncate_instr(a1, t),
&Instruction::Round(ref a1, t) => self.machine_st.round_instr(a1, t),
&Instruction::Ceiling(ref a1, t) => self.machine_st.ceiling_instr(a1, t),
&Instruction::Floor(ref a1, t) => self.machine_st.floor_instr(a1, t),
&Instruction::FloatFractionalPart(ref a1, t) => {
self.machine_st.float_fractional_part_instr(a1, t)
}
&Instruction::FloatIntegerPart(ref a1, t) => {
self.machine_st.float_integer_part_instr(a1, t)
}
&Instruction::Plus(ref a1, t) => self.machine_st.plus_instr(a1, t),
&Instruction::GetLevel(r) => self.machine_st.get_level_instr(r), &Instruction::GetLevel(r) => self.machine_st.get_level_instr(r),
&Instruction::GetPrevLevel(r) => self.machine_st.get_prev_level_instr(r), &Instruction::GetPrevLevel(r) => self.machine_st.get_prev_level_instr(r),
&Instruction::GetCutPoint(r) => self.machine_st.get_cut_point_instr(r), &Instruction::GetCutPoint(r) => self.machine_st.get_cut_point_instr(r),
@@ -1704,7 +1636,16 @@ impl Machine {
return exit_code; return exit_code;
} }
if self.machine_st.fail { if matches!(
self.code[self.machine_st.p],
Instruction::RetryMeElse(_)
| Instruction::TrustMe(_)
| Instruction::DefaultRetryMeElse(_)
| Instruction::DefaultTrustMe(_)
| Instruction::DynamicElse(..)
| Instruction::DynamicInternalElse(..)
| Instruction::IndexingCode(_)
) {
continue; continue;
} }