Compare commits

..

2 Commits

29 changed files with 574 additions and 6073 deletions

View File

@ -59,7 +59,6 @@ layout: manual
* [`legAngX`](kcl/legAngX) * [`legAngX`](kcl/legAngX)
* [`legAngY`](kcl/legAngY) * [`legAngY`](kcl/legAngY)
* [`legLen`](kcl/legLen) * [`legLen`](kcl/legLen)
* [`len`](kcl/len)
* [`line`](kcl/line) * [`line`](kcl/line)
* [`lineTo`](kcl/lineTo) * [`lineTo`](kcl/lineTo)
* [`ln`](kcl/ln) * [`ln`](kcl/ln)

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -17,8 +17,8 @@ push(array: [KclValue], elem: KclValue) -> KclValue
| Name | Type | Description | Required | | Name | Type | Description | Required |
|----------|------|-------------|----------| |----------|------|-------------|----------|
| `array` | [`[KclValue]`](/docs/kcl/types/KclValue) | | Yes | | `array` | [`[KclValue]`](/docs/kcl/types/KclValue) | The array to push to. | Yes |
| `elem` | [`KclValue`](/docs/kcl/types/KclValue) | Any KCL value. | Yes | | `elem` | [`KclValue`](/docs/kcl/types/KclValue) | The element to push to the array. | Yes |
### Returns ### Returns
@ -29,7 +29,7 @@ push(array: [KclValue], elem: KclValue) -> KclValue
```js ```js
arr = [1, 2, 3] arr = [1, 2, 3]
new_arr = push(arr, 4) new_arr = push(arr, elem = 4)
assertEqual(new_arr[3], 4, 0.00001, "4 was added to the end of the array") assertEqual(new_arr[3], 4, 0.00001, "4 was added to the end of the array")
``` ```

View File

@ -17,9 +17,9 @@ reduce(array: [KclValue], start: KclValue, reduce_fn: FunctionParam) -> KclValue
| Name | Type | Description | Required | | Name | Type | Description | Required |
|----------|------|-------------|----------| |----------|------|-------------|----------|
| `array` | [`[KclValue]`](/docs/kcl/types/KclValue) | | Yes | | `array` | [`[KclValue]`](/docs/kcl/types/KclValue) | The array to reduce. | Yes |
| `start` | [`KclValue`](/docs/kcl/types/KclValue) | Any KCL value. | Yes | | `start` | [`KclValue`](/docs/kcl/types/KclValue) | The starting value for the reduction. | Yes |
| `reduce_fn` | `FunctionParam` | | Yes | | `reduce_fn` | `FunctionParam` | The function to reduce the array with. | Yes |
### Returns ### Returns
@ -38,7 +38,7 @@ fn add(a, b) {
// It uses the `reduce` function, to call the `add` function on every // It uses the `reduce` function, to call the `add` function on every
// element of the `arr` parameter. The starting value is 0. // element of the `arr` parameter. The starting value is 0.
fn sum(arr) { fn sum(arr) {
return reduce(arr, 0, add) return reduce(arr, start = 0, reduce_fn = add)
} }
/* The above is basically like this pseudo-code: /* The above is basically like this pseudo-code:
@ -61,7 +61,7 @@ assertEqual(sum([1, 2, 3]), 6, 0.00001, "1 + 2 + 3 summed is 6")
// an anonymous `add` function as its parameter, instead of declaring a // an anonymous `add` function as its parameter, instead of declaring a
// named function outside. // named function outside.
arr = [1, 2, 3] arr = [1, 2, 3]
sum = reduce(arr, 0, fn(i, result_so_far) { sum = reduce(arr, start = 0, reduce_fn = fn(i, result_so_far) {
return i + result_so_far return i + result_so_far
}) })
@ -85,7 +85,7 @@ fn decagon(radius) {
// Use a `reduce` to draw the remaining decagon sides. // Use a `reduce` to draw the remaining decagon sides.
// For each number in the array 1..10, run the given function, // For each number in the array 1..10, run the given function,
// which takes a partially-sketched decagon and adds one more edge to it. // which takes a partially-sketched decagon and adds one more edge to it.
fullDecagon = reduce([1..10], startOfDecagonSketch, fn(i, partialDecagon) { fullDecagon = reduce([1..10], start = startOfDecagonSketch, reduce_fn = fn(i, partialDecagon) {
// Draw one edge of the decagon. // Draw one edge of the decagon.
x = cos(stepAngle * i) * radius x = cos(stepAngle * i) * radius
y = sin(stepAngle * i) * radius y = sin(stepAngle * i) * radius

File diff suppressed because it is too large Load Diff

View File

@ -368,13 +368,20 @@ export class LanguageServerPlugin implements PluginValue {
sortText, sortText,
filterText, filterText,
}) => { }) => {
const detailText = [
deprecated ? 'Deprecated' : undefined,
labelDetails ? labelDetails.detail : detail,
]
// Don't let undefined appear.
.filter(Boolean)
.join(' ')
const completion: Completion & { const completion: Completion & {
filterText: string filterText: string
sortText?: string sortText?: string
apply: string apply: string
} = { } = {
label, label,
detail: labelDetails ? labelDetails.detail : detail, detail: detailText,
apply: label, apply: label,
type: kind && CompletionItemKindMap[kind].toLowerCase(), type: kind && CompletionItemKindMap[kind].toLowerCase(),
sortText: sortText ?? label, sortText: sortText ?? label,
@ -382,7 +389,11 @@ export class LanguageServerPlugin implements PluginValue {
} }
if (documentation) { if (documentation) {
completion.info = () => { completion.info = () => {
const htmlString = formatMarkdownContents(documentation) const deprecatedHtml = deprecated
? '<p><strong>Deprecated</strong></p>'
: ''
const htmlString =
deprecatedHtml + formatMarkdownContents(documentation)
const htmlNode = document.createElement('div') const htmlNode = document.createElement('div')
htmlNode.style.display = 'contents' htmlNode.style.display = 'contents'
htmlNode.innerHTML = htmlString htmlNode.innerHTML = htmlString

View File

@ -1755,24 +1755,3 @@ mod array_elem_pop_fail {
super::execute(TEST_NAME, false).await super::execute(TEST_NAME, false).await
} }
} }
mod array_length {
const TEST_NAME: &str = "array_length";
/// Test parsing KCL.
#[test]
fn parse() {
super::parse(TEST_NAME)
}
/// Test that parsing and unparsing KCL produces the original KCL input.
#[test]
fn unparse() {
super::unparse(TEST_NAME)
}
/// Test that KCL is executed correctly.
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_execute() {
super::execute(TEST_NAME, false).await
}
}

View File

@ -1,9 +1,6 @@
use derive_docs::stdlib; use derive_docs::stdlib;
use super::{ use super::{args::Arg, Args, FnAsArg};
args::{Arg, FromArgs},
Args, FnAsArg,
};
use crate::{ use crate::{
errors::{KclError, KclErrorDetails}, errors::{KclError, KclErrorDetails},
execution::{ExecState, FunctionParam, KclValue}, execution::{ExecState, FunctionParam, KclValue},
@ -12,14 +9,47 @@ use crate::{
/// Apply a function to each element of an array. /// Apply a function to each element of an array.
pub async fn map(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> { pub async fn map(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let (array, f): (Vec<KclValue>, FnAsArg<'_>) = FromArgs::from_args(&args, 0)?; let array = args.get_unlabeled_kw_arg("array")?;
// Check that the array is an array
let array: Vec<KclValue> = match array {
KclValue::Array { value, meta: _ } => value,
_ => {
return Err(KclError::Semantic(KclErrorDetails {
source_ranges: vec![args.source_range],
message: format!(
"Expected an array to map, but got a value of type {}",
array.human_friendly_type()
),
}))
}
};
// Check that the map_fn is a function
let map_fn_kclvalue: KclValue = args.get_kw_arg("map_fn")?;
match map_fn_kclvalue {
KclValue::Function { .. } => (),
_ => {
return Err(KclError::Semantic(KclErrorDetails {
source_ranges: vec![args.source_range],
message: format!(
"Expected map_fn to be a function, but got a value of type {}",
map_fn_kclvalue.human_friendly_type()
),
}))
}
}
// Extract the function from the KclValue
let map_fn: FnAsArg<'_> = args.get_kw_arg("map_fn")?;
let meta = vec![args.source_range.into()]; let meta = vec![args.source_range.into()];
let map_fn = FunctionParam { let map_fn = FunctionParam {
inner: f.func, inner: map_fn.func,
fn_expr: f.expr, fn_expr: map_fn.expr,
meta: meta.clone(), meta: meta.clone(),
ctx: args.ctx.clone(), ctx: args.ctx.clone(),
memory: *f.memory, memory: *map_fn.memory,
}; };
let new_array = inner_map(array, map_fn, exec_state, &args).await?; let new_array = inner_map(array, map_fn, exec_state, &args).await?;
Ok(KclValue::Array { value: new_array, meta }) Ok(KclValue::Array { value: new_array, meta })
@ -41,7 +71,7 @@ pub async fn map(exec_state: &mut ExecState, args: Args) -> Result<KclValue, Kcl
/// // which is the return value from `map`. /// // which is the return value from `map`.
/// circles = map( /// circles = map(
/// [1..3], /// [1..3],
/// drawCircle /// map_fn = drawCircle
/// ) /// )
/// ``` /// ```
/// ```no_run /// ```no_run
@ -49,7 +79,7 @@ pub async fn map(exec_state: &mut ExecState, args: Args) -> Result<KclValue, Kcl
/// // Call `map`, using an anonymous function instead of a named one. /// // Call `map`, using an anonymous function instead of a named one.
/// circles = map( /// circles = map(
/// [1..3], /// [1..3],
/// fn(id) { /// map_fn = fn(id) {
/// return startSketchOn("XY") /// return startSketchOn("XY")
/// |> circle({ center: [id * 2 * r, 0], radius: r}, %) /// |> circle({ center: [id * 2 * r, 0], radius: r}, %)
/// } /// }
@ -57,6 +87,12 @@ pub async fn map(exec_state: &mut ExecState, args: Args) -> Result<KclValue, Kcl
/// ``` /// ```
#[stdlib { #[stdlib {
name = "map", name = "map",
keywords = true,
unlabeled_first = true,
arg_docs = {
array = "The array to map.",
map_fn = "The function to map the array with.",
}
}] }]
async fn inner_map<'a>( async fn inner_map<'a>(
array: Vec<KclValue>, array: Vec<KclValue>,
@ -91,13 +127,43 @@ async fn call_map_closure<'a>(
/// For each item in an array, update a value. /// For each item in an array, update a value.
pub async fn reduce(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> { pub async fn reduce(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let (array, start, f): (Vec<KclValue>, KclValue, FnAsArg<'_>) = FromArgs::from_args(&args, 0)?; let array_val = args.get_unlabeled_kw_arg("array")?;
let start = args.get_kw_arg("start")?;
let reduce_fn_kclvalue: KclValue = args.get_kw_arg("reduce_fn")?;
let array: Vec<KclValue> = match array_val {
KclValue::Array { value, meta: _ } => value,
_ => {
return Err(KclError::Semantic(KclErrorDetails {
source_ranges: vec![args.source_range],
message: format!("You can't reduce a value of type {}", array_val.human_friendly_type()),
}))
}
};
// Check that the reduce_fn is a function
match reduce_fn_kclvalue {
KclValue::Function { .. } => (),
_ => {
return Err(KclError::Semantic(KclErrorDetails {
source_ranges: vec![args.source_range],
message: format!(
"Expected reduce_fn to be a function, but got a value of type {}",
reduce_fn_kclvalue.human_friendly_type()
),
}))
}
}
// Extract the function from the KclValue
let reduce_fn: FnAsArg<'_> = args.get_kw_arg("reduce_fn")?;
let reduce_fn = FunctionParam { let reduce_fn = FunctionParam {
inner: f.func, inner: reduce_fn.func,
fn_expr: f.expr, fn_expr: reduce_fn.expr,
meta: vec![args.source_range.into()], meta: vec![args.source_range.into()],
ctx: args.ctx.clone(), ctx: args.ctx.clone(),
memory: *f.memory, memory: *reduce_fn.memory,
}; };
inner_reduce(array, start, reduce_fn, exec_state, &args).await inner_reduce(array, start, reduce_fn, exec_state, &args).await
} }
@ -111,7 +177,7 @@ pub async fn reduce(exec_state: &mut ExecState, args: Args) -> Result<KclValue,
/// // This function adds an array of numbers. /// // This function adds an array of numbers.
/// // It uses the `reduce` function, to call the `add` function on every /// // It uses the `reduce` function, to call the `add` function on every
/// // element of the `arr` parameter. The starting value is 0. /// // element of the `arr` parameter. The starting value is 0.
/// fn sum(arr) { return reduce(arr, 0, add) } /// fn sum(arr) { return reduce(arr, start = 0, reduce_fn = add) }
/// ///
/// /* /// /*
/// The above is basically like this pseudo-code: /// The above is basically like this pseudo-code:
@ -131,7 +197,7 @@ pub async fn reduce(exec_state: &mut ExecState, args: Args) -> Result<KclValue,
/// // an anonymous `add` function as its parameter, instead of declaring a /// // an anonymous `add` function as its parameter, instead of declaring a
/// // named function outside. /// // named function outside.
/// arr = [1, 2, 3] /// arr = [1, 2, 3]
/// sum = reduce(arr, 0, (i, result_so_far) => { return i + result_so_far }) /// sum = reduce(arr, start = 0, reduce_fn = (i, result_so_far) => { return i + result_so_far })
/// ///
/// // We use `assertEqual` to check that our `sum` function gives the /// // We use `assertEqual` to check that our `sum` function gives the
/// // expected result. It's good to check your work! /// // expected result. It's good to check your work!
@ -150,7 +216,7 @@ pub async fn reduce(exec_state: &mut ExecState, args: Args) -> Result<KclValue,
/// // Use a `reduce` to draw the remaining decagon sides. /// // Use a `reduce` to draw the remaining decagon sides.
/// // For each number in the array 1..10, run the given function, /// // For each number in the array 1..10, run the given function,
/// // which takes a partially-sketched decagon and adds one more edge to it. /// // which takes a partially-sketched decagon and adds one more edge to it.
/// fullDecagon = reduce([1..10], startOfDecagonSketch, fn(i, partialDecagon) { /// fullDecagon = reduce([1..10], start = startOfDecagonSketch, reduce_fn = fn(i, partialDecagon) {
/// // Draw one edge of the decagon. /// // Draw one edge of the decagon.
/// x = cos(stepAngle * i) * radius /// x = cos(stepAngle * i) * radius
/// y = sin(stepAngle * i) * radius /// y = sin(stepAngle * i) * radius
@ -183,6 +249,13 @@ pub async fn reduce(exec_state: &mut ExecState, args: Args) -> Result<KclValue,
/// ``` /// ```
#[stdlib { #[stdlib {
name = "reduce", name = "reduce",
keywords = true,
unlabeled_first = true,
arg_docs = {
array = "The array to reduce.",
start = "The starting value for the reduction.",
reduce_fn = "The function to reduce the array with.",
}
}] }]
async fn inner_reduce<'a>( async fn inner_reduce<'a>(
array: Vec<KclValue>, array: Vec<KclValue>,
@ -227,11 +300,17 @@ async fn call_reduce_closure<'a>(
/// ///
/// ```no_run /// ```no_run
/// arr = [1, 2, 3] /// arr = [1, 2, 3]
/// new_arr = push(arr, 4) /// new_arr = push(arr, elem = 4)
/// assertEqual(new_arr[3], 4, 0.00001, "4 was added to the end of the array") /// assertEqual(new_arr[3], 4, 0.00001, "4 was added to the end of the array")
/// ``` /// ```
#[stdlib { #[stdlib {
name = "push", name = "push",
keywords = true,
unlabeled_first = true,
arg_docs = {
array = "The array to push to.",
elem = "The element to push to the array.",
}
}] }]
async fn inner_push(mut array: Vec<KclValue>, elem: KclValue, args: &Args) -> Result<KclValue, KclError> { async fn inner_push(mut array: Vec<KclValue>, elem: KclValue, args: &Args) -> Result<KclValue, KclError> {
// Unwrap the KclValues to JValues for manipulation // Unwrap the KclValues to JValues for manipulation
@ -244,7 +323,8 @@ async fn inner_push(mut array: Vec<KclValue>, elem: KclValue, args: &Args) -> Re
pub async fn push(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> { pub async fn push(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
// Extract the array and the element from the arguments // Extract the array and the element from the arguments
let (val, elem): (KclValue, KclValue) = FromArgs::from_args(&args, 0)?; let val = args.get_unlabeled_kw_arg("array")?;
let elem = args.get_kw_arg("elem")?;
let meta = vec![args.source_range]; let meta = vec![args.source_range];
let KclValue::Array { value: array, meta: _ } = val else { let KclValue::Array { value: array, meta: _ } = val else {
@ -308,40 +388,3 @@ pub async fn pop(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, Kc
inner_pop(array, &args).await inner_pop(array, &args).await
} }
/// Get the length of an array.
///
/// Returns the number of elements in an array.
///
/// ```no_run
/// arr = [1, 2, 3]
/// length = len(arr)
/// assertEqual(length, 3, 0.00001, "The length of the array is 3")
/// ```
#[stdlib {
name = "len",
keywords = true,
unlabeled_first = true,
arg_docs = {
array = "The array to get the length of.",
}
}]
async fn inner_len(array: Vec<KclValue>, args: &Args) -> Result<KclValue, KclError> {
Ok(KclValue::Number {
value: array.len() as f64,
meta: vec![args.source_range.into()],
})
}
pub async fn len(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
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();
return Err(KclError::Semantic(KclErrorDetails {
source_ranges: meta,
message: format!("You can't get the length of a value of type {actual_type}, only an array"),
}));
};
inner_len(array, &args).await
}

View File

@ -108,7 +108,6 @@ lazy_static! {
Box::new(crate::std::array::Reduce), Box::new(crate::std::array::Reduce),
Box::new(crate::std::array::Map), Box::new(crate::std::array::Map),
Box::new(crate::std::array::Push), Box::new(crate::std::array::Push),
Box::new(crate::std::array::Len),
Box::new(crate::std::array::Pop), Box::new(crate::std::array::Pop),
Box::new(crate::std::chamfer::Chamfer), Box::new(crate::std::chamfer::Chamfer),
Box::new(crate::std::fillet::Fillet), Box::new(crate::std::fillet::Fillet),

View File

@ -1,6 +1,8 @@
--- ---
source: kcl/src/simulation_tests.rs source: kcl/src/simulation_tests.rs
assertion_line: 55
description: Result of parsing argument_error.kcl description: Result of parsing argument_error.kcl
snapshot_kind: text
--- ---
{ {
"Ok": { "Ok": {
@ -61,39 +63,39 @@ description: Result of parsing argument_error.kcl
"type": "VariableDeclaration" "type": "VariableDeclaration"
}, },
{ {
"end": 38, "end": 47,
"expression": { "expression": {
"arguments": [ "arguments": [
{ {
"end": 29, "type": "LabeledArg",
"name": "f", "label": {
"start": 28, "type": "Identifier",
"type": "Identifier", "name": "map_fn"
"type": "Identifier" },
}, "arg": {
{ "elements": [
"elements": [ {
{ "end": 42,
"end": 33, "raw": "0",
"raw": "0", "start": 41,
"start": 32, "type": "Literal",
"type": "Literal", "type": "Literal",
"type": "Literal", "value": 0.0
"value": 0.0 },
}, {
{ "end": 45,
"end": 36, "raw": "1",
"raw": "1", "start": 44,
"start": 35, "type": "Literal",
"type": "Literal", "type": "Literal",
"type": "Literal", "value": 1.0
"value": 1.0 }
} ],
], "end": 46,
"end": 37, "start": 40,
"start": 31, "type": "ArrayExpression",
"type": "ArrayExpression", "type": "ArrayExpression"
"type": "ArrayExpression" }
} }
], ],
"callee": { "callee": {
@ -102,17 +104,24 @@ description: Result of parsing argument_error.kcl
"start": 24, "start": 24,
"type": "Identifier" "type": "Identifier"
}, },
"end": 38, "end": 47,
"start": 24, "start": 24,
"type": "CallExpression", "type": "CallExpressionKw",
"type": "CallExpression" "type": "CallExpressionKw",
"unlabeled": {
"end": 29,
"name": "f",
"start": 28,
"type": "Identifier",
"type": "Identifier"
}
}, },
"start": 24, "start": 24,
"type": "ExpressionStatement", "type": "ExpressionStatement",
"type": "ExpressionStatement" "type": "ExpressionStatement"
} }
], ],
"end": 39, "end": 48,
"nonCodeMeta": { "nonCodeMeta": {
"nonCodeNodes": { "nonCodeNodes": {
"0": [ "0": [

View File

@ -1,12 +1,14 @@
--- ---
source: kcl/src/simulation_tests.rs source: kcl/src/simulation_tests.rs
assertion_line: 133
description: Error from executing argument_error.kcl description: Error from executing argument_error.kcl
snapshot_kind: text
--- ---
KCL Type error KCL Semantic error
× type: Expected an array but found Function × semantic: Expected an array to map, but got a value of type Function
╭─[5:5] ╭─[5:1]
4 │ 4 │
5 │ map(f, [0, 1]) 5 │ map(f, map_fn = [0, 1])
· · ──────────────────────
╰──── ╰────

View File

@ -2,4 +2,4 @@ fn f(i) {
return 5 return 5
} }
map(f, [0, 1]) map(f, map_fn = [0, 1])

View File

@ -1,6 +1,8 @@
--- ---
source: kcl/src/simulation_tests.rs source: kcl/src/simulation_tests.rs
assertion_line: 55
description: Result of parsing array_elem_push.kcl description: Result of parsing array_elem_push.kcl
snapshot_kind: text
--- ---
{ {
"Ok": { "Ok": {
@ -57,46 +59,53 @@ description: Result of parsing array_elem_push.kcl
}, },
{ {
"declaration": { "declaration": {
"end": 39, "end": 45,
"id": { "id": {
"end": 24, "end": 23,
"name": "new_arr1", "name": "newArr1",
"start": 16, "start": 16,
"type": "Identifier" "type": "Identifier"
}, },
"init": { "init": {
"arguments": [ "arguments": [
{ {
"end": 35, "type": "LabeledArg",
"name": "arr", "label": {
"start": 32, "type": "Identifier",
"type": "Identifier", "name": "elem"
"type": "Identifier" },
}, "arg": {
{ "end": 44,
"end": 38, "raw": "4",
"raw": "4", "start": 43,
"start": 37, "type": "Literal",
"type": "Literal", "type": "Literal",
"type": "Literal", "value": 4.0
"value": 4.0 }
} }
], ],
"callee": { "callee": {
"end": 31, "end": 30,
"name": "push", "name": "push",
"start": 27, "start": 26,
"type": "Identifier" "type": "Identifier"
}, },
"end": 39, "end": 45,
"start": 27, "start": 26,
"type": "CallExpression", "type": "CallExpressionKw",
"type": "CallExpression" "type": "CallExpressionKw",
"unlabeled": {
"end": 34,
"name": "arr",
"start": 31,
"type": "Identifier",
"type": "Identifier"
}
}, },
"start": 16, "start": 16,
"type": "VariableDeclarator" "type": "VariableDeclarator"
}, },
"end": 39, "end": 45,
"kind": "const", "kind": "const",
"start": 16, "start": 16,
"type": "VariableDeclaration", "type": "VariableDeclaration",
@ -104,647 +113,654 @@ description: Result of parsing array_elem_push.kcl
}, },
{ {
"declaration": { "declaration": {
"end": 68, "end": 79,
"id": { "id": {
"end": 48, "end": 53,
"name": "new_arr2", "name": "newArr2",
"start": 40, "start": 46,
"type": "Identifier" "type": "Identifier"
}, },
"init": { "init": {
"arguments": [ "arguments": [
{ {
"end": 64, "type": "LabeledArg",
"name": "new_arr1", "label": {
"start": 56, "type": "Identifier",
"type": "Identifier", "name": "elem"
"type": "Identifier" },
}, "arg": {
{ "end": 78,
"end": 67, "raw": "5",
"raw": "5", "start": 77,
"start": 66, "type": "Literal",
"type": "Literal", "type": "Literal",
"type": "Literal", "value": 5.0
"value": 5.0 }
} }
], ],
"callee": { "callee": {
"end": 55, "end": 60,
"name": "push", "name": "push",
"start": 51, "start": 56,
"type": "Identifier" "type": "Identifier"
}, },
"end": 68, "end": 79,
"start": 51, "start": 56,
"type": "CallExpression", "type": "CallExpressionKw",
"type": "CallExpression" "type": "CallExpressionKw",
"unlabeled": {
"end": 68,
"name": "newArr1",
"start": 61,
"type": "Identifier",
"type": "Identifier"
}
}, },
"start": 40, "start": 46,
"type": "VariableDeclarator" "type": "VariableDeclarator"
}, },
"end": 68, "end": 79,
"kind": "const", "kind": "const",
"start": 40, "start": 46,
"type": "VariableDeclaration", "type": "VariableDeclaration",
"type": "VariableDeclaration" "type": "VariableDeclaration"
}, },
{ {
"end": 142, "end": 152,
"expression": { "expression": {
"arguments": [ "arguments": [
{ {
"computed": false, "computed": false,
"end": 92, "end": 102,
"object": { "object": {
"end": 89, "end": 99,
"name": "new_arr1", "name": "newArr1",
"start": 81, "start": 92,
"type": "Identifier", "type": "Identifier",
"type": "Identifier" "type": "Identifier"
}, },
"property": { "property": {
"end": 91, "end": 101,
"raw": "0", "raw": "0",
"start": 90, "start": 100,
"type": "Literal", "type": "Literal",
"type": "Literal", "type": "Literal",
"value": 0.0 "value": 0.0
}, },
"start": 81, "start": 92,
"type": "MemberExpression", "type": "MemberExpression",
"type": "MemberExpression" "type": "MemberExpression"
}, },
{ {
"end": 95, "end": 105,
"raw": "1", "raw": "1",
"start": 94, "start": 104,
"type": "Literal", "type": "Literal",
"type": "Literal", "type": "Literal",
"value": 1.0 "value": 1.0
}, },
{ {
"end": 104, "end": 114,
"raw": "0.00001", "raw": "0.00001",
"start": 97, "start": 107,
"type": "Literal", "type": "Literal",
"type": "Literal", "type": "Literal",
"value": 0.00001 "value": 0.00001
}, },
{ {
"end": 141, "end": 151,
"raw": "\"element 0 should not have changed\"", "raw": "\"element 0 should not have changed\"",
"start": 106, "start": 116,
"type": "Literal", "type": "Literal",
"type": "Literal", "type": "Literal",
"value": "element 0 should not have changed" "value": "element 0 should not have changed"
} }
], ],
"callee": { "callee": {
"end": 80, "end": 91,
"name": "assertEqual", "name": "assertEqual",
"start": 69, "start": 80,
"type": "Identifier" "type": "Identifier"
}, },
"end": 142, "end": 152,
"start": 69, "start": 80,
"type": "CallExpression", "type": "CallExpression",
"type": "CallExpression" "type": "CallExpression"
}, },
"start": 69, "start": 80,
"type": "ExpressionStatement", "type": "ExpressionStatement",
"type": "ExpressionStatement" "type": "ExpressionStatement"
}, },
{ {
"end": 216, "end": 225,
"expression": { "expression": {
"arguments": [ "arguments": [
{ {
"computed": false, "computed": false,
"end": 166, "end": 175,
"object": { "object": {
"end": 163, "end": 172,
"name": "new_arr1", "name": "newArr1",
"start": 155, "start": 165,
"type": "Identifier", "type": "Identifier",
"type": "Identifier" "type": "Identifier"
}, },
"property": { "property": {
"end": 165, "end": 174,
"raw": "1", "raw": "1",
"start": 164, "start": 173,
"type": "Literal", "type": "Literal",
"type": "Literal", "type": "Literal",
"value": 1.0 "value": 1.0
}, },
"start": 155, "start": 165,
"type": "MemberExpression", "type": "MemberExpression",
"type": "MemberExpression" "type": "MemberExpression"
}, },
{
"end": 169,
"raw": "2",
"start": 168,
"type": "Literal",
"type": "Literal",
"value": 2.0
},
{ {
"end": 178, "end": 178,
"raw": "2",
"start": 177,
"type": "Literal",
"type": "Literal",
"value": 2.0
},
{
"end": 187,
"raw": "0.00001", "raw": "0.00001",
"start": 171, "start": 180,
"type": "Literal", "type": "Literal",
"type": "Literal", "type": "Literal",
"value": 0.00001 "value": 0.00001
}, },
{ {
"end": 215, "end": 224,
"raw": "\"element 1 should not have changed\"", "raw": "\"element 1 should not have changed\"",
"start": 180, "start": 189,
"type": "Literal", "type": "Literal",
"type": "Literal", "type": "Literal",
"value": "element 1 should not have changed" "value": "element 1 should not have changed"
} }
], ],
"callee": { "callee": {
"end": 154, "end": 164,
"name": "assertEqual", "name": "assertEqual",
"start": 143, "start": 153,
"type": "Identifier" "type": "Identifier"
}, },
"end": 216, "end": 225,
"start": 143, "start": 153,
"type": "CallExpression", "type": "CallExpression",
"type": "CallExpression" "type": "CallExpression"
}, },
"start": 143, "start": 153,
"type": "ExpressionStatement", "type": "ExpressionStatement",
"type": "ExpressionStatement" "type": "ExpressionStatement"
}, },
{ {
"end": 290, "end": 298,
"expression": { "expression": {
"arguments": [ "arguments": [
{ {
"computed": false, "computed": false,
"end": 240, "end": 248,
"object": { "object": {
"end": 237, "end": 245,
"name": "new_arr1", "name": "newArr1",
"start": 229, "start": 238,
"type": "Identifier", "type": "Identifier",
"type": "Identifier" "type": "Identifier"
}, },
"property": { "property": {
"end": 239, "end": 247,
"raw": "2", "raw": "2",
"start": 238, "start": 246,
"type": "Literal", "type": "Literal",
"type": "Literal", "type": "Literal",
"value": 2.0 "value": 2.0
}, },
"start": 229, "start": 238,
"type": "MemberExpression", "type": "MemberExpression",
"type": "MemberExpression" "type": "MemberExpression"
}, },
{ {
"end": 243, "end": 251,
"raw": "3", "raw": "3",
"start": 242, "start": 250,
"type": "Literal", "type": "Literal",
"type": "Literal", "type": "Literal",
"value": 3.0 "value": 3.0
}, },
{ {
"end": 252, "end": 260,
"raw": "0.00001", "raw": "0.00001",
"start": 245, "start": 253,
"type": "Literal", "type": "Literal",
"type": "Literal", "type": "Literal",
"value": 0.00001 "value": 0.00001
}, },
{ {
"end": 289, "end": 297,
"raw": "\"element 2 should not have changed\"", "raw": "\"element 2 should not have changed\"",
"start": 254, "start": 262,
"type": "Literal", "type": "Literal",
"type": "Literal", "type": "Literal",
"value": "element 2 should not have changed" "value": "element 2 should not have changed"
} }
], ],
"callee": { "callee": {
"end": 228, "end": 237,
"name": "assertEqual", "name": "assertEqual",
"start": 217, "start": 226,
"type": "Identifier" "type": "Identifier"
}, },
"end": 290, "end": 298,
"start": 217, "start": 226,
"type": "CallExpression", "type": "CallExpression",
"type": "CallExpression" "type": "CallExpression"
}, },
"start": 217, "start": 226,
"type": "ExpressionStatement", "type": "ExpressionStatement",
"type": "ExpressionStatement" "type": "ExpressionStatement"
}, },
{ {
"end": 366, "end": 373,
"expression": { "expression": {
"arguments": [ "arguments": [
{ {
"computed": false, "computed": false,
"end": 314, "end": 321,
"object": { "object": {
"end": 311, "end": 318,
"name": "new_arr1", "name": "newArr1",
"start": 303, "start": 311,
"type": "Identifier", "type": "Identifier",
"type": "Identifier" "type": "Identifier"
}, },
"property": { "property": {
"end": 313, "end": 320,
"raw": "3", "raw": "3",
"start": 312, "start": 319,
"type": "Literal", "type": "Literal",
"type": "Literal", "type": "Literal",
"value": 3.0 "value": 3.0
}, },
"start": 303, "start": 311,
"type": "MemberExpression", "type": "MemberExpression",
"type": "MemberExpression" "type": "MemberExpression"
}, },
{ {
"end": 317, "end": 324,
"raw": "4", "raw": "4",
"start": 316, "start": 323,
"type": "Literal", "type": "Literal",
"type": "Literal", "type": "Literal",
"value": 4.0 "value": 4.0
}, },
{ {
"end": 326, "end": 333,
"raw": "0.00001", "raw": "0.00001",
"start": 319, "start": 326,
"type": "Literal", "type": "Literal",
"type": "Literal", "type": "Literal",
"value": 0.00001 "value": 0.00001
}, },
{ {
"end": 365, "end": 372,
"raw": "\"4 was added to the end of the array\"", "raw": "\"4 was added to the end of the array\"",
"start": 328, "start": 335,
"type": "Literal", "type": "Literal",
"type": "Literal", "type": "Literal",
"value": "4 was added to the end of the array" "value": "4 was added to the end of the array"
} }
], ],
"callee": { "callee": {
"end": 302, "end": 310,
"name": "assertEqual", "name": "assertEqual",
"start": 291, "start": 299,
"type": "Identifier" "type": "Identifier"
}, },
"end": 366, "end": 373,
"start": 291, "start": 299,
"type": "CallExpression", "type": "CallExpression",
"type": "CallExpression" "type": "CallExpression"
}, },
"start": 291, "start": 299,
"type": "ExpressionStatement", "type": "ExpressionStatement",
"type": "ExpressionStatement" "type": "ExpressionStatement"
}, },
{ {
"end": 440, "end": 446,
"expression": { "expression": {
"arguments": [ "arguments": [
{ {
"computed": false, "computed": false,
"end": 390, "end": 396,
"object": { "object": {
"end": 387, "end": 393,
"name": "new_arr2", "name": "newArr2",
"start": 379, "start": 386,
"type": "Identifier", "type": "Identifier",
"type": "Identifier" "type": "Identifier"
}, },
"property": { "property": {
"end": 389, "end": 395,
"raw": "0", "raw": "0",
"start": 388, "start": 394,
"type": "Literal", "type": "Literal",
"type": "Literal", "type": "Literal",
"value": 0.0 "value": 0.0
}, },
"start": 379, "start": 386,
"type": "MemberExpression", "type": "MemberExpression",
"type": "MemberExpression" "type": "MemberExpression"
}, },
{ {
"end": 393, "end": 399,
"raw": "1", "raw": "1",
"start": 392, "start": 398,
"type": "Literal", "type": "Literal",
"type": "Literal", "type": "Literal",
"value": 1.0 "value": 1.0
}, },
{ {
"end": 402, "end": 408,
"raw": "0.00001", "raw": "0.00001",
"start": 395, "start": 401,
"type": "Literal", "type": "Literal",
"type": "Literal", "type": "Literal",
"value": 0.00001 "value": 0.00001
}, },
{ {
"end": 439, "end": 445,
"raw": "\"element 0 should not have changed\"", "raw": "\"element 0 should not have changed\"",
"start": 404, "start": 410,
"type": "Literal", "type": "Literal",
"type": "Literal", "type": "Literal",
"value": "element 0 should not have changed" "value": "element 0 should not have changed"
} }
], ],
"callee": { "callee": {
"end": 378, "end": 385,
"name": "assertEqual", "name": "assertEqual",
"start": 367, "start": 374,
"type": "Identifier" "type": "Identifier"
}, },
"end": 440, "end": 446,
"start": 367, "start": 374,
"type": "CallExpression", "type": "CallExpression",
"type": "CallExpression" "type": "CallExpression"
}, },
"start": 367, "start": 374,
"type": "ExpressionStatement", "type": "ExpressionStatement",
"type": "ExpressionStatement" "type": "ExpressionStatement"
}, },
{ {
"end": 514, "end": 519,
"expression": { "expression": {
"arguments": [ "arguments": [
{ {
"computed": false, "computed": false,
"end": 464, "end": 469,
"object": { "object": {
"end": 461, "end": 466,
"name": "new_arr2", "name": "newArr2",
"start": 453, "start": 459,
"type": "Identifier", "type": "Identifier",
"type": "Identifier" "type": "Identifier"
}, },
"property": { "property": {
"end": 463, "end": 468,
"raw": "1", "raw": "1",
"start": 462, "start": 467,
"type": "Literal", "type": "Literal",
"type": "Literal", "type": "Literal",
"value": 1.0 "value": 1.0
}, },
"start": 453, "start": 459,
"type": "MemberExpression", "type": "MemberExpression",
"type": "MemberExpression" "type": "MemberExpression"
}, },
{ {
"end": 467, "end": 472,
"raw": "2", "raw": "2",
"start": 466, "start": 471,
"type": "Literal", "type": "Literal",
"type": "Literal", "type": "Literal",
"value": 2.0 "value": 2.0
}, },
{ {
"end": 476, "end": 481,
"raw": "0.00001", "raw": "0.00001",
"start": 469, "start": 474,
"type": "Literal", "type": "Literal",
"type": "Literal", "type": "Literal",
"value": 0.00001 "value": 0.00001
}, },
{ {
"end": 513, "end": 518,
"raw": "\"element 1 should not have changed\"", "raw": "\"element 1 should not have changed\"",
"start": 478, "start": 483,
"type": "Literal", "type": "Literal",
"type": "Literal", "type": "Literal",
"value": "element 1 should not have changed" "value": "element 1 should not have changed"
} }
], ],
"callee": { "callee": {
"end": 452, "end": 458,
"name": "assertEqual", "name": "assertEqual",
"start": 441, "start": 447,
"type": "Identifier" "type": "Identifier"
}, },
"end": 514, "end": 519,
"start": 441, "start": 447,
"type": "CallExpression", "type": "CallExpression",
"type": "CallExpression" "type": "CallExpression"
}, },
"start": 441, "start": 447,
"type": "ExpressionStatement", "type": "ExpressionStatement",
"type": "ExpressionStatement" "type": "ExpressionStatement"
}, },
{ {
"end": 588, "end": 592,
"expression": { "expression": {
"arguments": [ "arguments": [
{ {
"computed": false, "computed": false,
"end": 538, "end": 542,
"object": { "object": {
"end": 535, "end": 539,
"name": "new_arr2", "name": "newArr2",
"start": 527, "start": 532,
"type": "Identifier", "type": "Identifier",
"type": "Identifier" "type": "Identifier"
}, },
"property": { "property": {
"end": 537, "end": 541,
"raw": "2", "raw": "2",
"start": 536, "start": 540,
"type": "Literal", "type": "Literal",
"type": "Literal", "type": "Literal",
"value": 2.0 "value": 2.0
}, },
"start": 527, "start": 532,
"type": "MemberExpression", "type": "MemberExpression",
"type": "MemberExpression" "type": "MemberExpression"
}, },
{ {
"end": 541, "end": 545,
"raw": "3", "raw": "3",
"start": 540, "start": 544,
"type": "Literal", "type": "Literal",
"type": "Literal", "type": "Literal",
"value": 3.0 "value": 3.0
}, },
{ {
"end": 550, "end": 554,
"raw": "0.00001", "raw": "0.00001",
"start": 543, "start": 547,
"type": "Literal", "type": "Literal",
"type": "Literal", "type": "Literal",
"value": 0.00001 "value": 0.00001
}, },
{ {
"end": 587, "end": 591,
"raw": "\"element 2 should not have changed\"", "raw": "\"element 2 should not have changed\"",
"start": 552, "start": 556,
"type": "Literal", "type": "Literal",
"type": "Literal", "type": "Literal",
"value": "element 2 should not have changed" "value": "element 2 should not have changed"
} }
], ],
"callee": { "callee": {
"end": 526, "end": 531,
"name": "assertEqual", "name": "assertEqual",
"start": 515, "start": 520,
"type": "Identifier" "type": "Identifier"
}, },
"end": 588, "end": 592,
"start": 515, "start": 520,
"type": "CallExpression", "type": "CallExpression",
"type": "CallExpression" "type": "CallExpression"
}, },
"start": 515, "start": 520,
"type": "ExpressionStatement", "type": "ExpressionStatement",
"type": "ExpressionStatement" "type": "ExpressionStatement"
}, },
{ {
"end": 664, "end": 667,
"expression": { "expression": {
"arguments": [ "arguments": [
{ {
"computed": false, "computed": false,
"end": 612, "end": 615,
"object": { "object": {
"end": 609, "end": 612,
"name": "new_arr2", "name": "newArr2",
"start": 601, "start": 605,
"type": "Identifier", "type": "Identifier",
"type": "Identifier" "type": "Identifier"
}, },
"property": { "property": {
"end": 611, "end": 614,
"raw": "3", "raw": "3",
"start": 610, "start": 613,
"type": "Literal", "type": "Literal",
"type": "Literal", "type": "Literal",
"value": 3.0 "value": 3.0
}, },
"start": 601, "start": 605,
"type": "MemberExpression", "type": "MemberExpression",
"type": "MemberExpression" "type": "MemberExpression"
}, },
{ {
"end": 615, "end": 618,
"raw": "4", "raw": "4",
"start": 614, "start": 617,
"type": "Literal", "type": "Literal",
"type": "Literal", "type": "Literal",
"value": 4.0 "value": 4.0
}, },
{ {
"end": 624, "end": 627,
"raw": "0.00001", "raw": "0.00001",
"start": 617, "start": 620,
"type": "Literal", "type": "Literal",
"type": "Literal", "type": "Literal",
"value": 0.00001 "value": 0.00001
}, },
{ {
"end": 663, "end": 666,
"raw": "\"4 was added to the end of the array\"", "raw": "\"4 was added to the end of the array\"",
"start": 626, "start": 629,
"type": "Literal", "type": "Literal",
"type": "Literal", "type": "Literal",
"value": "4 was added to the end of the array" "value": "4 was added to the end of the array"
} }
], ],
"callee": { "callee": {
"end": 600, "end": 604,
"name": "assertEqual", "name": "assertEqual",
"start": 589, "start": 593,
"type": "Identifier" "type": "Identifier"
}, },
"end": 664, "end": 667,
"start": 589, "start": 593,
"type": "CallExpression", "type": "CallExpression",
"type": "CallExpression" "type": "CallExpression"
}, },
"start": 589, "start": 593,
"type": "ExpressionStatement", "type": "ExpressionStatement",
"type": "ExpressionStatement" "type": "ExpressionStatement"
}, },
{ {
"end": 740, "end": 742,
"expression": { "expression": {
"arguments": [ "arguments": [
{ {
"computed": false, "computed": false,
"end": 688, "end": 690,
"object": { "object": {
"end": 685, "end": 687,
"name": "new_arr2", "name": "newArr2",
"start": 677, "start": 680,
"type": "Identifier", "type": "Identifier",
"type": "Identifier" "type": "Identifier"
}, },
"property": { "property": {
"end": 687, "end": 689,
"raw": "4", "raw": "4",
"start": 686, "start": 688,
"type": "Literal", "type": "Literal",
"type": "Literal", "type": "Literal",
"value": 4.0 "value": 4.0
}, },
"start": 677, "start": 680,
"type": "MemberExpression", "type": "MemberExpression",
"type": "MemberExpression" "type": "MemberExpression"
}, },
{ {
"end": 691, "end": 693,
"raw": "5", "raw": "5",
"start": 690, "start": 692,
"type": "Literal", "type": "Literal",
"type": "Literal", "type": "Literal",
"value": 5.0 "value": 5.0
}, },
{ {
"end": 700, "end": 702,
"raw": "0.00001", "raw": "0.00001",
"start": 693, "start": 695,
"type": "Literal", "type": "Literal",
"type": "Literal", "type": "Literal",
"value": 0.00001 "value": 0.00001
}, },
{ {
"end": 739, "end": 741,
"raw": "\"5 was added to the end of the array\"", "raw": "\"5 was added to the end of the array\"",
"start": 702, "start": 704,
"type": "Literal", "type": "Literal",
"type": "Literal", "type": "Literal",
"value": "5 was added to the end of the array" "value": "5 was added to the end of the array"
} }
], ],
"callee": { "callee": {
"end": 676, "end": 679,
"name": "assertEqual", "name": "assertEqual",
"start": 665, "start": 668,
"type": "Identifier" "type": "Identifier"
}, },
"end": 740, "end": 742,
"start": 665, "start": 668,
"type": "CallExpression", "type": "CallExpression",
"type": "CallExpression" "type": "CallExpression"
}, },
"start": 665, "start": 668,
"type": "ExpressionStatement", "type": "ExpressionStatement",
"type": "ExpressionStatement" "type": "ExpressionStatement"
} }
], ],
"end": 741, "end": 743,
"start": 0 "start": 0
} }
} }

View File

@ -1,12 +1,12 @@
arr = [1, 2, 3] arr = [1, 2, 3]
new_arr1 = push(arr, 4) newArr1 = push(arr, elem = 4)
new_arr2 = push(new_arr1, 5) newArr2 = push(newArr1, elem = 5)
assertEqual(new_arr1[0], 1, 0.00001, "element 0 should not have changed") assertEqual(newArr1[0], 1, 0.00001, "element 0 should not have changed")
assertEqual(new_arr1[1], 2, 0.00001, "element 1 should not have changed") assertEqual(newArr1[1], 2, 0.00001, "element 1 should not have changed")
assertEqual(new_arr1[2], 3, 0.00001, "element 2 should not have changed") assertEqual(newArr1[2], 3, 0.00001, "element 2 should not have changed")
assertEqual(new_arr1[3], 4, 0.00001, "4 was added to the end of the array") assertEqual(newArr1[3], 4, 0.00001, "4 was added to the end of the array")
assertEqual(new_arr2[0], 1, 0.00001, "element 0 should not have changed") assertEqual(newArr2[0], 1, 0.00001, "element 0 should not have changed")
assertEqual(new_arr2[1], 2, 0.00001, "element 1 should not have changed") assertEqual(newArr2[1], 2, 0.00001, "element 1 should not have changed")
assertEqual(new_arr2[2], 3, 0.00001, "element 2 should not have changed") assertEqual(newArr2[2], 3, 0.00001, "element 2 should not have changed")
assertEqual(new_arr2[3], 4, 0.00001, "4 was added to the end of the array") assertEqual(newArr2[3], 4, 0.00001, "4 was added to the end of the array")
assertEqual(new_arr2[4], 5, 0.00001, "5 was added to the end of the array") assertEqual(newArr2[4], 5, 0.00001, "5 was added to the end of the array")

View File

@ -1,6 +1,6 @@
--- ---
source: kcl/src/simulation_tests.rs source: kcl/src/simulation_tests.rs
assertion_line: 92 assertion_line: 99
description: Program memory after executing array_elem_push.kcl description: Program memory after executing array_elem_push.kcl
snapshot_kind: text snapshot_kind: text
--- ---
@ -81,7 +81,7 @@ snapshot_kind: text
} }
] ]
}, },
"new_arr1": { "newArr1": {
"type": "Array", "type": "Array",
"value": [ "value": [
{ {
@ -129,8 +129,8 @@ snapshot_kind: text
"__meta": [ "__meta": [
{ {
"sourceRange": [ "sourceRange": [
37, 43,
38, 44,
0 0
] ]
} }
@ -140,14 +140,14 @@ snapshot_kind: text
"__meta": [ "__meta": [
{ {
"sourceRange": [ "sourceRange": [
27, 26,
39, 45,
0 0
] ]
} }
] ]
}, },
"new_arr2": { "newArr2": {
"type": "Array", "type": "Array",
"value": [ "value": [
{ {
@ -195,8 +195,8 @@ snapshot_kind: text
"__meta": [ "__meta": [
{ {
"sourceRange": [ "sourceRange": [
37, 43,
38, 44,
0 0
] ]
} }
@ -208,8 +208,8 @@ snapshot_kind: text
"__meta": [ "__meta": [
{ {
"sourceRange": [ "sourceRange": [
66, 77,
67, 78,
0 0
] ]
} }
@ -219,8 +219,8 @@ snapshot_kind: text
"__meta": [ "__meta": [
{ {
"sourceRange": [ "sourceRange": [
51, 56,
68, 79,
0 0
] ]
} }

View File

@ -1,6 +1,8 @@
--- ---
source: kcl/src/simulation_tests.rs source: kcl/src/simulation_tests.rs
assertion_line: 55
description: Result of parsing array_elem_push_fail.kcl description: Result of parsing array_elem_push_fail.kcl
snapshot_kind: text
--- ---
{ {
"Ok": { "Ok": {
@ -57,7 +59,7 @@ description: Result of parsing array_elem_push_fail.kcl
}, },
{ {
"declaration": { "declaration": {
"end": 40, "end": 47,
"id": { "id": {
"end": 25, "end": 25,
"name": "pushedArr", "name": "pushedArr",
@ -67,19 +69,19 @@ description: Result of parsing array_elem_push_fail.kcl
"init": { "init": {
"arguments": [ "arguments": [
{ {
"end": 36, "type": "LabeledArg",
"name": "arr", "label": {
"start": 33, "type": "Identifier",
"type": "Identifier", "name": "elem"
"type": "Identifier" },
}, "arg": {
{ "end": 46,
"end": 39, "raw": "4",
"raw": "4", "start": 45,
"start": 38, "type": "Literal",
"type": "Literal", "type": "Literal",
"type": "Literal", "value": 4.0
"value": 4.0 }
} }
], ],
"callee": { "callee": {
@ -88,15 +90,22 @@ description: Result of parsing array_elem_push_fail.kcl
"start": 28, "start": 28,
"type": "Identifier" "type": "Identifier"
}, },
"end": 40, "end": 47,
"start": 28, "start": 28,
"type": "CallExpression", "type": "CallExpressionKw",
"type": "CallExpression" "type": "CallExpressionKw",
"unlabeled": {
"end": 36,
"name": "arr",
"start": 33,
"type": "Identifier",
"type": "Identifier"
}
}, },
"start": 16, "start": 16,
"type": "VariableDeclarator" "type": "VariableDeclarator"
}, },
"end": 40, "end": 47,
"kind": "const", "kind": "const",
"start": 16, "start": 16,
"type": "VariableDeclaration", "type": "VariableDeclaration",
@ -104,46 +113,46 @@ description: Result of parsing array_elem_push_fail.kcl
}, },
{ {
"declaration": { "declaration": {
"end": 54, "end": 61,
"id": { "id": {
"end": 45, "end": 52,
"name": "fail", "name": "fail",
"start": 41, "start": 48,
"type": "Identifier" "type": "Identifier"
}, },
"init": { "init": {
"computed": false, "computed": false,
"end": 54, "end": 61,
"object": { "object": {
"end": 51, "end": 58,
"name": "arr", "name": "arr",
"start": 48, "start": 55,
"type": "Identifier", "type": "Identifier",
"type": "Identifier" "type": "Identifier"
}, },
"property": { "property": {
"end": 53, "end": 60,
"raw": "3", "raw": "3",
"start": 52, "start": 59,
"type": "Literal", "type": "Literal",
"type": "Literal", "type": "Literal",
"value": 3.0 "value": 3.0
}, },
"start": 48, "start": 55,
"type": "MemberExpression", "type": "MemberExpression",
"type": "MemberExpression" "type": "MemberExpression"
}, },
"start": 41, "start": 48,
"type": "VariableDeclarator" "type": "VariableDeclarator"
}, },
"end": 54, "end": 61,
"kind": "const", "kind": "const",
"start": 41, "start": 48,
"type": "VariableDeclaration", "type": "VariableDeclaration",
"type": "VariableDeclaration" "type": "VariableDeclaration"
} }
], ],
"end": 55, "end": 62,
"start": 0 "start": 0
} }
} }

View File

@ -1,12 +1,14 @@
--- ---
source: kcl/src/simulation_tests.rs source: kcl/src/simulation_tests.rs
assertion_line: 133
description: Error from executing array_elem_push_fail.kcl description: Error from executing array_elem_push_fail.kcl
snapshot_kind: text
--- ---
KCL UndefinedValue error KCL UndefinedValue error
× undefined value: The array doesn't have any item at index 3 × undefined value: The array doesn't have any item at index 3
╭─[3:8] ╭─[3:8]
2 │ pushedArr = push(arr, 4) 2 │ pushedArr = push(arr, elem = 4)
3 │ fail = arr[3] 3 │ fail = arr[3]
· ────── · ──────
╰──── ╰────

View File

@ -1,3 +1,3 @@
arr = [1, 2, 3] arr = [1, 2, 3]
pushedArr = push(arr, 4) pushedArr = push(arr, elem = 4)
fail = arr[3] fail = arr[3]

View File

@ -1,284 +0,0 @@
---
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
}
}
]

View File

@ -1,282 +0,0 @@
---
source: kcl/src/simulation_tests.rs
description: Result of parsing array_length.kcl
---
{
"Ok": {
"body": [
{
"declaration": {
"end": 15,
"id": {
"end": 3,
"name": "arr",
"start": 0,
"type": "Identifier"
},
"init": {
"elements": [
{
"end": 8,
"raw": "1",
"start": 7,
"type": "Literal",
"type": "Literal",
"value": 1.0
},
{
"end": 11,
"raw": "2",
"start": 10,
"type": "Literal",
"type": "Literal",
"value": 2.0
},
{
"end": 14,
"raw": "3",
"start": 13,
"type": "Literal",
"type": "Literal",
"value": 3.0
}
],
"end": 15,
"start": 6,
"type": "ArrayExpression",
"type": "ArrayExpression"
},
"start": 0,
"type": "VariableDeclarator"
},
"end": 15,
"kind": "const",
"start": 0,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"declaration": {
"end": 34,
"id": {
"end": 23,
"name": "arr_len",
"start": 16,
"type": "Identifier"
},
"init": {
"arguments": [
{
"end": 33,
"name": "arr",
"start": 30,
"type": "Identifier",
"type": "Identifier"
}
],
"callee": {
"end": 29,
"name": "len",
"start": 26,
"type": "Identifier"
},
"end": 34,
"start": 26,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 16,
"type": "VariableDeclarator"
},
"end": 34,
"kind": "const",
"start": 16,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"end": 99,
"expression": {
"arguments": [
{
"end": 54,
"name": "arr_len",
"start": 47,
"type": "Identifier",
"type": "Identifier"
},
{
"end": 57,
"raw": "3",
"start": 56,
"type": "Literal",
"type": "Literal",
"value": 3.0
},
{
"end": 66,
"raw": "0.00001",
"start": 59,
"type": "Literal",
"type": "Literal",
"value": 0.00001
},
{
"end": 98,
"raw": "\"The length of the array is 3\"",
"start": 68,
"type": "Literal",
"type": "Literal",
"value": "The length of the array is 3"
}
],
"callee": {
"end": 46,
"name": "assertEqual",
"start": 35,
"type": "Identifier"
},
"end": 99,
"start": 35,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 35,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"declaration": {
"end": 115,
"id": {
"end": 110,
"name": "arr_empty",
"start": 101,
"type": "Identifier"
},
"init": {
"elements": [],
"end": 115,
"start": 113,
"type": "ArrayExpression",
"type": "ArrayExpression"
},
"start": 101,
"type": "VariableDeclarator"
},
"end": 115,
"kind": "const",
"start": 101,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"declaration": {
"end": 142,
"id": {
"end": 125,
"name": "len_empty",
"start": 116,
"type": "Identifier"
},
"init": {
"arguments": [
{
"end": 141,
"name": "arr_empty",
"start": 132,
"type": "Identifier",
"type": "Identifier"
}
],
"callee": {
"end": 131,
"name": "len",
"start": 128,
"type": "Identifier"
},
"end": 142,
"start": 128,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 116,
"type": "VariableDeclarator"
},
"end": 142,
"kind": "const",
"start": 116,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"end": 209,
"expression": {
"arguments": [
{
"end": 164,
"name": "len_empty",
"start": 155,
"type": "Identifier",
"type": "Identifier"
},
{
"end": 167,
"raw": "0",
"start": 166,
"type": "Literal",
"type": "Literal",
"value": 0.0
},
{
"end": 176,
"raw": "0.00001",
"start": 169,
"type": "Literal",
"type": "Literal",
"value": 0.00001
},
{
"end": 208,
"raw": "\"The length of the array is 0\"",
"start": 178,
"type": "Literal",
"type": "Literal",
"value": "The length of the array is 0"
}
],
"callee": {
"end": 154,
"name": "assertEqual",
"start": 143,
"type": "Identifier"
},
"end": 209,
"start": 143,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 143,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
}
],
"end": 210,
"nonCodeMeta": {
"nonCodeNodes": {
"2": [
{
"end": 101,
"start": 99,
"type": "NonCodeNode",
"value": {
"type": "newLine"
}
}
]
},
"startNodes": []
},
"start": 0
}
}

View File

@ -1,7 +0,0 @@
arr = [1, 2, 3]
arr_len = len(arr)
assertEqual(arr_len, 3, 0.00001, "The length of the array is 3")
arr_empty = []
len_empty = len(arr_empty)
assertEqual(len_empty, 0, 0.00001, "The length of the array is 0")

View File

@ -1,5 +0,0 @@
---
source: kcl/src/simulation_tests.rs
description: Operations executed array_length.kcl
---
[]

View File

@ -1,127 +0,0 @@
---
source: kcl/src/simulation_tests.rs
description: Program memory after executing array_length.kcl
---
{
"environments": [
{
"bindings": {
"HALF_TURN": {
"type": "Number",
"value": 180.0,
"__meta": []
},
"QUARTER_TURN": {
"type": "Number",
"value": 90.0,
"__meta": []
},
"THREE_QUARTER_TURN": {
"type": "Number",
"value": 270.0,
"__meta": []
},
"ZERO": {
"type": "Number",
"value": 0.0,
"__meta": []
},
"arr": {
"type": "Array",
"value": [
{
"type": "Number",
"value": 1.0,
"__meta": [
{
"sourceRange": [
7,
8,
0
]
}
]
},
{
"type": "Number",
"value": 2.0,
"__meta": [
{
"sourceRange": [
10,
11,
0
]
}
]
},
{
"type": "Number",
"value": 3.0,
"__meta": [
{
"sourceRange": [
13,
14,
0
]
}
]
}
],
"__meta": [
{
"sourceRange": [
6,
15,
0
]
}
]
},
"arr_empty": {
"type": "Array",
"value": [],
"__meta": [
{
"sourceRange": [
113,
115,
0
]
}
]
},
"arr_len": {
"type": "Number",
"value": 3.0,
"__meta": [
{
"sourceRange": [
26,
34,
0
]
}
]
},
"len_empty": {
"type": "Number",
"value": 0.0,
"__meta": [
{
"sourceRange": [
128,
142,
0
]
}
]
}
},
"parent": null
}
],
"currentEnv": 0,
"return": null
}

View File

@ -1,6 +1,8 @@
--- ---
source: kcl/src/simulation_tests.rs source: kcl/src/simulation_tests.rs
assertion_line: 55
description: Result of parsing double_map_fn.kcl description: Result of parsing double_map_fn.kcl
snapshot_kind: text
--- ---
{ {
"Ok": { "Ok": {
@ -117,7 +119,7 @@ description: Result of parsing double_map_fn.kcl
}, },
{ {
"declaration": { "declaration": {
"end": 101, "end": 119,
"id": { "id": {
"end": 50, "end": 50,
"name": "ys", "name": "ys",
@ -136,17 +138,18 @@ description: Result of parsing double_map_fn.kcl
{ {
"arguments": [ "arguments": [
{ {
"end": 66, "type": "LabeledArg",
"start": 65, "label": {
"type": "PipeSubstitution", "type": "Identifier",
"type": "PipeSubstitution" "name": "map_fn"
}, },
{ "arg": {
"end": 77, "end": 86,
"name": "increment", "name": "increment",
"start": 68, "start": 77,
"type": "Identifier", "type": "Identifier",
"type": "Identifier" "type": "Identifier"
}
} }
], ],
"callee": { "callee": {
@ -155,40 +158,53 @@ description: Result of parsing double_map_fn.kcl
"start": 61, "start": 61,
"type": "Identifier" "type": "Identifier"
}, },
"end": 78, "end": 87,
"start": 61, "start": 61,
"type": "CallExpression", "type": "CallExpressionKw",
"type": "CallExpression" "type": "CallExpressionKw",
"unlabeled": {
"end": 66,
"start": 65,
"type": "PipeSubstitution",
"type": "PipeSubstitution"
}
}, },
{ {
"arguments": [ "arguments": [
{ {
"end": 89, "type": "LabeledArg",
"start": 88, "label": {
"type": "PipeSubstitution", "type": "Identifier",
"type": "PipeSubstitution" "name": "map_fn"
}, },
{ "arg": {
"end": 100, "end": 118,
"name": "increment", "name": "increment",
"start": 91, "start": 109,
"type": "Identifier", "type": "Identifier",
"type": "Identifier" "type": "Identifier"
}
} }
], ],
"callee": { "callee": {
"end": 87, "end": 96,
"name": "map", "name": "map",
"start": 84, "start": 93,
"type": "Identifier" "type": "Identifier"
}, },
"end": 101, "end": 119,
"start": 84, "start": 93,
"type": "CallExpression", "type": "CallExpressionKw",
"type": "CallExpression" "type": "CallExpressionKw",
"unlabeled": {
"end": 98,
"start": 97,
"type": "PipeSubstitution",
"type": "PipeSubstitution"
}
} }
], ],
"end": 101, "end": 119,
"start": 53, "start": 53,
"type": "PipeExpression", "type": "PipeExpression",
"type": "PipeExpression" "type": "PipeExpression"
@ -196,14 +212,14 @@ description: Result of parsing double_map_fn.kcl
"start": 48, "start": 48,
"type": "VariableDeclarator" "type": "VariableDeclarator"
}, },
"end": 101, "end": 119,
"kind": "const", "kind": "const",
"start": 48, "start": 48,
"type": "VariableDeclaration", "type": "VariableDeclaration",
"type": "VariableDeclaration" "type": "VariableDeclaration"
} }
], ],
"end": 102, "end": 120,
"nonCodeMeta": { "nonCodeMeta": {
"nonCodeNodes": { "nonCodeNodes": {
"0": [ "0": [

View File

@ -4,5 +4,5 @@ fn increment(i) {
xs = [0..2] xs = [0..2]
ys = xs ys = xs
|> map(%, increment) |> map(%, map_fn = increment)
|> map(%, increment) |> map(%, map_fn = increment)

View File

@ -1,5 +1,6 @@
--- ---
source: kcl/src/simulation_tests.rs source: kcl/src/simulation_tests.rs
assertion_line: 99
description: Program memory after executing double_map_fn.kcl description: Program memory after executing double_map_fn.kcl
snapshot_kind: text snapshot_kind: text
--- ---
@ -261,8 +262,8 @@ snapshot_kind: text
"__meta": [ "__meta": [
{ {
"sourceRange": [ "sourceRange": [
84, 93,
101, 119,
0 0
] ]
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

View File

@ -1169,25 +1169,25 @@ async fn kcl_test_plumbus_fillets() {
return sg return sg
} }
fn pentagon = (sideLen) => { fn pentagon = (len) => {
sg = startSketchOn('XY') sg = startSketchOn('XY')
|> startProfileAt([-sideLen / 2, -sideLen / 2], %) |> startProfileAt([-len / 2, -len / 2], %)
|> angledLine({ angle: 0, length: sideLen }, %, $a) |> angledLine({ angle: 0, length: len }, %, $a)
|> angledLine({ |> angledLine({
angle: segAng(a) + 180 - 108, angle: segAng(a) + 180 - 108,
length: sideLen length: len
}, %, $b) }, %, $b)
|> angledLine({ |> angledLine({
angle: segAng(b) + 180 - 108, angle: segAng(b) + 180 - 108,
length: sideLen length: len
}, %, $c) }, %, $c)
|> angledLine({ |> angledLine({
angle: segAng(c) + 180 - 108, angle: segAng(c) + 180 - 108,
length: sideLen length: len
}, %, $d) }, %, $d)
|> angledLine({ |> angledLine({
angle: segAng(d) + 180 - 108, angle: segAng(d) + 180 - 108,
length: sideLen length: len
}, %) }, %)
return sg return sg
@ -1653,17 +1653,17 @@ part001 = cube([0,0], 20)
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn kcl_test_duplicate_tags_should_error() { async fn kcl_test_duplicate_tags_should_error() {
let code = r#"fn triangle = (sideLen) => { let code = r#"fn triangle = (len) => {
return startSketchOn('XY') return startSketchOn('XY')
|> startProfileAt([-sideLen / 2, -sideLen / 2], %) |> startProfileAt([-len / 2, -len / 2], %)
|> angledLine({ angle: 0, length: sideLen }, %, $a) |> angledLine({ angle: 0, length: len }, %, $a)
|> angledLine({ |> angledLine({
angle: segAng(a) + 120, angle: segAng(a) + 120,
length: sideLen length: len
}, %, $b) }, %, $b)
|> angledLine({ |> angledLine({
angle: segAng(b) + 120, angle: segAng(b) + 120,
length: sideLen length: len
}, %, $a) }, %, $a)
} }
@ -1674,7 +1674,7 @@ let p = triangle(200)
assert!(result.is_err()); assert!(result.is_err());
assert_eq!( assert_eq!(
result.err().unwrap().to_string(), result.err().unwrap().to_string(),
r#"value already defined: KclErrorDetails { source_ranges: [SourceRange([335, 337, 0]), SourceRange([350, 363, 0])], message: "Cannot redefine `a`" }"# r#"value already defined: KclErrorDetails { source_ranges: [SourceRange([311, 313, 0]), SourceRange([326, 339, 0])], message: "Cannot redefine `a`" }"#
); );
} }