diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 542d18680..f80a678c6 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -4638,9 +4638,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.122" +version = "1.0.124" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "784b6203951c57ff748476b126ccb5e8e2959a5c19e5c617ab1956be3dbc68da" +checksum = "66ad62847a56b3dba58cc891acd13884b9c61138d330c0d7b6181713d4fce38d" dependencies = [ "indexmap 2.2.6", "itoa 1.0.11", diff --git a/src/lang/wasm.ts b/src/lang/wasm.ts index 3a8553ea9..320cbc060 100644 --- a/src/lang/wasm.ts +++ b/src/lang/wasm.ts @@ -23,7 +23,7 @@ import { KclError as RustKclError } from '../wasm-lib/kcl/bindings/KclError' import { EngineCommandManager } from './std/engineConnection' import { ProgramReturn } from '../wasm-lib/kcl/bindings/ProgramReturn' import { Discovered } from '../wasm-lib/kcl/bindings/Discovered' -import { MemoryItem } from '../wasm-lib/kcl/bindings/MemoryItem' +import { KclValue } from '../wasm-lib/kcl/bindings/KclValue' import type { Program } from '../wasm-lib/kcl/bindings/Program' import type { Token } from '../wasm-lib/kcl/bindings/Token' import { Coords2d } from './std/sketch' @@ -81,7 +81,7 @@ export type { SourceRange } from '../wasm-lib/kcl/bindings/SourceRange' export type { Path } from '../wasm-lib/kcl/bindings/Path' export type { SketchGroup } from '../wasm-lib/kcl/bindings/SketchGroup' export type { ExtrudeGroup } from '../wasm-lib/kcl/bindings/ExtrudeGroup' -export type { MemoryItem } from '../wasm-lib/kcl/bindings/MemoryItem' +export type { KclValue } from '../wasm-lib/kcl/bindings/KclValue' export type { ExtrudeSurface } from '../wasm-lib/kcl/bindings/ExtrudeSurface' export const wasmUrl = () => { @@ -140,7 +140,7 @@ export const parse = (code: string | Error): Program | Error => { export type PathToNode = [string | number, string][] interface Memory { - [key: string]: MemoryItem + [key: string]: KclValue } type EnvironmentRef = number @@ -215,7 +215,7 @@ export class ProgramMemory { return false } - get(name: string): MemoryItem | null { + get(name: string): KclValue | null { let envRef = this.currentEnv while (true) { const env = this.environments[envRef] @@ -230,7 +230,7 @@ export class ProgramMemory { return null } - set(name: string, value: MemoryItem): Error | null { + set(name: string, value: KclValue): Error | null { if (this.environments.length === 0) { return new Error('No environment to set memory in') } @@ -240,14 +240,14 @@ export class ProgramMemory { } /** - * Returns a new ProgramMemory with only `MemoryItem`s that pass the + * Returns a new ProgramMemory with only `KclValue`s that pass the * predicate. Values are deep copied. * * Note: Return value of the returned ProgramMemory is always null. */ filterVariables( keepPrelude: boolean, - predicate: (value: MemoryItem) => boolean + predicate: (value: KclValue) => boolean ): ProgramMemory | Error { const environments: Environment[] = [] for (const [i, env] of this.environments.entries()) { @@ -290,8 +290,8 @@ export class ProgramMemory { * * This should only be used to display in the MemoryPane UI. */ - visibleEntries(): Map { - const map = new Map() + visibleEntries(): Map { + const map = new Map() let envRef = this.currentEnv while (true) { const env = this.environments[envRef] diff --git a/src/wasm-lib/derive-docs/src/lib.rs b/src/wasm-lib/derive-docs/src/lib.rs index d5bd575ac..36b6659f4 100644 --- a/src/wasm-lib/derive-docs/src/lib.rs +++ b/src/wasm-lib/derive-docs/src/lib.rs @@ -389,7 +389,7 @@ fn do_stdlib_inner( fn #boxed_fn_name_ident( args: crate::std::Args, ) -> std::pin::Pin< - Box> + Send>, + Box> + Send>, > { Box::pin(#fn_name_ident(args)) } diff --git a/src/wasm-lib/derive-docs/tests/args_with_lifetime.gen b/src/wasm-lib/derive-docs/tests/args_with_lifetime.gen index f9da0f97e..29344c185 100644 --- a/src/wasm-lib/derive-docs/tests/args_with_lifetime.gen +++ b/src/wasm-lib/derive-docs/tests/args_with_lifetime.gen @@ -48,7 +48,7 @@ fn boxed_someFn( ) -> std::pin::Pin< Box< dyn std::future::Future< - Output = anyhow::Result, + Output = anyhow::Result, > + Send, >, > { diff --git a/src/wasm-lib/derive-docs/tests/args_with_refs.gen b/src/wasm-lib/derive-docs/tests/args_with_refs.gen index 334cd7005..27dd11d8f 100644 --- a/src/wasm-lib/derive-docs/tests/args_with_refs.gen +++ b/src/wasm-lib/derive-docs/tests/args_with_refs.gen @@ -48,7 +48,7 @@ fn boxed_someFn( ) -> std::pin::Pin< Box< dyn std::future::Future< - Output = anyhow::Result, + Output = anyhow::Result, > + Send, >, > { diff --git a/src/wasm-lib/derive-docs/tests/array.gen b/src/wasm-lib/derive-docs/tests/array.gen index d5cf5eba0..15c6215b9 100644 --- a/src/wasm-lib/derive-docs/tests/array.gen +++ b/src/wasm-lib/derive-docs/tests/array.gen @@ -81,7 +81,7 @@ fn boxed_show( ) -> std::pin::Pin< Box< dyn std::future::Future< - Output = anyhow::Result, + Output = anyhow::Result, > + Send, >, > { diff --git a/src/wasm-lib/derive-docs/tests/box.gen b/src/wasm-lib/derive-docs/tests/box.gen index 499a7353b..03b7d58ba 100644 --- a/src/wasm-lib/derive-docs/tests/box.gen +++ b/src/wasm-lib/derive-docs/tests/box.gen @@ -48,7 +48,7 @@ fn boxed_show( ) -> std::pin::Pin< Box< dyn std::future::Future< - Output = anyhow::Result, + Output = anyhow::Result, > + Send, >, > { diff --git a/src/wasm-lib/derive-docs/tests/doc_comment_with_code.gen b/src/wasm-lib/derive-docs/tests/doc_comment_with_code.gen index 10966a981..0bca8be47 100644 --- a/src/wasm-lib/derive-docs/tests/doc_comment_with_code.gen +++ b/src/wasm-lib/derive-docs/tests/doc_comment_with_code.gen @@ -82,7 +82,7 @@ fn boxed_my_func( ) -> std::pin::Pin< Box< dyn std::future::Future< - Output = anyhow::Result, + Output = anyhow::Result, > + Send, >, > { diff --git a/src/wasm-lib/derive-docs/tests/lineTo.gen b/src/wasm-lib/derive-docs/tests/lineTo.gen index 6e60a7a30..e5a3fb0ce 100644 --- a/src/wasm-lib/derive-docs/tests/lineTo.gen +++ b/src/wasm-lib/derive-docs/tests/lineTo.gen @@ -82,7 +82,7 @@ fn boxed_line_to( ) -> std::pin::Pin< Box< dyn std::future::Future< - Output = anyhow::Result, + Output = anyhow::Result, > + Send, >, > { diff --git a/src/wasm-lib/derive-docs/tests/min.gen b/src/wasm-lib/derive-docs/tests/min.gen index 984ffab40..9f2f70682 100644 --- a/src/wasm-lib/derive-docs/tests/min.gen +++ b/src/wasm-lib/derive-docs/tests/min.gen @@ -81,7 +81,7 @@ fn boxed_min( ) -> std::pin::Pin< Box< dyn std::future::Future< - Output = anyhow::Result, + Output = anyhow::Result, > + Send, >, > { diff --git a/src/wasm-lib/derive-docs/tests/option.gen b/src/wasm-lib/derive-docs/tests/option.gen index 84276b197..cc0d52691 100644 --- a/src/wasm-lib/derive-docs/tests/option.gen +++ b/src/wasm-lib/derive-docs/tests/option.gen @@ -48,7 +48,7 @@ fn boxed_show( ) -> std::pin::Pin< Box< dyn std::future::Future< - Output = anyhow::Result, + Output = anyhow::Result, > + Send, >, > { diff --git a/src/wasm-lib/derive-docs/tests/option_input_format.gen b/src/wasm-lib/derive-docs/tests/option_input_format.gen index 0e3f5fab8..7fe11a06d 100644 --- a/src/wasm-lib/derive-docs/tests/option_input_format.gen +++ b/src/wasm-lib/derive-docs/tests/option_input_format.gen @@ -48,7 +48,7 @@ fn boxed_import( ) -> std::pin::Pin< Box< dyn std::future::Future< - Output = anyhow::Result, + Output = anyhow::Result, > + Send, >, > { diff --git a/src/wasm-lib/derive-docs/tests/return_vec_box_sketch_group.gen b/src/wasm-lib/derive-docs/tests/return_vec_box_sketch_group.gen index ca669ca6a..38ac2d2fa 100644 --- a/src/wasm-lib/derive-docs/tests/return_vec_box_sketch_group.gen +++ b/src/wasm-lib/derive-docs/tests/return_vec_box_sketch_group.gen @@ -48,7 +48,7 @@ fn boxed_import( ) -> std::pin::Pin< Box< dyn std::future::Future< - Output = anyhow::Result, + Output = anyhow::Result, > + Send, >, > { diff --git a/src/wasm-lib/derive-docs/tests/return_vec_sketch_group.gen b/src/wasm-lib/derive-docs/tests/return_vec_sketch_group.gen index 3c4f1983b..6784e9122 100644 --- a/src/wasm-lib/derive-docs/tests/return_vec_sketch_group.gen +++ b/src/wasm-lib/derive-docs/tests/return_vec_sketch_group.gen @@ -48,7 +48,7 @@ fn boxed_import( ) -> std::pin::Pin< Box< dyn std::future::Future< - Output = anyhow::Result, + Output = anyhow::Result, > + Send, >, > { diff --git a/src/wasm-lib/derive-docs/tests/show.gen b/src/wasm-lib/derive-docs/tests/show.gen index 7fec1c2fe..d0b5094bf 100644 --- a/src/wasm-lib/derive-docs/tests/show.gen +++ b/src/wasm-lib/derive-docs/tests/show.gen @@ -48,7 +48,7 @@ fn boxed_show( ) -> std::pin::Pin< Box< dyn std::future::Future< - Output = anyhow::Result, + Output = anyhow::Result, > + Send, >, > { diff --git a/src/wasm-lib/kcl/src/ast/types.rs b/src/wasm-lib/kcl/src/ast/types.rs index bf941cb08..76ba8f842 100644 --- a/src/wasm-lib/kcl/src/ast/types.rs +++ b/src/wasm-lib/kcl/src/ast/types.rs @@ -23,7 +23,7 @@ use crate::{ docs::StdLibFn, errors::{KclError, KclErrorDetails}, executor::{ - BodyType, DynamicState, ExecutorContext, MemoryItem, Metadata, PipeInfo, ProgramMemory, SourceRange, + BodyType, DynamicState, ExecutorContext, KclValue, Metadata, PipeInfo, ProgramMemory, SourceRange, StatementKind, TagEngineInfo, TagIdentifier, UserVal, }, parser::PIPE_OPERATOR, @@ -922,7 +922,7 @@ impl BinaryPart { dynamic_state: &DynamicState, pipe_info: &PipeInfo, ctx: &ExecutorContext, - ) -> Result { + ) -> Result { match self { BinaryPart::Literal(literal) => Ok(literal.into()), BinaryPart::Identifier(identifier) => { @@ -1322,10 +1322,10 @@ impl CallExpression { dynamic_state: &DynamicState, pipe_info: &PipeInfo, ctx: &ExecutorContext, - ) -> Result { + ) -> Result { let fn_name = self.callee.name.clone(); - let mut fn_args: Vec = Vec::with_capacity(self.arguments.len()); + let mut fn_args: Vec = Vec::with_capacity(self.arguments.len()); for arg in &self.arguments { let metadata = Metadata { @@ -1356,12 +1356,12 @@ impl CallExpression { // TODO: This could probably be done in a better way, but as of now this was my only idea // and it works. match result { - MemoryItem::SketchGroup(ref sketch_group) => { + KclValue::SketchGroup(ref sketch_group) => { for (_, tag) in sketch_group.tags.iter() { memory.update_tag(&tag.value, tag.clone())?; } } - MemoryItem::ExtrudeGroup(ref mut extrude_group) => { + KclValue::ExtrudeGroup(ref mut extrude_group) => { for value in &extrude_group.value { if let Some(tag) = value.get_tag() { // Get the past tag and update it. @@ -1448,7 +1448,7 @@ impl CallExpression { } else { fn_memory.add( ¶m.identifier.name, - MemoryItem::UserVal(UserVal { + KclValue::UserVal(UserVal { value: serde_json::value::Value::Null, meta: Default::default(), }), @@ -1497,7 +1497,7 @@ impl CallExpression { let result = result.ok_or_else(|| { let mut source_ranges: Vec = vec![self.into()]; // We want to send the source range of the original function. - if let MemoryItem::Function { meta, .. } = func { + if let KclValue::Function { meta, .. } = func { source_ranges = meta.iter().map(|m| m.source_range).collect(); }; KclError::UndefinedValue(KclErrorDetails { @@ -1972,9 +1972,9 @@ impl Literal { } } -impl From for MemoryItem { +impl From for KclValue { fn from(literal: Literal) -> Self { - MemoryItem::UserVal(UserVal { + KclValue::UserVal(UserVal { value: JValue::from(literal.value.clone()), meta: vec![Metadata { source_range: literal.into(), @@ -1983,9 +1983,9 @@ impl From for MemoryItem { } } -impl From<&Box> for MemoryItem { +impl From<&Box> for KclValue { fn from(literal: &Box) -> Self { - MemoryItem::UserVal(UserVal { + KclValue::UserVal(UserVal { value: JValue::from(literal.value.clone()), meta: vec![Metadata { source_range: literal.into(), @@ -2067,15 +2067,15 @@ impl From> for Vec { } } -impl From<&Box> for MemoryItem { +impl From<&Box> for KclValue { fn from(tag: &Box) -> Self { - MemoryItem::TagDeclarator(tag.clone()) + KclValue::TagDeclarator(tag.clone()) } } -impl From<&TagDeclarator> for MemoryItem { +impl From<&TagDeclarator> for KclValue { fn from(tag: &TagDeclarator) -> Self { - MemoryItem::TagDeclarator(Box::new(tag.clone())) + KclValue::TagDeclarator(Box::new(tag.clone())) } } @@ -2152,8 +2152,8 @@ impl TagDeclarator { } } - pub async fn execute(&self, memory: &mut ProgramMemory) -> Result { - let memory_item = MemoryItem::TagIdentifier(Box::new(TagIdentifier { + pub async fn execute(&self, memory: &mut ProgramMemory) -> Result { + let memory_item = KclValue::TagIdentifier(Box::new(TagIdentifier { value: self.name.clone(), info: None, meta: vec![Metadata { @@ -2336,7 +2336,7 @@ impl ArrayExpression { dynamic_state: &DynamicState, pipe_info: &PipeInfo, ctx: &ExecutorContext, - ) -> Result { + ) -> Result { let mut results = Vec::with_capacity(self.elements.len()); for element in &self.elements { @@ -2391,7 +2391,7 @@ impl ArrayExpression { results.push(result); } - Ok(MemoryItem::UserVal(UserVal { + Ok(KclValue::UserVal(UserVal { value: results.into(), meta: vec![Metadata { source_range: self.into(), @@ -2523,7 +2523,7 @@ impl ObjectExpression { dynamic_state: &DynamicState, pipe_info: &PipeInfo, ctx: &ExecutorContext, - ) -> Result { + ) -> Result { let mut object = Map::new(); for property in &self.properties { let result = match &property.value { @@ -2576,7 +2576,7 @@ impl ObjectExpression { object.insert(property.key.name.clone(), result.get_json_value()?); } - Ok(MemoryItem::UserVal(UserVal { + Ok(KclValue::UserVal(UserVal { value: object.into(), meta: vec![Metadata { source_range: self.into(), @@ -2801,7 +2801,7 @@ impl MemberExpression { None } - pub fn get_result_array(&self, memory: &mut ProgramMemory, index: usize) -> Result { + pub fn get_result_array(&self, memory: &mut ProgramMemory, index: usize) -> Result { let array = match &self.object { MemberObject::MemberExpression(member_expr) => member_expr.get_result(memory)?, MemberObject::Identifier(identifier) => { @@ -2814,7 +2814,7 @@ impl MemberExpression { if let serde_json::Value::Array(array) = array_json { if let Some(value) = array.get(index) { - Ok(MemoryItem::UserVal(UserVal { + Ok(KclValue::UserVal(UserVal { value: value.clone(), meta: vec![Metadata { source_range: self.into(), @@ -2834,7 +2834,7 @@ impl MemberExpression { } } - pub fn get_result(&self, memory: &mut ProgramMemory) -> Result { + pub fn get_result(&self, memory: &mut ProgramMemory) -> Result { #[derive(Debug)] enum Property { Number(usize), @@ -2862,7 +2862,7 @@ impl MemberExpression { } else { // Actually evaluate memory to compute the property. let prop = memory.get(&name, property_src)?; - let MemoryItem::UserVal(prop) = prop else { + let KclValue::UserVal(prop) = prop else { return Err(KclError::Semantic(KclErrorDetails { source_ranges: property_sr, message: format!( @@ -2936,7 +2936,7 @@ impl MemberExpression { match (object_json, property) { (JValue::Object(map), Property::String(property)) => { if let Some(value) = map.get(&property) { - Ok(MemoryItem::UserVal(UserVal { + Ok(KclValue::UserVal(UserVal { value: value.clone(), meta: vec![Metadata { source_range: self.into(), @@ -2959,7 +2959,7 @@ impl MemberExpression { (JValue::Array(arr), Property::Number(index)) => { let value_of_arr: Option<&JValue> = arr.get(index); if let Some(value) = value_of_arr { - Ok(MemoryItem::UserVal(UserVal { + Ok(KclValue::UserVal(UserVal { value: value.clone(), meta: vec![Metadata { source_range: self.into(), @@ -3120,7 +3120,7 @@ impl BinaryExpression { dynamic_state: &DynamicState, pipe_info: &PipeInfo, ctx: &ExecutorContext, - ) -> Result { + ) -> Result { let left_json_value = self .left .get_result(memory, dynamic_state, pipe_info, ctx) @@ -3139,7 +3139,7 @@ impl BinaryExpression { parse_json_value_as_string(&right_json_value), ) { let value = serde_json::Value::String(format!("{}{}", left, right)); - return Ok(MemoryItem::UserVal(UserVal { + return Ok(KclValue::UserVal(UserVal { value, meta: vec![Metadata { source_range: self.into(), @@ -3160,7 +3160,7 @@ impl BinaryExpression { BinaryOperator::Pow => (left.powf(right)).into(), }; - Ok(MemoryItem::UserVal(UserVal { + Ok(KclValue::UserVal(UserVal { value, meta: vec![Metadata { source_range: self.into(), @@ -3338,7 +3338,7 @@ impl UnaryExpression { dynamic_state: &DynamicState, pipe_info: &PipeInfo, ctx: &ExecutorContext, - ) -> Result { + ) -> Result { let num = parse_json_number_as_f64( &self .argument @@ -3347,7 +3347,7 @@ impl UnaryExpression { .get_json_value()?, self.into(), )?; - Ok(MemoryItem::UserVal(UserVal { + Ok(KclValue::UserVal(UserVal { value: (-(num)).into(), meta: vec![Metadata { source_range: self.into(), @@ -3516,7 +3516,7 @@ impl PipeExpression { dynamic_state: &DynamicState, pipe_info: &PipeInfo, ctx: &ExecutorContext, - ) -> Result { + ) -> Result { execute_pipe_body(memory, dynamic_state, &self.body, pipe_info, self.into(), ctx).await } @@ -3536,7 +3536,7 @@ async fn execute_pipe_body( pipe_info: &PipeInfo, source_range: SourceRange, ctx: &ExecutorContext, -) -> Result { +) -> Result { let mut body = body.iter(); let first = body.next().ok_or_else(|| { KclError::Semantic(KclErrorDetails { diff --git a/src/wasm-lib/kcl/src/ast/types/none.rs b/src/wasm-lib/kcl/src/ast/types/none.rs index 887c4404f..d4176bdda 100644 --- a/src/wasm-lib/kcl/src/ast/types/none.rs +++ b/src/wasm-lib/kcl/src/ast/types/none.rs @@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize}; use crate::{ ast::types::ConstraintLevel, - executor::{MemoryItem, SourceRange, UserVal}, + executor::{KclValue, SourceRange, UserVal}, }; /// KCL value for an optional parameter which was not given an argument. @@ -37,10 +37,10 @@ impl From<&KclNone> for UserVal { } } -impl From<&KclNone> for MemoryItem { +impl From<&KclNone> for KclValue { fn from(none: &KclNone) -> Self { let val = UserVal::from(none); - MemoryItem::UserVal(val) + KclValue::UserVal(val) } } diff --git a/src/wasm-lib/kcl/src/executor.rs b/src/wasm-lib/kcl/src/executor.rs index 9a0002053..b5f67393b 100644 --- a/src/wasm-lib/kcl/src/executor.rs +++ b/src/wasm-lib/kcl/src/executor.rs @@ -46,7 +46,7 @@ impl ProgramMemory { } /// Add to the program memory in the current scope. - pub fn add(&mut self, key: &str, value: MemoryItem, source_range: SourceRange) -> Result<(), KclError> { + pub fn add(&mut self, key: &str, value: KclValue, source_range: SourceRange) -> Result<(), KclError> { if self.environments[self.current_env.index()].contains_key(key) { return Err(KclError::ValueAlreadyDefined(KclErrorDetails { message: format!("Cannot redefine `{}`", key), @@ -60,14 +60,14 @@ impl ProgramMemory { } pub fn update_tag(&mut self, tag: &str, value: TagIdentifier) -> Result<(), KclError> { - self.environments[self.current_env.index()].insert(tag.to_string(), MemoryItem::TagIdentifier(Box::new(value))); + self.environments[self.current_env.index()].insert(tag.to_string(), KclValue::TagIdentifier(Box::new(value))); Ok(()) } /// Get a value from the program memory. /// Return Err if not found. - pub fn get(&self, var: &str, source_range: SourceRange) -> Result<&MemoryItem, KclError> { + pub fn get(&self, var: &str, source_range: SourceRange) -> Result<&KclValue, KclError> { let mut env_ref = self.current_env; loop { let env = &self.environments[env_ref.index()]; @@ -97,7 +97,7 @@ impl ProgramMemory { env.bindings .values() .filter_map(|item| match item { - MemoryItem::ExtrudeGroup(eg) if eg.sketch_group.id == sketch_group_id => Some(eg.clone()), + KclValue::ExtrudeGroup(eg) if eg.sketch_group.id == sketch_group_id => Some(eg.clone()), _ => None, }) .collect::>() @@ -128,7 +128,7 @@ impl EnvironmentRef { #[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)] pub struct Environment { - bindings: HashMap, + bindings: HashMap, parent: Option, } @@ -139,28 +139,28 @@ impl Environment { bindings: HashMap::from([ ( "ZERO".to_string(), - MemoryItem::UserVal(UserVal { + KclValue::UserVal(UserVal { value: serde_json::Value::Number(serde_json::value::Number::from(0)), meta: Default::default(), }), ), ( "QUARTER_TURN".to_string(), - MemoryItem::UserVal(UserVal { + KclValue::UserVal(UserVal { value: serde_json::Value::Number(serde_json::value::Number::from(90)), meta: Default::default(), }), ), ( "HALF_TURN".to_string(), - MemoryItem::UserVal(UserVal { + KclValue::UserVal(UserVal { value: serde_json::Value::Number(serde_json::value::Number::from(180)), meta: Default::default(), }), ), ( "THREE_QUARTER_TURN".to_string(), - MemoryItem::UserVal(UserVal { + KclValue::UserVal(UserVal { value: serde_json::Value::Number(serde_json::value::Number::from(270)), meta: Default::default(), }), @@ -177,7 +177,7 @@ impl Environment { } } - pub fn get(&self, key: &str, source_range: SourceRange) -> Result<&MemoryItem, KclError> { + pub fn get(&self, key: &str, source_range: SourceRange) -> Result<&KclValue, KclError> { self.bindings.get(key).ok_or_else(|| { KclError::UndefinedValue(KclErrorDetails { message: format!("memory item key `{}` is not defined", key), @@ -186,7 +186,7 @@ impl Environment { }) } - pub fn insert(&mut self, key: String, value: MemoryItem) { + pub fn insert(&mut self, key: String, value: KclValue) { self.bindings.insert(key, value); } @@ -200,7 +200,7 @@ impl Environment { } for (_, val) in self.bindings.iter_mut() { - if let MemoryItem::SketchGroup(ref mut sketch_group) = val { + if let KclValue::SketchGroup(ref mut sketch_group) = val { if sketch_group.original_id == sg.original_id { for tag in sg.tags.iter() { sketch_group.tags.insert(tag.0.clone(), tag.1.clone()); @@ -234,7 +234,7 @@ impl DynamicState { pub fn append(&mut self, memory: &ProgramMemory) { for env in &memory.environments { for item in env.bindings.values() { - if let MemoryItem::ExtrudeGroup(eg) = item { + if let KclValue::ExtrudeGroup(eg) = item { self.extrude_group_ids.push(ExtrudeGroupLazyIds::from(eg.as_ref())); } } @@ -260,7 +260,7 @@ impl DynamicState { #[serde(rename_all = "camelCase", untagged)] pub enum ProgramReturn { Arguments, - Value(MemoryItem), + Value(KclValue), } impl From for Vec { @@ -273,7 +273,7 @@ impl From for Vec { } impl ProgramReturn { - pub fn get_value(&self) -> Result { + pub fn get_value(&self) -> Result { match self { ProgramReturn::Value(v) => Ok(v.clone()), ProgramReturn::Arguments => Err(KclError::Semantic(KclErrorDetails { @@ -288,7 +288,7 @@ impl ProgramReturn { #[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)] #[ts(export)] #[serde(tag = "type")] -pub enum MemoryItem { +pub enum KclValue { UserVal(UserVal), TagIdentifier(Box), TagDeclarator(Box), @@ -314,12 +314,12 @@ pub enum MemoryItem { }, } -impl MemoryItem { +impl KclValue { pub(crate) fn get_sketch_group_set(&self) -> Result { match self { - MemoryItem::SketchGroup(s) => Ok(SketchGroupSet::SketchGroup(s.clone())), - MemoryItem::SketchGroups { value } => Ok(SketchGroupSet::SketchGroups(value.clone())), - MemoryItem::UserVal(value) => { + KclValue::SketchGroup(s) => Ok(SketchGroupSet::SketchGroup(s.clone())), + KclValue::SketchGroups { value } => Ok(SketchGroupSet::SketchGroups(value.clone())), + KclValue::UserVal(value) => { let sg: Vec> = serde_json::from_value(value.value.clone()) .map_err(|e| anyhow::anyhow!("Failed to deserialize array of sketch groups from JSON: {}", e))?; Ok(sg.into()) @@ -330,9 +330,9 @@ impl MemoryItem { pub(crate) fn get_extrude_group_set(&self) -> Result { match self { - MemoryItem::ExtrudeGroup(e) => Ok(ExtrudeGroupSet::ExtrudeGroup(e.clone())), - MemoryItem::ExtrudeGroups { value } => Ok(ExtrudeGroupSet::ExtrudeGroups(value.clone())), - MemoryItem::UserVal(value) => { + KclValue::ExtrudeGroup(e) => Ok(ExtrudeGroupSet::ExtrudeGroup(e.clone())), + KclValue::ExtrudeGroups { value } => Ok(ExtrudeGroupSet::ExtrudeGroups(value.clone())), + KclValue::UserVal(value) => { let eg: Vec> = serde_json::from_value(value.value.clone()) .map_err(|e| anyhow::anyhow!("Failed to deserialize array of extrude groups from JSON: {}", e))?; Ok(eg.into()) @@ -342,40 +342,40 @@ impl MemoryItem { } } -impl From for MemoryItem { +impl From for KclValue { fn from(sg: SketchGroupSet) -> Self { match sg { - SketchGroupSet::SketchGroup(sg) => MemoryItem::SketchGroup(sg), - SketchGroupSet::SketchGroups(sgs) => MemoryItem::SketchGroups { value: sgs }, + SketchGroupSet::SketchGroup(sg) => KclValue::SketchGroup(sg), + SketchGroupSet::SketchGroups(sgs) => KclValue::SketchGroups { value: sgs }, } } } -impl From>> for MemoryItem { +impl From>> for KclValue { fn from(sg: Vec>) -> Self { if sg.len() == 1 { - MemoryItem::SketchGroup(sg[0].clone()) + KclValue::SketchGroup(sg[0].clone()) } else { - MemoryItem::SketchGroups { value: sg } + KclValue::SketchGroups { value: sg } } } } -impl From for MemoryItem { +impl From for KclValue { fn from(eg: ExtrudeGroupSet) -> Self { match eg { - ExtrudeGroupSet::ExtrudeGroup(eg) => MemoryItem::ExtrudeGroup(eg), - ExtrudeGroupSet::ExtrudeGroups(egs) => MemoryItem::ExtrudeGroups { value: egs }, + ExtrudeGroupSet::ExtrudeGroup(eg) => KclValue::ExtrudeGroup(eg), + ExtrudeGroupSet::ExtrudeGroups(egs) => KclValue::ExtrudeGroups { value: egs }, } } } -impl From>> for MemoryItem { +impl From>> for KclValue { fn from(eg: Vec>) -> Self { if eg.len() == 1 { - MemoryItem::ExtrudeGroup(eg[0].clone()) + KclValue::ExtrudeGroup(eg[0].clone()) } else { - MemoryItem::ExtrudeGroups { value: eg } + KclValue::ExtrudeGroups { value: eg } } } } @@ -679,7 +679,7 @@ impl std::hash::Hash for TagIdentifier { pub type MemoryFunction = fn( - s: Vec, + s: Vec, memory: ProgramMemory, expression: Box, metadata: Vec, @@ -689,7 +689,7 @@ pub type MemoryFunction = fn force_memory_function< F: Fn( - Vec, + Vec, ProgramMemory, Box, Vec, @@ -702,33 +702,33 @@ fn force_memory_function< f } -impl From for Vec { - fn from(item: MemoryItem) -> Self { +impl From for Vec { + fn from(item: KclValue) -> Self { match item { - MemoryItem::UserVal(u) => u.meta.iter().map(|m| m.source_range).collect(), - MemoryItem::TagDeclarator(t) => t.into(), - MemoryItem::TagIdentifier(t) => t.meta.iter().map(|m| m.source_range).collect(), - MemoryItem::SketchGroup(s) => s.meta.iter().map(|m| m.source_range).collect(), - MemoryItem::SketchGroups { value } => value + KclValue::UserVal(u) => u.meta.iter().map(|m| m.source_range).collect(), + KclValue::TagDeclarator(t) => t.into(), + KclValue::TagIdentifier(t) => t.meta.iter().map(|m| m.source_range).collect(), + KclValue::SketchGroup(s) => s.meta.iter().map(|m| m.source_range).collect(), + KclValue::SketchGroups { value } => value .iter() .flat_map(|sg| sg.meta.iter().map(|m| m.source_range)) .collect(), - MemoryItem::ExtrudeGroup(e) => e.meta.iter().map(|m| m.source_range).collect(), - MemoryItem::ExtrudeGroups { value } => value + KclValue::ExtrudeGroup(e) => e.meta.iter().map(|m| m.source_range).collect(), + KclValue::ExtrudeGroups { value } => value .iter() .flat_map(|eg| eg.meta.iter().map(|m| m.source_range)) .collect(), - MemoryItem::ImportedGeometry(i) => i.meta.iter().map(|m| m.source_range).collect(), - MemoryItem::Function { meta, .. } => meta.iter().map(|m| m.source_range).collect(), - MemoryItem::Plane(p) => p.meta.iter().map(|m| m.source_range).collect(), - MemoryItem::Face(f) => f.meta.iter().map(|m| m.source_range).collect(), + KclValue::ImportedGeometry(i) => i.meta.iter().map(|m| m.source_range).collect(), + KclValue::Function { meta, .. } => meta.iter().map(|m| m.source_range).collect(), + KclValue::Plane(p) => p.meta.iter().map(|m| m.source_range).collect(), + KclValue::Face(f) => f.meta.iter().map(|m| m.source_range).collect(), } } } -impl MemoryItem { +impl KclValue { pub fn get_json_value(&self) -> Result { - if let MemoryItem::UserVal(user_val) = self { + if let KclValue::UserVal(user_val) = self { Ok(user_val.value.clone()) } else { serde_json::to_value(self).map_err(|err| { @@ -775,7 +775,7 @@ impl MemoryItem { } pub fn as_user_val(&self) -> Option<&UserVal> { - if let MemoryItem::UserVal(x) = self { + if let KclValue::UserVal(x) = self { Some(x) } else { None @@ -797,7 +797,7 @@ impl MemoryItem { /// If this value is of type function, return it. pub fn get_function(&self) -> Option> { - let MemoryItem::Function { + let KclValue::Function { func, expression, memory, @@ -817,8 +817,8 @@ impl MemoryItem { /// Get a tag identifier from a memory item. pub fn get_tag_identifier(&self) -> Result { match self { - MemoryItem::TagIdentifier(t) => Ok(*t.clone()), - MemoryItem::UserVal(_) => { + KclValue::TagIdentifier(t) => Ok(*t.clone()), + KclValue::UserVal(_) => { if let Some(identifier) = self.get_json_opt::()? { Ok(identifier) } else { @@ -838,7 +838,7 @@ impl MemoryItem { /// Get a tag declarator from a memory item. pub fn get_tag_declarator(&self) -> Result { match self { - MemoryItem::TagDeclarator(t) => Ok(*t.clone()), + KclValue::TagDeclarator(t) => Ok(*t.clone()), _ => Err(KclError::Semantic(KclErrorDetails { message: format!("Not a tag declarator: {:?}", self), source_ranges: self.clone().into(), @@ -849,7 +849,7 @@ impl MemoryItem { /// Get an optional tag from a memory item. pub fn get_tag_declarator_opt(&self) -> Result, KclError> { match self { - MemoryItem::TagDeclarator(t) => Ok(Some(*t.clone())), + KclValue::TagDeclarator(t) => Ok(Some(*t.clone())), _ => Err(KclError::Semantic(KclErrorDetails { message: format!("Not a tag declarator: {:?}", self), source_ranges: self.clone().into(), @@ -861,11 +861,11 @@ impl MemoryItem { /// If it's not a function, return Err. pub async fn call_fn( &self, - args: Vec, + args: Vec, dynamic_state: &DynamicState, ctx: ExecutorContext, ) -> Result, KclError> { - let MemoryItem::Function { + let KclValue::Function { func, expression, memory: closure_memory, @@ -1518,7 +1518,7 @@ impl ExtrudeSurface { #[ts(export)] #[serde(rename_all = "camelCase")] pub struct PipeInfo { - pub previous_results: Option, + pub previous_results: Option, } impl PipeInfo { @@ -1812,7 +1812,7 @@ impl ExecutorContext { Expr::PipeSubstitution(_) => {} Expr::FunctionExpression(_) => {} Expr::None(none) => { - memory.return_ = Some(ProgramReturn::Value(MemoryItem::from(none))); + memory.return_ = Some(ProgramReturn::Value(KclValue::from(none))); } }, } @@ -1841,7 +1841,7 @@ impl ExecutorContext { pipe_info: &PipeInfo, metadata: &Metadata, statement_kind: StatementKind<'a>, - ) -> Result { + ) -> Result { let item = match init { Expr::None(none) => none.into(), Expr::Literal(literal) => literal.into(), @@ -1857,7 +1857,7 @@ impl ExecutorContext { } Expr::FunctionExpression(function_expression) => { let mem_func = force_memory_function( - |args: Vec, + |args: Vec, memory: ProgramMemory, function_expression: Box, _metadata: Vec, @@ -1890,7 +1890,7 @@ impl ExecutorContext { // Cloning memory here is crucial for semantics so that we close // over variables. Variables defined lexically later shouldn't // be available to the function body. - MemoryItem::Function { + KclValue::Function { expression: function_expression.clone(), meta: vec![metadata.to_owned()], func: Some(mem_func), @@ -1992,7 +1992,7 @@ impl ExecutorContext { /// Returns Err if too few/too many arguments were given for the function. fn assign_args_to_params( function_expression: &FunctionExpression, - args: Vec, + args: Vec, mut fn_memory: ProgramMemory, ) -> Result { let num_args = function_expression.number_of_args(); @@ -2030,7 +2030,7 @@ fn assign_args_to_params( }; fn_memory.add( ¶m.identifier.name, - MemoryItem::from(&none), + KclValue::from(&none), (¶m.identifier).into(), )?; } else { @@ -2823,8 +2823,8 @@ let w = f() + f() #[test] fn test_assign_args_to_params() { // Set up a little framework for this test. - fn mem(number: usize) -> MemoryItem { - MemoryItem::UserVal(UserVal { + fn mem(number: usize) -> KclValue { + KclValue::UserVal(UserVal { value: number.into(), meta: Default::default(), }) @@ -2853,7 +2853,7 @@ let w = f() + f() digest: None, } } - fn additional_program_memory(items: &[(String, MemoryItem)]) -> ProgramMemory { + fn additional_program_memory(items: &[(String, KclValue)]) -> ProgramMemory { let mut program_memory = ProgramMemory::new(); for (name, item) in items { program_memory @@ -2886,7 +2886,7 @@ let w = f() + f() vec![], Ok(additional_program_memory(&[( "x".to_owned(), - MemoryItem::from(&KclNone::default()), + KclValue::from(&KclNone::default()), )])), ), ( @@ -2904,7 +2904,7 @@ let w = f() + f() vec![mem(1)], Ok(additional_program_memory(&[ ("x".to_owned(), mem(1)), - ("y".to_owned(), MemoryItem::from(&KclNone::default())), + ("y".to_owned(), KclValue::from(&KclNone::default())), ])), ), ( @@ -2951,7 +2951,7 @@ let w = f() + f() #[test] fn test_serialize_memory_item() { - let mem = MemoryItem::ExtrudeGroups { + let mem = KclValue::ExtrudeGroups { value: Default::default(), }; let json = serde_json::to_string(&mem).unwrap(); diff --git a/src/wasm-lib/kcl/src/function_param.rs b/src/wasm-lib/kcl/src/function_param.rs index f2b732af3..ba4e4a855 100644 --- a/src/wasm-lib/kcl/src/function_param.rs +++ b/src/wasm-lib/kcl/src/function_param.rs @@ -3,7 +3,7 @@ use schemars::JsonSchema; use crate::{ ast::types::FunctionExpression, errors::KclError, - executor::{DynamicState, ExecutorContext, MemoryFunction, MemoryItem, Metadata, ProgramMemory, ProgramReturn}, + executor::{DynamicState, ExecutorContext, KclValue, MemoryFunction, Metadata, ProgramMemory, ProgramReturn}, }; /// A function being used as a parameter into a stdlib function. @@ -17,7 +17,7 @@ pub struct FunctionParam<'a> { } impl<'a> FunctionParam<'a> { - pub async fn call(&self, args: Vec) -> Result, KclError> { + pub async fn call(&self, args: Vec) -> Result, KclError> { (self.inner)( args, self.memory.clone(), diff --git a/src/wasm-lib/kcl/src/std/args.rs b/src/wasm-lib/kcl/src/std/args.rs index 1d428b35e..4ae7336fd 100644 --- a/src/wasm-lib/kcl/src/std/args.rs +++ b/src/wasm-lib/kcl/src/std/args.rs @@ -8,14 +8,14 @@ use crate::{ ast::types::{parse_json_number_as_f64, TagDeclarator}, errors::{KclError, KclErrorDetails}, executor::{ - DynamicState, ExecutorContext, ExtrudeGroup, ExtrudeGroupSet, ExtrudeSurface, MemoryItem, Metadata, + DynamicState, ExecutorContext, ExtrudeGroup, ExtrudeGroupSet, ExtrudeSurface, KclValue, Metadata, ProgramMemory, SketchGroup, SketchGroupSet, SketchSurface, SourceRange, TagIdentifier, }, }; #[derive(Debug, Clone)] pub struct Args { - pub args: Vec, + pub args: Vec, pub source_range: SourceRange, pub ctx: ExecutorContext, pub current_program_memory: ProgramMemory, @@ -24,7 +24,7 @@ pub struct Args { impl Args { pub fn new( - args: Vec, + args: Vec, source_range: SourceRange, ctx: ExecutorContext, current_program_memory: ProgramMemory, @@ -72,7 +72,7 @@ impl Args { &'a self, tag: &'a TagIdentifier, ) -> Result<&'a crate::executor::TagEngineInfo, KclError> { - if let MemoryItem::TagIdentifier(t) = self.current_program_memory.get(&tag.value, self.source_range)? { + if let KclValue::TagIdentifier(t) = self.current_program_memory.get(&tag.value, self.source_range)? { Ok(t.info.as_ref().ok_or_else(|| { KclError::Type(KclErrorDetails { message: format!("Tag `{}` does not have engine info", tag.value), @@ -167,8 +167,8 @@ impl Args { Ok(()) } - fn make_user_val_from_json(&self, j: serde_json::Value) -> Result { - Ok(MemoryItem::UserVal(crate::executor::UserVal { + fn make_user_val_from_json(&self, j: serde_json::Value) -> Result { + Ok(KclValue::UserVal(crate::executor::UserVal { value: j, meta: vec![Metadata { source_range: self.source_range, @@ -176,15 +176,15 @@ impl Args { })) } - pub(crate) fn make_null_user_val(&self) -> Result { + pub(crate) fn make_null_user_val(&self) -> Result { self.make_user_val_from_json(serde_json::Value::Null) } - pub(crate) fn make_user_val_from_i64(&self, n: i64) -> Result { + pub(crate) fn make_user_val_from_i64(&self, n: i64) -> Result { self.make_user_val_from_json(serde_json::Value::Number(serde_json::Number::from(n))) } - pub(crate) fn make_user_val_from_f64(&self, f: f64) -> Result { + pub(crate) fn make_user_val_from_f64(&self, f: f64) -> Result { self.make_user_val_from_json(serde_json::Value::Number(serde_json::Number::from_f64(f).ok_or_else( || { KclError::Type(KclErrorDetails { @@ -195,7 +195,7 @@ impl Args { )?)) } - pub(crate) fn make_user_val_from_f64_array(&self, f: Vec) -> Result { + pub(crate) fn make_user_val_from_f64_array(&self, f: Vec) -> Result { let mut arr = Vec::new(); for n in f { arr.push(serde_json::Value::Number(serde_json::Number::from_f64(n).ok_or_else( @@ -281,7 +281,7 @@ impl Args { pub(crate) fn get_data_and_optional_tag<'a, T>(&'a self) -> Result<(T, Option), KclError> where - T: serde::de::DeserializeOwned + FromMemoryItem<'a> + Sized, + T: serde::de::DeserializeOwned + FromKclValue<'a> + Sized, { FromArgs::from_args(self, 0) } @@ -304,7 +304,7 @@ impl Args { &'a self, ) -> Result<(T, Box, Option), KclError> where - T: serde::de::DeserializeOwned + FromMemoryItem<'a> + Sized, + T: serde::de::DeserializeOwned + FromKclValue<'a> + Sized, { FromArgs::from_args(self, 0) } @@ -313,21 +313,21 @@ impl Args { &'a self, ) -> Result<(T, SketchSurface, Option), KclError> where - T: serde::de::DeserializeOwned + FromMemoryItem<'a> + Sized, + T: serde::de::DeserializeOwned + FromKclValue<'a> + Sized, { FromArgs::from_args(self, 0) } pub(crate) fn get_data_and_extrude_group_set<'a, T>(&'a self) -> Result<(T, ExtrudeGroupSet), KclError> where - T: serde::de::DeserializeOwned + FromMemoryItem<'a> + Sized, + T: serde::de::DeserializeOwned + FromKclValue<'a> + Sized, { FromArgs::from_args(self, 0) } pub(crate) fn get_data_and_extrude_group<'a, T>(&'a self) -> Result<(T, Box), KclError> where - T: serde::de::DeserializeOwned + FromMemoryItem<'a> + Sized, + T: serde::de::DeserializeOwned + FromKclValue<'a> + Sized, { FromArgs::from_args(self, 0) } @@ -336,7 +336,7 @@ impl Args { &'a self, ) -> Result<(T, Box, Option), KclError> where - T: serde::de::DeserializeOwned + FromMemoryItem<'a> + Sized, + T: serde::de::DeserializeOwned + FromKclValue<'a> + Sized, { FromArgs::from_args(self, 0) } @@ -443,15 +443,15 @@ pub trait FromArgs<'a>: Sized { fn from_args(args: &'a Args, index: usize) -> Result; } -/// Types which impl this trait can be extracted from a `MemoryItem`. -pub trait FromMemoryItem<'a>: Sized { - /// Try to convert a MemoryItem into this type. - fn from_mem_item(arg: &'a MemoryItem) -> Option; +/// Types which impl this trait can be extracted from a `KclValue`. +pub trait FromKclValue<'a>: Sized { + /// Try to convert a KclValue into this type. + fn from_mem_item(arg: &'a KclValue) -> Option; } impl<'a, T> FromArgs<'a> for T where - T: FromMemoryItem<'a> + Sized, + T: FromKclValue<'a> + Sized, { fn from_args(args: &'a Args, i: usize) -> Result { let Some(arg) = args.args.get(i) else { @@ -475,7 +475,7 @@ where impl<'a, T> FromArgs<'a> for Option where - T: FromMemoryItem<'a> + Sized, + T: FromKclValue<'a> + Sized, { fn from_args(args: &'a Args, i: usize) -> Result { let Some(arg) = args.args.get(i) else { return Ok(None) }; @@ -533,27 +533,27 @@ where } } -impl<'a> FromMemoryItem<'a> for &'a str { - fn from_mem_item(arg: &'a MemoryItem) -> Option { +impl<'a> FromKclValue<'a> for &'a str { + fn from_mem_item(arg: &'a KclValue) -> Option { arg.as_user_val().and_then(|uv| uv.value.as_str()) } } -impl<'a> FromMemoryItem<'a> for TagDeclarator { - fn from_mem_item(arg: &'a MemoryItem) -> Option { +impl<'a> FromKclValue<'a> for TagDeclarator { + fn from_mem_item(arg: &'a KclValue) -> Option { arg.get_tag_declarator().ok() } } -impl<'a> FromMemoryItem<'a> for TagIdentifier { - fn from_mem_item(arg: &'a MemoryItem) -> Option { +impl<'a> FromKclValue<'a> for TagIdentifier { + fn from_mem_item(arg: &'a KclValue) -> Option { arg.get_tag_identifier().ok() } } -impl<'a> FromMemoryItem<'a> for &'a SketchGroup { - fn from_mem_item(arg: &'a MemoryItem) -> Option { - let MemoryItem::SketchGroup(s) = arg else { +impl<'a> FromKclValue<'a> for &'a SketchGroup { + fn from_mem_item(arg: &'a KclValue) -> Option { + let KclValue::SketchGroup(s) = arg else { return None; }; Some(s.as_ref()) @@ -562,8 +562,8 @@ impl<'a> FromMemoryItem<'a> for &'a SketchGroup { macro_rules! impl_from_arg_via_json { ($typ:path) => { - impl<'a> FromMemoryItem<'a> for $typ { - fn from_mem_item(arg: &'a MemoryItem) -> Option { + impl<'a> FromKclValue<'a> for $typ { + fn from_mem_item(arg: &'a KclValue) -> Option { from_user_val(arg) } } @@ -572,20 +572,20 @@ macro_rules! impl_from_arg_via_json { macro_rules! impl_from_arg_for_array { ($n:literal) => { - impl<'a, T> FromMemoryItem<'a> for [T; $n] + impl<'a, T> FromKclValue<'a> for [T; $n] where - T: serde::de::DeserializeOwned + FromMemoryItem<'a>, + T: serde::de::DeserializeOwned + FromKclValue<'a>, { - fn from_mem_item(arg: &'a MemoryItem) -> Option { + fn from_mem_item(arg: &'a KclValue) -> Option { from_user_val(arg) } } }; } -fn from_user_val(arg: &MemoryItem) -> Option { +fn from_user_val(arg: &KclValue) -> Option { let v = match arg { - MemoryItem::UserVal(v) => v.value.clone(), + KclValue::UserVal(v) => v.value.clone(), other => serde_json::to_value(other).ok()?, }; serde_json::from_value(v).ok() @@ -619,64 +619,64 @@ impl_from_arg_via_json!(bool); impl_from_arg_for_array!(2); impl_from_arg_for_array!(3); -impl<'a> FromMemoryItem<'a> for &'a Box { - fn from_mem_item(arg: &'a MemoryItem) -> Option { - let MemoryItem::SketchGroup(s) = arg else { +impl<'a> FromKclValue<'a> for &'a Box { + fn from_mem_item(arg: &'a KclValue) -> Option { + let KclValue::SketchGroup(s) = arg else { return None; }; Some(s) } } -impl<'a> FromMemoryItem<'a> for Box { - fn from_mem_item(arg: &'a MemoryItem) -> Option { - let MemoryItem::SketchGroup(s) = arg else { +impl<'a> FromKclValue<'a> for Box { + fn from_mem_item(arg: &'a KclValue) -> Option { + let KclValue::SketchGroup(s) = arg else { return None; }; Some(s.to_owned()) } } -impl<'a> FromMemoryItem<'a> for Box { - fn from_mem_item(arg: &'a MemoryItem) -> Option { - let MemoryItem::ExtrudeGroup(s) = arg else { +impl<'a> FromKclValue<'a> for Box { + fn from_mem_item(arg: &'a KclValue) -> Option { + let KclValue::ExtrudeGroup(s) = arg else { return None; }; Some(s.to_owned()) } } -impl<'a> FromMemoryItem<'a> for FnAsArg<'a> { - fn from_mem_item(arg: &'a MemoryItem) -> Option { +impl<'a> FromKclValue<'a> for FnAsArg<'a> { + fn from_mem_item(arg: &'a KclValue) -> Option { arg.get_function() } } -impl<'a> FromMemoryItem<'a> for ExtrudeGroupSet { - fn from_mem_item(arg: &'a MemoryItem) -> Option { +impl<'a> FromKclValue<'a> for ExtrudeGroupSet { + fn from_mem_item(arg: &'a KclValue) -> Option { arg.get_extrude_group_set().ok() } } -impl<'a> FromMemoryItem<'a> for SketchGroupSet { - fn from_mem_item(arg: &'a MemoryItem) -> Option { +impl<'a> FromKclValue<'a> for SketchGroupSet { + fn from_mem_item(arg: &'a KclValue) -> Option { arg.get_sketch_group_set().ok() } } -impl<'a> FromMemoryItem<'a> for SketchSurfaceOrGroup { - fn from_mem_item(arg: &'a MemoryItem) -> Option { +impl<'a> FromKclValue<'a> for SketchSurfaceOrGroup { + fn from_mem_item(arg: &'a KclValue) -> Option { match arg { - MemoryItem::SketchGroup(sg) => Some(Self::SketchGroup(sg.clone())), - MemoryItem::Plane(sg) => Some(Self::SketchSurface(SketchSurface::Plane(sg.clone()))), - MemoryItem::Face(sg) => Some(Self::SketchSurface(SketchSurface::Face(sg.clone()))), + KclValue::SketchGroup(sg) => Some(Self::SketchGroup(sg.clone())), + KclValue::Plane(sg) => Some(Self::SketchSurface(SketchSurface::Plane(sg.clone()))), + KclValue::Face(sg) => Some(Self::SketchSurface(SketchSurface::Face(sg.clone()))), _ => None, } } } -impl<'a> FromMemoryItem<'a> for SketchSurface { - fn from_mem_item(arg: &'a MemoryItem) -> Option { +impl<'a> FromKclValue<'a> for SketchSurface { + fn from_mem_item(arg: &'a KclValue) -> Option { match arg { - MemoryItem::Plane(sg) => Some(Self::Plane(sg.clone())), - MemoryItem::Face(sg) => Some(Self::Face(sg.clone())), + KclValue::Plane(sg) => Some(Self::Plane(sg.clone())), + KclValue::Face(sg) => Some(Self::Face(sg.clone())), _ => None, } } diff --git a/src/wasm-lib/kcl/src/std/assert.rs b/src/wasm-lib/kcl/src/std/assert.rs index d1d837823..55506fa2f 100644 --- a/src/wasm-lib/kcl/src/std/assert.rs +++ b/src/wasm-lib/kcl/src/std/assert.rs @@ -6,7 +6,7 @@ use schemars::JsonSchema; use crate::{ errors::{KclError, KclErrorDetails}, - executor::MemoryItem, + executor::KclValue, std::Args, }; @@ -22,7 +22,7 @@ async fn _assert(value: bool, message: &str, args: &Args) -> Result<(), KclError /// Check that the provided value is true, or raise a [KclError] /// with the provided description. -pub async fn assert(args: Args) -> Result { +pub async fn assert(args: Args) -> Result { let (data, description): (bool, String) = args.get_data()?; inner_assert(data, &description, &args).await?; args.make_null_user_val() @@ -42,7 +42,7 @@ async fn inner_assert(data: bool, message: &str, args: &Args) -> Result<(), KclE _assert(data, message, args).await } -pub async fn assert_lt(args: Args) -> Result { +pub async fn assert_lt(args: Args) -> Result { let (left, right, description): (f64, f64, String) = args.get_data()?; inner_assert_lt(left, right, &description, &args).await?; args.make_null_user_val() @@ -61,7 +61,7 @@ async fn inner_assert_lt(left: f64, right: f64, message: &str, args: &Args) -> R _assert(left < right, message, args).await } -pub async fn assert_gt(args: Args) -> Result { +pub async fn assert_gt(args: Args) -> Result { let (left, right, description): (f64, f64, String) = args.get_data()?; inner_assert_gt(left, right, &description, &args).await?; args.make_null_user_val() @@ -82,7 +82,7 @@ async fn inner_assert_equal(left: f64, right: f64, epsilon: f64, message: &str, _assert((right - left).abs() < epsilon, message, args).await } -pub async fn assert_equal(args: Args) -> Result { +pub async fn assert_equal(args: Args) -> Result { let (left, right, epsilon, description): (f64, f64, f64, String) = args.get_data()?; inner_assert_equal(left, right, epsilon, &description, &args).await?; args.make_null_user_val() @@ -101,7 +101,7 @@ async fn inner_assert_gt(left: f64, right: f64, message: &str, args: &Args) -> R _assert(left > right, message, args).await } -pub async fn assert_lte(args: Args) -> Result { +pub async fn assert_lte(args: Args) -> Result { let (left, right, description): (f64, f64, String) = args.get_data()?; inner_assert_lte(left, right, &description, &args).await?; args.make_null_user_val() @@ -121,7 +121,7 @@ async fn inner_assert_lte(left: f64, right: f64, message: &str, args: &Args) -> _assert(left <= right, message, args).await } -pub async fn assert_gte(args: Args) -> Result { +pub async fn assert_gte(args: Args) -> Result { let (left, right, description): (f64, f64, String) = args.get_data()?; inner_assert_gte(left, right, &description, &args).await?; args.make_null_user_val() diff --git a/src/wasm-lib/kcl/src/std/chamfer.rs b/src/wasm-lib/kcl/src/std/chamfer.rs index d02b57cce..97b26951b 100644 --- a/src/wasm-lib/kcl/src/std/chamfer.rs +++ b/src/wasm-lib/kcl/src/std/chamfer.rs @@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize}; use crate::{ ast::types::TagDeclarator, errors::{KclError, KclErrorDetails}, - executor::{ChamferSurface, ExtrudeGroup, ExtrudeSurface, FilletOrChamfer, GeoMeta, MemoryItem}, + executor::{ChamferSurface, ExtrudeGroup, ExtrudeSurface, FilletOrChamfer, GeoMeta, KclValue}, std::{fillet::EdgeReference, Args}, }; @@ -27,12 +27,12 @@ pub struct ChamferData { } /// Create chamfers on tagged paths. -pub async fn chamfer(args: Args) -> Result { +pub async fn chamfer(args: Args) -> Result { let (data, extrude_group, tag): (ChamferData, Box, Option) = args.get_data_and_extrude_group_and_tag()?; let extrude_group = inner_chamfer(data, extrude_group, tag, args).await?; - Ok(MemoryItem::ExtrudeGroup(extrude_group)) + Ok(KclValue::ExtrudeGroup(extrude_group)) } /// Cut a straight transitional edge along a tagged path. diff --git a/src/wasm-lib/kcl/src/std/convert.rs b/src/wasm-lib/kcl/src/std/convert.rs index 566da80ce..8ce353b4f 100644 --- a/src/wasm-lib/kcl/src/std/convert.rs +++ b/src/wasm-lib/kcl/src/std/convert.rs @@ -5,7 +5,7 @@ use schemars::JsonSchema; use crate::{ errors::{KclError, KclErrorDetails}, - executor::{MemoryItem, SourceRange}, + executor::{KclValue, SourceRange}, std::Args, }; @@ -31,7 +31,7 @@ impl ConversionError { } /// Converts a number to integer. -pub async fn int(args: Args) -> Result { +pub async fn int(args: Args) -> Result { let num = args.get_number()?; let converted = inner_int(num).map_err(|err| err.into_kcl_error(args.source_range))?; diff --git a/src/wasm-lib/kcl/src/std/extrude.rs b/src/wasm-lib/kcl/src/std/extrude.rs index 9b5ff556a..52208230c 100644 --- a/src/wasm-lib/kcl/src/std/extrude.rs +++ b/src/wasm-lib/kcl/src/std/extrude.rs @@ -8,14 +8,14 @@ use uuid::Uuid; use crate::{ errors::{KclError, KclErrorDetails}, executor::{ - ExtrudeGroup, ExtrudeGroupSet, ExtrudeSurface, GeoMeta, MemoryItem, Path, SketchGroup, SketchGroupSet, + ExtrudeGroup, ExtrudeGroupSet, ExtrudeSurface, GeoMeta, KclValue, Path, SketchGroup, SketchGroupSet, SketchSurface, }, std::Args, }; /// Extrudes by a given amount. -pub async fn extrude(args: Args) -> Result { +pub async fn extrude(args: Args) -> Result { let (length, sketch_group_set) = args.get_number_sketch_group_set()?; let result = inner_extrude(length, sketch_group_set, args).await?; diff --git a/src/wasm-lib/kcl/src/std/fillet.rs b/src/wasm-lib/kcl/src/std/fillet.rs index dbf619e2d..72c492972 100644 --- a/src/wasm-lib/kcl/src/std/fillet.rs +++ b/src/wasm-lib/kcl/src/std/fillet.rs @@ -11,7 +11,7 @@ use crate::{ ast::types::TagDeclarator, errors::{KclError, KclErrorDetails}, executor::{ - ExtrudeGroup, ExtrudeSurface, FilletOrChamfer, FilletSurface, GeoMeta, MemoryItem, TagIdentifier, UserVal, + ExtrudeGroup, ExtrudeSurface, FilletOrChamfer, FilletSurface, GeoMeta, KclValue, TagIdentifier, UserVal, }, std::Args, }; @@ -41,12 +41,12 @@ pub enum EdgeReference { } /// Create fillets on tagged paths. -pub async fn fillet(args: Args) -> Result { +pub async fn fillet(args: Args) -> Result { let (data, extrude_group, tag): (FilletData, Box, Option) = args.get_data_and_extrude_group_and_tag()?; let extrude_group = inner_fillet(data, extrude_group, tag, args).await?; - Ok(MemoryItem::ExtrudeGroup(extrude_group)) + Ok(KclValue::ExtrudeGroup(extrude_group)) } /// Blend a transitional edge along a tagged path, smoothing the sharp edge. @@ -145,11 +145,11 @@ async fn inner_fillet( } /// Get the opposite edge to the edge given. -pub async fn get_opposite_edge(args: Args) -> Result { +pub async fn get_opposite_edge(args: Args) -> Result { let tag: TagIdentifier = args.get_data()?; let edge = inner_get_opposite_edge(tag, args.clone()).await?; - Ok(MemoryItem::UserVal(UserVal { + Ok(KclValue::UserVal(UserVal { value: serde_json::to_value(edge).map_err(|e| { KclError::Type(KclErrorDetails { message: format!("Failed to convert Uuid to json: {}", e), @@ -222,11 +222,11 @@ async fn inner_get_opposite_edge(tag: TagIdentifier, args: Args) -> Result Result { +pub async fn get_next_adjacent_edge(args: Args) -> Result { let tag: TagIdentifier = args.get_data()?; let edge = inner_get_next_adjacent_edge(tag, args.clone()).await?; - Ok(MemoryItem::UserVal(UserVal { + Ok(KclValue::UserVal(UserVal { value: serde_json::to_value(edge).map_err(|e| { KclError::Type(KclErrorDetails { message: format!("Failed to convert Uuid to json: {}", e), @@ -304,11 +304,11 @@ async fn inner_get_next_adjacent_edge(tag: TagIdentifier, args: Args) -> Result< } /// Get the previous adjacent edge to the edge given. -pub async fn get_previous_adjacent_edge(args: Args) -> Result { +pub async fn get_previous_adjacent_edge(args: Args) -> Result { let tag: TagIdentifier = args.get_data()?; let edge = inner_get_previous_adjacent_edge(tag, args.clone()).await?; - Ok(MemoryItem::UserVal(UserVal { + Ok(KclValue::UserVal(UserVal { value: serde_json::to_value(edge).map_err(|e| { KclError::Type(KclErrorDetails { message: format!("Failed to convert Uuid to json: {}", e), diff --git a/src/wasm-lib/kcl/src/std/helix.rs b/src/wasm-lib/kcl/src/std/helix.rs index 8e0541e26..220bf650b 100644 --- a/src/wasm-lib/kcl/src/std/helix.rs +++ b/src/wasm-lib/kcl/src/std/helix.rs @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize}; use crate::{ errors::KclError, - executor::{ExtrudeGroup, MemoryItem}, + executor::{ExtrudeGroup, KclValue}, std::Args, }; @@ -31,11 +31,11 @@ pub struct HelixData { } /// Create a helix on a cylinder. -pub async fn helix(args: Args) -> Result { +pub async fn helix(args: Args) -> Result { let (data, extrude_group): (HelixData, Box) = args.get_data_and_extrude_group()?; let extrude_group = inner_helix(data, extrude_group, args).await?; - Ok(MemoryItem::ExtrudeGroup(extrude_group)) + Ok(KclValue::ExtrudeGroup(extrude_group)) } /// Create a helix on a cylinder. diff --git a/src/wasm-lib/kcl/src/std/import.rs b/src/wasm-lib/kcl/src/std/import.rs index dd9eebaad..2d7fed754 100644 --- a/src/wasm-lib/kcl/src/std/import.rs +++ b/src/wasm-lib/kcl/src/std/import.rs @@ -9,7 +9,7 @@ use schemars::JsonSchema; use crate::{ errors::{KclError, KclErrorDetails}, - executor::{ImportedGeometry, MemoryItem}, + executor::{ImportedGeometry, KclValue}, fs::FileSystem, std::Args, }; @@ -117,11 +117,11 @@ impl From for kittycad::types::InputFormat { /// /// Import paths are relative to the current project directory. This only works in the desktop app /// not in browser. -pub async fn import(args: Args) -> Result { +pub async fn import(args: Args) -> Result { let (file_path, options): (String, Option) = args.get_import_data()?; let imported_geometry = inner_import(file_path, options, args).await?; - Ok(MemoryItem::ImportedGeometry(imported_geometry)) + Ok(KclValue::ImportedGeometry(imported_geometry)) } /// Import a CAD file. diff --git a/src/wasm-lib/kcl/src/std/math.rs b/src/wasm-lib/kcl/src/std/math.rs index 3100efe7a..d53307c17 100644 --- a/src/wasm-lib/kcl/src/std/math.rs +++ b/src/wasm-lib/kcl/src/std/math.rs @@ -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 { +pub async fn cos(args: Args) -> Result { let num = args.get_number()?; let result = inner_cos(num)?; @@ -41,7 +41,7 @@ fn inner_cos(num: f64) -> Result { } /// Compute the sine of a number (in radians). -pub async fn sin(args: Args) -> Result { +pub async fn sin(args: Args) -> Result { let num = args.get_number()?; let result = inner_sin(num)?; @@ -71,7 +71,7 @@ fn inner_sin(num: f64) -> Result { } /// Compute the tangent of a number (in radians). -pub async fn tan(args: Args) -> Result { +pub async fn tan(args: Args) -> Result { let num = args.get_number()?; let result = inner_tan(num)?; @@ -101,7 +101,7 @@ fn inner_tan(num: f64) -> Result { } /// Return the value of `pi`. Archimedes’ constant (π). -pub async fn pi(args: Args) -> Result { +pub async fn pi(args: Args) -> Result { let result = inner_pi()?; args.make_user_val_from_f64(result) @@ -126,7 +126,7 @@ fn inner_pi() -> Result { } /// Compute the square root of a number. -pub async fn sqrt(args: Args) -> Result { +pub async fn sqrt(args: Args) -> Result { let num = args.get_number()?; let result = inner_sqrt(num)?; @@ -156,7 +156,7 @@ fn inner_sqrt(num: f64) -> Result { } /// Compute the absolute value of a number. -pub async fn abs(args: Args) -> Result { +pub async fn abs(args: Args) -> Result { let num = args.get_number()?; let result = inner_abs(num)?; @@ -193,7 +193,7 @@ fn inner_abs(num: f64) -> Result { } /// Compute the largest integer less than or equal to a number. -pub async fn floor(args: Args) -> Result { +pub async fn floor(args: Args) -> Result { let num = args.get_number()?; let result = inner_floor(num)?; @@ -221,7 +221,7 @@ fn inner_floor(num: f64) -> Result { } /// Compute the smallest integer greater than or equal to a number. -pub async fn ceil(args: Args) -> Result { +pub async fn ceil(args: Args) -> Result { let num = args.get_number()?; let result = inner_ceil(num)?; @@ -249,7 +249,7 @@ fn inner_ceil(num: f64) -> Result { } /// Compute the minimum of the given arguments. -pub async fn min(args: Args) -> Result { +pub async fn min(args: Args) -> Result { let nums = args.get_number_array()?; let result = inner_min(nums); @@ -286,7 +286,7 @@ fn inner_min(args: Vec) -> f64 { } /// Compute the maximum of the given arguments. -pub async fn max(args: Args) -> Result { +pub async fn max(args: Args) -> Result { let nums = args.get_number_array()?; let result = inner_max(nums); @@ -323,7 +323,7 @@ fn inner_max(args: Vec) -> f64 { } /// Compute the number to a power. -pub async fn pow(args: Args) -> Result { +pub async fn pow(args: Args) -> Result { 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 { } /// Compute the arccosine of a number (in radians). -pub async fn acos(args: Args) -> Result { +pub async fn acos(args: Args) -> Result { let num = args.get_number()?; let result = inner_acos(num)?; @@ -398,7 +398,7 @@ fn inner_acos(num: f64) -> Result { } /// Compute the arcsine of a number (in radians). -pub async fn asin(args: Args) -> Result { +pub async fn asin(args: Args) -> Result { let num = args.get_number()?; let result = inner_asin(num)?; @@ -428,7 +428,7 @@ fn inner_asin(num: f64) -> Result { } /// Compute the arctangent of a number (in radians). -pub async fn atan(args: Args) -> Result { +pub async fn atan(args: Args) -> Result { let num = args.get_number()?; let result = inner_atan(num)?; @@ -462,7 +462,7 @@ fn inner_atan(num: f64) -> Result { /// 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 { +pub async fn log(args: Args) -> Result { 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 { } /// Compute the base 2 logarithm of the number. -pub async fn log2(args: Args) -> Result { +pub async fn log2(args: Args) -> Result { let num = args.get_number()?; let result = inner_log2(num)?; @@ -535,7 +535,7 @@ fn inner_log2(num: f64) -> Result { } /// Compute the base 10 logarithm of the number. -pub async fn log10(args: Args) -> Result { +pub async fn log10(args: Args) -> Result { let num = args.get_number()?; let result = inner_log10(num)?; @@ -563,7 +563,7 @@ fn inner_log10(num: f64) -> Result { } /// Compute the natural logarithm of the number. -pub async fn ln(args: Args) -> Result { +pub async fn ln(args: Args) -> Result { let num = args.get_number()?; let result = inner_ln(num)?; @@ -591,7 +591,7 @@ fn inner_ln(num: f64) -> Result { } /// Return the value of Euler’s number `e`. -pub async fn e(args: Args) -> Result { +pub async fn e(args: Args) -> Result { let result = inner_e()?; args.make_user_val_from_f64(result) @@ -620,7 +620,7 @@ fn inner_e() -> Result { } /// Return the value of `tau`. The full circle constant (τ). Equal to 2π. -pub async fn tau(args: Args) -> Result { +pub async fn tau(args: Args) -> Result { let result = inner_tau()?; args.make_user_val_from_f64(result) @@ -649,7 +649,7 @@ fn inner_tau() -> Result { } /// Converts a number from degrees to radians. -pub async fn to_radians(args: Args) -> Result { +pub async fn to_radians(args: Args) -> Result { let num = args.get_number()?; let result = inner_to_radians(num)?; @@ -679,7 +679,7 @@ fn inner_to_radians(num: f64) -> Result { } /// Converts a number from radians to degrees. -pub async fn to_degrees(args: Args) -> Result { +pub async fn to_degrees(args: Args) -> Result { let num = args.get_number()?; let result = inner_to_degrees(num)?; diff --git a/src/wasm-lib/kcl/src/std/mod.rs b/src/wasm-lib/kcl/src/std/mod.rs index e2db4c3f6..3fcf2e4ef 100644 --- a/src/wasm-lib/kcl/src/std/mod.rs +++ b/src/wasm-lib/kcl/src/std/mod.rs @@ -34,11 +34,11 @@ use crate::{ ast::types::FunctionExpression, docs::StdLibFn, errors::KclError, - executor::{MemoryItem, ProgramMemory, SketchGroup, SketchSurface}, + executor::{KclValue, ProgramMemory, SketchGroup, SketchSurface}, std::kcl_stdlib::KclStdLibFn, }; -pub type StdFn = fn(Args) -> std::pin::Pin> + Send>>; +pub type StdFn = fn(Args) -> std::pin::Pin> + Send>>; pub type FnMap = HashMap; @@ -213,7 +213,7 @@ pub enum FunctionKind { } /// Compute the length of the given leg. -pub async fn leg_length(args: Args) -> Result { +pub async fn leg_length(args: Args) -> Result { let (hypotenuse, leg) = args.get_hypotenuse_leg()?; let result = inner_leg_length(hypotenuse, leg); args.make_user_val_from_f64(result) @@ -233,7 +233,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 { +pub async fn leg_angle_x(args: Args) -> Result { let (hypotenuse, leg) = args.get_hypotenuse_leg()?; let result = inner_leg_angle_x(hypotenuse, leg); args.make_user_val_from_f64(result) @@ -253,7 +253,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 { +pub async fn leg_angle_y(args: Args) -> Result { let (hypotenuse, leg) = args.get_hypotenuse_leg()?; let result = inner_leg_angle_y(hypotenuse, leg); args.make_user_val_from_f64(result) diff --git a/src/wasm-lib/kcl/src/std/patterns.rs b/src/wasm-lib/kcl/src/std/patterns.rs index 1daf5ca1d..964c6c362 100644 --- a/src/wasm-lib/kcl/src/std/patterns.rs +++ b/src/wasm-lib/kcl/src/std/patterns.rs @@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize}; use crate::{ errors::{KclError, KclErrorDetails}, executor::{ - ExtrudeGroup, ExtrudeGroupSet, Geometries, Geometry, MemoryItem, Point3d, ProgramReturn, SketchGroup, + ExtrudeGroup, ExtrudeGroupSet, Geometries, Geometry, KclValue, Point3d, ProgramReturn, SketchGroup, SketchGroupSet, SourceRange, UserVal, }, function_param::FunctionParam, @@ -77,7 +77,7 @@ impl LinearPattern { /// A linear pattern /// Each element in the pattern repeats a particular piece of geometry. /// The repetitions can be transformed by the `transform` parameter. -pub async fn pattern_transform(args: Args) -> Result { +pub async fn pattern_transform(args: Args) -> Result { let (num_repetitions, transform, extr) = args.get_pattern_transform_args()?; let extrude_groups = inner_pattern_transform( @@ -94,7 +94,7 @@ pub async fn pattern_transform(args: Args) -> Result { &args, ) .await?; - Ok(MemoryItem::ExtrudeGroups { value: extrude_groups }) + Ok(KclValue::ExtrudeGroups { value: extrude_groups }) } /// Repeat a 3-dimensional solid by successively applying a transformation (such @@ -203,7 +203,7 @@ async fn make_transform<'a>( source_range: SourceRange, ) -> Result { // Call the transform fn for this repetition. - let repetition_num = MemoryItem::UserVal(UserVal { + let repetition_num = KclValue::UserVal(UserVal { value: serde_json::Value::Number(i.into()), meta: vec![source_range.into()], }); @@ -224,7 +224,7 @@ async fn make_transform<'a>( source_ranges: source_ranges.clone(), })); }; - let MemoryItem::UserVal(transform) = transform_fn_return else { + let KclValue::UserVal(transform) = transform_fn_return else { return Err(KclError::Semantic(KclErrorDetails { message: "Transform function must return a transform object".to_string(), source_ranges: source_ranges.clone(), @@ -303,7 +303,7 @@ mod tests { } /// A linear pattern on a 2D sketch. -pub async fn pattern_linear_2d(args: Args) -> Result { +pub async fn pattern_linear_2d(args: Args) -> Result { let (data, sketch_group_set): (LinearPattern2dData, SketchGroupSet) = args.get_data_and_sketch_group_set()?; if data.axis == [0.0, 0.0] { @@ -370,7 +370,7 @@ async fn inner_pattern_linear_2d( } /// A linear pattern on a 3D model. -pub async fn pattern_linear_3d(args: Args) -> Result { +pub async fn pattern_linear_3d(args: Args) -> Result { let (data, extrude_group_set): (LinearPattern3dData, ExtrudeGroupSet) = args.get_data_and_extrude_group_set()?; if data.axis == [0.0, 0.0, 0.0] { @@ -578,7 +578,7 @@ impl CircularPattern { } /// A circular pattern on a 2D sketch. -pub async fn pattern_circular_2d(args: Args) -> Result { +pub async fn pattern_circular_2d(args: Args) -> Result { let (data, sketch_group_set): (CircularPattern2dData, SketchGroupSet) = args.get_data_and_sketch_group_set()?; let sketch_groups = inner_pattern_circular_2d(data, sketch_group_set, args).await?; @@ -643,7 +643,7 @@ async fn inner_pattern_circular_2d( } /// A circular pattern on a 3D model. -pub async fn pattern_circular_3d(args: Args) -> Result { +pub async fn pattern_circular_3d(args: Args) -> Result { let (data, extrude_group_set): (CircularPattern3dData, ExtrudeGroupSet) = args.get_data_and_extrude_group_set()?; let extrude_groups = inner_pattern_circular_3d(data, extrude_group_set, args).await?; diff --git a/src/wasm-lib/kcl/src/std/polar.rs b/src/wasm-lib/kcl/src/std/polar.rs index 487a16a80..5385f0e11 100644 --- a/src/wasm-lib/kcl/src/std/polar.rs +++ b/src/wasm-lib/kcl/src/std/polar.rs @@ -5,7 +5,7 @@ use derive_docs::stdlib; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; -use crate::{errors::KclError, executor::MemoryItem, std::Args}; +use crate::{errors::KclError, executor::KclValue, std::Args}; /// Data for polar coordinates. #[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)] @@ -19,7 +19,7 @@ pub struct PolarCoordsData { } /// Convert from polar/sphere coordinates to cartesian coordinates. -pub async fn polar(args: Args) -> Result { +pub async fn polar(args: Args) -> Result { let data: PolarCoordsData = args.get_data()?; let result = inner_polar(&data)?; diff --git a/src/wasm-lib/kcl/src/std/revolve.rs b/src/wasm-lib/kcl/src/std/revolve.rs index 1c7533d26..a4f6c3bed 100644 --- a/src/wasm-lib/kcl/src/std/revolve.rs +++ b/src/wasm-lib/kcl/src/std/revolve.rs @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize}; use crate::{ errors::{KclError, KclErrorDetails}, - executor::{ExtrudeGroup, MemoryItem, SketchGroup}, + executor::{ExtrudeGroup, KclValue, SketchGroup}, std::{ extrude::do_post_extrude, fillet::{EdgeReference, DEFAULT_TOLERANCE}, @@ -98,11 +98,11 @@ impl RevolveAxisAndOrigin { } /// Revolve a sketch around an axis. -pub async fn revolve(args: Args) -> Result { +pub async fn revolve(args: Args) -> Result { let (data, sketch_group): (RevolveData, Box) = args.get_data_and_sketch_group()?; let extrude_group = inner_revolve(data, sketch_group, args).await?; - Ok(MemoryItem::ExtrudeGroup(extrude_group)) + Ok(KclValue::ExtrudeGroup(extrude_group)) } /// Rotate a sketch around some provided axis, creating a solid from its extent. diff --git a/src/wasm-lib/kcl/src/std/segment.rs b/src/wasm-lib/kcl/src/std/segment.rs index 49ae8167f..d67d21b3c 100644 --- a/src/wasm-lib/kcl/src/std/segment.rs +++ b/src/wasm-lib/kcl/src/std/segment.rs @@ -6,12 +6,12 @@ use schemars::JsonSchema; use crate::{ errors::{KclError, KclErrorDetails}, - executor::{MemoryItem, SketchGroup, TagIdentifier}, + executor::{KclValue, SketchGroup, TagIdentifier}, std::{utils::between, Args}, }; /// Returns the segment end of x. -pub async fn segment_end_x(args: Args) -> Result { +pub async fn segment_end_x(args: Args) -> Result { let tag: TagIdentifier = args.get_data()?; let result = inner_segment_end_x(&tag, args.clone())?; @@ -47,7 +47,7 @@ fn inner_segment_end_x(tag: &TagIdentifier, args: Args) -> Result } /// Returns the segment end of y. -pub async fn segment_end_y(args: Args) -> Result { +pub async fn segment_end_y(args: Args) -> Result { let tag: TagIdentifier = args.get_data()?; let result = inner_segment_end_y(&tag, args.clone())?; @@ -84,7 +84,7 @@ fn inner_segment_end_y(tag: &TagIdentifier, args: Args) -> Result } /// Returns the last segment of x. -pub async fn last_segment_x(args: Args) -> Result { +pub async fn last_segment_x(args: Args) -> Result { let sketch_group = args.get_sketch_group()?; let result = inner_last_segment_x(sketch_group, args.clone())?; @@ -127,7 +127,7 @@ fn inner_last_segment_x(sketch_group: Box, args: Args) -> Result Result { +pub async fn last_segment_y(args: Args) -> Result { let sketch_group = args.get_sketch_group()?; let result = inner_last_segment_y(sketch_group, args.clone())?; @@ -170,7 +170,7 @@ fn inner_last_segment_y(sketch_group: Box, args: Args) -> Result Result { +pub async fn segment_length(args: Args) -> Result { let tag: TagIdentifier = args.get_data()?; let result = inner_segment_length(&tag, args.clone())?; args.make_user_val_from_f64(result) @@ -215,7 +215,7 @@ fn inner_segment_length(tag: &TagIdentifier, args: Args) -> Result Result { +pub async fn segment_angle(args: Args) -> Result { let tag: TagIdentifier = args.get_data()?; let result = inner_segment_angle(&tag, args.clone())?; @@ -255,7 +255,7 @@ fn inner_segment_angle(tag: &TagIdentifier, args: Args) -> Result } /// Returns the angle to match the given length for x. -pub async fn angle_to_match_length_x(args: Args) -> Result { +pub async fn angle_to_match_length_x(args: Args) -> Result { let (tag, to, sketch_group) = args.get_tag_to_number_sketch_group()?; let result = inner_angle_to_match_length_x(&tag, to, sketch_group, args.clone())?; args.make_user_val_from_f64(result) @@ -320,7 +320,7 @@ fn inner_angle_to_match_length_x( } /// Returns the angle to match the given length for y. -pub async fn angle_to_match_length_y(args: Args) -> Result { +pub async fn angle_to_match_length_y(args: Args) -> Result { let (tag, to, sketch_group) = args.get_tag_to_number_sketch_group()?; let result = inner_angle_to_match_length_y(&tag, to, sketch_group, args.clone())?; args.make_user_val_from_f64(result) diff --git a/src/wasm-lib/kcl/src/std/shapes.rs b/src/wasm-lib/kcl/src/std/shapes.rs index 5e89befa9..c1151e879 100644 --- a/src/wasm-lib/kcl/src/std/shapes.rs +++ b/src/wasm-lib/kcl/src/std/shapes.rs @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize}; use crate::{ ast::types::TagDeclarator, errors::KclError, - executor::MemoryItem, + executor::KclValue, std::{Args, SketchGroup, SketchSurface}, }; @@ -22,12 +22,12 @@ pub enum SketchSurfaceOrGroup { } /// Sketch a circle. -pub async fn circle(args: Args) -> Result { +pub async fn circle(args: Args) -> Result { let (center, radius, sketch_surface_or_group, tag): ([f64; 2], f64, SketchSurfaceOrGroup, Option) = args.get_circle_args()?; let sketch_group = inner_circle(center, radius, sketch_surface_or_group, tag, args).await?; - Ok(MemoryItem::SketchGroup(sketch_group)) + Ok(KclValue::SketchGroup(sketch_group)) } /// Construct a 2-dimensional circle, of the specified radius, centered at diff --git a/src/wasm-lib/kcl/src/std/shell.rs b/src/wasm-lib/kcl/src/std/shell.rs index 891d9cf68..efec3cbf5 100644 --- a/src/wasm-lib/kcl/src/std/shell.rs +++ b/src/wasm-lib/kcl/src/std/shell.rs @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize}; use crate::{ errors::{KclError, KclErrorDetails}, - executor::{ExtrudeGroup, MemoryItem}, + executor::{ExtrudeGroup, KclValue}, std::{sketch::FaceTag, Args}, }; @@ -24,11 +24,11 @@ pub struct ShellData { } /// Create a shell. -pub async fn shell(args: Args) -> Result { +pub async fn shell(args: Args) -> Result { let (data, extrude_group): (ShellData, Box) = args.get_data_and_extrude_group()?; let extrude_group = inner_shell(data, extrude_group, args).await?; - Ok(MemoryItem::ExtrudeGroup(extrude_group)) + Ok(KclValue::ExtrudeGroup(extrude_group)) } /// Remove volume from a 3-dimensional shape such that a wall of the diff --git a/src/wasm-lib/kcl/src/std/sketch.rs b/src/wasm-lib/kcl/src/std/sketch.rs index 510188f9b..4359170f5 100644 --- a/src/wasm-lib/kcl/src/std/sketch.rs +++ b/src/wasm-lib/kcl/src/std/sketch.rs @@ -13,7 +13,7 @@ use crate::{ ast::types::TagDeclarator, errors::{KclError, KclErrorDetails}, executor::{ - BasePath, ExtrudeGroup, Face, GeoMeta, MemoryItem, Path, Plane, PlaneType, Point2d, Point3d, SketchGroup, + BasePath, ExtrudeGroup, Face, GeoMeta, KclValue, Path, Plane, PlaneType, Point2d, Point3d, SketchGroup, SketchGroupSet, SketchSurface, SourceRange, TagEngineInfo, TagIdentifier, UserVal, }, std::{ @@ -89,12 +89,12 @@ pub enum StartOrEnd { } /// Draw a line to a point. -pub async fn line_to(args: Args) -> Result { +pub async fn line_to(args: Args) -> Result { let (to, sketch_group, tag): ([f64; 2], Box, Option) = args.get_data_and_sketch_group_and_tag()?; let new_sketch_group = inner_line_to(to, sketch_group, tag, args).await?; - Ok(MemoryItem::SketchGroup(new_sketch_group)) + Ok(KclValue::SketchGroup(new_sketch_group)) } /// Draw a line from the current origin to some absolute (x, y) point. @@ -160,12 +160,12 @@ async fn inner_line_to( } /// Draw a line to a point on the x-axis. -pub async fn x_line_to(args: Args) -> Result { +pub async fn x_line_to(args: Args) -> Result { let (to, sketch_group, tag): (f64, Box, Option) = args.get_data_and_sketch_group_and_tag()?; let new_sketch_group = inner_x_line_to(to, sketch_group, tag, args).await?; - Ok(MemoryItem::SketchGroup(new_sketch_group)) + Ok(KclValue::SketchGroup(new_sketch_group)) } /// Draw a line parallel to the X axis, that ends at the given X. @@ -208,12 +208,12 @@ async fn inner_x_line_to( } /// Draw a line to a point on the y-axis. -pub async fn y_line_to(args: Args) -> Result { +pub async fn y_line_to(args: Args) -> Result { let (to, sketch_group, tag): (f64, Box, Option) = args.get_data_and_sketch_group_and_tag()?; let new_sketch_group = inner_y_line_to(to, sketch_group, tag, args).await?; - Ok(MemoryItem::SketchGroup(new_sketch_group)) + Ok(KclValue::SketchGroup(new_sketch_group)) } /// Draw a line parallel to the Y axis, that ends at the given Y. @@ -248,12 +248,12 @@ async fn inner_y_line_to( } /// Draw a line. -pub async fn line(args: Args) -> Result { +pub async fn line(args: Args) -> Result { let (delta, sketch_group, tag): ([f64; 2], Box, Option) = args.get_data_and_sketch_group_and_tag()?; let new_sketch_group = inner_line(delta, sketch_group, tag, args).await?; - Ok(MemoryItem::SketchGroup(new_sketch_group)) + Ok(KclValue::SketchGroup(new_sketch_group)) } /// Draw a line relative to the current origin to a specified (x, y) away @@ -333,12 +333,12 @@ async fn inner_line( } /// Draw a line on the x-axis. -pub async fn x_line(args: Args) -> Result { +pub async fn x_line(args: Args) -> Result { let (length, sketch_group, tag): (f64, Box, Option) = args.get_data_and_sketch_group_and_tag()?; let new_sketch_group = inner_x_line(length, sketch_group, tag, args).await?; - Ok(MemoryItem::SketchGroup(new_sketch_group)) + Ok(KclValue::SketchGroup(new_sketch_group)) } /// Draw a line relative to the current origin to a specified distance away @@ -376,12 +376,12 @@ async fn inner_x_line( } /// Draw a line on the y-axis. -pub async fn y_line(args: Args) -> Result { +pub async fn y_line(args: Args) -> Result { let (length, sketch_group, tag): (f64, Box, Option) = args.get_data_and_sketch_group_and_tag()?; let new_sketch_group = inner_y_line(length, sketch_group, tag, args).await?; - Ok(MemoryItem::SketchGroup(new_sketch_group)) + Ok(KclValue::SketchGroup(new_sketch_group)) } /// Draw a line relative to the current origin to a specified distance away @@ -430,12 +430,12 @@ pub enum AngledLineData { } /// Draw an angled line. -pub async fn angled_line(args: Args) -> Result { +pub async fn angled_line(args: Args) -> Result { let (data, sketch_group, tag): (AngledLineData, Box, Option) = args.get_data_and_sketch_group_and_tag()?; let new_sketch_group = inner_angled_line(data, sketch_group, tag, args).await?; - Ok(MemoryItem::SketchGroup(new_sketch_group)) + Ok(KclValue::SketchGroup(new_sketch_group)) } /// Draw a line segment relative to the current origin using the polar @@ -519,12 +519,12 @@ async fn inner_angled_line( } /// Draw an angled line of a given x length. -pub async fn angled_line_of_x_length(args: Args) -> Result { +pub async fn angled_line_of_x_length(args: Args) -> Result { let (data, sketch_group, tag): (AngledLineData, Box, Option) = args.get_data_and_sketch_group_and_tag()?; let new_sketch_group = inner_angled_line_of_x_length(data, sketch_group, tag, args).await?; - Ok(MemoryItem::SketchGroup(new_sketch_group)) + Ok(KclValue::SketchGroup(new_sketch_group)) } /// Create a line segment from the current 2-dimensional sketch origin @@ -587,12 +587,12 @@ pub struct AngledLineToData { } /// Draw an angled line to a given x coordinate. -pub async fn angled_line_to_x(args: Args) -> Result { +pub async fn angled_line_to_x(args: Args) -> Result { let (data, sketch_group, tag): (AngledLineToData, Box, Option) = args.get_data_and_sketch_group_and_tag()?; let new_sketch_group = inner_angled_line_to_x(data, sketch_group, tag, args).await?; - Ok(MemoryItem::SketchGroup(new_sketch_group)) + Ok(KclValue::SketchGroup(new_sketch_group)) } /// Create a line segment from the current 2-dimensional sketch origin @@ -644,13 +644,13 @@ async fn inner_angled_line_to_x( } /// Draw an angled line of a given y length. -pub async fn angled_line_of_y_length(args: Args) -> Result { +pub async fn angled_line_of_y_length(args: Args) -> Result { let (data, sketch_group, tag): (AngledLineData, Box, Option) = args.get_data_and_sketch_group_and_tag()?; let new_sketch_group = inner_angled_line_of_y_length(data, sketch_group, tag, args).await?; - Ok(MemoryItem::SketchGroup(new_sketch_group)) + Ok(KclValue::SketchGroup(new_sketch_group)) } /// Create a line segment from the current 2-dimensional sketch origin @@ -704,12 +704,12 @@ async fn inner_angled_line_of_y_length( } /// Draw an angled line to a given y coordinate. -pub async fn angled_line_to_y(args: Args) -> Result { +pub async fn angled_line_to_y(args: Args) -> Result { let (data, sketch_group, tag): (AngledLineToData, Box, Option) = args.get_data_and_sketch_group_and_tag()?; let new_sketch_group = inner_angled_line_to_y(data, sketch_group, tag, args).await?; - Ok(MemoryItem::SketchGroup(new_sketch_group)) + Ok(KclValue::SketchGroup(new_sketch_group)) } /// Create a line segment from the current 2-dimensional sketch origin @@ -775,11 +775,11 @@ pub struct AngledLineThatIntersectsData { } /// Draw an angled line that intersects with a given line. -pub async fn angled_line_that_intersects(args: Args) -> Result { +pub async fn angled_line_that_intersects(args: Args) -> Result { let (data, sketch_group, tag): (AngledLineThatIntersectsData, Box, Option) = args.get_data_and_sketch_group_and_tag()?; let new_sketch_group = inner_angled_line_that_intersects(data, sketch_group, tag, args).await?; - Ok(MemoryItem::SketchGroup(new_sketch_group)) + Ok(KclValue::SketchGroup(new_sketch_group)) } /// Draw an angled line from the current origin, constructing a line segment @@ -831,11 +831,11 @@ async fn inner_angled_line_that_intersects( } /// Start a sketch at a given point. -pub async fn start_sketch_at(args: Args) -> Result { +pub async fn start_sketch_at(args: Args) -> Result { let data: [f64; 2] = args.get_data()?; let sketch_group = inner_start_sketch_at(data, args).await?; - Ok(MemoryItem::SketchGroup(sketch_group)) + Ok(KclValue::SketchGroup(sketch_group)) } /// Start a new 2-dimensional sketch at a given point on the 'XY' plane. @@ -1006,12 +1006,12 @@ impl From for Plane { } /// Start a sketch on a specific plane or face. -pub async fn start_sketch_on(args: Args) -> Result { +pub async fn start_sketch_on(args: Args) -> Result { let (data, tag): (SketchData, Option) = args.get_data_and_optional_tag()?; match inner_start_sketch_on(data, tag, args).await? { - SketchSurface::Plane(plane) => Ok(MemoryItem::Plane(plane)), - SketchSurface::Face(face) => Ok(MemoryItem::Face(face)), + SketchSurface::Plane(plane) => Ok(KclValue::Plane(plane)), + SketchSurface::Face(face) => Ok(KclValue::Face(face)), } } @@ -1199,12 +1199,12 @@ async fn start_sketch_on_plane(data: PlaneData, args: Args) -> Result } /// Start a new profile at a given point. -pub async fn start_profile_at(args: Args) -> Result { +pub async fn start_profile_at(args: Args) -> Result { let (start, sketch_surface, tag): ([f64; 2], SketchSurface, Option) = args.get_data_and_sketch_surface()?; let sketch_group = inner_start_profile_at(start, sketch_surface, tag, args).await?; - Ok(MemoryItem::SketchGroup(sketch_group)) + Ok(KclValue::SketchGroup(sketch_group)) } /// Start a new profile at a given point. @@ -1328,7 +1328,7 @@ pub(crate) async fn inner_start_profile_at( } /// Returns the X component of the sketch profile start point. -pub async fn profile_start_x(args: Args) -> Result { +pub async fn profile_start_x(args: Args) -> Result { let sketch_group: Box = args.get_sketch_group()?; let x = inner_profile_start_x(sketch_group)?; args.make_user_val_from_f64(x) @@ -1352,7 +1352,7 @@ pub(crate) fn inner_profile_start_x(sketch_group: Box) -> Result Result { +pub async fn profile_start_y(args: Args) -> Result { let sketch_group: Box = args.get_sketch_group()?; let x = inner_profile_start_y(sketch_group)?; args.make_user_val_from_f64(x) @@ -1375,10 +1375,10 @@ pub(crate) fn inner_profile_start_y(sketch_group: Box) -> Result Result { +pub async fn profile_start(args: Args) -> Result { let sketch_group: Box = args.get_sketch_group()?; let point = inner_profile_start(sketch_group)?; - Ok(MemoryItem::UserVal(UserVal { + Ok(KclValue::UserVal(UserVal { value: serde_json::to_value(point).map_err(|e| { KclError::Type(KclErrorDetails { message: format!("Failed to convert point to json: {}", e), @@ -1409,12 +1409,12 @@ pub(crate) fn inner_profile_start(sketch_group: Box) -> Result<[f64 } /// Close the current sketch. -pub async fn close(args: Args) -> Result { +pub async fn close(args: Args) -> Result { let (sketch_group, tag): (Box, Option) = args.get_sketch_group_and_optional_tag()?; let new_sketch_group = inner_close(sketch_group, tag, args).await?; - Ok(MemoryItem::SketchGroup(new_sketch_group)) + Ok(KclValue::SketchGroup(new_sketch_group)) } /// Construct a line segment from the current origin back to the profile's @@ -1516,12 +1516,12 @@ pub enum ArcData { } /// Draw an arc. -pub async fn arc(args: Args) -> Result { +pub async fn arc(args: Args) -> Result { let (data, sketch_group, tag): (ArcData, Box, Option) = args.get_data_and_sketch_group_and_tag()?; let new_sketch_group = inner_arc(data, sketch_group, tag, args).await?; - Ok(MemoryItem::SketchGroup(new_sketch_group)) + Ok(KclValue::SketchGroup(new_sketch_group)) } /// Starting at the current sketch's origin, draw a curved line segment along @@ -1639,12 +1639,12 @@ pub enum TangentialArcData { } /// Draw a tangential arc. -pub async fn tangential_arc(args: Args) -> Result { +pub async fn tangential_arc(args: Args) -> Result { let (data, sketch_group, tag): (TangentialArcData, Box, Option) = args.get_data_and_sketch_group_and_tag()?; let new_sketch_group = inner_tangential_arc(data, sketch_group, tag, args).await?; - Ok(MemoryItem::SketchGroup(new_sketch_group)) + Ok(KclValue::SketchGroup(new_sketch_group)) } /// Starting at the current sketch's origin, draw a curved line segment along @@ -1787,7 +1787,7 @@ fn get_arg(it: &mut I, src: SourceRange) -> Result Result { +pub async fn tangential_arc_to(args: Args) -> Result { let src = args.source_range; // Get arguments to function call @@ -1801,7 +1801,7 @@ pub async fn tangential_arc_to(args: Args) -> Result { }; let new_sketch_group = inner_tangential_arc_to(to, sketch_group, tag, args).await?; - Ok(MemoryItem::SketchGroup(new_sketch_group)) + Ok(KclValue::SketchGroup(new_sketch_group)) } /// Starting at the current sketch's origin, draw a curved line segment along @@ -1887,12 +1887,12 @@ pub struct BezierData { } /// Draw a bezier curve. -pub async fn bezier_curve(args: Args) -> Result { +pub async fn bezier_curve(args: Args) -> Result { let (data, sketch_group, tag): (BezierData, Box, Option) = args.get_data_and_sketch_group_and_tag()?; let new_sketch_group = inner_bezier_curve(data, sketch_group, tag, args).await?; - Ok(MemoryItem::SketchGroup(new_sketch_group)) + Ok(KclValue::SketchGroup(new_sketch_group)) } /// Draw a smooth, continuous, curved line segment from the current origin to @@ -1979,11 +1979,11 @@ async fn inner_bezier_curve( } /// Use a sketch to cut a hole in another sketch. -pub async fn hole(args: Args) -> Result { +pub async fn hole(args: Args) -> Result { let (hole_sketch_group, sketch_group): (SketchGroupSet, Box) = args.get_sketch_groups()?; let new_sketch_group = inner_hole(hole_sketch_group, sketch_group, args).await?; - Ok(MemoryItem::SketchGroup(new_sketch_group)) + Ok(KclValue::SketchGroup(new_sketch_group)) } /// Use a 2-dimensional sketch to cut a hole in another 2-dimensional sketch. diff --git a/src/wasm-lib/tests/modify/main.rs b/src/wasm-lib/tests/modify/main.rs index 89ca22887..fa7c0319c 100644 --- a/src/wasm-lib/tests/modify/main.rs +++ b/src/wasm-lib/tests/modify/main.rs @@ -1,7 +1,7 @@ use anyhow::Result; use kcl_lib::{ ast::{modify::modify_ast_for_sketch, types::Program}, - executor::{ExecutorContext, MemoryItem, PlaneType, SourceRange}, + executor::{ExecutorContext, KclValue, PlaneType, SourceRange}, }; use kittycad::types::{ModelingCmd, Point3D}; use pretty_assertions::assert_eq; @@ -39,7 +39,7 @@ async fn setup(code: &str, name: &str) -> Result<(ExecutorContext, Program, uuid // We need to get the sketch ID. // Get the sketch group ID from memory. - let MemoryItem::SketchGroup(sketch_group) = memory.get(name, SourceRange::default()).unwrap() else { + let KclValue::SketchGroup(sketch_group) = memory.get(name, SourceRange::default()).unwrap() else { anyhow::bail!("part001 not found in memory: {:?}", memory); }; let sketch_id = sketch_group.id;