From 8b9580b178dcd46bafb509a193652bf81c99a856 Mon Sep 17 00:00:00 2001 From: arnav Date: Thu, 9 Jan 2025 07:20:48 -0500 Subject: [PATCH] array len with kw args --- docs/kcl/len.md | 2 +- docs/kcl/std.json | 227 +++++++++++++- src/wasm-lib/kcl/src/std/array.rs | 7 +- .../tests/array_length/artifact_commands.snap | 284 ++++++++++++++++++ src/wasm-lib/kcl/tests/array_length/ops.snap | 5 + 5 files changed, 521 insertions(+), 4 deletions(-) create mode 100644 src/wasm-lib/kcl/tests/array_length/artifact_commands.snap create mode 100644 src/wasm-lib/kcl/tests/array_length/ops.snap diff --git a/docs/kcl/len.md b/docs/kcl/len.md index 85c6667ff..87d7b4f85 100644 --- a/docs/kcl/len.md +++ b/docs/kcl/len.md @@ -17,7 +17,7 @@ len(array: [KclValue]) -> KclValue | Name | Type | Description | Required | |----------|------|-------------|----------| -| `array` | [`[KclValue]`](/docs/kcl/types/KclValue) | | Yes | +| `array` | [`[KclValue]`](/docs/kcl/types/KclValue) | The array to get the length of. | Yes | ### Returns diff --git a/docs/kcl/std.json b/docs/kcl/std.json index 95d9d03d2..208b36f98 100644 --- a/docs/kcl/std.json +++ b/docs/kcl/std.json @@ -90163,7 +90163,7 @@ "summary": "Get the length of an array.", "description": "Returns the number of elements in an array.", "tags": [], - "keywordArguments": false, + "keywordArguments": true, "args": [ { "name": "array", @@ -90703,6 +90703,51 @@ } } }, + { + "description": "A helix.", + "type": "object", + "required": [ + "__meta", + "angleStart", + "ccw", + "revolutions", + "type", + "value" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "Helix" + ] + }, + "value": { + "description": "The id of the helix.", + "type": "string", + "format": "uuid" + }, + "revolutions": { + "description": "Number of revolutions.", + "type": "number", + "format": "double" + }, + "angleStart": { + "description": "Start angle (in degrees).", + "type": "number", + "format": "double" + }, + "ccw": { + "description": "Is the helix rotation counter clockwise?", + "type": "boolean" + }, + "__meta": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Metadata" + } + } + } + }, { "description": "Data for an imported geometry.", "type": "object", @@ -90764,6 +90809,31 @@ } } }, + { + "type": "object", + "required": [ + "__meta", + "type", + "value" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "Module" + ] + }, + "value": { + "$ref": "#/components/schemas/ModuleId" + }, + "__meta": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Metadata" + } + } + } + }, { "type": "object", "required": [ @@ -92145,6 +92215,12 @@ } } }, + "ModuleId": { + "description": "Identifier of a source file. Uses a u32 to keep the size small.", + "type": "integer", + "format": "uint32", + "minimum": 0.0 + }, "KclNone": { "description": "KCL value for an optional parameter which was not given an argument. (remember, parameters are in the function declaration, arguments are in the function call/application).", "type": "object", @@ -92165,7 +92241,8 @@ } }, "required": true, - "labelRequired": true + "description": "The array to get the length of.", + "labelRequired": false } ], "returnValue": { @@ -92700,6 +92777,51 @@ } } }, + { + "description": "A helix.", + "type": "object", + "required": [ + "__meta", + "angleStart", + "ccw", + "revolutions", + "type", + "value" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "Helix" + ] + }, + "value": { + "description": "The id of the helix.", + "type": "string", + "format": "uuid" + }, + "revolutions": { + "description": "Number of revolutions.", + "type": "number", + "format": "double" + }, + "angleStart": { + "description": "Start angle (in degrees).", + "type": "number", + "format": "double" + }, + "ccw": { + "description": "Is the helix rotation counter clockwise?", + "type": "boolean" + }, + "__meta": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Metadata" + } + } + } + }, { "description": "Data for an imported geometry.", "type": "object", @@ -92761,6 +92883,31 @@ } } }, + { + "type": "object", + "required": [ + "__meta", + "type", + "value" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "Module" + ] + }, + "value": { + "$ref": "#/components/schemas/ModuleId" + }, + "__meta": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Metadata" + } + } + } + }, { "type": "object", "required": [ @@ -93342,6 +93489,51 @@ } } }, + { + "description": "A helix.", + "type": "object", + "required": [ + "__meta", + "angleStart", + "ccw", + "revolutions", + "type", + "value" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "Helix" + ] + }, + "value": { + "description": "The id of the helix.", + "type": "string", + "format": "uuid" + }, + "revolutions": { + "description": "Number of revolutions.", + "type": "number", + "format": "double" + }, + "angleStart": { + "description": "Start angle (in degrees).", + "type": "number", + "format": "double" + }, + "ccw": { + "description": "Is the helix rotation counter clockwise?", + "type": "boolean" + }, + "__meta": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Metadata" + } + } + } + }, { "description": "Data for an imported geometry.", "type": "object", @@ -93403,6 +93595,31 @@ } } }, + { + "type": "object", + "required": [ + "__meta", + "type", + "value" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "Module" + ] + }, + "value": { + "$ref": "#/components/schemas/ModuleId" + }, + "__meta": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Metadata" + } + } + } + }, { "type": "object", "required": [ @@ -94757,6 +94974,12 @@ } } }, + "ModuleId": { + "description": "Identifier of a source file. Uses a u32 to keep the size small.", + "type": "integer", + "format": "uint32", + "minimum": 0.0 + }, "KclNone": { "description": "KCL value for an optional parameter which was not given an argument. (remember, parameters are in the function declaration, arguments are in the function call/application).", "type": "object", diff --git a/src/wasm-lib/kcl/src/std/array.rs b/src/wasm-lib/kcl/src/std/array.rs index e334b2577..caeabc3a0 100644 --- a/src/wasm-lib/kcl/src/std/array.rs +++ b/src/wasm-lib/kcl/src/std/array.rs @@ -320,6 +320,11 @@ pub async fn pop(_exec_state: &mut ExecState, args: Args) -> Result, args: &Args) -> Result { Ok(KclValue::Number { @@ -329,7 +334,7 @@ async fn inner_len(array: Vec, args: &Args) -> Result Result { - let val: KclValue = FromArgs::from_args(&args, 0)?; + let val = args.get_unlabeled_kw_arg("array")?; let meta = vec![args.source_range]; let KclValue::Array { value: array, meta: _ } = val else { let actual_type = val.human_friendly_type(); diff --git a/src/wasm-lib/kcl/tests/array_length/artifact_commands.snap b/src/wasm-lib/kcl/tests/array_length/artifact_commands.snap new file mode 100644 index 000000000..101c44b1d --- /dev/null +++ b/src/wasm-lib/kcl/tests/array_length/artifact_commands.snap @@ -0,0 +1,284 @@ +--- +source: kcl/src/simulation_tests.rs +description: Artifact commands array_length.kcl +--- +[ + { + "cmdId": "[uuid]", + "range": [ + 0, + 0, + 0 + ], + "command": { + "type": "make_plane", + "origin": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "x_axis": { + "x": 1.0, + "y": 0.0, + "z": 0.0 + }, + "y_axis": { + "x": 0.0, + "y": 1.0, + "z": 0.0 + }, + "size": 100.0, + "clobber": false, + "hide": true + } + }, + { + "cmdId": "[uuid]", + "range": [ + 0, + 0, + 0 + ], + "command": { + "type": "plane_set_color", + "plane_id": "[uuid]", + "color": { + "r": 0.7, + "g": 0.28, + "b": 0.28, + "a": 0.4 + } + } + }, + { + "cmdId": "[uuid]", + "range": [ + 0, + 0, + 0 + ], + "command": { + "type": "make_plane", + "origin": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "x_axis": { + "x": 0.0, + "y": 1.0, + "z": 0.0 + }, + "y_axis": { + "x": 0.0, + "y": 0.0, + "z": 1.0 + }, + "size": 100.0, + "clobber": false, + "hide": true + } + }, + { + "cmdId": "[uuid]", + "range": [ + 0, + 0, + 0 + ], + "command": { + "type": "plane_set_color", + "plane_id": "[uuid]", + "color": { + "r": 0.28, + "g": 0.7, + "b": 0.28, + "a": 0.4 + } + } + }, + { + "cmdId": "[uuid]", + "range": [ + 0, + 0, + 0 + ], + "command": { + "type": "make_plane", + "origin": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "x_axis": { + "x": 1.0, + "y": 0.0, + "z": 0.0 + }, + "y_axis": { + "x": 0.0, + "y": 0.0, + "z": 1.0 + }, + "size": 100.0, + "clobber": false, + "hide": true + } + }, + { + "cmdId": "[uuid]", + "range": [ + 0, + 0, + 0 + ], + "command": { + "type": "plane_set_color", + "plane_id": "[uuid]", + "color": { + "r": 0.28, + "g": 0.28, + "b": 0.7, + "a": 0.4 + } + } + }, + { + "cmdId": "[uuid]", + "range": [ + 0, + 0, + 0 + ], + "command": { + "type": "make_plane", + "origin": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "x_axis": { + "x": -1.0, + "y": 0.0, + "z": 0.0 + }, + "y_axis": { + "x": 0.0, + "y": 1.0, + "z": 0.0 + }, + "size": 100.0, + "clobber": false, + "hide": true + } + }, + { + "cmdId": "[uuid]", + "range": [ + 0, + 0, + 0 + ], + "command": { + "type": "make_plane", + "origin": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "x_axis": { + "x": 0.0, + "y": -1.0, + "z": 0.0 + }, + "y_axis": { + "x": 0.0, + "y": 0.0, + "z": 1.0 + }, + "size": 100.0, + "clobber": false, + "hide": true + } + }, + { + "cmdId": "[uuid]", + "range": [ + 0, + 0, + 0 + ], + "command": { + "type": "make_plane", + "origin": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "x_axis": { + "x": -1.0, + "y": 0.0, + "z": 0.0 + }, + "y_axis": { + "x": 0.0, + "y": 0.0, + "z": 1.0 + }, + "size": 100.0, + "clobber": false, + "hide": true + } + }, + { + "cmdId": "[uuid]", + "range": [ + 0, + 0, + 0 + ], + "command": { + "type": "edge_lines_visible", + "hidden": false + } + }, + { + "cmdId": "[uuid]", + "range": [ + 0, + 0, + 0 + ], + "command": { + "type": "set_scene_units", + "unit": "mm" + } + }, + { + "cmdId": "[uuid]", + "range": [ + 0, + 0, + 0 + ], + "command": { + "type": "object_visible", + "object_id": "[uuid]", + "hidden": true + } + }, + { + "cmdId": "[uuid]", + "range": [ + 0, + 0, + 0 + ], + "command": { + "type": "object_visible", + "object_id": "[uuid]", + "hidden": true + } + } +] diff --git a/src/wasm-lib/kcl/tests/array_length/ops.snap b/src/wasm-lib/kcl/tests/array_length/ops.snap new file mode 100644 index 000000000..eb98d4e64 --- /dev/null +++ b/src/wasm-lib/kcl/tests/array_length/ops.snap @@ -0,0 +1,5 @@ +--- +source: kcl/src/simulation_tests.rs +description: Operations executed array_length.kcl +--- +[]