misc: remove i128 support
Rather than doing this, we should use a BigNumber library
This commit is contained in:
parent
f1083009a4
commit
e4484297a9
3 changed files with 5 additions and 47 deletions
47
mute-interpreter/src/env/core.rs
vendored
47
mute-interpreter/src/env/core.rs
vendored
|
@ -1,9 +1,9 @@
|
|||
use std::borrow::Borrow;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::{Error, Node};
|
||||
use crate::evaluator::{eval, eval_node};
|
||||
use crate::macros::arg_count;
|
||||
use crate::{Error, Node};
|
||||
|
||||
pub(super) fn core() -> HashMap<String, Node> {
|
||||
[
|
||||
|
@ -92,23 +92,13 @@ pub(super) fn core() -> HashMap<String, Node> {
|
|||
let res = args
|
||||
.into_iter()
|
||||
.reduce(|lhs, rhs| match (lhs, rhs) {
|
||||
(Node::Int(lhs), Node::Int(rhs)) => match lhs.checked_add(rhs) {
|
||||
Some(val) => Node::Int(val),
|
||||
None => Node::Int128(lhs as i128 + rhs as i128),
|
||||
},
|
||||
(Node::Int128(lhs), Node::Int128(rhs)) => Node::Int128(lhs + rhs),
|
||||
(Node::Int(lhs), Node::Int128(rhs)) => {
|
||||
Node::Int128(lhs as i128 + rhs as i128)
|
||||
}
|
||||
(Node::Int128(lhs), Node::Int(rhs)) => Node::Int128(lhs + rhs as i128),
|
||||
|
||||
(Node::Int(lhs), Node::Int(rhs)) => Node::Int(lhs + rhs),
|
||||
(Node::Float(lhs), Node::Float(rhs)) => Node::Float(lhs + rhs),
|
||||
(Node::Int(lhs), Node::Float(rhs)) => Node::Float(lhs as f64 + rhs),
|
||||
(Node::Float(lhs), Node::Int(rhs)) => Node::Float(lhs + rhs as f64),
|
||||
_ => todo!(),
|
||||
})
|
||||
.unwrap_or(Node::Int(0));
|
||||
|
||||
Ok(res)
|
||||
}),
|
||||
),
|
||||
|
@ -118,16 +108,7 @@ pub(super) fn core() -> HashMap<String, Node> {
|
|||
let res = args
|
||||
.into_iter()
|
||||
.reduce(|lhs, rhs| match (lhs, rhs) {
|
||||
(Node::Int(lhs), Node::Int(rhs)) => match lhs.checked_sub(rhs) {
|
||||
Some(val) => Node::Int(val),
|
||||
None => Node::Int128(lhs as i128 - rhs as i128),
|
||||
},
|
||||
(Node::Int128(lhs), Node::Int128(rhs)) => Node::Int128(lhs - rhs),
|
||||
(Node::Int(lhs), Node::Int128(rhs)) => {
|
||||
Node::Int128(lhs as i128 - rhs as i128)
|
||||
}
|
||||
(Node::Int128(lhs), Node::Int(rhs)) => Node::Int128(lhs - rhs as i128),
|
||||
|
||||
(Node::Int(lhs), Node::Int(rhs)) => Node::Int(lhs - rhs),
|
||||
(Node::Float(lhs), Node::Float(rhs)) => Node::Float(lhs - rhs),
|
||||
(Node::Float(lhs), Node::Int(rhs)) => Node::Float(lhs - rhs as f64),
|
||||
(Node::Int(lhs), Node::Float(rhs)) => Node::Float(lhs as f64 - rhs),
|
||||
|
@ -144,16 +125,7 @@ pub(super) fn core() -> HashMap<String, Node> {
|
|||
let res = args
|
||||
.into_iter()
|
||||
.reduce(|lhs, rhs| match (lhs, rhs) {
|
||||
(Node::Int(lhs), Node::Int(rhs)) => match lhs.checked_mul(rhs) {
|
||||
Some(val) => Node::Int(val),
|
||||
None => Node::Int128(lhs as i128 * rhs as i128),
|
||||
},
|
||||
(Node::Int128(lhs), Node::Int128(rhs)) => Node::Int128(lhs * rhs),
|
||||
(Node::Int(lhs), Node::Int128(rhs)) => {
|
||||
Node::Int128(lhs as i128 * rhs as i128)
|
||||
}
|
||||
(Node::Int128(lhs), Node::Int(rhs)) => Node::Int128(lhs * rhs as i128),
|
||||
|
||||
(Node::Int(lhs), Node::Int(rhs)) => Node::Int(lhs * rhs),
|
||||
(Node::Float(lhs), Node::Float(rhs)) => Node::Float(lhs * rhs),
|
||||
(Node::Float(lhs), Node::Int(rhs)) => Node::Float(lhs * rhs as f64),
|
||||
(Node::Int(lhs), Node::Float(rhs)) => Node::Float(lhs as f64 * rhs),
|
||||
|
@ -170,16 +142,7 @@ pub(super) fn core() -> HashMap<String, Node> {
|
|||
let res = args
|
||||
.into_iter()
|
||||
.reduce(|lhs, rhs| match (lhs, rhs) {
|
||||
(Node::Int(lhs), Node::Int(rhs)) => match lhs.checked_div(rhs) {
|
||||
Some(val) => Node::Int(val),
|
||||
None => Node::Int128(lhs as i128 / rhs as i128),
|
||||
},
|
||||
(Node::Int128(lhs), Node::Int128(rhs)) => Node::Int128(lhs / rhs),
|
||||
(Node::Int(lhs), Node::Int128(rhs)) => {
|
||||
Node::Int128(lhs as i128 / rhs as i128)
|
||||
}
|
||||
(Node::Int128(lhs), Node::Int(rhs)) => Node::Int128(lhs / rhs as i128),
|
||||
|
||||
(Node::Int(lhs), Node::Int(rhs)) => Node::Int(lhs / rhs),
|
||||
(Node::Float(lhs), Node::Float(rhs)) => Node::Float(lhs / rhs),
|
||||
(Node::Float(lhs), Node::Int(rhs)) => Node::Float(lhs / rhs as f64),
|
||||
(Node::Int(lhs), Node::Float(rhs)) => Node::Float(lhs as f64 / rhs),
|
||||
|
|
|
@ -10,7 +10,6 @@ pub enum Node {
|
|||
Symbol(String),
|
||||
Keyword(String),
|
||||
Int(i64),
|
||||
Int128(i128),
|
||||
Float(f64),
|
||||
String(String),
|
||||
Boolean(bool),
|
||||
|
@ -36,7 +35,6 @@ impl From<mute_parser::Node> for Node {
|
|||
mute_parser::Node::Symbol(symbol) => Node::Symbol(symbol),
|
||||
mute_parser::Node::Keyword(keyword) => Node::Keyword(keyword),
|
||||
mute_parser::Node::Int(int) => Node::Int(int),
|
||||
mute_parser::Node::Int128(int) => Node::Int128(int),
|
||||
mute_parser::Node::Float(float) => Node::Float(float),
|
||||
mute_parser::Node::String(string) => Node::String(string),
|
||||
mute_parser::Node::Boolean(boolean) => Node::Boolean(boolean),
|
||||
|
@ -65,7 +63,6 @@ impl std::fmt::Display for Node {
|
|||
}
|
||||
|
||||
Node::Int(val) => write!(f, "{}", val),
|
||||
Node::Int128(val) => write!(f, "{}", val),
|
||||
Node::Float(val) => write!(f, "{}", val),
|
||||
Node::Boolean(true) => write!(f, "true"),
|
||||
Node::Boolean(false) => write!(f, "false"),
|
||||
|
|
|
@ -7,7 +7,6 @@ pub enum Node {
|
|||
Symbol(String),
|
||||
Keyword(String),
|
||||
Int(i64),
|
||||
Int128(i128),
|
||||
Float(f64),
|
||||
String(String),
|
||||
Boolean(bool),
|
||||
|
@ -31,7 +30,6 @@ impl std::fmt::Display for Node {
|
|||
}
|
||||
|
||||
Node::Int(val) => write!(f, "{}", val),
|
||||
Node::Int128(val) => write!(f, "{}", val),
|
||||
Node::Float(val) => write!(f, "{}", val),
|
||||
Node::Boolean(true) => write!(f, "true"),
|
||||
Node::Boolean(false) => write!(f, "false"),
|
||||
|
|
Loading…
Reference in a new issue