summaryrefslogtreecommitdiff
path: root/src/library/utility/math.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-05-25 13:50:33 +0200
committerLaurenz <laurmaedje@gmail.com>2022-05-25 13:59:06 +0200
commitc010cbc17dcbb2f0d6005d21530143bf57cb5871 (patch)
tree937fe79f0c121bcc025480181287fd4a3d0c0f4f /src/library/utility/math.rs
parent6935cf8dfefff3d6cf234f077a7d61661fd5ca57 (diff)
Move route from context to VM
Diffstat (limited to 'src/library/utility/math.rs')
-rw-r--r--src/library/utility/math.rs18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/library/utility/math.rs b/src/library/utility/math.rs
index 63ec5e55..05c706ca 100644
--- a/src/library/utility/math.rs
+++ b/src/library/utility/math.rs
@@ -3,7 +3,7 @@ use std::cmp::Ordering;
use crate::library::prelude::*;
/// Convert a value to a integer.
-pub fn int(_: &mut Context, args: &mut Args) -> TypResult<Value> {
+pub fn int(_: &mut Machine, args: &mut Args) -> TypResult<Value> {
let Spanned { v, span } = args.expect("value")?;
Ok(Value::Int(match v {
Value::Bool(v) => v as i64,
@@ -18,7 +18,7 @@ pub fn int(_: &mut Context, args: &mut Args) -> TypResult<Value> {
}
/// Convert a value to a float.
-pub fn float(_: &mut Context, args: &mut Args) -> TypResult<Value> {
+pub fn float(_: &mut Machine, args: &mut Args) -> TypResult<Value> {
let Spanned { v, span } = args.expect("value")?;
Ok(Value::Float(match v {
Value::Int(v) => v as f64,
@@ -32,7 +32,7 @@ pub fn float(_: &mut Context, args: &mut Args) -> TypResult<Value> {
}
/// The absolute value of a numeric value.
-pub fn abs(_: &mut Context, args: &mut Args) -> TypResult<Value> {
+pub fn abs(_: &mut Machine, args: &mut Args) -> TypResult<Value> {
let Spanned { v, span } = args.expect("numeric value")?;
Ok(match v {
Value::Int(v) => Value::Int(v.abs()),
@@ -48,12 +48,12 @@ pub fn abs(_: &mut Context, args: &mut Args) -> TypResult<Value> {
}
/// The minimum of a sequence of values.
-pub fn min(_: &mut Context, args: &mut Args) -> TypResult<Value> {
+pub fn min(_: &mut Machine, args: &mut Args) -> TypResult<Value> {
minmax(args, Ordering::Less)
}
/// The maximum of a sequence of values.
-pub fn max(_: &mut Context, args: &mut Args) -> TypResult<Value> {
+pub fn max(_: &mut Machine, args: &mut Args) -> TypResult<Value> {
minmax(args, Ordering::Greater)
}
@@ -79,17 +79,17 @@ fn minmax(args: &mut Args, goal: Ordering) -> TypResult<Value> {
}
/// Whether an integer is even.
-pub fn even(_: &mut Context, args: &mut Args) -> TypResult<Value> {
+pub fn even(_: &mut Machine, args: &mut Args) -> TypResult<Value> {
Ok(Value::Bool(args.expect::<i64>("integer")? % 2 == 0))
}
/// Whether an integer is odd.
-pub fn odd(_: &mut Context, args: &mut Args) -> TypResult<Value> {
+pub fn odd(_: &mut Machine, args: &mut Args) -> TypResult<Value> {
Ok(Value::Bool(args.expect::<i64>("integer")? % 2 != 0))
}
/// The modulo of two numbers.
-pub fn mod_(_: &mut Context, args: &mut Args) -> TypResult<Value> {
+pub fn mod_(_: &mut Machine, args: &mut Args) -> TypResult<Value> {
let Spanned { v: v1, span: span1 } = args.expect("integer or float")?;
let Spanned { v: v2, span: span2 } = args.expect("integer or float")?;
@@ -119,7 +119,7 @@ pub fn mod_(_: &mut Context, args: &mut Args) -> TypResult<Value> {
}
/// Create a sequence of numbers.
-pub fn range(_: &mut Context, args: &mut Args) -> TypResult<Value> {
+pub fn range(_: &mut Machine, args: &mut Args) -> TypResult<Value> {
let first = args.expect::<i64>("end")?;
let (start, end) = match args.eat::<i64>()? {
Some(second) => (first, second),