changed length() to len()

This commit is contained in:
damirka 2021-09-10 16:55:32 +03:00
parent 093517109b
commit 158576f8f5
18 changed files with 18 additions and 90 deletions

View File

@ -118,7 +118,7 @@ In order to do something with the array, e.g. add all its elements and return th
Thus, this RFC also proposed to extend Leo with such an operator.
A possibility is `<expression>.length`, where `<expression>` is an expression of array type.
A variation is `<expression>.length()`, if we want it look more like a built-in method on arrays.
A variation is `<expression>.len()`, if we want it look more like a built-in method on arrays.
Yet another option is `length(<expression>)`, which is more like a built-in function.
A shorter name could be `len`, leading to the three possibilities
`<expression>.len`, `<expression>.len()`, and `len(<expression>)`.
@ -155,4 +155,4 @@ None.
# Alternatives
None.
None.

View File

@ -838,7 +838,7 @@ create_errors!(
@formatted
lengthof_can_only_be_used_on_arrays {
args: (),
msg: "length() can only be called on an array value".to_string(),
msg: "len() can only be called on an array value".to_string(),
help: None,
}
);

View File

@ -388,7 +388,7 @@ impl Token {
return (len, Some(Token::DotDotDot));
} else if let Some(len) = eat(input, "..") {
return (len, Some(Token::DotDot));
} else if let Some(len) = eat(input, ".length()") {
} else if let Some(len) = eat(input, ".len()") {
// FIXME: remove this code once we allow method calls
return (len, Some(Token::LengthOf));
}

View File

@ -141,7 +141,7 @@ pub enum Token {
Type,
// Not yet in ABNF
// arr.length() token - hacky zone
// arr.len() token - hacky zone
LengthOf,
// Not yet in ABNF
@ -313,7 +313,7 @@ impl fmt::Display for Token {
Static => write!(f, "static"),
String => write!(f, "string"),
Type => write!(f, "type"),
LengthOf => write!(f, ".length()"), // FIXME
LengthOf => write!(f, ".len()"), // FIXME
Eof => write!(f, ""),
// BitAnd => write!(f, "&"),
// BitAndEq => write!(f, "&="),

View File

@ -5,5 +5,5 @@ input_file: input/dummy.in
*/
function main(a: [char; 11], y: bool) -> bool {
return y == (a.length() == 11);
return y == (a.len() == 11);
}

View File

@ -5,5 +5,5 @@ input_file: input/dummy.in
*/
function main(y: bool) {
return 10.length() == 10u8;
return (10u8.len() == 10u32) == y;
}

View File

@ -13,5 +13,5 @@ function main(y: bool) -> bool {
}
function strlen(str: [char; _]) -> u32 {
return str.length();
return str.len();
}

View File

@ -1,5 +0,0 @@
---
namespace: Compile
expectation: Fail
outputs:
- "Error [EASG0373047]: a function input cannot be named `x` as a alias with that name already exists in this scope\n --> compiler-test:5:15\n |\n 5 | function main(x: u32, y: bool) -> bool {\n | ^"

View File

@ -1,5 +0,0 @@
---
namespace: Compile
expectation: Fail
outputs:
- "Error [EASG0373047]: a function input cannot be named `int` as a alias with that name already exists in this scope\n --> compiler-test:6:9\n |\n 6 | let int: int = 1u32;\n | ^^^"

View File

@ -16,7 +16,7 @@ outputs:
r0:
type: bool
value: "true"
initial_ast: f8b64e1675dcb9624011ccf7a6ee9cd4fd7767f9fffbea3c87cbb21cbe734d67
imports_resolved_ast: f8b64e1675dcb9624011ccf7a6ee9cd4fd7767f9fffbea3c87cbb21cbe734d67
canonicalized_ast: f8b64e1675dcb9624011ccf7a6ee9cd4fd7767f9fffbea3c87cbb21cbe734d67
type_inferenced_ast: 4934eaa23f00ce1dfd8e1062e7a6b3bdbc6c5cd4e5f53641a930e910fde34206
initial_ast: d8e3de13a7f12866871e4117b7c4cf9872350154b19e82087fe8100adeba1354
imports_resolved_ast: d8e3de13a7f12866871e4117b7c4cf9872350154b19e82087fe8100adeba1354
canonicalized_ast: d8e3de13a7f12866871e4117b7c4cf9872350154b19e82087fe8100adeba1354
type_inferenced_ast: 06be9e7e193c4fcdca75ba8218de79dcc8317b1eb63d9c2f33ca790c614a472b

View File

@ -2,4 +2,4 @@
namespace: Compile
expectation: Fail
outputs:
- "Error [EASG0373025]: unexpected type, expected: '()', received: 'bool'\n --> compiler-test:4:12\n |\n 4 | return 10.length() == 10u8;\n | ^^^^^^^^^^^^^^^^^^^"
- "Error [EASG0373025]: unexpected type, expected: '()', received: 'bool'\n --> compiler-test:4:13\n |\n 4 | return (10u8.len() == 10u32) == y;\n | ^^^^^^^^^^^^^^^^^^^^^^^^^"

View File

@ -16,7 +16,7 @@ outputs:
r0:
type: bool
value: "true"
initial_ast: 3cd71a0e1c6b7aea15b7822c7ad19f400886e82ded67c55d24046d179d202ab0
imports_resolved_ast: 3cd71a0e1c6b7aea15b7822c7ad19f400886e82ded67c55d24046d179d202ab0
canonicalized_ast: 2f670f34d1dffb2dd07782b566d6da942ea1cbb0ed5c3da1fc7e78e39fa096f7
type_inferenced_ast: 4c616d4451798fff86c86c586729b643ad8194248c22956880f168b40a8eddba
initial_ast: 9886d4d97c894fade697bd99ac9cbe2a56973037837f34884e3dbad4dd4d5d65
imports_resolved_ast: 9886d4d97c894fade697bd99ac9cbe2a56973037837f34884e3dbad4dd4d5d65
canonicalized_ast: 36dbb999756e8e8bb68c69388889f0cfc217fbdbb0467f43453e19feb5c55d22
type_inferenced_ast: 4fff72622455ea5bfc073c8e90e2266545b01e3004b73e4ee909b37b0bd75f46

View File

@ -1,21 +0,0 @@
---
namespace: Compile
expectation: Pass
outputs:
- circuit:
num_public_variables: 0
num_private_variables: 1
num_constraints: 1
at: 042610d0fd1fe6d6ac112138f8755752f44c7d2a00f1b5960574d6da5cda393f
bt: e97756698880ab7555a959a5fb5c6b4e15bd64612aa677adbfe2d0bd91f0a83c
ct: cf1cbb66a638b4860a516671fb74850e6ccf787fe6c4c8d29e9c04efe880bd05
output:
- input_file: input/dummy.in
output:
registers:
r0:
type: bool
value: "true"
initial_ast: 80d3dbfdeb9d6fb6e9ba17ba028bd2bf71014b4353f34db9d69a66ee1d0914cf
canonicalized_ast: 80d3dbfdeb9d6fb6e9ba17ba028bd2bf71014b4353f34db9d69a66ee1d0914cf
type_inferenced_ast: bbad9d7593fb1aa2bcc25f2f2625ace659e18f293af35082ad39b1e3cd71e8b5

View File

@ -1,5 +0,0 @@
---
namespace: Compile
expectation: Fail
outputs:
- aborting due to syntax error

View File

@ -1,5 +0,0 @@
---
namespace: Compile
expectation: Fail
outputs:
- aborting due to syntax error

View File

@ -1,5 +0,0 @@
---
namespace: Compile
expectation: Fail
outputs:
- " --> compiler-test:3:15\n |\n 3 | function main(a: u32) {\n | ^\n |\n = expected data type `u32`, found `u8`"

View File

@ -1,5 +0,0 @@
---
namespace: Compile
expectation: Fail
outputs:
- aborting due to syntax error

View File

@ -1,21 +0,0 @@
---
namespace: Compile
expectation: Pass
outputs:
- circuit:
num_public_variables: 0
num_private_variables: 1
num_constraints: 1
at: 042610d0fd1fe6d6ac112138f8755752f44c7d2a00f1b5960574d6da5cda393f
bt: e97756698880ab7555a959a5fb5c6b4e15bd64612aa677adbfe2d0bd91f0a83c
ct: cf1cbb66a638b4860a516671fb74850e6ccf787fe6c4c8d29e9c04efe880bd05
output:
- input_file: inputs/dummy.in
output:
registers:
r0:
type: bool
value: "true"
initial_ast: 75fbb3ed1613fbf39ce803ff903befe209b26a953ba8db1d68e35066655d96e6
canonicalized_ast: a96cae2c9e347245e07c63b5c94cf43497063c3f548c615627da4b1775e9a17b
type_inferenced_ast: dc663974ed1cce7b15c35eda29c9b1af5426eafddbd108b5a03cd7071ad4a6bc