Implicit conversion of round numbers to integers (#4542)

Signed-off-by: Nick Cameron <nrc@ncameron.org>
This commit is contained in:
Nick Cameron
2024-11-25 10:50:43 +13:00
committed by GitHub
parent 66f6b741c4
commit 4fe17fe3ab
174 changed files with 1603 additions and 1518 deletions

View File

@ -86,6 +86,7 @@ layout: manual
* [`reduce`](kcl/reduce)
* [`rem`](kcl/rem)
* [`revolve`](kcl/revolve)
* [`round`](kcl/round)
* [`segAng`](kcl/segAng)
* [`segEnd`](kcl/segEnd)
* [`segEndX`](kcl/segEndX)

View File

@ -6,12 +6,10 @@ layout: manual
Convert a number to an integer.
Callers should use floor(), ceil(), or other rounding function first if they care about how numbers with fractional parts are converted. If the number has a fractional part, it's truncated, moving the number towards zero.
If the number is NaN or has a magnitude, either positive or negative, that is too large to fit into the internal integer representation, the result is a runtime error.
DEPRECATED use floor(), ceil(), or round().
```js
int(num: number) -> i64
int(num: number) -> number
```
### Tags
@ -27,7 +25,7 @@ int(num: number) -> i64
### Returns
`i64`
`number`
### Examples

File diff suppressed because one or more lines are too long

46
docs/kcl/round.md Normal file

File diff suppressed because one or more lines are too long

View File

@ -78541,7 +78541,7 @@
{
"name": "int",
"summary": "Convert a number to an integer.",
"description": "Callers should use floor(), ceil(), or other rounding function first if they care about how numbers with fractional parts are converted. If the number has a fractional part, it's truncated, moving the number towards zero.\n\nIf the number is NaN or has a magnitude, either positive or negative, that is too large to fit into the internal integer representation, the result is a runtime error.",
"description": "DEPRECATED use floor(), ceil(), or round().",
"tags": [
"convert"
],
@ -78560,12 +78560,12 @@
],
"returnValue": {
"name": "",
"type": "i64",
"type": "number",
"schema": {
"$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema",
"title": "int64",
"type": "integer",
"format": "int64"
"title": "double",
"type": "number",
"format": "double"
},
"required": true
},
@ -96858,10 +96858,6 @@
},
"LiteralValue": {
"anyOf": [
{
"type": "integer",
"format": "int64"
},
{
"type": "number",
"format": "double"
@ -100829,10 +100825,6 @@
},
"LiteralValue": {
"anyOf": [
{
"type": "integer",
"format": "int64"
},
{
"type": "number",
"format": "double"
@ -104804,10 +104796,6 @@
},
"LiteralValue": {
"anyOf": [
{
"type": "integer",
"format": "int64"
},
{
"type": "number",
"format": "double"
@ -110015,11 +110003,9 @@
"properties": {
"instances": {
"description": "The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect.",
"allOf": [
{
"$ref": "#/components/schemas/Uint"
}
]
"type": "integer",
"format": "uint32",
"minimum": 0.0
},
"center": {
"description": "The center about which to make the pattern. This is a 2D vector.",
@ -110040,13 +110026,6 @@
"description": "Whether or not to rotate the duplicates as they are copied.",
"type": "boolean"
}
},
"definitions": {
"Uint": {
"type": "integer",
"format": "uint32",
"minimum": 0.0
}
}
},
"required": true
@ -110143,11 +110122,6 @@
}
],
"definitions": {
"Uint": {
"type": "integer",
"format": "uint32",
"minimum": 0.0
},
"Path": {
"description": "A path.",
"oneOf": [
@ -112800,11 +112774,9 @@
"properties": {
"instances": {
"description": "The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect.",
"allOf": [
{
"$ref": "#/components/schemas/Uint"
}
]
"type": "integer",
"format": "uint32",
"minimum": 0.0
},
"axis": {
"description": "The axis around which to make the pattern. This is a 3D vector.",
@ -112835,13 +112807,6 @@
"description": "Whether or not to rotate the duplicates as they are copied.",
"type": "boolean"
}
},
"definitions": {
"Uint": {
"type": "integer",
"format": "uint32",
"minimum": 0.0
}
}
},
"required": true
@ -112947,11 +112912,6 @@
}
],
"definitions": {
"Uint": {
"type": "integer",
"format": "uint32",
"minimum": 0.0
},
"ExtrudeSurface": {
"description": "An extrude surface.",
"oneOf": [
@ -115602,11 +115562,9 @@
"properties": {
"instances": {
"description": "The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect.",
"allOf": [
{
"$ref": "#/components/schemas/Uint"
}
]
"type": "integer",
"format": "uint32",
"minimum": 0.0
},
"distance": {
"description": "The distance between each repetition. This can also be referred to as spacing.",
@ -115623,13 +115581,6 @@
"maxItems": 2,
"minItems": 2
}
},
"definitions": {
"Uint": {
"type": "integer",
"format": "uint32",
"minimum": 0.0
}
}
},
"required": true
@ -115726,11 +115677,6 @@
}
],
"definitions": {
"Uint": {
"type": "integer",
"format": "uint32",
"minimum": 0.0
},
"Path": {
"description": "A path.",
"oneOf": [
@ -118381,11 +118327,9 @@
"properties": {
"instances": {
"description": "The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect.",
"allOf": [
{
"$ref": "#/components/schemas/Uint"
}
]
"type": "integer",
"format": "uint32",
"minimum": 0.0
},
"distance": {
"description": "The distance between each repetition. This can also be referred to as spacing.",
@ -118402,13 +118346,6 @@
"maxItems": 3,
"minItems": 3
}
},
"definitions": {
"Uint": {
"type": "integer",
"format": "uint32",
"minimum": 0.0
}
}
},
"required": true
@ -118514,11 +118451,6 @@
}
],
"definitions": {
"Uint": {
"type": "integer",
"format": "uint32",
"minimum": 0.0
},
"ExtrudeSurface": {
"description": "An extrude surface.",
"oneOf": [
@ -137985,10 +137917,6 @@
},
"LiteralValue": {
"anyOf": [
{
"type": "integer",
"format": "int64"
},
{
"type": "number",
"format": "double"
@ -142572,10 +142500,6 @@
},
"LiteralValue": {
"anyOf": [
{
"type": "integer",
"format": "int64"
},
{
"type": "number",
"format": "double"
@ -147160,10 +147084,6 @@
},
"LiteralValue": {
"anyOf": [
{
"type": "integer",
"format": "int64"
},
{
"type": "number",
"format": "double"
@ -151146,10 +151066,6 @@
},
"LiteralValue": {
"anyOf": [
{
"type": "integer",
"format": "int64"
},
{
"type": "number",
"format": "double"
@ -155733,10 +155649,6 @@
},
"LiteralValue": {
"anyOf": [
{
"type": "integer",
"format": "int64"
},
{
"type": "number",
"format": "double"
@ -159704,10 +159616,6 @@
},
"LiteralValue": {
"anyOf": [
{
"type": "integer",
"format": "int64"
},
{
"type": "number",
"format": "double"
@ -164292,10 +164200,6 @@
},
"LiteralValue": {
"anyOf": [
{
"type": "integer",
"format": "int64"
},
{
"type": "number",
"format": "double"
@ -165360,7 +165264,7 @@
"unpublished": false,
"deprecated": false,
"examples": [
"assertEqual(rem(int(7), int(4)), 3, 0.01, \"remainder is 3\")\nassertEqual(rem(int(-7), int(4)), -3, 0.01, \"remainder is 3\")\nassertEqual(rem(int(7), int(-4)), 3, 0.01, \"remainder is 3\")"
"assertEqual(rem(7, 4), 3, 0.01, \"remainder is 3\")\nassertEqual(rem(-7, 4), -3, 0.01, \"remainder is 3\")\nassertEqual(rem(7, -4), 3, 0.01, \"remainder is 3\")"
]
},
{
@ -169249,6 +169153,43 @@
"sketch001 = startSketchOn('XY')\n |> startProfileAt([10, 0], %)\n |> line([5, -5], %)\n |> line([5, 5], %)\n |> lineTo([profileStartX(%), profileStartY(%)], %)\n |> close(%)\n\npart001 = revolve({\n axis = {\n custom = {\n axis = [0.0, 1.0],\n origin = [0.0, 0.0]\n }\n }\n}, sketch001)"
]
},
{
"name": "round",
"summary": "Round a number to the nearest integer.",
"description": "",
"tags": [
"math"
],
"args": [
{
"name": "num",
"type": "number",
"schema": {
"$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema",
"title": "double",
"type": "number",
"format": "double"
},
"required": true
}
],
"returnValue": {
"name": "",
"type": "number",
"schema": {
"$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema",
"title": "double",
"type": "number",
"format": "double"
},
"required": true
},
"unpublished": false,
"deprecated": false,
"examples": [
"sketch001 = startSketchOn('XZ')\n |> startProfileAt([0, 0], %)\n |> lineTo([12, 10], %)\n |> line([round(7.02986), 0], %)\n |> yLineTo(0, %)\n |> close(%)\n\nextrude001 = extrude(5, sketch001)"
]
},
{
"name": "segAng",
"summary": "Compute the angle (in degrees) of the provided line segment.",

View File

@ -16,7 +16,7 @@ Data for a circular pattern on a 2D sketch.
| Property | Type | Description | Required |
|----------|------|-------------|----------|
| `instances` |[`Uint`](/docs/kcl/types/Uint)| The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect. | No |
| `instances` |`integer`| The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect. | No |
| `center` |`[number, number]`| The center about which to make the pattern. This is a 2D vector. | No |
| `arcDegrees` |`number`| The arc angle (in degrees) to place the repetitions. Must be greater than 0. | No |
| `rotateDuplicates` |`boolean`| Whether or not to rotate the duplicates as they are copied. | No |

View File

@ -16,7 +16,7 @@ Data for a circular pattern on a 3D model.
| Property | Type | Description | Required |
|----------|------|-------------|----------|
| `instances` |[`Uint`](/docs/kcl/types/Uint)| The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect. | No |
| `instances` |`integer`| The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect. | No |
| `axis` |`[number, number, number]`| The axis around which to make the pattern. This is a 3D vector. | No |
| `center` |`[number, number, number]`| The center about which to make the pattern. This is a 3D vector. | No |
| `arcDegrees` |`number`| The arc angle (in degrees) to place the repetitions. Must be greater than 0. | No |

View File

@ -16,7 +16,7 @@ Data for a linear pattern on a 2D sketch.
| Property | Type | Description | Required |
|----------|------|-------------|----------|
| `instances` |[`Uint`](/docs/kcl/types/Uint)| The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect. | No |
| `instances` |`integer`| The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect. | No |
| `distance` |`number`| The distance between each repetition. This can also be referred to as spacing. | No |
| `axis` |`[number, number]`| The axis of the pattern. This is a 2D vector. | No |

View File

@ -16,7 +16,7 @@ Data for a linear pattern on a 3D model.
| Property | Type | Description | Required |
|----------|------|-------------|----------|
| `instances` |[`Uint`](/docs/kcl/types/Uint)| The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect. | No |
| `instances` |`integer`| The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect. | No |
| `distance` |`number`| The distance between each repetition. This can also be referred to as spacing. | No |
| `axis` |`[number, number, number]`| The axis of the pattern. | No |

View File

@ -11,16 +11,6 @@ layout: manual
**This schema accepts any of the following:**
**Type:** `integer` (`int64`)
----
**Type:** `number` (`double`)

View File

@ -230,7 +230,7 @@ const newVar = myVar + 1`
const mem = await exe(code)
// TODO path to node is probably wrong here, zero indexes are not correct
expect(mem.get('three')).toEqual({
type: 'Int',
type: 'Number',
value: 3,
__meta: [
{
@ -241,9 +241,9 @@ const newVar = myVar + 1`
expect(mem.get('yo')).toEqual({
type: 'Array',
value: [
{ type: 'Int', value: 1, __meta: [{ sourceRange: [28, 29, 0] }] },
{ type: 'Number', value: 1, __meta: [{ sourceRange: [28, 29, 0] }] },
{ type: 'String', value: '2', __meta: [{ sourceRange: [31, 34, 0] }] },
{ type: 'Int', value: 3, __meta: [{ sourceRange: [14, 15, 0] }] },
{ type: 'Number', value: 3, __meta: [{ sourceRange: [14, 15, 0] }] },
{
type: 'Number',
value: 9,
@ -274,9 +274,13 @@ const newVar = myVar + 1`
value: 'str',
__meta: [{ sourceRange: [34, 39, 0] }],
},
anum: { type: 'Int', value: 2, __meta: [{ sourceRange: [47, 48, 0] }] },
anum: {
type: 'Number',
value: 2,
__meta: [{ sourceRange: [47, 48, 0] }],
},
identifier: {
type: 'Int',
type: 'Number',
value: 3,
__meta: [{ sourceRange: [14, 15, 0] }],
},
@ -394,7 +398,7 @@ describe('testing math operators', () => {
sourceRange: [15, 16, 0],
},
],
type: 'Int',
type: 'Number',
value: 1,
},
{

View File

@ -1718,8 +1718,7 @@ impl From<Node<Literal>> for KclValue {
fn from(literal: Node<Literal>) -> Self {
let meta = vec![literal.metadata()];
match literal.inner.value {
LiteralValue::IInteger(value) => KclValue::Int { value, meta },
LiteralValue::Fractional(value) => KclValue::Number { value, meta },
LiteralValue::Number(value) => KclValue::Number { value, meta },
LiteralValue::String(value) => KclValue::String { value, meta },
LiteralValue::Bool(value) => KclValue::Bool { value, meta },
}

View File

@ -95,7 +95,7 @@ impl Node<MemberExpression> {
source_ranges: vec![self.clone().into()],
}))
}
(KclValue::Array { value: arr, meta: _ }, Property::Number(index)) => {
(KclValue::Array { value: arr, meta: _ }, Property::UInt(index)) => {
let value_of_arr = arr.get(index);
if let Some(value) = value_of_arr {
Ok(value.to_owned())
@ -747,7 +747,7 @@ impl Node<IfExpression> {
#[derive(Debug)]
enum Property {
Number(usize),
UInt(usize),
String(String),
}
@ -775,9 +775,9 @@ impl Property {
LiteralIdentifier::Literal(literal) => {
let value = literal.value.clone();
match value {
LiteralValue::IInteger(x) => {
if let Ok(x) = u64::try_from(x) {
Ok(Property::Number(x.try_into().unwrap()))
LiteralValue::Number(x) => {
if let Some(x) = crate::try_f64_to_usize(x) {
Ok(Property::UInt(x))
} else {
Err(KclError::Semantic(KclErrorDetails {
source_ranges: property_sr,
@ -788,7 +788,7 @@ impl Property {
LiteralValue::String(s) => Ok(Property::String(s)),
_ => Err(KclError::Semantic(KclErrorDetails {
source_ranges: vec![sr],
message: "Only strings or ints (>= 0) can be properties/indexes".to_owned(),
message: "Only strings or numbers (>= 0) can be properties/indexes".to_owned(),
})),
}
}
@ -807,7 +807,7 @@ fn jvalue_to_prop(value: &KclValue, property_sr: Vec<SourceRange>, name: &str) -
KclValue::Int { value:num, meta: _ } => {
let maybe_int: Result<usize, _> = (*num).try_into();
if let Ok(uint) = maybe_int {
Ok(Property::Number(uint))
Ok(Property::UInt(uint))
}
else {
make_err(format!("'{num}' is negative, so you can't index an array with it"))
@ -821,7 +821,7 @@ fn jvalue_to_prop(value: &KclValue, property_sr: Vec<SourceRange>, name: &str) -
let nearest_int = num.round();
let delta = num-nearest_int;
if delta < FLOAT_TO_INT_MAX_DELTA {
Ok(Property::Number(nearest_int as usize))
Ok(Property::UInt(nearest_int as usize))
} else {
make_err(format!("'{num}' is not an integer, so you can't index an array with it"))
}
@ -835,7 +835,7 @@ fn jvalue_to_prop(value: &KclValue, property_sr: Vec<SourceRange>, name: &str) -
impl Property {
fn type_name(&self) -> &'static str {
match self {
Property::Number(_) => "number",
Property::UInt(_) => "number",
Property::String(_) => "string",
}
}

View File

@ -12,8 +12,7 @@ use super::Node;
#[ts(export)]
#[serde(untagged, rename_all = "snake_case")]
pub enum LiteralValue {
IInteger(i64),
Fractional(f64),
Number(f64),
String(String),
Bool(bool),
}
@ -21,8 +20,7 @@ pub enum LiteralValue {
impl LiteralValue {
pub fn digestable_id(&self) -> Vec<u8> {
match self {
LiteralValue::IInteger(i) => i.to_ne_bytes().into(),
LiteralValue::Fractional(frac) => frac.to_ne_bytes().into(),
LiteralValue::Number(frac) => frac.to_ne_bytes().into(),
LiteralValue::String(st) => st.as_bytes().into(),
LiteralValue::Bool(b) => {
if *b {
@ -44,8 +42,7 @@ impl From<Node<Literal>> for Expr {
impl From<LiteralValue> for JValue {
fn from(value: LiteralValue) -> Self {
match value {
LiteralValue::IInteger(x) => x.into(),
LiteralValue::Fractional(x) => x.into(),
LiteralValue::Number(x) => x.into(),
LiteralValue::String(x) => x.into(),
LiteralValue::Bool(b) => b.into(),
}
@ -54,13 +51,13 @@ impl From<LiteralValue> for JValue {
impl From<f64> for LiteralValue {
fn from(value: f64) -> Self {
Self::Fractional(value)
Self::Number(value)
}
}
impl From<i64> for LiteralValue {
fn from(value: i64) -> Self {
Self::IInteger(value)
Self::Number(value as f64)
}
}
@ -72,17 +69,17 @@ impl From<String> for LiteralValue {
impl From<u32> for LiteralValue {
fn from(value: u32) -> Self {
Self::IInteger(value as i64)
Self::Number(value as f64)
}
}
impl From<u16> for LiteralValue {
fn from(value: u16) -> Self {
Self::IInteger(value as i64)
Self::Number(value as f64)
}
}
impl From<u8> for LiteralValue {
fn from(value: u8) -> Self {
Self::IInteger(value as i64)
Self::Number(value as f64)
}
}
impl From<&'static str> for LiteralValue {

View File

@ -2821,7 +2821,7 @@ let notNull = !myNull
assert_eq!(
parse_execute(code2).await.unwrap_err().downcast::<KclError>().unwrap(),
KclError::Semantic(KclErrorDetails {
message: "Cannot apply unary operator ! to non-boolean value: integer".to_owned(),
message: "Cannot apply unary operator ! to non-boolean value: number".to_owned(),
source_ranges: vec![SourceRange([14, 16, 0])],
})
);
@ -2844,7 +2844,7 @@ let notMember = !obj.a
assert_eq!(
parse_execute(code4).await.unwrap_err().downcast::<KclError>().unwrap(),
KclError::Semantic(KclErrorDetails {
message: "Cannot apply unary operator ! to non-boolean value: integer".to_owned(),
message: "Cannot apply unary operator ! to non-boolean value: number".to_owned(),
source_ranges: vec![SourceRange([36, 42, 0])],
})
);

View File

@ -273,16 +273,17 @@ impl KclValue {
pub(crate) fn as_usize(&self) -> Option<usize> {
match self {
KclValue::Int { value, .. } => Some(*value as usize),
KclValue::Int { value, .. } if *value > 0 => Some(*value as usize),
KclValue::Number { value, .. } => crate::try_f64_to_usize(*value),
_ => None,
}
}
pub fn as_int(&self) -> Option<i64> {
if let KclValue::Int { value, meta: _ } = &self {
Some(*value)
} else {
None
match self {
KclValue::Int { value, .. } => Some(*value),
KclValue::Number { value, .. } => crate::try_f64_to_i64(*value),
_ => None,
}
}

View File

@ -122,3 +122,83 @@ impl From<ast::types::Node<ast::types::Program>> for Program {
Self { ast }
}
}
#[inline]
fn try_f64_to_usize(f: f64) -> Option<usize> {
let i = f as usize;
if i as f64 == f {
Some(i)
} else {
None
}
}
#[inline]
fn try_f64_to_u32(f: f64) -> Option<u32> {
let i = f as u32;
if i as f64 == f {
Some(i)
} else {
None
}
}
#[inline]
fn try_f64_to_u64(f: f64) -> Option<u64> {
let i = f as u64;
if i as f64 == f {
Some(i)
} else {
None
}
}
#[inline]
fn try_f64_to_i64(f: f64) -> Option<i64> {
let i = f as i64;
if i as f64 == f {
Some(i)
} else {
None
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn convert_int() {
assert_eq!(try_f64_to_usize(0.0), Some(0));
assert_eq!(try_f64_to_usize(42.0), Some(42));
assert_eq!(try_f64_to_usize(0.00000000001), None);
assert_eq!(try_f64_to_usize(-1.0), None);
assert_eq!(try_f64_to_usize(f64::NAN), None);
assert_eq!(try_f64_to_usize(f64::INFINITY), None);
assert_eq!(try_f64_to_usize((0.1 + 0.2) * 10.0), None);
assert_eq!(try_f64_to_u32(0.0), Some(0));
assert_eq!(try_f64_to_u32(42.0), Some(42));
assert_eq!(try_f64_to_u32(0.00000000001), None);
assert_eq!(try_f64_to_u32(-1.0), None);
assert_eq!(try_f64_to_u32(f64::NAN), None);
assert_eq!(try_f64_to_u32(f64::INFINITY), None);
assert_eq!(try_f64_to_u32((0.1 + 0.2) * 10.0), None);
assert_eq!(try_f64_to_u64(0.0), Some(0));
assert_eq!(try_f64_to_u64(42.0), Some(42));
assert_eq!(try_f64_to_u64(0.00000000001), None);
assert_eq!(try_f64_to_u64(-1.0), None);
assert_eq!(try_f64_to_u64(f64::NAN), None);
assert_eq!(try_f64_to_u64(f64::INFINITY), None);
assert_eq!(try_f64_to_u64((0.1 + 0.2) * 10.0), None);
assert_eq!(try_f64_to_i64(0.0), Some(0));
assert_eq!(try_f64_to_i64(42.0), Some(42));
assert_eq!(try_f64_to_i64(0.00000000001), None);
assert_eq!(try_f64_to_i64(-1.0), Some(-1));
assert_eq!(try_f64_to_i64(f64::NAN), None);
assert_eq!(try_f64_to_i64(f64::INFINITY), None);
assert_eq!(try_f64_to_i64((0.1 + 0.2) * 10.0), None);
}
}

View File

@ -161,8 +161,7 @@ fn get_xyz(point: &ObjectExpression) -> Option<(f64, f64, f64)> {
fn unlitafy(lit: &LiteralValue) -> Option<f64> {
Some(match lit {
LiteralValue::IInteger(value) => *value as f64,
LiteralValue::Fractional(value) => *value,
LiteralValue::Number(value) => *value,
_ => {
return None;
}

View File

@ -352,9 +352,6 @@ pub(crate) fn unsigned_number_literal(i: TokenSlice) -> PResult<Node<Literal>> {
let (value, token) = any
.try_map(|token: Token| match token.token_type {
TokenType::Number => {
if let Ok(x) = token.value.parse::<u64>() {
return Ok((LiteralValue::IInteger(x as i64), token));
}
let x: f64 = token.value.parse().map_err(|_| {
KclError::Syntax(KclErrorDetails {
source_ranges: token.as_source_ranges(),
@ -362,7 +359,7 @@ pub(crate) fn unsigned_number_literal(i: TokenSlice) -> PResult<Node<Literal>> {
})
})?;
Ok((LiteralValue::Fractional(x), token))
Ok((LiteralValue::Number(x), token))
}
_ => Err(KclError::Syntax(KclErrorDetails {
source_ranges: token.as_source_ranges(),

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3609
expression: actual
snapshot_kind: text
---
@ -9,7 +10,7 @@ snapshot_kind: text
"left": {
"type": "Literal",
"type": "Literal",
"value": 1,
"value": 1.0,
"raw": "1",
"start": 0,
"end": 1
@ -17,7 +18,7 @@ snapshot_kind: text
"right": {
"type": "Literal",
"type": "Literal",
"value": 2,
"value": 2.0,
"raw": "2",
"start": 4,
"end": 5

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3610
expression: actual
snapshot_kind: text
---
@ -9,7 +10,7 @@ snapshot_kind: text
"left": {
"type": "Literal",
"type": "Literal",
"value": 1,
"value": 1.0,
"raw": "1",
"start": 0,
"end": 1
@ -17,7 +18,7 @@ snapshot_kind: text
"right": {
"type": "Literal",
"type": "Literal",
"value": 2,
"value": 2.0,
"raw": "2",
"start": 2,
"end": 3

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3611
expression: actual
snapshot_kind: text
---
@ -9,7 +10,7 @@ snapshot_kind: text
"left": {
"type": "Literal",
"type": "Literal",
"value": 1,
"value": 1.0,
"raw": "1",
"start": 0,
"end": 1
@ -17,7 +18,7 @@ snapshot_kind: text
"right": {
"type": "Literal",
"type": "Literal",
"value": 2,
"value": 2.0,
"raw": "2",
"start": 3,
"end": 4

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3612
expression: actual
snapshot_kind: text
---
@ -9,7 +10,7 @@ snapshot_kind: text
"left": {
"type": "Literal",
"type": "Literal",
"value": 1,
"value": 1.0,
"raw": "1",
"start": 0,
"end": 1
@ -21,7 +22,7 @@ snapshot_kind: text
"left": {
"type": "Literal",
"type": "Literal",
"value": 2,
"value": 2.0,
"raw": "2",
"start": 4,
"end": 5
@ -29,7 +30,7 @@ snapshot_kind: text
"right": {
"type": "Literal",
"type": "Literal",
"value": 3,
"value": 3.0,
"raw": "3",
"start": 8,
"end": 9

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3613
expression: actual
snapshot_kind: text
---
@ -9,7 +10,7 @@ snapshot_kind: text
"left": {
"type": "Literal",
"type": "Literal",
"value": 1,
"value": 1.0,
"raw": "1",
"start": 0,
"end": 1
@ -21,7 +22,7 @@ snapshot_kind: text
"left": {
"type": "Literal",
"type": "Literal",
"value": 2,
"value": 2.0,
"raw": "2",
"start": 6,
"end": 7
@ -29,7 +30,7 @@ snapshot_kind: text
"right": {
"type": "Literal",
"type": "Literal",
"value": 3,
"value": 3.0,
"raw": "3",
"start": 10,
"end": 11

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3614
expression: actual
snapshot_kind: text
---
@ -13,7 +14,7 @@ snapshot_kind: text
"left": {
"type": "Literal",
"type": "Literal",
"value": 1,
"value": 1.0,
"raw": "1",
"start": 0,
"end": 1
@ -25,7 +26,7 @@ snapshot_kind: text
"left": {
"type": "Literal",
"type": "Literal",
"value": 2,
"value": 2.0,
"raw": "2",
"start": 6,
"end": 7
@ -33,7 +34,7 @@ snapshot_kind: text
"right": {
"type": "Literal",
"type": "Literal",
"value": 3,
"value": 3.0,
"raw": "3",
"start": 10,
"end": 11
@ -47,7 +48,7 @@ snapshot_kind: text
"right": {
"type": "Literal",
"type": "Literal",
"value": 4,
"value": 4.0,
"raw": "4",
"start": 16,
"end": 17

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3615
expression: actual
snapshot_kind: text
---
@ -9,7 +10,7 @@ snapshot_kind: text
"left": {
"type": "Literal",
"type": "Literal",
"value": 1,
"value": 1.0,
"raw": "1",
"start": 0,
"end": 1
@ -25,7 +26,7 @@ snapshot_kind: text
"left": {
"type": "Literal",
"type": "Literal",
"value": 2,
"value": 2.0,
"raw": "2",
"start": 6,
"end": 7
@ -33,7 +34,7 @@ snapshot_kind: text
"right": {
"type": "Literal",
"type": "Literal",
"value": 3,
"value": 3.0,
"raw": "3",
"start": 10,
"end": 11
@ -44,7 +45,7 @@ snapshot_kind: text
"right": {
"type": "Literal",
"type": "Literal",
"value": 4,
"value": 4.0,
"raw": "4",
"start": 16,
"end": 17

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3616
expression: actual
snapshot_kind: text
---
@ -9,7 +10,7 @@ snapshot_kind: text
"left": {
"type": "Literal",
"type": "Literal",
"value": 1,
"value": 1.0,
"raw": "1",
"start": 0,
"end": 1
@ -29,7 +30,7 @@ snapshot_kind: text
"left": {
"type": "Literal",
"type": "Literal",
"value": 2,
"value": 2.0,
"raw": "2",
"start": 7,
"end": 8
@ -37,7 +38,7 @@ snapshot_kind: text
"right": {
"type": "Literal",
"type": "Literal",
"value": 3,
"value": 3.0,
"raw": "3",
"start": 11,
"end": 12
@ -48,7 +49,7 @@ snapshot_kind: text
"right": {
"type": "Literal",
"type": "Literal",
"value": 4,
"value": 4.0,
"raw": "4",
"start": 17,
"end": 18
@ -59,7 +60,7 @@ snapshot_kind: text
"right": {
"type": "Literal",
"type": "Literal",
"value": 5,
"value": 5.0,
"raw": "5",
"start": 21,
"end": 22

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3617
expression: actual
snapshot_kind: text
---
@ -9,7 +10,7 @@ snapshot_kind: text
"left": {
"type": "Literal",
"type": "Literal",
"value": 1,
"value": 1.0,
"raw": "1",
"start": 0,
"end": 1
@ -21,7 +22,7 @@ snapshot_kind: text
"left": {
"type": "Literal",
"type": "Literal",
"value": 2,
"value": 2.0,
"raw": "2",
"start": 8,
"end": 9
@ -29,7 +30,7 @@ snapshot_kind: text
"right": {
"type": "Literal",
"type": "Literal",
"value": 3,
"value": 3.0,
"raw": "3",
"start": 12,
"end": 13

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3618
expression: actual
snapshot_kind: text
---
@ -48,7 +49,7 @@ snapshot_kind: text
"right": {
"type": "Literal",
"type": "Literal",
"value": 6,
"value": 6.0,
"raw": "6",
"start": 21,
"end": 22

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3619
expression: actual
snapshot_kind: text
---
@ -9,7 +10,7 @@ snapshot_kind: text
"left": {
"type": "Literal",
"type": "Literal",
"value": 2,
"value": 2.0,
"raw": "2",
"start": 0,
"end": 1
@ -17,7 +18,7 @@ snapshot_kind: text
"right": {
"type": "Literal",
"type": "Literal",
"value": 3,
"value": 3.0,
"raw": "3",
"start": 7,
"end": 8

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3649
expression: actual
snapshot_kind: text
---
@ -27,7 +28,7 @@ snapshot_kind: text
"start": 33,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
},
{
"end": 37,
@ -35,7 +36,7 @@ snapshot_kind: text
"start": 36,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
}
],
"end": 38,
@ -66,7 +67,7 @@ snapshot_kind: text
"start": 53,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
},
{
"end": 58,
@ -74,7 +75,7 @@ snapshot_kind: text
"start": 56,
"type": "Literal",
"type": "Literal",
"value": 10
"value": 10.0
}
],
"end": 59,
@ -112,7 +113,7 @@ snapshot_kind: text
"start": 87,
"type": "Literal",
"type": "Literal",
"value": 5
"value": 5.0
},
"end": 88,
"operator": "-",
@ -126,7 +127,7 @@ snapshot_kind: text
"start": 90,
"type": "Literal",
"type": "Literal",
"value": 5
"value": 5.0
}
],
"end": 92,
@ -163,7 +164,7 @@ snapshot_kind: text
"start": 110,
"type": "Literal",
"type": "Literal",
"value": 5
"value": 5.0
},
{
"argument": {
@ -172,7 +173,7 @@ snapshot_kind: text
"start": 114,
"type": "Literal",
"type": "Literal",
"value": 15
"value": 15.0
},
"end": 116,
"operator": "-",
@ -213,7 +214,7 @@ snapshot_kind: text
"start": 137,
"type": "Literal",
"type": "Literal",
"value": 10
"value": 10.0
},
{
"end": 142,

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3720
expression: actual
snapshot_kind: text
---
@ -30,7 +31,7 @@ snapshot_kind: text
"start": 14,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
},
{
"argument": {
@ -39,7 +40,7 @@ snapshot_kind: text
"start": 18,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
},
"end": 19,
"operator": "-",

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3721
expression: actual
snapshot_kind: text
---
@ -23,7 +24,7 @@ snapshot_kind: text
"start": 20,
"type": "Literal",
"type": "Literal",
"value": 10
"value": 10.0
},
"endInclusive": true,
"start": 16,
@ -33,7 +34,7 @@ snapshot_kind: text
"start": 17,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
},
"type": "ArrayRangeExpression",
"type": "ArrayRangeExpression"

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3722
expression: actual
snapshot_kind: text
---
@ -25,7 +26,7 @@ snapshot_kind: text
"start": 50,
"type": "Literal",
"type": "Literal",
"value": 2
"value": 2.0
},
"end": 51,
"start": 43,

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3737
expression: actual
snapshot_kind: text
---
@ -27,7 +28,7 @@ snapshot_kind: text
"start": 32,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
},
{
"end": 35,
@ -35,7 +36,7 @@ snapshot_kind: text
"start": 34,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
}
],
"end": 36,
@ -66,7 +67,7 @@ snapshot_kind: text
"start": 57,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
},
{
"end": 61,
@ -74,7 +75,7 @@ snapshot_kind: text
"start": 60,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
}
],
"end": 62,
@ -118,7 +119,7 @@ snapshot_kind: text
"start": 95,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
},
{
"end": 99,
@ -126,7 +127,7 @@ snapshot_kind: text
"start": 98,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
}
],
"end": 100,
@ -163,7 +164,7 @@ snapshot_kind: text
"start": 124,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
},
{
"end": 128,
@ -171,7 +172,7 @@ snapshot_kind: text
"start": 127,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
}
],
"end": 129,

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3745
expression: actual
snapshot_kind: text
---
@ -27,7 +28,7 @@ snapshot_kind: text
"start": 32,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
},
{
"end": 35,
@ -35,7 +36,7 @@ snapshot_kind: text
"start": 34,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
}
],
"end": 36,
@ -66,7 +67,7 @@ snapshot_kind: text
"start": 49,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
},
{
"end": 53,
@ -74,7 +75,7 @@ snapshot_kind: text
"start": 52,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
}
],
"end": 54,

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3750
expression: actual
snapshot_kind: text
---
@ -25,7 +26,7 @@ snapshot_kind: text
"start": 16,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
}
],
"callee": {
@ -48,7 +49,7 @@ snapshot_kind: text
"start": 24,
"type": "Literal",
"type": "Literal",
"value": 2
"value": 2.0
},
{
"end": 28,

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3751
expression: actual
snapshot_kind: text
---
@ -49,7 +50,7 @@ snapshot_kind: text
"start": 40,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
},
{
"end": 44,

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3752
expression: actual
snapshot_kind: text
---
@ -30,7 +31,7 @@ snapshot_kind: text
"start": 14,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
},
{
"end": 18,
@ -38,7 +39,7 @@ snapshot_kind: text
"start": 17,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
}
],
"end": 19,

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3753
expression: actual
snapshot_kind: text
---
@ -30,7 +31,7 @@ snapshot_kind: text
"start": 14,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
},
{
"end": 18,
@ -38,7 +39,7 @@ snapshot_kind: text
"start": 17,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
}
],
"end": 19,
@ -65,7 +66,7 @@ snapshot_kind: text
"start": 28,
"type": "Literal",
"type": "Literal",
"value": 3
"value": 3.0
},
{
"end": 32,
@ -73,7 +74,7 @@ snapshot_kind: text
"start": 31,
"type": "Literal",
"type": "Literal",
"value": 3
"value": 3.0
}
],
"end": 33,

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3754
expression: actual
snapshot_kind: text
---
@ -30,7 +31,7 @@ snapshot_kind: text
"start": 12,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
},
{
"end": 16,
@ -38,7 +39,7 @@ snapshot_kind: text
"start": 15,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
}
],
"end": 17,

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3755
expression: actual
snapshot_kind: text
---
@ -30,7 +31,7 @@ snapshot_kind: text
"start": 14,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
},
{
"end": 18,
@ -38,7 +39,7 @@ snapshot_kind: text
"start": 17,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
}
],
"end": 19,
@ -65,7 +66,7 @@ snapshot_kind: text
"start": 28,
"type": "Literal",
"type": "Literal",
"value": 3
"value": 3.0
},
{
"end": 32,
@ -73,7 +74,7 @@ snapshot_kind: text
"start": 31,
"type": "Literal",
"type": "Literal",
"value": 3
"value": 3.0
}
],
"end": 33,

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3756
expression: actual
snapshot_kind: text
---
@ -30,7 +31,7 @@ snapshot_kind: text
"start": 14,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
},
{
"end": 18,
@ -38,7 +39,7 @@ snapshot_kind: text
"start": 17,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
}
],
"end": 19,
@ -65,7 +66,7 @@ snapshot_kind: text
"start": 27,
"type": "Literal",
"type": "Literal",
"value": 3
"value": 3.0
},
{
"end": 31,
@ -73,7 +74,7 @@ snapshot_kind: text
"start": 30,
"type": "Literal",
"type": "Literal",
"value": 3
"value": 3.0
}
],
"end": 32,

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3757
expression: actual
snapshot_kind: text
---
@ -25,7 +26,7 @@ snapshot_kind: text
"start": 32,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
},
{
"end": 35,
@ -33,7 +34,7 @@ snapshot_kind: text
"start": 34,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
}
],
"end": 36,

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3758
expression: actual
snapshot_kind: text
---
@ -15,7 +16,7 @@ snapshot_kind: text
"start": 4,
"type": "Literal",
"type": "Literal",
"value": 5
"value": 5.0
},
{
"end": 14,

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3759
expression: actual
snapshot_kind: text
---
@ -15,7 +16,7 @@ snapshot_kind: text
"start": 0,
"type": "Literal",
"type": "Literal",
"value": 5
"value": 5.0
},
"operator": "+",
"right": {

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3760
expression: actual
snapshot_kind: text
---
@ -17,7 +18,7 @@ snapshot_kind: text
"start": 6,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
},
{
"end": 10,

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3761
expression: actual
snapshot_kind: text
---
@ -63,7 +64,7 @@ snapshot_kind: text
"start": 62,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
},
{
"end": 66,
@ -71,7 +72,7 @@ snapshot_kind: text
"start": 65,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
}
],
"end": 67,
@ -96,7 +97,7 @@ snapshot_kind: text
"start": 77,
"type": "Literal",
"type": "Literal",
"value": 22
"value": 22.0
}
}
],
@ -131,7 +132,7 @@ snapshot_kind: text
"start": 101,
"type": "Literal",
"type": "Literal",
"value": 14
"value": 14.0
},
{
"end": 106,

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3762
expression: actual
snapshot_kind: text
---
@ -34,7 +35,7 @@ snapshot_kind: text
"start": 43,
"type": "Literal",
"type": "Literal",
"value": 360
"value": 360.0
}
],
"callee": {

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3763
expression: actual
snapshot_kind: text
---
@ -23,7 +24,7 @@ snapshot_kind: text
"start": 28,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
},
{
"end": 80,
@ -31,7 +32,7 @@ snapshot_kind: text
"start": 79,
"type": "Literal",
"type": "Literal",
"value": 3
"value": 3.0
}
],
"end": 91,

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3772
expression: actual
snapshot_kind: text
---
@ -23,7 +24,7 @@ snapshot_kind: text
"start": 28,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
},
{
"end": 44,
@ -31,7 +32,7 @@ snapshot_kind: text
"start": 43,
"type": "Literal",
"type": "Literal",
"value": 2
"value": 2.0
}
],
"end": 91,

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3781
expression: actual
snapshot_kind: text
---
@ -51,7 +52,7 @@ snapshot_kind: text
"start": 29,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
}
},
{
@ -70,7 +71,7 @@ snapshot_kind: text
"start": 68,
"type": "Literal",
"type": "Literal",
"value": 3
"value": 3.0
}
}
],

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3789
expression: actual
snapshot_kind: text
---
@ -51,7 +52,7 @@ snapshot_kind: text
"start": 29,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
}
},
{
@ -70,7 +71,7 @@ snapshot_kind: text
"start": 68,
"type": "Literal",
"type": "Literal",
"value": 3
"value": 3.0
}
}
],

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3658
expression: actual
snapshot_kind: text
---
@ -23,7 +24,7 @@ snapshot_kind: text
"start": 18,
"type": "Literal",
"type": "Literal",
"value": 5
"value": 5.0
},
{
"argument": {
@ -34,7 +35,7 @@ snapshot_kind: text
"start": 30,
"type": "Literal",
"type": "Literal",
"value": 5
"value": 5.0
},
{
"end": 34,
@ -42,7 +43,7 @@ snapshot_kind: text
"start": 33,
"type": "Literal",
"type": "Literal",
"value": 4
"value": 4.0
}
],
"callee": {

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3808
expression: actual
snapshot_kind: text
---
@ -25,7 +26,7 @@ snapshot_kind: text
"start": 14,
"type": "Literal",
"type": "Literal",
"value": 4
"value": 4.0
},
"operator": "^",
"right": {
@ -34,7 +35,7 @@ snapshot_kind: text
"start": 18,
"type": "Literal",
"type": "Literal",
"value": 2
"value": 2.0
},
"start": 14,
"type": "BinaryExpression",
@ -51,7 +52,7 @@ snapshot_kind: text
"start": 22,
"type": "Literal",
"type": "Literal",
"value": 3
"value": 3.0
},
"operator": "^",
"right": {
@ -60,7 +61,7 @@ snapshot_kind: text
"start": 26,
"type": "Literal",
"type": "Literal",
"value": 2
"value": 2.0
},
"start": 22,
"type": "BinaryExpression",
@ -73,7 +74,7 @@ snapshot_kind: text
"start": 30,
"type": "Literal",
"type": "Literal",
"value": 2
"value": 2.0
},
"start": 22,
"type": "BinaryExpression",

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3814
expression: actual
snapshot_kind: text
---
@ -37,7 +38,7 @@ snapshot_kind: text
"start": 63,
"type": "Literal",
"type": "Literal",
"value": 4
"value": 4.0
},
"start": 63,
"type": "ExpressionStatement",
@ -58,7 +59,7 @@ snapshot_kind: text
"start": 32,
"type": "Literal",
"type": "Literal",
"value": 3
"value": 3.0
},
"start": 32,
"type": "ExpressionStatement",

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3822
expression: actual
snapshot_kind: text
---
@ -62,7 +63,7 @@ snapshot_kind: text
"start": 79,
"type": "Literal",
"type": "Literal",
"value": 4
"value": 4.0
},
"start": 79,
"type": "ExpressionStatement",
@ -86,7 +87,7 @@ snapshot_kind: text
"start": 110,
"type": "Literal",
"type": "Literal",
"value": 5
"value": 5.0
},
"start": 110,
"type": "ExpressionStatement",
@ -107,7 +108,7 @@ snapshot_kind: text
"start": 32,
"type": "Literal",
"type": "Literal",
"value": 3
"value": 3.0
},
"start": 32,
"type": "ExpressionStatement",

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3832
expression: actual
snapshot_kind: text
---
@ -23,7 +24,7 @@ snapshot_kind: text
"start": 8,
"type": "Literal",
"type": "Literal",
"value": 3
"value": 3.0
},
"operator": "==",
"right": {
@ -32,7 +33,7 @@ snapshot_kind: text
"start": 13,
"type": "Literal",
"type": "Literal",
"value": 3
"value": 3.0
},
"start": 8,
"type": "BinaryExpression",

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3833
expression: actual
snapshot_kind: text
---
@ -23,7 +24,7 @@ snapshot_kind: text
"start": 8,
"type": "Literal",
"type": "Literal",
"value": 3
"value": 3.0
},
"operator": "!=",
"right": {
@ -32,7 +33,7 @@ snapshot_kind: text
"start": 13,
"type": "Literal",
"type": "Literal",
"value": 3
"value": 3.0
},
"start": 8,
"type": "BinaryExpression",

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3834
expression: actual
snapshot_kind: text
---
@ -21,7 +22,7 @@ snapshot_kind: text
"start": 4,
"type": "Literal",
"type": "Literal",
"value": 4
"value": 4.0
},
"start": 0,
"type": "VariableDeclarator"

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3835
expression: actual
snapshot_kind: text
---
@ -36,7 +37,7 @@ snapshot_kind: text
"start": 23,
"type": "Literal",
"type": "Literal",
"value": 10
"value": 10.0
},
{
"end": 29,
@ -44,7 +45,7 @@ snapshot_kind: text
"start": 27,
"type": "Literal",
"type": "Literal",
"value": 10
"value": 10.0
}
],
"end": 30,
@ -69,7 +70,7 @@ snapshot_kind: text
"start": 40,
"type": "Literal",
"type": "Literal",
"value": 5
"value": 5.0
}
}
],

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3836
expression: actual
snapshot_kind: text
---
@ -21,7 +22,7 @@ snapshot_kind: text
"start": 4,
"type": "Literal",
"type": "Literal",
"value": 3
"value": 3.0
},
"start": 0,
"type": "VariableDeclarator"
@ -80,7 +81,7 @@ snapshot_kind: text
"start": 28,
"type": "Literal",
"type": "Literal",
"value": 4
"value": 4.0
}
}
],

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3660
expression: actual
snapshot_kind: text
---
@ -26,7 +27,7 @@ snapshot_kind: text
"start": 26,
"type": "Literal",
"type": "Literal",
"value": 5
"value": 5.0
},
{
"end": 30,
@ -34,7 +35,7 @@ snapshot_kind: text
"start": 29,
"type": "Literal",
"type": "Literal",
"value": 4
"value": 4.0
}
],
"callee": {
@ -61,7 +62,7 @@ snapshot_kind: text
"start": 33,
"type": "Literal",
"type": "Literal",
"value": 5
"value": 5.0
}
],
"callee": {

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3661
expression: actual
snapshot_kind: text
---
@ -25,7 +26,7 @@ snapshot_kind: text
"start": 14,
"type": "Literal",
"type": "Literal",
"value": 5
"value": 5.0
},
"operator": "+",
"right": {
@ -34,7 +35,7 @@ snapshot_kind: text
"start": 18,
"type": "Literal",
"type": "Literal",
"value": 6
"value": 6.0
},
"start": 14,
"type": "BinaryExpression",
@ -48,7 +49,7 @@ snapshot_kind: text
"start": 30,
"type": "Literal",
"type": "Literal",
"value": 45
"value": 45.0
},
{
"end": 35,

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3662
expression: actual
snapshot_kind: text
---
@ -23,7 +24,7 @@ snapshot_kind: text
"start": 8,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
},
"operator": "*",
"right": {
@ -34,7 +35,7 @@ snapshot_kind: text
"start": 13,
"type": "Literal",
"type": "Literal",
"value": 3
"value": 3.0
},
"operator": "-",
"right": {
@ -43,7 +44,7 @@ snapshot_kind: text
"start": 17,
"type": "Literal",
"type": "Literal",
"value": 4
"value": 4.0
},
"start": 13,
"type": "BinaryExpression",

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3663
expression: actual
snapshot_kind: text
---
@ -21,7 +22,7 @@ snapshot_kind: text
"start": 10,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
},
"start": 6,
"type": "VariableDeclarator"

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3672
expression: actual
snapshot_kind: text
---
@ -34,7 +35,7 @@ snapshot_kind: text
"start": 17,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
}
},
{
@ -53,7 +54,7 @@ snapshot_kind: text
"start": 23,
"type": "Literal",
"type": "Literal",
"value": 2
"value": 2.0
}
}
],
@ -89,7 +90,7 @@ snapshot_kind: text
"start": 46,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
},
"operator": "-",
"right": {

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3677
expression: actual
snapshot_kind: text
---
@ -34,7 +35,7 @@ snapshot_kind: text
"start": 17,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
}
},
{
@ -53,7 +54,7 @@ snapshot_kind: text
"start": 23,
"type": "Literal",
"type": "Literal",
"value": 2
"value": 2.0
}
}
],
@ -89,7 +90,7 @@ snapshot_kind: text
"start": 47,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
},
"operator": "-",
"right": {

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3682
expression: actual
snapshot_kind: text
---
@ -34,7 +35,7 @@ snapshot_kind: text
"start": 17,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
}
},
{
@ -53,7 +54,7 @@ snapshot_kind: text
"start": 23,
"type": "Literal",
"type": "Literal",
"value": 2
"value": 2.0
}
}
],
@ -112,7 +113,7 @@ snapshot_kind: text
"start": 57,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
},
"start": 46,
"type": "BinaryExpression",

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3687
expression: actual
snapshot_kind: text
---
@ -34,7 +35,7 @@ snapshot_kind: text
"start": 17,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
}
},
{
@ -53,7 +54,7 @@ snapshot_kind: text
"start": 23,
"type": "Literal",
"type": "Literal",
"value": 2
"value": 2.0
}
}
],
@ -91,7 +92,7 @@ snapshot_kind: text
"start": 47,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
},
"operator": "-",
"right": {
@ -126,7 +127,7 @@ snapshot_kind: text
"start": 61,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
}
],
"end": 63,

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3692
expression: actual
snapshot_kind: text
---
@ -34,7 +35,7 @@ snapshot_kind: text
"start": 17,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
}
},
{
@ -53,7 +54,7 @@ snapshot_kind: text
"start": 23,
"type": "Literal",
"type": "Literal",
"value": 2
"value": 2.0
}
}
],
@ -114,7 +115,7 @@ snapshot_kind: text
"start": 58,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
},
"start": 47,
"type": "BinaryExpression",
@ -126,7 +127,7 @@ snapshot_kind: text
"start": 61,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
}
],
"end": 63,

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3697
expression: actual
snapshot_kind: text
---
@ -34,7 +35,7 @@ snapshot_kind: text
"start": 17,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
}
},
{
@ -53,7 +54,7 @@ snapshot_kind: text
"start": 23,
"type": "Literal",
"type": "Literal",
"value": 2
"value": 2.0
}
}
],
@ -114,7 +115,7 @@ snapshot_kind: text
"start": 57,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
},
"start": 47,
"type": "BinaryExpression",
@ -126,7 +127,7 @@ snapshot_kind: text
"start": 60,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
}
],
"end": 62,

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3702
expression: actual
snapshot_kind: text
---
@ -23,7 +24,7 @@ snapshot_kind: text
"start": 15,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
},
"operator": "-",
"right": {

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3703
expression: actual
snapshot_kind: text
---
@ -25,7 +26,7 @@ snapshot_kind: text
"start": 12,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
},
"operator": "+",
"right": {
@ -34,7 +35,7 @@ snapshot_kind: text
"start": 16,
"type": "Literal",
"type": "Literal",
"value": 2
"value": 2.0
},
"start": 12,
"type": "BinaryExpression",
@ -47,7 +48,7 @@ snapshot_kind: text
"start": 20,
"type": "Literal",
"type": "Literal",
"value": 3
"value": 3.0
},
"start": 12,
"type": "BinaryExpression",

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3704
expression: actual
snapshot_kind: text
---
@ -25,7 +26,7 @@ snapshot_kind: text
"start": 13,
"type": "Literal",
"type": "Literal",
"value": 3
"value": 3.0
},
"operator": "*",
"right": {
@ -34,7 +35,7 @@ snapshot_kind: text
"start": 17,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
},
"start": 13,
"type": "BinaryExpression",
@ -47,7 +48,7 @@ snapshot_kind: text
"start": 21,
"type": "Literal",
"type": "Literal",
"value": 2
"value": 2.0
},
"start": 13,
"type": "BinaryExpression",

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3705
expression: actual
snapshot_kind: text
---
@ -45,7 +46,7 @@ snapshot_kind: text
"start": 27,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
}
],
"end": 30,

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3706
expression: actual
snapshot_kind: text
---
@ -34,7 +35,7 @@ snapshot_kind: text
"start": 17,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
}
},
{
@ -53,7 +54,7 @@ snapshot_kind: text
"start": 23,
"type": "Literal",
"type": "Literal",
"value": 2
"value": 2.0
}
}
],

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3714
expression: actual
snapshot_kind: text
---
@ -31,7 +32,7 @@ snapshot_kind: text
"start": 15,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
},
"start": 12,
"type": "MemberExpression",

View File

@ -1,5 +1,6 @@
---
source: kcl/src/parser/parser_impl.rs
assertion_line: 3718
expression: actual
snapshot_kind: text
---
@ -49,7 +50,7 @@ snapshot_kind: text
"start": 39,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
},
{
"argument": {

View File

@ -11,7 +11,7 @@ use crate::{
ExecState, ExecutorContext, ExtrudeSurface, KclValue, Metadata, Sketch, SketchSet, SketchSurface, Solid,
SolidSet, SourceRange, TagIdentifier,
},
std::{shapes::SketchOrSurface, sketch::FaceTag, types::Uint, FnAsArg},
std::{shapes::SketchOrSurface, sketch::FaceTag, FnAsArg},
};
use super::shapes::PolygonType;
@ -921,7 +921,6 @@ impl<'a> FromKclValue<'a> for super::patterns::CircularPattern3dData {
let_field_of!(obj, instances);
let_field_of!(obj, arc_degrees "arcDegrees");
let_field_of!(obj, rotate_duplicates "rotateDuplicates");
let instances = Uint::new(instances);
let_field_of!(obj, axis);
let_field_of!(obj, center);
Some(Self {
@ -940,7 +939,6 @@ impl<'a> FromKclValue<'a> for super::patterns::CircularPattern2dData {
let_field_of!(obj, instances);
let_field_of!(obj, arc_degrees "arcDegrees");
let_field_of!(obj, rotate_duplicates "rotateDuplicates");
let instances = Uint::new(instances);
let_field_of!(obj, center);
Some(Self {
instances,
@ -956,7 +954,6 @@ impl<'a> FromKclValue<'a> for super::patterns::LinearPattern3dData {
let obj = arg.as_object()?;
let_field_of!(obj, distance);
let_field_of!(obj, instances);
let instances = Uint::new(instances);
let_field_of!(obj, axis);
Some(Self {
instances,
@ -971,7 +968,6 @@ impl<'a> FromKclValue<'a> for super::patterns::LinearPattern2dData {
let obj = arg.as_object()?;
let_field_of!(obj, distance);
let_field_of!(obj, instances);
let instances = Uint::new(instances);
let_field_of!(obj, axis);
Some(Self {
instances,
@ -1414,10 +1410,11 @@ impl<'a> FromKclValue<'a> for super::sketch::AngledLineData {
impl<'a> FromKclValue<'a> for i64 {
fn from_kcl_val(arg: &'a KclValue) -> Option<Self> {
let KclValue::Int { value, meta: _ } = arg else {
return None;
};
Some(*value)
match arg {
KclValue::Number { value, meta: _ } => crate::try_f64_to_i64(*value),
KclValue::Int { value, meta: _ } => Some(*value),
_ => None,
}
}
}
@ -1450,10 +1447,11 @@ impl<'a> FromKclValue<'a> for uuid::Uuid {
impl<'a> FromKclValue<'a> for u32 {
fn from_kcl_val(arg: &'a KclValue) -> Option<Self> {
let KclValue::Int { value, meta: _ } = arg else {
return None;
};
Some(*value as u32)
match arg {
KclValue::Number { value, meta: _ } => crate::try_f64_to_u32(*value),
KclValue::Int { value, meta: _ } => Some(*value as u32),
_ => None,
}
}
}
@ -1465,10 +1463,11 @@ impl<'a> FromKclValue<'a> for NonZeroU32 {
impl<'a> FromKclValue<'a> for u64 {
fn from_kcl_val(arg: &'a KclValue) -> Option<Self> {
let KclValue::Int { value, meta: _ } = arg else {
return None;
};
Some(*value as u64)
match arg {
KclValue::Number { value, meta: _ } => crate::try_f64_to_u64(*value),
KclValue::Int { value, meta: _ } => Some(*value as u64),
_ => None,
}
}
}
impl<'a> FromKclValue<'a> for f64 {

View File

@ -3,49 +3,22 @@
use derive_docs::stdlib;
use crate::{
errors::{KclError, KclErrorDetails},
executor::{ExecState, KclValue, SourceRange},
errors::KclError,
executor::{ExecState, KclValue},
std::Args,
};
#[derive(Debug, PartialEq, Eq)]
enum ConversionError {
Nan,
TooLarge,
}
impl ConversionError {
pub fn into_kcl_error(self, source_range: SourceRange) -> KclError {
match self {
ConversionError::Nan => KclError::Semantic(KclErrorDetails {
message: "NaN cannot be converted to an integer".to_owned(),
source_ranges: vec![source_range],
}),
ConversionError::TooLarge => KclError::Semantic(KclErrorDetails {
message: "Number is too large to convert to integer".to_owned(),
source_ranges: vec![source_range],
}),
}
}
}
/// Converts a number to integer.
pub async fn int(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let num = args.get_number()?;
let converted = inner_int(num).map_err(|err| err.into_kcl_error(args.source_range))?;
let converted = inner_int(num)?;
Ok(args.make_user_val_from_i64(converted))
Ok(args.make_user_val_from_f64(converted))
}
/// Convert a number to an integer.
///
/// Callers should use floor(), ceil(), or other rounding function first if they
/// care about how numbers with fractional parts are converted. If the number
/// has a fractional part, it's truncated, moving the number towards zero.
///
/// If the number is NaN or has a magnitude, either positive or negative, that
/// is too large to fit into the internal integer representation, the result is
/// a runtime error.
/// DEPRECATED use floor(), ceil(), or round().
///
/// ```no_run
/// let n = int(ceil(5/2))
@ -62,42 +35,6 @@ pub async fn int(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, Kc
name = "int",
tags = ["convert"],
}]
fn inner_int(num: f64) -> Result<i64, ConversionError> {
if num.is_nan() {
return Err(ConversionError::Nan);
}
if num > 2_f64.powi(53) || num < -(2_f64.powi(53)) {
// 2^53 is the largest magnitude integer that can be represented in f64
// and accurately converted.
return Err(ConversionError::TooLarge);
}
Ok(num as i64)
}
#[cfg(test)]
mod tests {
use core::f64;
use pretty_assertions::assert_eq;
use super::*;
#[test]
fn test_inner_int() {
assert_eq!(inner_int(0.0), Ok(0));
assert_eq!(inner_int(-0.0), Ok(0));
assert_eq!(inner_int(3.0), Ok(3));
assert_eq!(inner_int(2.5), Ok(2));
assert_eq!(inner_int(-2.5), Ok(-2));
assert_eq!(inner_int(f64::NAN), Err(ConversionError::Nan));
assert_eq!(inner_int(f64::INFINITY), Err(ConversionError::TooLarge));
assert_eq!(inner_int(f64::NEG_INFINITY), Err(ConversionError::TooLarge));
assert_eq!(inner_int(2_f64.powi(53)), Ok(2_i64.pow(53)));
assert_eq!(inner_int(-(2_f64.powi(53))), Ok(-(2_i64.pow(53))));
// Note: 2_f64.powi(53) + 1.0 can't be represented.
assert_eq!(inner_int(2_f64.powi(53) + 2.0), Err(ConversionError::TooLarge));
assert_eq!(inner_int(-(2_f64.powi(53)) - 2.0), Err(ConversionError::TooLarge));
assert_eq!(inner_int(-(2_f64.powi(64))), Err(ConversionError::TooLarge));
}
fn inner_int(num: f64) -> Result<f64, KclError> {
Ok(num)
}

View File

@ -23,9 +23,9 @@ pub async fn rem(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, Kc
/// If `num` is negative, the result will be too.
///
/// ```no_run
/// assertEqual(rem(int( 7), int(4)), 3, 0.01, "remainder is 3")
/// assertEqual(rem(int(-7), int(4)), -3, 0.01, "remainder is 3")
/// assertEqual(rem(int( 7), int(-4)), 3, 0.01, "remainder is 3")
/// assertEqual(rem(7, 4), 3, 0.01, "remainder is 3")
/// assertEqual(rem(-7, 4), -3, 0.01, "remainder is 3")
/// assertEqual(rem(7, -4), 3, 0.01, "remainder is 3")
/// ```
#[stdlib {
name = "rem",
@ -217,6 +217,34 @@ fn inner_abs(num: f64) -> Result<f64, KclError> {
Ok(num.abs())
}
/// Round a number to the nearest integer.
pub async fn round(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let num = args.get_number()?;
let result = inner_round(num)?;
Ok(args.make_user_val_from_f64(result))
}
/// Round a number to the nearest integer.
///
/// ```no_run
/// const sketch001 = startSketchOn('XZ')
/// |> startProfileAt([0, 0], %)
/// |> lineTo([12, 10], %)
/// |> line([round(7.02986), 0], %)
/// |> yLineTo(0, %)
/// |> close(%)
///
/// const extrude001 = extrude(5, sketch001)
/// ```
#[stdlib {
name = "round",
tags = ["math"],
}]
fn inner_round(num: f64) -> Result<f64, KclError> {
Ok(num.round())
}
/// Compute the largest integer less than or equal to a number.
pub async fn floor(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let num = args.get_number()?;

View File

@ -129,6 +129,7 @@ lazy_static! {
Box::new(crate::std::math::Sqrt),
Box::new(crate::std::math::Abs),
Box::new(crate::std::math::Rem),
Box::new(crate::std::math::Round),
Box::new(crate::std::math::Floor),
Box::new(crate::std::math::Ceil),
Box::new(crate::std::math::Min),

View File

@ -22,7 +22,7 @@ use crate::{
ExecState, Geometries, Geometry, KclValue, Point2d, Point3d, Sketch, SketchSet, Solid, SolidSet, SourceRange,
},
function_param::FunctionParam,
std::{types::Uint, Args},
std::Args,
};
use super::args::Arg;
@ -38,7 +38,7 @@ pub struct LinearPattern2dData {
/// This includes the original entity. For example, if instances is 2,
/// there will be two copies -- the original, and one new copy.
/// If instances is 1, this has no effect.
pub instances: Uint,
pub instances: u32,
/// The distance between each repetition. This can also be referred to as spacing.
pub distance: f64,
/// The axis of the pattern. This is a 2D vector.
@ -54,7 +54,7 @@ pub struct LinearPattern3dData {
/// This includes the original entity. For example, if instances is 2,
/// there will be two copies -- the original, and one new copy.
/// If instances is 1, this has no effect.
pub instances: Uint,
pub instances: u32,
/// The distance between each repetition. This can also be referred to as spacing.
pub distance: f64,
/// The axis of the pattern.
@ -712,7 +712,7 @@ async fn inner_pattern_linear_2d(
let [x, y] = axis;
let axis_len = f64::sqrt(x * x + y * y);
let normalized_axis = kcmc::shared::Point2d::from([x / axis_len, y / axis_len]);
let transforms: Vec<_> = (1..data.instances.u64())
let transforms: Vec<_> = (1..data.instances)
.map(|i| {
let d = data.distance * (i as f64);
let translate = (normalized_axis * d).with_z(0.0).map(LengthUnit);
@ -773,7 +773,7 @@ async fn inner_pattern_linear_3d(
let [x, y, z] = axis;
let axis_len = f64::sqrt(x * x + y * y + z * z);
let normalized_axis = kcmc::shared::Point3d::from([x / axis_len, y / axis_len, z / axis_len]);
let transforms: Vec<_> = (1..data.instances.u64())
let transforms: Vec<_> = (1..data.instances)
.map(|i| {
let d = data.distance * (i as f64);
let translate = (normalized_axis * d).map(LengthUnit);
@ -795,7 +795,7 @@ pub struct CircularPattern2dData {
/// This includes the original entity. For example, if instances is 2,
/// there will be two copies -- the original, and one new copy.
/// If instances is 1, this has no effect.
pub instances: Uint,
pub instances: u32,
/// The center about which to make the pattern. This is a 2D vector.
pub center: [f64; 2],
/// The arc angle (in degrees) to place the repetitions. Must be greater than 0.
@ -813,7 +813,7 @@ pub struct CircularPattern3dData {
/// This includes the original entity. For example, if instances is 2,
/// there will be two copies -- the original, and one new copy.
/// If instances is 1, this has no effect.
pub instances: Uint,
pub instances: u32,
/// The axis around which to make the pattern. This is a 3D vector.
pub axis: [f64; 3],
/// The center about which to make the pattern. This is a 3D vector.
@ -865,8 +865,8 @@ impl CircularPattern {
fn repetitions(&self) -> RepetitionsNeeded {
let n = match self {
CircularPattern::TwoD(lp) => lp.instances.u32(),
CircularPattern::ThreeD(lp) => lp.instances.u32(),
CircularPattern::TwoD(lp) => lp.instances,
CircularPattern::ThreeD(lp) => lp.instances,
};
RepetitionsNeeded::from(n)
}

View File

@ -1,41 +1 @@
//! Custom types for various standard library types.
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
/// A Uint that allows us to do math but rounds to a uint.
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Serialize, Deserialize, ts_rs::TS)]
#[ts(export)]
pub struct Uint(f64);
#[allow(dead_code)]
impl Uint {
pub fn new(value: f64) -> Self {
if value < 0.0 {
panic!("Uint cannot be negative");
}
Self(value)
}
pub fn value(&self) -> f64 {
self.0
}
pub fn u32(&self) -> u32 {
self.0.round() as u32
}
pub fn u64(&self) -> u64 {
self.0.round() as u64
}
}
impl JsonSchema for Uint {
fn schema_name() -> String {
"Uint".to_string()
}
fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
gen.subschema_for::<u32>()
}
}

View File

@ -217,14 +217,13 @@ impl VariableDeclaration {
impl Literal {
fn recast(&self) -> String {
match self.value {
LiteralValue::Fractional(x) => {
if x.fract() == 0.0 {
LiteralValue::Number(x) => {
if self.raw.contains('.') && x.fract() == 0.0 {
format!("{x:?}")
} else {
self.raw.clone()
}
}
LiteralValue::IInteger(_) => self.raw.clone(),
LiteralValue::String(ref s) => {
let quote = if self.raw.trim().starts_with('"') { '"' } else { '\'' };
format!("{quote}{s}{quote}")

View File

@ -1,5 +1,6 @@
---
source: kcl/src/simulation_tests.rs
assertion_line: 52
description: Result of parsing add_lots.kcl
snapshot_kind: text
---
@ -36,7 +37,7 @@ snapshot_kind: text
"start": 29,
"type": "Literal",
"type": "Literal",
"value": 2
"value": 2.0
},
"start": 25,
"type": "BinaryExpression",
@ -296,7 +297,7 @@ snapshot_kind: text
"start": 40,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
}
],
"callee": {
@ -320,7 +321,7 @@ snapshot_kind: text
"start": 47,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
}
],
"callee": {
@ -348,7 +349,7 @@ snapshot_kind: text
"start": 54,
"type": "Literal",
"type": "Literal",
"value": 2
"value": 2.0
}
],
"callee": {
@ -376,7 +377,7 @@ snapshot_kind: text
"start": 61,
"type": "Literal",
"type": "Literal",
"value": 3
"value": 3.0
}
],
"callee": {
@ -404,7 +405,7 @@ snapshot_kind: text
"start": 68,
"type": "Literal",
"type": "Literal",
"value": 4
"value": 4.0
}
],
"callee": {
@ -432,7 +433,7 @@ snapshot_kind: text
"start": 75,
"type": "Literal",
"type": "Literal",
"value": 5
"value": 5.0
}
],
"callee": {
@ -460,7 +461,7 @@ snapshot_kind: text
"start": 82,
"type": "Literal",
"type": "Literal",
"value": 6
"value": 6.0
}
],
"callee": {
@ -488,7 +489,7 @@ snapshot_kind: text
"start": 89,
"type": "Literal",
"type": "Literal",
"value": 7
"value": 7.0
}
],
"callee": {
@ -516,7 +517,7 @@ snapshot_kind: text
"start": 96,
"type": "Literal",
"type": "Literal",
"value": 8
"value": 8.0
}
],
"callee": {
@ -544,7 +545,7 @@ snapshot_kind: text
"start": 103,
"type": "Literal",
"type": "Literal",
"value": 9
"value": 9.0
}
],
"callee": {
@ -572,7 +573,7 @@ snapshot_kind: text
"start": 110,
"type": "Literal",
"type": "Literal",
"value": 10
"value": 10.0
}
],
"callee": {
@ -600,7 +601,7 @@ snapshot_kind: text
"start": 118,
"type": "Literal",
"type": "Literal",
"value": 11
"value": 11.0
}
],
"callee": {
@ -628,7 +629,7 @@ snapshot_kind: text
"start": 126,
"type": "Literal",
"type": "Literal",
"value": 12
"value": 12.0
}
],
"callee": {
@ -656,7 +657,7 @@ snapshot_kind: text
"start": 134,
"type": "Literal",
"type": "Literal",
"value": 13
"value": 13.0
}
],
"callee": {
@ -684,7 +685,7 @@ snapshot_kind: text
"start": 142,
"type": "Literal",
"type": "Literal",
"value": 14
"value": 14.0
}
],
"callee": {
@ -712,7 +713,7 @@ snapshot_kind: text
"start": 150,
"type": "Literal",
"type": "Literal",
"value": 15
"value": 15.0
}
],
"callee": {
@ -740,7 +741,7 @@ snapshot_kind: text
"start": 158,
"type": "Literal",
"type": "Literal",
"value": 16
"value": 16.0
}
],
"callee": {
@ -768,7 +769,7 @@ snapshot_kind: text
"start": 166,
"type": "Literal",
"type": "Literal",
"value": 17
"value": 17.0
}
],
"callee": {
@ -796,7 +797,7 @@ snapshot_kind: text
"start": 174,
"type": "Literal",
"type": "Literal",
"value": 18
"value": 18.0
}
],
"callee": {
@ -824,7 +825,7 @@ snapshot_kind: text
"start": 182,
"type": "Literal",
"type": "Literal",
"value": 19
"value": 19.0
}
],
"callee": {
@ -852,7 +853,7 @@ snapshot_kind: text
"start": 190,
"type": "Literal",
"type": "Literal",
"value": 20
"value": 20.0
}
],
"callee": {
@ -880,7 +881,7 @@ snapshot_kind: text
"start": 198,
"type": "Literal",
"type": "Literal",
"value": 21
"value": 21.0
}
],
"callee": {
@ -908,7 +909,7 @@ snapshot_kind: text
"start": 206,
"type": "Literal",
"type": "Literal",
"value": 22
"value": 22.0
}
],
"callee": {
@ -936,7 +937,7 @@ snapshot_kind: text
"start": 214,
"type": "Literal",
"type": "Literal",
"value": 23
"value": 23.0
}
],
"callee": {
@ -964,7 +965,7 @@ snapshot_kind: text
"start": 222,
"type": "Literal",
"type": "Literal",
"value": 24
"value": 24.0
}
],
"callee": {
@ -992,7 +993,7 @@ snapshot_kind: text
"start": 230,
"type": "Literal",
"type": "Literal",
"value": 25
"value": 25.0
}
],
"callee": {
@ -1020,7 +1021,7 @@ snapshot_kind: text
"start": 238,
"type": "Literal",
"type": "Literal",
"value": 26
"value": 26.0
}
],
"callee": {
@ -1048,7 +1049,7 @@ snapshot_kind: text
"start": 246,
"type": "Literal",
"type": "Literal",
"value": 27
"value": 27.0
}
],
"callee": {
@ -1076,7 +1077,7 @@ snapshot_kind: text
"start": 254,
"type": "Literal",
"type": "Literal",
"value": 28
"value": 28.0
}
],
"callee": {
@ -1104,7 +1105,7 @@ snapshot_kind: text
"start": 262,
"type": "Literal",
"type": "Literal",
"value": 29
"value": 29.0
}
],
"callee": {
@ -1132,7 +1133,7 @@ snapshot_kind: text
"start": 270,
"type": "Literal",
"type": "Literal",
"value": 30
"value": 30.0
}
],
"callee": {
@ -1160,7 +1161,7 @@ snapshot_kind: text
"start": 278,
"type": "Literal",
"type": "Literal",
"value": 31
"value": 31.0
}
],
"callee": {
@ -1188,7 +1189,7 @@ snapshot_kind: text
"start": 286,
"type": "Literal",
"type": "Literal",
"value": 32
"value": 32.0
}
],
"callee": {
@ -1216,7 +1217,7 @@ snapshot_kind: text
"start": 294,
"type": "Literal",
"type": "Literal",
"value": 33
"value": 33.0
}
],
"callee": {
@ -1244,7 +1245,7 @@ snapshot_kind: text
"start": 302,
"type": "Literal",
"type": "Literal",
"value": 34
"value": 34.0
}
],
"callee": {
@ -1272,7 +1273,7 @@ snapshot_kind: text
"start": 310,
"type": "Literal",
"type": "Literal",
"value": 35
"value": 35.0
}
],
"callee": {
@ -1300,7 +1301,7 @@ snapshot_kind: text
"start": 318,
"type": "Literal",
"type": "Literal",
"value": 36
"value": 36.0
}
],
"callee": {
@ -1328,7 +1329,7 @@ snapshot_kind: text
"start": 326,
"type": "Literal",
"type": "Literal",
"value": 37
"value": 37.0
}
],
"callee": {
@ -1356,7 +1357,7 @@ snapshot_kind: text
"start": 334,
"type": "Literal",
"type": "Literal",
"value": 38
"value": 38.0
}
],
"callee": {
@ -1384,7 +1385,7 @@ snapshot_kind: text
"start": 342,
"type": "Literal",
"type": "Literal",
"value": 39
"value": 39.0
}
],
"callee": {
@ -1412,7 +1413,7 @@ snapshot_kind: text
"start": 350,
"type": "Literal",
"type": "Literal",
"value": 40
"value": 40.0
}
],
"callee": {
@ -1440,7 +1441,7 @@ snapshot_kind: text
"start": 358,
"type": "Literal",
"type": "Literal",
"value": 41
"value": 41.0
}
],
"callee": {
@ -1468,7 +1469,7 @@ snapshot_kind: text
"start": 366,
"type": "Literal",
"type": "Literal",
"value": 42
"value": 42.0
}
],
"callee": {
@ -1496,7 +1497,7 @@ snapshot_kind: text
"start": 374,
"type": "Literal",
"type": "Literal",
"value": 43
"value": 43.0
}
],
"callee": {
@ -1524,7 +1525,7 @@ snapshot_kind: text
"start": 382,
"type": "Literal",
"type": "Literal",
"value": 44
"value": 44.0
}
],
"callee": {
@ -1552,7 +1553,7 @@ snapshot_kind: text
"start": 390,
"type": "Literal",
"type": "Literal",
"value": 45
"value": 45.0
}
],
"callee": {
@ -1580,7 +1581,7 @@ snapshot_kind: text
"start": 398,
"type": "Literal",
"type": "Literal",
"value": 46
"value": 46.0
}
],
"callee": {
@ -1608,7 +1609,7 @@ snapshot_kind: text
"start": 406,
"type": "Literal",
"type": "Literal",
"value": 47
"value": 47.0
}
],
"callee": {
@ -1636,7 +1637,7 @@ snapshot_kind: text
"start": 414,
"type": "Literal",
"type": "Literal",
"value": 48
"value": 48.0
}
],
"callee": {
@ -1664,7 +1665,7 @@ snapshot_kind: text
"start": 422,
"type": "Literal",
"type": "Literal",
"value": 49
"value": 49.0
}
],
"callee": {
@ -1692,7 +1693,7 @@ snapshot_kind: text
"start": 430,
"type": "Literal",
"type": "Literal",
"value": 50
"value": 50.0
}
],
"callee": {
@ -1720,7 +1721,7 @@ snapshot_kind: text
"start": 438,
"type": "Literal",
"type": "Literal",
"value": 51
"value": 51.0
}
],
"callee": {
@ -1748,7 +1749,7 @@ snapshot_kind: text
"start": 446,
"type": "Literal",
"type": "Literal",
"value": 52
"value": 52.0
}
],
"callee": {
@ -1776,7 +1777,7 @@ snapshot_kind: text
"start": 454,
"type": "Literal",
"type": "Literal",
"value": 53
"value": 53.0
}
],
"callee": {
@ -1804,7 +1805,7 @@ snapshot_kind: text
"start": 462,
"type": "Literal",
"type": "Literal",
"value": 54
"value": 54.0
}
],
"callee": {
@ -1832,7 +1833,7 @@ snapshot_kind: text
"start": 470,
"type": "Literal",
"type": "Literal",
"value": 55
"value": 55.0
}
],
"callee": {
@ -1860,7 +1861,7 @@ snapshot_kind: text
"start": 478,
"type": "Literal",
"type": "Literal",
"value": 56
"value": 56.0
}
],
"callee": {
@ -1888,7 +1889,7 @@ snapshot_kind: text
"start": 486,
"type": "Literal",
"type": "Literal",
"value": 57
"value": 57.0
}
],
"callee": {
@ -1916,7 +1917,7 @@ snapshot_kind: text
"start": 494,
"type": "Literal",
"type": "Literal",
"value": 58
"value": 58.0
}
],
"callee": {
@ -1944,7 +1945,7 @@ snapshot_kind: text
"start": 502,
"type": "Literal",
"type": "Literal",
"value": 59
"value": 59.0
}
],
"callee": {
@ -1972,7 +1973,7 @@ snapshot_kind: text
"start": 510,
"type": "Literal",
"type": "Literal",
"value": 60
"value": 60.0
}
],
"callee": {
@ -2000,7 +2001,7 @@ snapshot_kind: text
"start": 518,
"type": "Literal",
"type": "Literal",
"value": 61
"value": 61.0
}
],
"callee": {
@ -2028,7 +2029,7 @@ snapshot_kind: text
"start": 526,
"type": "Literal",
"type": "Literal",
"value": 62
"value": 62.0
}
],
"callee": {
@ -2056,7 +2057,7 @@ snapshot_kind: text
"start": 534,
"type": "Literal",
"type": "Literal",
"value": 63
"value": 63.0
}
],
"callee": {
@ -2084,7 +2085,7 @@ snapshot_kind: text
"start": 542,
"type": "Literal",
"type": "Literal",
"value": 64
"value": 64.0
}
],
"callee": {
@ -2112,7 +2113,7 @@ snapshot_kind: text
"start": 550,
"type": "Literal",
"type": "Literal",
"value": 65
"value": 65.0
}
],
"callee": {
@ -2140,7 +2141,7 @@ snapshot_kind: text
"start": 558,
"type": "Literal",
"type": "Literal",
"value": 66
"value": 66.0
}
],
"callee": {
@ -2168,7 +2169,7 @@ snapshot_kind: text
"start": 566,
"type": "Literal",
"type": "Literal",
"value": 67
"value": 67.0
}
],
"callee": {
@ -2196,7 +2197,7 @@ snapshot_kind: text
"start": 574,
"type": "Literal",
"type": "Literal",
"value": 68
"value": 68.0
}
],
"callee": {
@ -2224,7 +2225,7 @@ snapshot_kind: text
"start": 582,
"type": "Literal",
"type": "Literal",
"value": 69
"value": 69.0
}
],
"callee": {
@ -2252,7 +2253,7 @@ snapshot_kind: text
"start": 590,
"type": "Literal",
"type": "Literal",
"value": 70
"value": 70.0
}
],
"callee": {
@ -2280,7 +2281,7 @@ snapshot_kind: text
"start": 598,
"type": "Literal",
"type": "Literal",
"value": 71
"value": 71.0
}
],
"callee": {
@ -2308,7 +2309,7 @@ snapshot_kind: text
"start": 606,
"type": "Literal",
"type": "Literal",
"value": 72
"value": 72.0
}
],
"callee": {
@ -2336,7 +2337,7 @@ snapshot_kind: text
"start": 614,
"type": "Literal",
"type": "Literal",
"value": 73
"value": 73.0
}
],
"callee": {
@ -2364,7 +2365,7 @@ snapshot_kind: text
"start": 622,
"type": "Literal",
"type": "Literal",
"value": 74
"value": 74.0
}
],
"callee": {
@ -2392,7 +2393,7 @@ snapshot_kind: text
"start": 630,
"type": "Literal",
"type": "Literal",
"value": 75
"value": 75.0
}
],
"callee": {
@ -2420,7 +2421,7 @@ snapshot_kind: text
"start": 638,
"type": "Literal",
"type": "Literal",
"value": 76
"value": 76.0
}
],
"callee": {
@ -2448,7 +2449,7 @@ snapshot_kind: text
"start": 646,
"type": "Literal",
"type": "Literal",
"value": 77
"value": 77.0
}
],
"callee": {
@ -2476,7 +2477,7 @@ snapshot_kind: text
"start": 654,
"type": "Literal",
"type": "Literal",
"value": 78
"value": 78.0
}
],
"callee": {
@ -2504,7 +2505,7 @@ snapshot_kind: text
"start": 662,
"type": "Literal",
"type": "Literal",
"value": 79
"value": 79.0
}
],
"callee": {
@ -2532,7 +2533,7 @@ snapshot_kind: text
"start": 670,
"type": "Literal",
"type": "Literal",
"value": 80
"value": 80.0
}
],
"callee": {
@ -2560,7 +2561,7 @@ snapshot_kind: text
"start": 678,
"type": "Literal",
"type": "Literal",
"value": 81
"value": 81.0
}
],
"callee": {
@ -2588,7 +2589,7 @@ snapshot_kind: text
"start": 686,
"type": "Literal",
"type": "Literal",
"value": 82
"value": 82.0
}
],
"callee": {
@ -2616,7 +2617,7 @@ snapshot_kind: text
"start": 694,
"type": "Literal",
"type": "Literal",
"value": 83
"value": 83.0
}
],
"callee": {
@ -2644,7 +2645,7 @@ snapshot_kind: text
"start": 702,
"type": "Literal",
"type": "Literal",
"value": 84
"value": 84.0
}
],
"callee": {
@ -2672,7 +2673,7 @@ snapshot_kind: text
"start": 710,
"type": "Literal",
"type": "Literal",
"value": 85
"value": 85.0
}
],
"callee": {
@ -2700,7 +2701,7 @@ snapshot_kind: text
"start": 718,
"type": "Literal",
"type": "Literal",
"value": 86
"value": 86.0
}
],
"callee": {
@ -2728,7 +2729,7 @@ snapshot_kind: text
"start": 726,
"type": "Literal",
"type": "Literal",
"value": 87
"value": 87.0
}
],
"callee": {
@ -2756,7 +2757,7 @@ snapshot_kind: text
"start": 734,
"type": "Literal",
"type": "Literal",
"value": 88
"value": 88.0
}
],
"callee": {
@ -2784,7 +2785,7 @@ snapshot_kind: text
"start": 742,
"type": "Literal",
"type": "Literal",
"value": 89
"value": 89.0
}
],
"callee": {
@ -2812,7 +2813,7 @@ snapshot_kind: text
"start": 750,
"type": "Literal",
"type": "Literal",
"value": 90
"value": 90.0
}
],
"callee": {
@ -2840,7 +2841,7 @@ snapshot_kind: text
"start": 758,
"type": "Literal",
"type": "Literal",
"value": 91
"value": 91.0
}
],
"callee": {
@ -2868,7 +2869,7 @@ snapshot_kind: text
"start": 766,
"type": "Literal",
"type": "Literal",
"value": 92
"value": 92.0
}
],
"callee": {
@ -2896,7 +2897,7 @@ snapshot_kind: text
"start": 774,
"type": "Literal",
"type": "Literal",
"value": 93
"value": 93.0
}
],
"callee": {
@ -2924,7 +2925,7 @@ snapshot_kind: text
"start": 782,
"type": "Literal",
"type": "Literal",
"value": 94
"value": 94.0
}
],
"callee": {
@ -2952,7 +2953,7 @@ snapshot_kind: text
"start": 790,
"type": "Literal",
"type": "Literal",
"value": 95
"value": 95.0
}
],
"callee": {
@ -2980,7 +2981,7 @@ snapshot_kind: text
"start": 798,
"type": "Literal",
"type": "Literal",
"value": 96
"value": 96.0
}
],
"callee": {
@ -3008,7 +3009,7 @@ snapshot_kind: text
"start": 806,
"type": "Literal",
"type": "Literal",
"value": 97
"value": 97.0
}
],
"callee": {
@ -3036,7 +3037,7 @@ snapshot_kind: text
"start": 814,
"type": "Literal",
"type": "Literal",
"value": 98
"value": 98.0
}
],
"callee": {
@ -3064,7 +3065,7 @@ snapshot_kind: text
"start": 822,
"type": "Literal",
"type": "Literal",
"value": 99
"value": 99.0
}
],
"callee": {
@ -3092,7 +3093,7 @@ snapshot_kind: text
"start": 830,
"type": "Literal",
"type": "Literal",
"value": 100
"value": 100.0
}
],
"callee": {
@ -3138,7 +3139,7 @@ snapshot_kind: text
"start": 851,
"type": "Literal",
"type": "Literal",
"value": 10100
"value": 10100.0
},
{
"end": 861,

View File

@ -1,5 +1,6 @@
---
source: kcl/src/simulation_tests.rs
assertion_line: 92
description: Program memory after executing add_lots.kcl
snapshot_kind: text
---
@ -49,7 +50,7 @@ snapshot_kind: text
"start": 29,
"type": "Literal",
"type": "Literal",
"value": 2
"value": 2.0
},
"start": 25,
"type": "BinaryExpression",

View File

@ -1,5 +1,6 @@
---
source: kcl/src/simulation_tests.rs
assertion_line: 52
description: Result of parsing angled_line.kcl
snapshot_kind: text
---
@ -389,7 +390,7 @@ snapshot_kind: text
"start": 260,
"type": "Literal",
"type": "Literal",
"value": 4
"value": 4.0
},
{
"end": 264,

View File

@ -1,6 +1,8 @@
---
source: kcl/src/simulation_tests.rs
assertion_line: 52
description: Result of parsing argument_error.kcl
snapshot_kind: text
---
{
"Ok": {
@ -25,7 +27,7 @@ description: Result of parsing argument_error.kcl
"start": 25,
"type": "Literal",
"type": "Literal",
"value": 5
"value": 5.0
},
"end": 26,
"start": 18,
@ -82,7 +84,7 @@ description: Result of parsing argument_error.kcl
"start": 38,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
},
{
"end": 42,
@ -90,7 +92,7 @@ description: Result of parsing argument_error.kcl
"start": 41,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
}
],
"end": 43,

View File

@ -1,5 +1,6 @@
---
source: kcl/src/simulation_tests.rs
assertion_line: 52
description: Result of parsing array_elem_push.kcl
snapshot_kind: text
---
@ -24,7 +25,7 @@ snapshot_kind: text
"start": 7,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
},
{
"end": 11,
@ -32,7 +33,7 @@ snapshot_kind: text
"start": 10,
"type": "Literal",
"type": "Literal",
"value": 2
"value": 2.0
},
{
"end": 14,
@ -40,7 +41,7 @@ snapshot_kind: text
"start": 13,
"type": "Literal",
"type": "Literal",
"value": 3
"value": 3.0
}
],
"end": 15,
@ -83,7 +84,7 @@ snapshot_kind: text
"start": 37,
"type": "Literal",
"type": "Literal",
"value": 4
"value": 4.0
}
],
"callee": {
@ -133,7 +134,7 @@ snapshot_kind: text
"start": 66,
"type": "Literal",
"type": "Literal",
"value": 5
"value": 5.0
}
],
"callee": {
@ -178,7 +179,7 @@ snapshot_kind: text
"start": 90,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
},
"start": 81,
"type": "MemberExpression",
@ -190,7 +191,7 @@ snapshot_kind: text
"start": 94,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
},
{
"end": 104,
@ -245,7 +246,7 @@ snapshot_kind: text
"start": 164,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
},
"start": 155,
"type": "MemberExpression",
@ -257,7 +258,7 @@ snapshot_kind: text
"start": 168,
"type": "Literal",
"type": "Literal",
"value": 2
"value": 2.0
},
{
"end": 178,
@ -312,7 +313,7 @@ snapshot_kind: text
"start": 238,
"type": "Literal",
"type": "Literal",
"value": 2
"value": 2.0
},
"start": 229,
"type": "MemberExpression",
@ -324,7 +325,7 @@ snapshot_kind: text
"start": 242,
"type": "Literal",
"type": "Literal",
"value": 3
"value": 3.0
},
{
"end": 252,
@ -379,7 +380,7 @@ snapshot_kind: text
"start": 312,
"type": "Literal",
"type": "Literal",
"value": 3
"value": 3.0
},
"start": 303,
"type": "MemberExpression",
@ -391,7 +392,7 @@ snapshot_kind: text
"start": 316,
"type": "Literal",
"type": "Literal",
"value": 4
"value": 4.0
},
{
"end": 326,
@ -446,7 +447,7 @@ snapshot_kind: text
"start": 388,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
},
"start": 379,
"type": "MemberExpression",
@ -458,7 +459,7 @@ snapshot_kind: text
"start": 392,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
},
{
"end": 402,
@ -513,7 +514,7 @@ snapshot_kind: text
"start": 462,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
},
"start": 453,
"type": "MemberExpression",
@ -525,7 +526,7 @@ snapshot_kind: text
"start": 466,
"type": "Literal",
"type": "Literal",
"value": 2
"value": 2.0
},
{
"end": 476,
@ -580,7 +581,7 @@ snapshot_kind: text
"start": 536,
"type": "Literal",
"type": "Literal",
"value": 2
"value": 2.0
},
"start": 527,
"type": "MemberExpression",
@ -592,7 +593,7 @@ snapshot_kind: text
"start": 540,
"type": "Literal",
"type": "Literal",
"value": 3
"value": 3.0
},
{
"end": 550,
@ -647,7 +648,7 @@ snapshot_kind: text
"start": 610,
"type": "Literal",
"type": "Literal",
"value": 3
"value": 3.0
},
"start": 601,
"type": "MemberExpression",
@ -659,7 +660,7 @@ snapshot_kind: text
"start": 614,
"type": "Literal",
"type": "Literal",
"value": 4
"value": 4.0
},
{
"end": 624,
@ -714,7 +715,7 @@ snapshot_kind: text
"start": 686,
"type": "Literal",
"type": "Literal",
"value": 4
"value": 4.0
},
"start": 677,
"type": "MemberExpression",
@ -726,7 +727,7 @@ snapshot_kind: text
"start": 690,
"type": "Literal",
"type": "Literal",
"value": 5
"value": 5.0
},
{
"end": 700,

View File

@ -1,5 +1,6 @@
---
source: kcl/src/simulation_tests.rs
assertion_line: 92
description: Program memory after executing array_elem_push.kcl
snapshot_kind: text
---
@ -31,8 +32,8 @@ snapshot_kind: text
"type": "Array",
"value": [
{
"type": "Int",
"value": 1,
"type": "Number",
"value": 1.0,
"__meta": [
{
"sourceRange": [
@ -44,8 +45,8 @@ snapshot_kind: text
]
},
{
"type": "Int",
"value": 2,
"type": "Number",
"value": 2.0,
"__meta": [
{
"sourceRange": [
@ -57,8 +58,8 @@ snapshot_kind: text
]
},
{
"type": "Int",
"value": 3,
"type": "Number",
"value": 3.0,
"__meta": [
{
"sourceRange": [
@ -84,8 +85,8 @@ snapshot_kind: text
"type": "Array",
"value": [
{
"type": "Int",
"value": 1,
"type": "Number",
"value": 1.0,
"__meta": [
{
"sourceRange": [
@ -97,8 +98,8 @@ snapshot_kind: text
]
},
{
"type": "Int",
"value": 2,
"type": "Number",
"value": 2.0,
"__meta": [
{
"sourceRange": [
@ -110,8 +111,8 @@ snapshot_kind: text
]
},
{
"type": "Int",
"value": 3,
"type": "Number",
"value": 3.0,
"__meta": [
{
"sourceRange": [
@ -123,8 +124,8 @@ snapshot_kind: text
]
},
{
"type": "Int",
"value": 4,
"type": "Number",
"value": 4.0,
"__meta": [
{
"sourceRange": [
@ -150,8 +151,8 @@ snapshot_kind: text
"type": "Array",
"value": [
{
"type": "Int",
"value": 1,
"type": "Number",
"value": 1.0,
"__meta": [
{
"sourceRange": [
@ -163,8 +164,8 @@ snapshot_kind: text
]
},
{
"type": "Int",
"value": 2,
"type": "Number",
"value": 2.0,
"__meta": [
{
"sourceRange": [
@ -176,8 +177,8 @@ snapshot_kind: text
]
},
{
"type": "Int",
"value": 3,
"type": "Number",
"value": 3.0,
"__meta": [
{
"sourceRange": [
@ -189,8 +190,8 @@ snapshot_kind: text
]
},
{
"type": "Int",
"value": 4,
"type": "Number",
"value": 4.0,
"__meta": [
{
"sourceRange": [
@ -202,8 +203,8 @@ snapshot_kind: text
]
},
{
"type": "Int",
"value": 5,
"type": "Number",
"value": 5.0,
"__meta": [
{
"sourceRange": [

View File

@ -1,5 +1,6 @@
---
source: kcl/src/simulation_tests.rs
assertion_line: 52
description: Result of parsing array_elem_push_fail.kcl
snapshot_kind: text
---
@ -24,7 +25,7 @@ snapshot_kind: text
"start": 7,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
},
{
"end": 11,
@ -32,7 +33,7 @@ snapshot_kind: text
"start": 10,
"type": "Literal",
"type": "Literal",
"value": 2
"value": 2.0
},
{
"end": 14,
@ -40,7 +41,7 @@ snapshot_kind: text
"start": 13,
"type": "Literal",
"type": "Literal",
"value": 3
"value": 3.0
}
],
"end": 15,
@ -83,7 +84,7 @@ snapshot_kind: text
"start": 38,
"type": "Literal",
"type": "Literal",
"value": 4
"value": 4.0
}
],
"callee": {
@ -134,7 +135,7 @@ snapshot_kind: text
"start": 52,
"type": "Literal",
"type": "Literal",
"value": 3
"value": 3.0
},
"start": 48,
"type": "MemberExpression",

View File

@ -1,5 +1,6 @@
---
source: kcl/src/simulation_tests.rs
assertion_line: 52
description: Result of parsing array_index_oob.kcl
snapshot_kind: text
---
@ -59,7 +60,7 @@ snapshot_kind: text
"start": 17,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
},
"start": 13,
"type": "MemberExpression",

View File

@ -1,7 +1,6 @@
---
source: kcl/src/simulation_tests.rs
description: Result of parsing array_range_expr.kcl
snapshot_kind: text
---
{
"Ok": {
@ -24,7 +23,7 @@ snapshot_kind: text
"start": 9,
"type": "Literal",
"type": "Literal",
"value": 4
"value": 4.0
},
"endInclusive": true,
"start": 5,
@ -34,7 +33,7 @@ snapshot_kind: text
"start": 6,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
},
"type": "ArrayRangeExpression",
"type": "ArrayRangeExpression"
@ -69,7 +68,7 @@ snapshot_kind: text
"start": 27,
"type": "Literal",
"type": "Literal",
"value": 4
"value": 4.0
},
"start": 24,
"type": "MemberExpression",
@ -81,7 +80,7 @@ snapshot_kind: text
"start": 31,
"type": "Literal",
"type": "Literal",
"value": 4
"value": 4.0
},
{
"end": 41,
@ -132,7 +131,7 @@ snapshot_kind: text
"start": 79,
"type": "Literal",
"type": "Literal",
"value": 4
"value": 4.0
},
"start": 72,
"type": "VariableDeclarator"
@ -160,7 +159,7 @@ snapshot_kind: text
"start": 88,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
},
"start": 81,
"type": "VariableDeclarator"
@ -233,7 +232,7 @@ snapshot_kind: text
"start": 123,
"type": "Literal",
"type": "Literal",
"value": 4
"value": 4.0
},
"start": 120,
"type": "MemberExpression",
@ -245,7 +244,7 @@ snapshot_kind: text
"start": 127,
"type": "Literal",
"type": "Literal",
"value": 4
"value": 4.0
},
{
"end": 137,
@ -308,7 +307,7 @@ snapshot_kind: text
"start": 186,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
},
"start": 179,
"type": "BinaryExpression",
@ -398,7 +397,7 @@ snapshot_kind: text
"start": 222,
"type": "Literal",
"type": "Literal",
"value": 4
"value": 4.0
},
"start": 219,
"type": "MemberExpression",
@ -410,7 +409,7 @@ snapshot_kind: text
"start": 226,
"type": "Literal",
"type": "Literal",
"value": 4
"value": 4.0
},
{
"end": 236,
@ -465,7 +464,7 @@ snapshot_kind: text
"start": 291,
"type": "Literal",
"type": "Literal",
"value": 5
"value": 5.0
},
"start": 288,
"type": "MemberExpression",
@ -477,7 +476,7 @@ snapshot_kind: text
"start": 295,
"type": "Literal",
"type": "Literal",
"value": 5
"value": 5.0
},
{
"end": 305,
@ -542,7 +541,7 @@ snapshot_kind: text
"start": 370,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
},
"start": 363,
"type": "BinaryExpression",
@ -581,7 +580,7 @@ snapshot_kind: text
"start": 353,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
},
"start": 346,
"type": "BinaryExpression",
@ -633,7 +632,7 @@ snapshot_kind: text
"start": 389,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
},
"start": 386,
"type": "MemberExpression",
@ -645,7 +644,7 @@ snapshot_kind: text
"start": 393,
"type": "Literal",
"type": "Literal",
"value": 1
"value": 1.0
},
{
"end": 403,
@ -700,7 +699,7 @@ snapshot_kind: text
"start": 442,
"type": "Literal",
"type": "Literal",
"value": 2
"value": 2.0
},
"start": 439,
"type": "MemberExpression",
@ -712,7 +711,7 @@ snapshot_kind: text
"start": 446,
"type": "Literal",
"type": "Literal",
"value": 3
"value": 3.0
},
{
"end": 456,
@ -767,7 +766,7 @@ snapshot_kind: text
"start": 504,
"type": "Literal",
"type": "Literal",
"value": 3
"value": 3.0
},
"start": 501,
"type": "MemberExpression",
@ -779,7 +778,7 @@ snapshot_kind: text
"start": 508,
"type": "Literal",
"type": "Literal",
"value": 4
"value": 4.0
},
{
"end": 518,

View File

@ -1,5 +1,6 @@
---
source: kcl/src/simulation_tests.rs
assertion_line: 92
description: Program memory after executing array_range_expr.kcl
snapshot_kind: text
---
@ -28,8 +29,8 @@ snapshot_kind: text
"__meta": []
},
"five": {
"type": "Int",
"value": 5,
"type": "Number",
"value": 5.0,
"__meta": [
{
"sourceRange": [
@ -41,8 +42,8 @@ snapshot_kind: text
]
},
"four": {
"type": "Int",
"value": 4,
"type": "Number",
"value": 4.0,
"__meta": [
{
"sourceRange": [
@ -370,8 +371,8 @@ snapshot_kind: text
]
},
"zero": {
"type": "Int",
"value": 0,
"type": "Number",
"value": 0.0,
"__meta": [
{
"sourceRange": [

View File

@ -1,7 +1,6 @@
---
source: kcl/src/simulation_tests.rs
description: Result of parsing array_range_negative_expr.kcl
snapshot_kind: text
---
{
"Ok": {
@ -24,7 +23,7 @@ snapshot_kind: text
"start": 17,
"type": "Literal",
"type": "Literal",
"value": 5
"value": 5.0
},
"endInclusive": true,
"start": 5,
@ -37,7 +36,7 @@ snapshot_kind: text
"start": 11,
"type": "Literal",
"type": "Literal",
"value": 5
"value": 5.0
},
"end": 12,
"operator": "-",
@ -91,7 +90,7 @@ snapshot_kind: text
"start": 35,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
},
"start": 32,
"type": "MemberExpression",
@ -104,7 +103,7 @@ snapshot_kind: text
"start": 40,
"type": "Literal",
"type": "Literal",
"value": 5
"value": 5.0
},
"end": 41,
"operator": "-",

View File

@ -1,5 +1,6 @@
---
source: kcl/src/simulation_tests.rs
assertion_line: 92
description: Program memory after executing array_range_negative_expr.kcl
snapshot_kind: text
---

View File

@ -1,6 +1,6 @@
---
source: kcl/src/simulation_tests.rs
assertion_line: 65
assertion_line: 52
description: Result of parsing basic_fillet_cube_close_opposite.kcl
snapshot_kind: text
---
@ -52,7 +52,7 @@ snapshot_kind: text
"start": 51,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
},
{
"end": 55,
@ -60,7 +60,7 @@ snapshot_kind: text
"start": 54,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
}
],
"end": 56,
@ -97,7 +97,7 @@ snapshot_kind: text
"start": 72,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
},
{
"end": 77,
@ -105,7 +105,7 @@ snapshot_kind: text
"start": 75,
"type": "Literal",
"type": "Literal",
"value": 10
"value": 10.0
}
],
"end": 78,
@ -149,7 +149,7 @@ snapshot_kind: text
"start": 102,
"type": "Literal",
"type": "Literal",
"value": 10
"value": 10.0
},
{
"end": 107,
@ -157,7 +157,7 @@ snapshot_kind: text
"start": 106,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
}
],
"end": 108,
@ -194,7 +194,7 @@ snapshot_kind: text
"start": 124,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
},
{
"argument": {
@ -203,7 +203,7 @@ snapshot_kind: text
"start": 128,
"type": "Literal",
"type": "Literal",
"value": 10
"value": 10.0
},
"end": 130,
"operator": "-",
@ -279,7 +279,7 @@ snapshot_kind: text
"start": 181,
"type": "Literal",
"type": "Literal",
"value": 10
"value": 10.0
},
{
"end": 186,
@ -321,7 +321,7 @@ snapshot_kind: text
"start": 218,
"type": "Literal",
"type": "Literal",
"value": 2
"value": 2.0
}
},
{

View File

@ -1,6 +1,6 @@
---
source: kcl/src/simulation_tests.rs
assertion_line: 65
assertion_line: 52
description: Result of parsing basic_fillet_cube_end.kcl
snapshot_kind: text
---
@ -52,7 +52,7 @@ snapshot_kind: text
"start": 51,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
},
{
"end": 55,
@ -60,7 +60,7 @@ snapshot_kind: text
"start": 54,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
}
],
"end": 56,
@ -97,7 +97,7 @@ snapshot_kind: text
"start": 72,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
},
{
"end": 77,
@ -105,7 +105,7 @@ snapshot_kind: text
"start": 75,
"type": "Literal",
"type": "Literal",
"value": 10
"value": 10.0
}
],
"end": 78,
@ -149,7 +149,7 @@ snapshot_kind: text
"start": 102,
"type": "Literal",
"type": "Literal",
"value": 10
"value": 10.0
},
{
"end": 107,
@ -157,7 +157,7 @@ snapshot_kind: text
"start": 106,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
}
],
"end": 108,
@ -194,7 +194,7 @@ snapshot_kind: text
"start": 124,
"type": "Literal",
"type": "Literal",
"value": 0
"value": 0.0
},
{
"argument": {
@ -203,7 +203,7 @@ snapshot_kind: text
"start": 128,
"type": "Literal",
"type": "Literal",
"value": 10
"value": 10.0
},
"end": 130,
"operator": "-",
@ -272,7 +272,7 @@ snapshot_kind: text
"start": 172,
"type": "Literal",
"type": "Literal",
"value": 10
"value": 10.0
},
{
"end": 177,
@ -314,7 +314,7 @@ snapshot_kind: text
"start": 209,
"type": "Literal",
"type": "Literal",
"value": 2
"value": 2.0
}
},
{

Some files were not shown because too many files have changed in this diff Show More