Rename MemoryItem to KclValue (#3378)

As @jon points out, "It's not only used in ProgramMemory. It's also
used as the return value of functions and as what gets substituted in
for the pipe substitution symbol %"
This commit is contained in:
Adam Chalmers
2024-08-12 16:53:24 -05:00
committed by GitHub
parent 13986fcfd7
commit 3dabab2c74
37 changed files with 335 additions and 335 deletions

View File

@ -6,12 +6,12 @@ use schemars::JsonSchema;
use crate::{
errors::{KclError, KclErrorDetails},
executor::MemoryItem,
executor::KclValue,
std::Args,
};
/// Compute the cosine of a number (in radians).
pub async fn cos(args: Args) -> Result<MemoryItem, KclError> {
pub async fn cos(args: Args) -> Result<KclValue, KclError> {
let num = args.get_number()?;
let result = inner_cos(num)?;
@ -41,7 +41,7 @@ fn inner_cos(num: f64) -> Result<f64, KclError> {
}
/// Compute the sine of a number (in radians).
pub async fn sin(args: Args) -> Result<MemoryItem, KclError> {
pub async fn sin(args: Args) -> Result<KclValue, KclError> {
let num = args.get_number()?;
let result = inner_sin(num)?;
@ -71,7 +71,7 @@ fn inner_sin(num: f64) -> Result<f64, KclError> {
}
/// Compute the tangent of a number (in radians).
pub async fn tan(args: Args) -> Result<MemoryItem, KclError> {
pub async fn tan(args: Args) -> Result<KclValue, KclError> {
let num = args.get_number()?;
let result = inner_tan(num)?;
@ -101,7 +101,7 @@ fn inner_tan(num: f64) -> Result<f64, KclError> {
}
/// Return the value of `pi`. Archimedes constant (π).
pub async fn pi(args: Args) -> Result<MemoryItem, KclError> {
pub async fn pi(args: Args) -> Result<KclValue, KclError> {
let result = inner_pi()?;
args.make_user_val_from_f64(result)
@ -126,7 +126,7 @@ fn inner_pi() -> Result<f64, KclError> {
}
/// Compute the square root of a number.
pub async fn sqrt(args: Args) -> Result<MemoryItem, KclError> {
pub async fn sqrt(args: Args) -> Result<KclValue, KclError> {
let num = args.get_number()?;
let result = inner_sqrt(num)?;
@ -156,7 +156,7 @@ fn inner_sqrt(num: f64) -> Result<f64, KclError> {
}
/// Compute the absolute value of a number.
pub async fn abs(args: Args) -> Result<MemoryItem, KclError> {
pub async fn abs(args: Args) -> Result<KclValue, KclError> {
let num = args.get_number()?;
let result = inner_abs(num)?;
@ -193,7 +193,7 @@ fn inner_abs(num: f64) -> Result<f64, KclError> {
}
/// Compute the largest integer less than or equal to a number.
pub async fn floor(args: Args) -> Result<MemoryItem, KclError> {
pub async fn floor(args: Args) -> Result<KclValue, KclError> {
let num = args.get_number()?;
let result = inner_floor(num)?;
@ -221,7 +221,7 @@ fn inner_floor(num: f64) -> Result<f64, KclError> {
}
/// Compute the smallest integer greater than or equal to a number.
pub async fn ceil(args: Args) -> Result<MemoryItem, KclError> {
pub async fn ceil(args: Args) -> Result<KclValue, KclError> {
let num = args.get_number()?;
let result = inner_ceil(num)?;
@ -249,7 +249,7 @@ fn inner_ceil(num: f64) -> Result<f64, KclError> {
}
/// Compute the minimum of the given arguments.
pub async fn min(args: Args) -> Result<MemoryItem, KclError> {
pub async fn min(args: Args) -> Result<KclValue, KclError> {
let nums = args.get_number_array()?;
let result = inner_min(nums);
@ -286,7 +286,7 @@ fn inner_min(args: Vec<f64>) -> f64 {
}
/// Compute the maximum of the given arguments.
pub async fn max(args: Args) -> Result<MemoryItem, KclError> {
pub async fn max(args: Args) -> Result<KclValue, KclError> {
let nums = args.get_number_array()?;
let result = inner_max(nums);
@ -323,7 +323,7 @@ fn inner_max(args: Vec<f64>) -> f64 {
}
/// Compute the number to a power.
pub async fn pow(args: Args) -> Result<MemoryItem, KclError> {
pub async fn pow(args: Args) -> Result<KclValue, KclError> {
let nums = args.get_number_array()?;
if nums.len() > 2 {
return Err(KclError::Type(KclErrorDetails {
@ -367,7 +367,7 @@ fn inner_pow(num: f64, pow: f64) -> Result<f64, KclError> {
}
/// Compute the arccosine of a number (in radians).
pub async fn acos(args: Args) -> Result<MemoryItem, KclError> {
pub async fn acos(args: Args) -> Result<KclValue, KclError> {
let num = args.get_number()?;
let result = inner_acos(num)?;
@ -398,7 +398,7 @@ fn inner_acos(num: f64) -> Result<f64, KclError> {
}
/// Compute the arcsine of a number (in radians).
pub async fn asin(args: Args) -> Result<MemoryItem, KclError> {
pub async fn asin(args: Args) -> Result<KclValue, KclError> {
let num = args.get_number()?;
let result = inner_asin(num)?;
@ -428,7 +428,7 @@ fn inner_asin(num: f64) -> Result<f64, KclError> {
}
/// Compute the arctangent of a number (in radians).
pub async fn atan(args: Args) -> Result<MemoryItem, KclError> {
pub async fn atan(args: Args) -> Result<KclValue, KclError> {
let num = args.get_number()?;
let result = inner_atan(num)?;
@ -462,7 +462,7 @@ fn inner_atan(num: f64) -> Result<f64, KclError> {
/// The result might not be correctly rounded owing to implementation
/// details; `log2()` can produce more accurate results for base 2,
/// and `log10()` can produce more accurate results for base 10.
pub async fn log(args: Args) -> Result<MemoryItem, KclError> {
pub async fn log(args: Args) -> Result<KclValue, KclError> {
let nums = args.get_number_array()?;
if nums.len() > 2 {
return Err(KclError::Type(KclErrorDetails {
@ -507,7 +507,7 @@ fn inner_log(num: f64, base: f64) -> Result<f64, KclError> {
}
/// Compute the base 2 logarithm of the number.
pub async fn log2(args: Args) -> Result<MemoryItem, KclError> {
pub async fn log2(args: Args) -> Result<KclValue, KclError> {
let num = args.get_number()?;
let result = inner_log2(num)?;
@ -535,7 +535,7 @@ fn inner_log2(num: f64) -> Result<f64, KclError> {
}
/// Compute the base 10 logarithm of the number.
pub async fn log10(args: Args) -> Result<MemoryItem, KclError> {
pub async fn log10(args: Args) -> Result<KclValue, KclError> {
let num = args.get_number()?;
let result = inner_log10(num)?;
@ -563,7 +563,7 @@ fn inner_log10(num: f64) -> Result<f64, KclError> {
}
/// Compute the natural logarithm of the number.
pub async fn ln(args: Args) -> Result<MemoryItem, KclError> {
pub async fn ln(args: Args) -> Result<KclValue, KclError> {
let num = args.get_number()?;
let result = inner_ln(num)?;
@ -591,7 +591,7 @@ fn inner_ln(num: f64) -> Result<f64, KclError> {
}
/// Return the value of Eulers number `e`.
pub async fn e(args: Args) -> Result<MemoryItem, KclError> {
pub async fn e(args: Args) -> Result<KclValue, KclError> {
let result = inner_e()?;
args.make_user_val_from_f64(result)
@ -620,7 +620,7 @@ fn inner_e() -> Result<f64, KclError> {
}
/// Return the value of `tau`. The full circle constant (τ). Equal to 2π.
pub async fn tau(args: Args) -> Result<MemoryItem, KclError> {
pub async fn tau(args: Args) -> Result<KclValue, KclError> {
let result = inner_tau()?;
args.make_user_val_from_f64(result)
@ -649,7 +649,7 @@ fn inner_tau() -> Result<f64, KclError> {
}
/// Converts a number from degrees to radians.
pub async fn to_radians(args: Args) -> Result<MemoryItem, KclError> {
pub async fn to_radians(args: Args) -> Result<KclValue, KclError> {
let num = args.get_number()?;
let result = inner_to_radians(num)?;
@ -679,7 +679,7 @@ fn inner_to_radians(num: f64) -> Result<f64, KclError> {
}
/// Converts a number from radians to degrees.
pub async fn to_degrees(args: Args) -> Result<MemoryItem, KclError> {
pub async fn to_degrees(args: Args) -> Result<KclValue, KclError> {
let num = args.get_number()?;
let result = inner_to_degrees(num)?;