Unify execution state into a single struct (#3877)
* Add ExecState that combines ProgramMemory and DynamicState * Remove unneeded clones * Add exec_state parameter to all KCL stdlib functions * Move pipe value into ExecState * Add test for pipe substitution not leaking into function calls * KCL: Better message on assertEqual function Also add a new no-visual test for performance testing. * Fix new array module to use ExecState --------- Co-authored-by: Adam Chalmers <adam.chalmers@zoo.dev>
This commit is contained in:
@ -38,11 +38,14 @@ use crate::{
|
||||
ast::types::FunctionExpression,
|
||||
docs::StdLibFn,
|
||||
errors::KclError,
|
||||
executor::{KclValue, ProgramMemory, SketchGroup, SketchSurface},
|
||||
executor::{ExecState, KclValue, ProgramMemory, SketchGroup, SketchSurface},
|
||||
std::kcl_stdlib::KclStdLibFn,
|
||||
};
|
||||
|
||||
pub type StdFn = fn(Args) -> std::pin::Pin<Box<dyn std::future::Future<Output = Result<KclValue, KclError>> + Send>>;
|
||||
pub type StdFn = fn(
|
||||
&mut ExecState,
|
||||
Args,
|
||||
) -> std::pin::Pin<Box<dyn std::future::Future<Output = Result<KclValue, KclError>> + Send + '_>>;
|
||||
|
||||
pub type FnMap = HashMap<String, StdFn>;
|
||||
|
||||
@ -228,7 +231,7 @@ pub enum FunctionKind {
|
||||
}
|
||||
|
||||
/// Compute the length of the given leg.
|
||||
pub async fn leg_length(args: Args) -> Result<KclValue, KclError> {
|
||||
pub async fn leg_length(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
||||
let (hypotenuse, leg) = args.get_hypotenuse_leg()?;
|
||||
let result = inner_leg_length(hypotenuse, leg);
|
||||
args.make_user_val_from_f64(result)
|
||||
@ -248,7 +251,7 @@ fn inner_leg_length(hypotenuse: f64, leg: f64) -> f64 {
|
||||
}
|
||||
|
||||
/// Compute the angle of the given leg for x.
|
||||
pub async fn leg_angle_x(args: Args) -> Result<KclValue, KclError> {
|
||||
pub async fn leg_angle_x(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
||||
let (hypotenuse, leg) = args.get_hypotenuse_leg()?;
|
||||
let result = inner_leg_angle_x(hypotenuse, leg);
|
||||
args.make_user_val_from_f64(result)
|
||||
@ -268,7 +271,7 @@ fn inner_leg_angle_x(hypotenuse: f64, leg: f64) -> f64 {
|
||||
}
|
||||
|
||||
/// Compute the angle of the given leg for y.
|
||||
pub async fn leg_angle_y(args: Args) -> Result<KclValue, KclError> {
|
||||
pub async fn leg_angle_y(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
||||
let (hypotenuse, leg) = args.get_hypotenuse_leg()?;
|
||||
let result = inner_leg_angle_y(hypotenuse, leg);
|
||||
args.make_user_val_from_f64(result)
|
||||
@ -302,8 +305,9 @@ pub enum Primitive {
|
||||
Uuid,
|
||||
}
|
||||
|
||||
/// A closure used as an argument to a stdlib function.
|
||||
pub struct FnAsArg<'a> {
|
||||
pub func: &'a crate::executor::MemoryFunction,
|
||||
pub func: Option<&'a crate::executor::MemoryFunction>,
|
||||
pub expr: Box<FunctionExpression>,
|
||||
pub memory: Box<ProgramMemory>,
|
||||
}
|
||||
|
Reference in New Issue
Block a user