Merge pull request #3185 from mthom/install_verify_attr_opt
Optimize `verify_attr` by removing the need to scan instructions
This commit is contained in:
@@ -22,7 +22,7 @@ use num_order::NumOrd;
|
||||
use ordered_float::{Float, OrderedFloat};
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::cmp::{max, min, Ordering};
|
||||
use std::cmp::Ordering;
|
||||
use std::convert::TryFrom;
|
||||
use std::f64;
|
||||
use std::num::FpCategory;
|
||||
@@ -31,21 +31,11 @@ use std::vec::Vec;
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub enum ArithmeticTerm {
|
||||
IntermReg(usize),
|
||||
Reg(RegType),
|
||||
Interm(usize),
|
||||
Number(Number),
|
||||
}
|
||||
|
||||
impl ArithmeticTerm {
|
||||
pub(crate) fn interm_or(&self, interm: usize) -> usize {
|
||||
if let &ArithmeticTerm::Interm(interm) = self {
|
||||
interm
|
||||
} else {
|
||||
interm
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for ArithmeticTerm {
|
||||
fn default() -> Self {
|
||||
ArithmeticTerm::Number(Number::default())
|
||||
@@ -57,7 +47,7 @@ pub(crate) struct ArithInstructionIterator<'a> {
|
||||
state_stack: Vec<TermIterState<'a>>,
|
||||
}
|
||||
|
||||
pub(crate) type ArithCont = (CodeDeque, Option<ArithmeticTerm>);
|
||||
pub(crate) type ArithCont = (CodeDeque, ArithmeticTerm);
|
||||
|
||||
impl<'a> ArithInstructionIterator<'a> {
|
||||
fn push_subterm(&mut self, lvl: Level, term: &'a Term) {
|
||||
@@ -90,7 +80,7 @@ impl<'a> ArithInstructionIterator<'a> {
|
||||
#[derive(Debug)]
|
||||
pub(crate) enum ArithTermRef<'a> {
|
||||
Literal(Literal),
|
||||
Op(Atom, usize), // name, arity.
|
||||
Op(Level, &'a Cell<RegType>, Atom, usize), // name, arity.
|
||||
Var(Level, &'a Cell<VarReg>, VarPtr),
|
||||
}
|
||||
|
||||
@@ -105,7 +95,7 @@ impl<'a> Iterator for ArithInstructionIterator<'a> {
|
||||
let arity = subterms.len();
|
||||
|
||||
if child_num == arity {
|
||||
return Some(Ok(ArithTermRef::Op(name, arity)));
|
||||
return Some(Ok(ArithTermRef::Op(lvl, cell, name, arity)));
|
||||
} else {
|
||||
self.state_stack.push(TermIterState::Clause(
|
||||
lvl,
|
||||
@@ -139,7 +129,6 @@ impl<'a> Iterator for ArithInstructionIterator<'a> {
|
||||
pub(crate) struct ArithmeticEvaluator<'a> {
|
||||
marker: &'a mut DebrayAllocator,
|
||||
interm: Vec<ArithmeticTerm>,
|
||||
interm_c: usize,
|
||||
}
|
||||
|
||||
pub(crate) trait ArithmeticTermIter<'a> {
|
||||
@@ -180,11 +169,10 @@ fn push_literal(interm: &mut Vec<ArithmeticTerm>, c: &Literal) -> Result<(), Ari
|
||||
}
|
||||
|
||||
impl<'a> ArithmeticEvaluator<'a> {
|
||||
pub(crate) fn new(marker: &'a mut DebrayAllocator, target_int: usize) -> Self {
|
||||
pub(crate) fn new(marker: &'a mut DebrayAllocator) -> Self {
|
||||
ArithmeticEvaluator {
|
||||
marker,
|
||||
interm: Vec::new(),
|
||||
interm_c: target_int,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,56 +240,37 @@ impl<'a> ArithmeticEvaluator<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn incr_interm(&mut self) -> usize {
|
||||
let temp = self.interm_c;
|
||||
|
||||
self.interm.push(ArithmeticTerm::Interm(temp));
|
||||
self.interm_c += 1;
|
||||
|
||||
temp
|
||||
fn try_add_to_free_list(&mut self, a1: ArithmeticTerm) {
|
||||
if let ArithmeticTerm::IntermReg(t) = a1 {
|
||||
self.marker.add_reg_to_free_list(RegType::Temp(t));
|
||||
}
|
||||
}
|
||||
|
||||
fn instr_from_clause(
|
||||
&mut self,
|
||||
name: Atom,
|
||||
arity: usize,
|
||||
arg: usize,
|
||||
) -> Result<Instruction, ArithmeticError> {
|
||||
match arity {
|
||||
1 => {
|
||||
let a1 = self.interm.pop().unwrap();
|
||||
|
||||
let ninterm = if a1.interm_or(0) == 0 {
|
||||
self.incr_interm()
|
||||
} else {
|
||||
self.interm.push(a1);
|
||||
a1.interm_or(0)
|
||||
};
|
||||
self.interm.push(ArithmeticTerm::IntermReg(arg));
|
||||
self.try_add_to_free_list(a1);
|
||||
|
||||
self.get_unary_instr(name, a1, ninterm)
|
||||
self.get_unary_instr(name, a1, arg)
|
||||
}
|
||||
2 => {
|
||||
let a2 = self.interm.pop().unwrap();
|
||||
let a1 = self.interm.pop().unwrap();
|
||||
|
||||
let min_interm = min(a1.interm_or(0), a2.interm_or(0));
|
||||
self.interm.push(ArithmeticTerm::IntermReg(arg));
|
||||
|
||||
let ninterm = if min_interm == 0 {
|
||||
let max_interm = max(a1.interm_or(0), a2.interm_or(0));
|
||||
self.try_add_to_free_list(a1);
|
||||
self.try_add_to_free_list(a2);
|
||||
|
||||
if max_interm == 0 {
|
||||
self.incr_interm()
|
||||
} else {
|
||||
self.interm.push(ArithmeticTerm::Interm(max_interm));
|
||||
self.interm_c = max_interm + 1;
|
||||
max_interm
|
||||
}
|
||||
} else {
|
||||
self.interm.push(ArithmeticTerm::Interm(min_interm));
|
||||
self.interm_c = min_interm + 1;
|
||||
min_interm
|
||||
};
|
||||
|
||||
self.get_binary_instr(name, a1, a2, ninterm)
|
||||
self.get_binary_instr(name, a1, a2, arg)
|
||||
}
|
||||
_ => Err(ArithmeticError::NonEvaluableFunctor(
|
||||
Literal::Atom(name),
|
||||
@@ -346,13 +315,20 @@ impl<'a> ArithmeticEvaluator<'a> {
|
||||
|
||||
self.interm.push(ArithmeticTerm::Reg(r));
|
||||
}
|
||||
ArithTermRef::Op(name, arity) => {
|
||||
code.push_back(self.instr_from_clause(name, arity)?);
|
||||
ArithTermRef::Op(lvl, cell, name, arity) => {
|
||||
self.marker
|
||||
.mark_non_var::<QueryInstruction>(lvl, term_loc, cell, &mut code);
|
||||
|
||||
if let RegType::Temp(t) = cell.get() {
|
||||
code.push_back(self.instr_from_clause(name, arity, t)?);
|
||||
} else {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok((code, self.interm.pop()))
|
||||
Ok((code, self.interm.pop().unwrap()))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -560,20 +560,12 @@ impl CodeGenerator {
|
||||
&InlinedClauseType::CompareNumber(mut cmp) => {
|
||||
self.marker.reset_arg(2);
|
||||
|
||||
let (mut lcode, at_1) = self.compile_arith_expr(&terms[0], 1, term_loc, 1)?;
|
||||
|
||||
if !matches!(terms[0], Term::Var(..)) {
|
||||
self.marker.advance_arg();
|
||||
}
|
||||
|
||||
let (mut rcode, at_2) = self.compile_arith_expr(&terms[1], 2, term_loc, 2)?;
|
||||
let (mut lcode, at_1) = self.compile_arith_expr(&terms[0], term_loc, 1)?;
|
||||
let (mut rcode, at_2) = self.compile_arith_expr(&terms[1], term_loc, 2)?;
|
||||
|
||||
code.append(&mut lcode);
|
||||
code.append(&mut rcode);
|
||||
|
||||
let at_1 = at_1.unwrap_or(interm!(1));
|
||||
let at_2 = at_2.unwrap_or(interm!(2));
|
||||
|
||||
compare_number_instr!(cmp, at_1, at_2)
|
||||
}
|
||||
InlinedClauseType::IsAtom(..) => match &terms[0] {
|
||||
@@ -787,11 +779,10 @@ impl CodeGenerator {
|
||||
fn compile_arith_expr(
|
||||
&mut self,
|
||||
term: &Term,
|
||||
target_int: usize,
|
||||
term_loc: GenContext,
|
||||
arg: usize,
|
||||
) -> Result<ArithCont, ArithmeticError> {
|
||||
let mut evaluator = ArithmeticEvaluator::new(&mut self.marker, target_int);
|
||||
let mut evaluator = ArithmeticEvaluator::new(&mut self.marker);
|
||||
evaluator.compile_is(term, term_loc, arg)
|
||||
}
|
||||
|
||||
@@ -804,7 +795,7 @@ impl CodeGenerator {
|
||||
) -> Result<(), CompilationError> {
|
||||
macro_rules! compile_expr {
|
||||
($self:expr, $terms:expr, $term_loc:expr, $code:expr) => {{
|
||||
let (acode, at) = $self.compile_arith_expr($terms, 1, $term_loc, 2)?;
|
||||
let (acode, at) = $self.compile_arith_expr($terms, $term_loc, 2)?;
|
||||
$code.extend(acode.into_iter());
|
||||
at
|
||||
}};
|
||||
@@ -859,16 +850,18 @@ impl CodeGenerator {
|
||||
}
|
||||
}
|
||||
Term::Literal(
|
||||
_,
|
||||
ref cell,
|
||||
c @ Literal::Integer(_)
|
||||
| c @ Literal::F64(..)
|
||||
| c @ Literal::Rational(_)
|
||||
| c @ Literal::Fixnum(_),
|
||||
) => {
|
||||
let v = HeapCellValue::from(c);
|
||||
code.push_back(instr!("put_constant", Level::Shallow, v, temp_v!(1)));
|
||||
|
||||
self.marker.advance_arg();
|
||||
self.marker
|
||||
.mark_non_var::<QueryInstruction>(Level::Shallow, term_loc, &cell, code);
|
||||
|
||||
code.push_back(instr!("put_constant", Level::Shallow, v, temp_v!(1)));
|
||||
compile_expr!(self, &terms[1], term_loc, code)
|
||||
}
|
||||
_ => {
|
||||
@@ -877,7 +870,6 @@ impl CodeGenerator {
|
||||
}
|
||||
};
|
||||
|
||||
let at = at.unwrap_or(interm!(1));
|
||||
self.add_call(code, instr!("is", temp_v!(1), at), call_policy);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ get_attrs_var_check(Module) -->
|
||||
!,
|
||||
'$get_attr_list'(Var, Ls),
|
||||
nonvar(Ls),
|
||||
atts:'$copy_attr_list'(Ls, Module, Attr))].
|
||||
atts:'$copy_attr_list'(Ls, Module, Attr))].
|
||||
|
||||
put_attrs(Name/Arity, Module) -->
|
||||
put_attr(Name, Arity, Module),
|
||||
|
||||
@@ -21,7 +21,6 @@ use ordered_float::{Float, OrderedFloat};
|
||||
use std::cmp;
|
||||
use std::convert::TryFrom;
|
||||
use std::f64;
|
||||
use std::mem;
|
||||
|
||||
macro_rules! try_numeric_result {
|
||||
($e: expr, $stub_gen: expr) => {
|
||||
@@ -1120,23 +1119,18 @@ pub(crate) fn bitwise_complement(n1: Number, arena: &mut Arena) -> Result<Number
|
||||
impl MachineState {
|
||||
#[inline]
|
||||
pub fn get_number(&mut self, at: &ArithmeticTerm) -> Result<Number, MachineStub> {
|
||||
match at {
|
||||
&ArithmeticTerm::Reg(r) => {
|
||||
let value = self.store(self.deref(self[r]));
|
||||
let value = match at {
|
||||
&ArithmeticTerm::Reg(r) => self.store(self.deref(self[r])),
|
||||
&ArithmeticTerm::IntermReg(i) => self.registers[i],
|
||||
ArithmeticTerm::Number(n) => return Ok(*n),
|
||||
};
|
||||
|
||||
match Number::try_from((value, &self.arena.f64_tbl)) {
|
||||
Ok(n) => Ok(n),
|
||||
Err(_) => {
|
||||
self.heap[0] = value;
|
||||
self.arith_eval_by_metacall(0)
|
||||
}
|
||||
}
|
||||
match Number::try_from((value, &self.arena.f64_tbl)) {
|
||||
Ok(n) => Ok(n),
|
||||
Err(_) => {
|
||||
self.heap[0] = value;
|
||||
self.arith_eval_by_metacall(0)
|
||||
}
|
||||
&ArithmeticTerm::Interm(i) => Ok(mem::replace(
|
||||
&mut self.interms[i - 1],
|
||||
Number::Fixnum(Fixnum::build_with(0)),
|
||||
)),
|
||||
ArithmeticTerm::Number(n) => Ok(*n),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1158,6 +1152,7 @@ impl MachineState {
|
||||
term_loc: usize,
|
||||
) -> Result<Number, MachineStub> {
|
||||
let stub_gen = || functor_stub(atom!("is"), 2);
|
||||
let mut interms = vec![];
|
||||
let mut iter =
|
||||
stackful_post_order_iter::<NonListElider>(&mut self.heap, &mut self.stack, term_loc);
|
||||
|
||||
@@ -1194,38 +1189,38 @@ impl MachineState {
|
||||
read_heap_cell!(value,
|
||||
(HeapCellValueTag::Atom, (name, arity)) => {
|
||||
if arity == 2 {
|
||||
let a2 = self.interms.pop().unwrap();
|
||||
let a1 = self.interms.pop().unwrap();
|
||||
let a2 = interms.pop().unwrap();
|
||||
let a1 = interms.pop().unwrap();
|
||||
|
||||
match name {
|
||||
atom!("+") => self.interms.push(drop_iter_on_err!(
|
||||
atom!("+") => interms.push(drop_iter_on_err!(
|
||||
self,
|
||||
iter,
|
||||
try_numeric_result!(add(a1, a2, &mut self.arena), stub_gen)
|
||||
)),
|
||||
atom!("-") => self.interms.push(drop_iter_on_err!(
|
||||
atom!("-") => interms.push(drop_iter_on_err!(
|
||||
self,
|
||||
iter,
|
||||
try_numeric_result!(sub(a1, a2, &mut self.arena), stub_gen)
|
||||
)),
|
||||
atom!("*") => self.interms.push(drop_iter_on_err!(
|
||||
atom!("*") => interms.push(drop_iter_on_err!(
|
||||
self,
|
||||
iter,
|
||||
try_numeric_result!(mul(a1, a2, &mut self.arena), stub_gen)
|
||||
)),
|
||||
atom!("/") => self.interms.push(
|
||||
atom!("/") => interms.push(
|
||||
drop_iter_on_err!(self, iter, div(a1, a2))
|
||||
),
|
||||
atom!("**") => self.interms.push(
|
||||
atom!("**") => interms.push(
|
||||
drop_iter_on_err!(self, iter, pow(a1, a2, atom!("is")))
|
||||
),
|
||||
atom!("^") => self.interms.push(
|
||||
atom!("^") => interms.push(
|
||||
drop_iter_on_err!(self, iter, int_pow(a1, a2, &mut self.arena))
|
||||
),
|
||||
atom!("max") => self.interms.push(
|
||||
atom!("max") => interms.push(
|
||||
drop_iter_on_err!(self, iter, max(a1, a2))
|
||||
),
|
||||
atom!("min") => self.interms.push(
|
||||
atom!("min") => interms.push(
|
||||
drop_iter_on_err!(self, iter, min(a1, a2))
|
||||
),
|
||||
atom!("rdiv") => {
|
||||
@@ -1246,39 +1241,39 @@ impl MachineState {
|
||||
&mut self.arena
|
||||
);
|
||||
|
||||
self.interms.push(Number::Rational(result));
|
||||
interms.push(Number::Rational(result));
|
||||
}
|
||||
atom!("//") => self.interms.push(
|
||||
atom!("//") => interms.push(
|
||||
drop_iter_on_err!(self, iter, idiv(a1, a2, &mut self.arena))
|
||||
),
|
||||
atom!("div") => self.interms.push(
|
||||
atom!("div") => interms.push(
|
||||
drop_iter_on_err!(self, iter, int_floor_div(a1, a2, &mut self.arena))
|
||||
),
|
||||
atom!(">>") => self.interms.push(
|
||||
atom!(">>") => interms.push(
|
||||
drop_iter_on_err!(self, iter, shr(a1, a2, &mut self.arena))
|
||||
),
|
||||
atom!("<<") => self.interms.push(
|
||||
atom!("<<") => interms.push(
|
||||
drop_iter_on_err!(self, iter, shl(a1, a2, &mut self.arena))
|
||||
),
|
||||
atom!("/\\") => self.interms.push(
|
||||
atom!("/\\") => interms.push(
|
||||
drop_iter_on_err!(self, iter, and(a1, a2, &mut self.arena))
|
||||
),
|
||||
atom!("\\/") => self.interms.push(
|
||||
atom!("\\/") => interms.push(
|
||||
drop_iter_on_err!(self, iter, or(a1, a2, &mut self.arena))
|
||||
),
|
||||
atom!("xor") => self.interms.push(
|
||||
atom!("xor") => interms.push(
|
||||
drop_iter_on_err!(self, iter, xor(a1, a2, &mut self.arena))
|
||||
),
|
||||
atom!("mod") => self.interms.push(
|
||||
atom!("mod") => interms.push(
|
||||
drop_iter_on_err!(self, iter, modulus(a1, a2, &mut self.arena))
|
||||
),
|
||||
atom!("rem") => self.interms.push(
|
||||
atom!("rem") => interms.push(
|
||||
drop_iter_on_err!(self, iter, remainder(a1, a2, &mut self.arena))
|
||||
),
|
||||
atom!("atan2") => self.interms.push(Number::Float(OrderedFloat(
|
||||
atom!("atan2") => interms.push(Number::Float(OrderedFloat(
|
||||
drop_iter_on_err!(self, iter, atan2(a1, a2))
|
||||
))),
|
||||
atom!("gcd") => self.interms.push(
|
||||
atom!("gcd") => interms.push(
|
||||
drop_iter_on_err!(self, iter, gcd(a1, a2, &mut self.arena))
|
||||
),
|
||||
_ => {
|
||||
@@ -1294,56 +1289,56 @@ impl MachineState {
|
||||
|
||||
continue;
|
||||
} else if arity == 1 {
|
||||
let a1 = self.interms.pop().unwrap();
|
||||
let a1 = interms.pop().unwrap();
|
||||
|
||||
match name {
|
||||
atom!("-") => self.interms.push(neg(a1, &mut self.arena)),
|
||||
atom!("+") => self.interms.push(a1),
|
||||
atom!("cos") => self.interms.push(Number::Float(OrderedFloat(
|
||||
atom!("-") => interms.push(neg(a1, &mut self.arena)),
|
||||
atom!("+") => interms.push(a1),
|
||||
atom!("cos") => interms.push(Number::Float(OrderedFloat(
|
||||
drop_iter_on_err!(self, iter, cos(a1))
|
||||
))),
|
||||
atom!("sin") => self.interms.push(Number::Float(OrderedFloat(
|
||||
atom!("sin") => interms.push(Number::Float(OrderedFloat(
|
||||
drop_iter_on_err!(self, iter, sin(a1))
|
||||
))),
|
||||
atom!("tan") => self.interms.push(Number::Float(OrderedFloat(
|
||||
atom!("tan") => interms.push(Number::Float(OrderedFloat(
|
||||
drop_iter_on_err!(self, iter, tan(a1))
|
||||
))),
|
||||
atom!("float_fractional_part") => self.interms.push(Number::Float(OrderedFloat(
|
||||
atom!("float_fractional_part") => interms.push(Number::Float(OrderedFloat(
|
||||
drop_iter_on_err!(self, iter, float_fractional_part(a1))
|
||||
))),
|
||||
atom!("float_integer_part") => self.interms.push(Number::Float(OrderedFloat(
|
||||
atom!("float_integer_part") => interms.push(Number::Float(OrderedFloat(
|
||||
drop_iter_on_err!(self, iter, float_integer_part(a1))
|
||||
))),
|
||||
atom!("sqrt") => self.interms.push(Number::Float(OrderedFloat(
|
||||
atom!("sqrt") => interms.push(Number::Float(OrderedFloat(
|
||||
drop_iter_on_err!(self, iter, sqrt(a1))
|
||||
))),
|
||||
atom!("log") => self.interms.push(Number::Float(OrderedFloat(
|
||||
atom!("log") => interms.push(Number::Float(OrderedFloat(
|
||||
drop_iter_on_err!(self, iter, log(a1))
|
||||
))),
|
||||
atom!("exp") => self.interms.push(Number::Float(OrderedFloat(
|
||||
atom!("exp") => interms.push(Number::Float(OrderedFloat(
|
||||
drop_iter_on_err!(self, iter, exp(a1))
|
||||
))),
|
||||
atom!("acos") => self.interms.push(Number::Float(OrderedFloat(
|
||||
atom!("acos") => interms.push(Number::Float(OrderedFloat(
|
||||
drop_iter_on_err!(self, iter, acos(a1))
|
||||
))),
|
||||
atom!("asin") => self.interms.push(Number::Float(OrderedFloat(
|
||||
atom!("asin") => interms.push(Number::Float(OrderedFloat(
|
||||
drop_iter_on_err!(self, iter, asin(a1))
|
||||
))),
|
||||
atom!("atan") => self.interms.push(Number::Float(OrderedFloat(
|
||||
atom!("atan") => interms.push(Number::Float(OrderedFloat(
|
||||
drop_iter_on_err!(self, iter, atan(a1))
|
||||
))),
|
||||
atom!("abs") => self.interms.push(abs(a1, &mut self.arena)),
|
||||
atom!("float") => self.interms.push(Number::Float(OrderedFloat(
|
||||
atom!("abs") => interms.push(abs(a1, &mut self.arena)),
|
||||
atom!("float") => interms.push(Number::Float(OrderedFloat(
|
||||
drop_iter_on_err!(self, iter, float(a1))
|
||||
))),
|
||||
atom!("truncate") => self.interms.push(truncate(a1, &mut self.arena)),
|
||||
atom!("round") => self.interms.push(drop_iter_on_err!(self, iter, round(a1, &mut self.arena))),
|
||||
atom!("ceiling") => self.interms.push(ceiling(a1, &mut self.arena)),
|
||||
atom!("floor") => self.interms.push(floor(a1, &mut self.arena)),
|
||||
atom!("\\") => self.interms.push(
|
||||
atom!("truncate") => interms.push(truncate(a1, &mut self.arena)),
|
||||
atom!("round") => interms.push(drop_iter_on_err!(self, iter, round(a1, &mut self.arena))),
|
||||
atom!("ceiling") => interms.push(ceiling(a1, &mut self.arena)),
|
||||
atom!("floor") => interms.push(floor(a1, &mut self.arena)),
|
||||
atom!("\\") => interms.push(
|
||||
drop_iter_on_err!(self, iter, bitwise_complement(a1, &mut self.arena))
|
||||
),
|
||||
atom!("sign") => self.interms.push(a1.sign()),
|
||||
atom!("sign") => interms.push(a1.sign()),
|
||||
_ => {
|
||||
let evaluable_stub = functor_stub(name, 1);
|
||||
std::mem::drop(iter);
|
||||
@@ -1362,15 +1357,15 @@ impl MachineState {
|
||||
} else if arity == 0 {
|
||||
match name {
|
||||
atom!("pi") => {
|
||||
self.interms.push(Number::Float(OrderedFloat(f64::consts::PI)));
|
||||
interms.push(Number::Float(OrderedFloat(f64::consts::PI)));
|
||||
continue;
|
||||
}
|
||||
atom!("e") => {
|
||||
self.interms.push(Number::Float(OrderedFloat(f64::consts::E)));
|
||||
interms.push(Number::Float(OrderedFloat(f64::consts::E)));
|
||||
continue;
|
||||
}
|
||||
atom!("epsilon") => {
|
||||
self.interms.push(Number::Float(OrderedFloat(f64::EPSILON)));
|
||||
interms.push(Number::Float(OrderedFloat(f64::EPSILON)));
|
||||
continue;
|
||||
}
|
||||
_ => {
|
||||
@@ -1386,19 +1381,19 @@ impl MachineState {
|
||||
return Err(self.error_form(evaluable_error, stub));
|
||||
}
|
||||
(HeapCellValueTag::Fixnum, n) => {
|
||||
self.interms.push(Number::Fixnum(n));
|
||||
interms.push(Number::Fixnum(n));
|
||||
}
|
||||
(HeapCellValueTag::F64Offset, offset) => {
|
||||
let fl = self.arena.f64_tbl.get_entry(offset);
|
||||
self.interms.push(Number::Float(fl));
|
||||
interms.push(Number::Float(fl));
|
||||
}
|
||||
(HeapCellValueTag::Cons, ptr) => {
|
||||
match_untyped_arena_ptr!(ptr,
|
||||
(ArenaHeaderTag::Integer, n) => {
|
||||
self.interms.push(Number::Integer(n));
|
||||
interms.push(Number::Integer(n));
|
||||
}
|
||||
(ArenaHeaderTag::Rational, r) => {
|
||||
self.interms.push(Number::Rational(r));
|
||||
interms.push(Number::Rational(r));
|
||||
}
|
||||
_ => {
|
||||
std::mem::drop(iter);
|
||||
@@ -1429,7 +1424,7 @@ impl MachineState {
|
||||
)
|
||||
}
|
||||
|
||||
Ok(self.interms.pop().unwrap())
|
||||
Ok(interms.pop().unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@ pub(super) struct AttrVarInitializer {
|
||||
pub(super) bindings: Bindings,
|
||||
pub(super) p: usize,
|
||||
pub(super) cp: usize,
|
||||
// pub(super) instigating_p: usize,
|
||||
pub(super) verify_attrs_loc: usize,
|
||||
}
|
||||
|
||||
@@ -41,13 +40,13 @@ impl MachineState {
|
||||
pub(super) fn push_attr_var_binding(&mut self, h: usize, addr: HeapCellValue) {
|
||||
if self.attr_var_init.bindings.is_empty() {
|
||||
// save self.p and self.cp and ensure that the next
|
||||
// instruction is InstallVerifyAttrInterrupt.
|
||||
// instruction is RunVerifyAttrInterrupt.
|
||||
|
||||
self.attr_var_init.p = self.p;
|
||||
self.attr_var_init.cp = self.cp;
|
||||
|
||||
self.p = INSTALL_VERIFY_ATTR_INTERRUPT - 1;
|
||||
self.cp = INSTALL_VERIFY_ATTR_INTERRUPT;
|
||||
self.p = VERIFY_ATTR_INTERRUPT_LOC - 1;
|
||||
self.cp = VERIFY_ATTR_INTERRUPT_LOC;
|
||||
}
|
||||
|
||||
debug_assert_eq!(self.heap[h].get_tag(), HeapCellValueTag::AttrVar);
|
||||
@@ -122,7 +121,7 @@ impl MachineState {
|
||||
let e = self.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];
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -86,7 +86,6 @@ pub struct MachineState {
|
||||
pub(super) ball: Ball,
|
||||
pub(super) ball_stack: Vec<Ball>, // save current ball before jumping via, e.g., verify_attr interrupt.
|
||||
pub(super) lifted_heap: Heap,
|
||||
pub(super) interms: Vec<Number>, // intermediate numbers.
|
||||
// locations of cleaners, cut points, the previous scc_block. for setup_call_cleanup/3.
|
||||
pub(super) cont_pts: Vec<(HeapCellValue, usize, usize)>,
|
||||
pub(super) cwil: CWIL,
|
||||
@@ -125,7 +124,6 @@ impl fmt::Debug for MachineState {
|
||||
.field("ball", &self.ball)
|
||||
.field("ball_stack", &self.ball_stack)
|
||||
.field("lifted_heap", &self.lifted_heap)
|
||||
.field("interms", &self.interms)
|
||||
.field("flags", &self.flags)
|
||||
.field("cc", &self.cc)
|
||||
.field("global_clock", &self.global_clock)
|
||||
|
||||
@@ -58,7 +58,6 @@ impl MachineState {
|
||||
ball: Ball::new(),
|
||||
ball_stack: vec![],
|
||||
lifted_heap: Heap::new(),
|
||||
interms: vec![Number::default(); 256],
|
||||
cont_pts: Vec::with_capacity(256),
|
||||
cwil: CWIL::new(),
|
||||
flags: MachineFlags::default(),
|
||||
|
||||
@@ -143,9 +143,8 @@ mod libraries {
|
||||
}
|
||||
|
||||
pub static BREAK_FROM_DISPATCH_LOOP_LOC: usize = 0;
|
||||
pub static INSTALL_VERIFY_ATTR_INTERRUPT: usize = 1;
|
||||
pub static VERIFY_ATTR_INTERRUPT_LOC: usize = 2;
|
||||
pub static LIB_QUERY_SUCCESS: usize = 3;
|
||||
pub static VERIFY_ATTR_INTERRUPT_LOC: usize = 1;
|
||||
pub static LIB_QUERY_SUCCESS: usize = 2;
|
||||
|
||||
pub struct MachinePreludeView<'a> {
|
||||
pub indices: &'a mut IndexStore,
|
||||
@@ -418,12 +417,11 @@ impl Machine {
|
||||
}
|
||||
|
||||
pub(crate) fn add_impls_to_indices(&mut self) {
|
||||
let impls_offset = self.code.len() + 4;
|
||||
let impls_offset = self.code.len() + 3;
|
||||
|
||||
self.code.extend(vec![
|
||||
Instruction::BreakFromDispatchLoop,
|
||||
Instruction::InstallVerifyAttr,
|
||||
Instruction::VerifyAttrInterrupt(0),
|
||||
Instruction::RunVerifyAttr,
|
||||
Instruction::BreakFromDispatchLoop, // the location of LIB_QUERY_SUCCESS
|
||||
Instruction::ExecuteTermGreaterThan,
|
||||
Instruction::ExecuteTermLessThan,
|
||||
|
||||
@@ -25,7 +25,7 @@ use crate::machine::machine_state::*;
|
||||
use crate::machine::partial_string::*;
|
||||
use crate::machine::stack::*;
|
||||
use crate::machine::streams::*;
|
||||
use crate::machine::{get_structure_index, Machine, VERIFY_ATTR_INTERRUPT_LOC};
|
||||
use crate::machine::{get_structure_index, Machine};
|
||||
use crate::parser::ast::*;
|
||||
use crate::parser::char_reader::*;
|
||||
use crate::parser::dashu::Integer;
|
||||
@@ -6267,6 +6267,7 @@ impl Machine {
|
||||
self.machine_st.heap[var.get_value() as usize] = value;
|
||||
}
|
||||
|
||||
/*
|
||||
#[inline(always)]
|
||||
pub(super) fn restore_instr_at_verify_attr_interrupt(&mut self) {
|
||||
match &self.code[VERIFY_ATTR_INTERRUPT_LOC] {
|
||||
@@ -6281,10 +6282,11 @@ impl Machine {
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn reset_attr_var_state(&mut self, queue_len: usize) {
|
||||
self.restore_instr_at_verify_attr_interrupt();
|
||||
// self.restore_instr_at_verify_attr_interrupt();
|
||||
self.machine_st.attr_var_init.reset(queue_len);
|
||||
}
|
||||
|
||||
@@ -6315,7 +6317,7 @@ impl Machine {
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn return_from_verify_attr(&mut self) {
|
||||
self.restore_instr_at_verify_attr_interrupt();
|
||||
// self.restore_instr_at_verify_attr_interrupt();
|
||||
|
||||
let e = self.machine_st.e;
|
||||
let frame_len = self.machine_st.stack.index_and_frame(e).prelude.num_cells;
|
||||
|
||||
@@ -369,12 +369,6 @@ macro_rules! compare_number_instr {
|
||||
}};
|
||||
}
|
||||
|
||||
macro_rules! interm {
|
||||
($n: expr) => {
|
||||
ArithmeticTerm::Interm($n)
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! ar_reg {
|
||||
($r: expr) => {
|
||||
ArithmeticTerm::Reg($r)
|
||||
|
||||
Reference in New Issue
Block a user