| 98 | impl<'a> VM<'a> { |
| 99 | |
| 100 | pub fn call_abs(&mut self) -> Result<(), VmErr> { |
| 101 | let o = self.pop()?; |
| 102 | let v = if o.is_float() { |
| 103 | Val::float(o.as_float().abs()) |
| 104 | } else if let Some(i) = self.as_i128(o) { |
| 105 | // i128::MIN.checked_abs() is None, trap as OverflowError. |
| 106 | self.int_to_val(i.checked_abs())? |
| 107 | } else { |
| 108 | return Err(cold_type("abs() requires a number")); |
| 109 | }; |
| 110 | self.push(v); Ok(()) |
| 111 | } |
| 112 | |
| 113 | pub fn call_int(&mut self, argc: u16, chunk: &crate::modules::parser::SSAChunk, slots: &mut [Val]) -> Result<(), VmErr> { |
| 114 | // Two-arg form `int(string, base)`: parse the string in the given radix. |