implement unify_ginteger to address FIXME in skip_max_list_cycle
This commit is contained in:
@@ -278,6 +278,11 @@ impl MachineState {
|
|||||||
unifier.unify_fixnum(n1, value);
|
unifier.unify_fixnum(n1, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn unify_ginteger(&mut self, n1: GInteger, value: HeapCellValue) {
|
||||||
|
let mut unifier = DefaultUnifier::from(self);
|
||||||
|
unifier.unify_ginteger(n1, value);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn unify_big_int(&mut self, n1: TypedArenaPtr<Integer>, value: HeapCellValue) {
|
pub fn unify_big_int(&mut self, n1: TypedArenaPtr<Integer>, value: HeapCellValue) {
|
||||||
let mut unifier = DefaultUnifier::from(self);
|
let mut unifier = DefaultUnifier::from(self);
|
||||||
unifier.unify_big_integer(n1, value);
|
unifier.unify_big_integer(n1, value);
|
||||||
|
|||||||
@@ -744,11 +744,9 @@ impl MachineState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let target_n = self.store(self.deref(self.registers[1]));
|
let target_n = self.store(self.deref(self.registers[1]));
|
||||||
self.unify_fixnum(
|
let num_steps = fixnum!(GInteger, brent_st.num_steps() as i64, &mut self.arena);
|
||||||
/* FIXME this is not safe */
|
|
||||||
unsafe { Fixnum::build_with_unchecked(brent_st.num_steps() as i64) },
|
self.unify_ginteger(num_steps, target_n);
|
||||||
target_n,
|
|
||||||
);
|
|
||||||
|
|
||||||
if !self.fail {
|
if !self.fail {
|
||||||
unify!(self, self.registers[4], self.heap[prev_hare]);
|
unify!(self, self.registers[4], self.heap[prev_hare]);
|
||||||
|
|||||||
@@ -150,6 +150,13 @@ pub(crate) trait Unifier: DerefMut<Target = MachineState> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn unify_ginteger(&mut self, n: GInteger, value: HeapCellValue) {
|
||||||
|
match n {
|
||||||
|
GInteger::Integer(integer) => self.unify_big_int(integer, value),
|
||||||
|
GInteger::Fixnum(fixnum) => self.unify_fixnum(fixnum, value),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn unify_atom(&mut self, atom: Atom, value: HeapCellValue) {
|
fn unify_atom(&mut self, atom: Atom, value: HeapCellValue) {
|
||||||
read_heap_cell!(value,
|
read_heap_cell!(value,
|
||||||
(HeapCellValueTag::Atom, (name, arity)) => {
|
(HeapCellValueTag::Atom, (name, arity)) => {
|
||||||
|
|||||||
@@ -241,6 +241,22 @@ macro_rules! is_fy {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum GInteger {
|
||||||
|
Integer(TypedArenaPtr<Integer>),
|
||||||
|
Fixnum(Fixnum),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GInteger {
|
||||||
|
#[inline]
|
||||||
|
pub fn to_literal(self) -> Literal {
|
||||||
|
match self {
|
||||||
|
GInteger::Integer(integer) => Literal::Integer(integer),
|
||||||
|
GInteger::Fixnum(fixnum) => Literal::Fixnum(fixnum),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub enum RegType {
|
pub enum RegType {
|
||||||
Perm(usize),
|
Perm(usize),
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
use crate::arena::*;
|
|
||||||
use crate::atom_table::*;
|
use crate::atom_table::*;
|
||||||
pub use crate::machine::machine_state::*;
|
pub use crate::machine::machine_state::*;
|
||||||
use crate::offset_table::*;
|
use crate::offset_table::*;
|
||||||
@@ -67,7 +66,7 @@ impl NumberToken {
|
|||||||
fn to_token(self) -> Option<Token> {
|
fn to_token(self) -> Option<Token> {
|
||||||
match self {
|
match self {
|
||||||
NumberToken::Float(offset, fl) => Some(Token::Literal(Literal::F64(offset, fl))),
|
NumberToken::Float(offset, fl) => Some(Token::Literal(Literal::F64(offset, fl))),
|
||||||
NumberToken::Integer(GInteger::BigInt(n)) => Some(Token::Literal(Literal::Integer(n))),
|
NumberToken::Integer(GInteger::Integer(n)) => Some(Token::Literal(Literal::Integer(n))),
|
||||||
NumberToken::Integer(GInteger::Fixnum(n)) => Some(Token::Literal(Literal::Fixnum(n))),
|
NumberToken::Integer(GInteger::Fixnum(n)) => Some(Token::Literal(Literal::Fixnum(n))),
|
||||||
NumberToken::Partial(_) => None,
|
NumberToken::Partial(_) => None,
|
||||||
}
|
}
|
||||||
@@ -89,22 +88,6 @@ macro_rules! try_nt {
|
|||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
enum GInteger {
|
|
||||||
BigInt(TypedArenaPtr<Integer>),
|
|
||||||
Fixnum(Fixnum),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GInteger {
|
|
||||||
#[inline]
|
|
||||||
fn to_literal(self) -> Literal {
|
|
||||||
match self {
|
|
||||||
GInteger::BigInt(integer) => Literal::Integer(integer),
|
|
||||||
GInteger::Fixnum(fixnum) => Literal::Fixnum(fixnum),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) struct Lexer<'a, R> {
|
pub(crate) struct Lexer<'a, R> {
|
||||||
pub(crate) reader: R,
|
pub(crate) reader: R,
|
||||||
pub(crate) machine_st: &'a mut MachineState,
|
pub(crate) machine_st: &'a mut MachineState,
|
||||||
@@ -716,12 +699,15 @@ impl<'a, R: CharRead> Lexer<'a, R> {
|
|||||||
Fixnum::build_with_checked(n)
|
Fixnum::build_with_checked(n)
|
||||||
.map(GInteger::Fixnum)
|
.map(GInteger::Fixnum)
|
||||||
.unwrap_or_else(|_| {
|
.unwrap_or_else(|_| {
|
||||||
GInteger::BigInt(arena_alloc!(Integer::from(n), &mut self.machine_st.arena))
|
GInteger::Integer(arena_alloc!(
|
||||||
|
Integer::from(n),
|
||||||
|
&mut self.machine_st.arena
|
||||||
|
))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.or_else(|_| {
|
.or_else(|_| {
|
||||||
Integer::from_str_radix(token, radix)
|
Integer::from_str_radix(token, radix)
|
||||||
.map(|n| GInteger::BigInt(arena_alloc!(n, &mut self.machine_st.arena)))
|
.map(|n| GInteger::Integer(arena_alloc!(n, &mut self.machine_st.arena)))
|
||||||
.map_err(|_| ParserError::ParseBigInt(self.line_num, self.col_num))
|
.map_err(|_| ParserError::ParseBigInt(self.line_num, self.col_num))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user