Merge pull request #656 from notoria/try_from_number

Fixed some conversion issues
This commit is contained in:
Mark Thom
2020-08-08 12:24:29 -03:00
committed by GitHub
2 changed files with 13 additions and 0 deletions

View File

@@ -918,6 +918,7 @@ op(Priority, OpSpec, Op) :-
halt :- halt(0).
halt(N) :-
must_be_number(N, halt/1),
( -2^31 =< N, N =< 2^31 - 1 ->
'$halt'(N)
; throw(error(domain_error(exit_code, N), halt/1))

View File

@@ -1706,6 +1706,12 @@ impl MachineState {
Ok(Number::Integer(n)) => {
n.to_string()
}
Ok(Number::Rational(r)) => {
// n has already been confirmed as an integer, and
// internally, Rational is assumed reduced, so its
// denominator must be 1.
r.numer().to_string()
}
_ => {
unreachable!()
}
@@ -3766,6 +3772,12 @@ impl MachineState {
let code = match Number::try_from((code, &self.heap)) {
Ok(Number::Fixnum(n)) => n as i32,
Ok(Number::Integer(n)) => n.to_i32().unwrap(),
Ok(Number::Rational(r)) => {
// n has already been confirmed as an integer, and
// internally, Rational is assumed reduced, so its
// denominator must be 1.
r.numer().to_i32().unwrap()
}
_ => { unreachable!() }
};