19 lines
496 B
Rust
19 lines
496 B
Rust
use fix_error::Error;
|
|
|
|
use crate::value::StrictValue;
|
|
use crate::{NixNum, VmError};
|
|
|
|
pub(super) fn vm_err(msg: impl Into<String>) -> VmError {
|
|
VmError::Uncatchable(Error::eval_error(msg.into()))
|
|
}
|
|
|
|
pub(super) fn get_num(val: StrictValue<'_>) -> Option<NixNum> {
|
|
if let Some(i) = val.as_inline::<i32>() {
|
|
Some(NixNum::Int(i as i64))
|
|
} else if let Some(gc_i) = val.as_gc::<i64>() {
|
|
Some(NixNum::Int(*gc_i))
|
|
} else {
|
|
val.as_float().map(NixNum::Float)
|
|
}
|
|
}
|