🐐 LONGITVDO on strings
This commit is contained in:
@@ -191,9 +191,9 @@ Skips the rest of the current loop body and continues to the next iteration (`DV
|
|||||||
Breaks out of the current loop (`DVM` or `PER`). Has no meaningful return value.
|
Breaks out of the current loop (`DVM` or `PER`). Has no meaningful return value.
|
||||||
|
|
||||||
### LONGITVDO
|
### LONGITVDO
|
||||||
`LONGITVDO array`
|
`LONGITVDO array` or `LONGITVDO string`
|
||||||
|
|
||||||
Returns the length of `array` as an integer.
|
Returns the length of `array` (element count) or `string` (character count) as an integer.
|
||||||
|
|
||||||
## Modules
|
## Modules
|
||||||
Modules are additions to the base `CENTVRION` syntax. They add or change certain features. Modules are included in your code by having
|
Modules are additions to the base `CENTVRION` syntax. They add or change certain features. Modules are included in your code by having
|
||||||
|
|||||||
@@ -909,9 +909,9 @@ class BuiltIn(Node):
|
|||||||
raise CentvrionError("FORTIS_ELECTIONIS: cannot select from an empty array")
|
raise CentvrionError("FORTIS_ELECTIONIS: cannot select from an empty array")
|
||||||
return vtable, lst[random.randint(0, len(lst) - 1)]
|
return vtable, lst[random.randint(0, len(lst) - 1)]
|
||||||
case "LONGITVDO":
|
case "LONGITVDO":
|
||||||
if not isinstance(params[0], ValList):
|
if isinstance(params[0], (ValList, ValStr)):
|
||||||
raise CentvrionError("LONGITVDO requires an array")
|
|
||||||
return vtable, ValInt(len(params[0].value()))
|
return vtable, ValInt(len(params[0].value()))
|
||||||
|
raise CentvrionError("LONGITVDO requires an array or string")
|
||||||
case "EVERRO":
|
case "EVERRO":
|
||||||
print("\033[2J\033[H", end="", flush=True)
|
print("\033[2J\033[H", end="", flush=True)
|
||||||
return vtable, ValNul()
|
return vtable, ValNul()
|
||||||
|
|||||||
@@ -481,9 +481,10 @@ CentValue cent_avdi_numerus(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CentValue cent_longitudo(CentValue v) {
|
CentValue cent_longitudo(CentValue v) {
|
||||||
if (v.type != CENT_LIST)
|
if (v.type == CENT_LIST) return cent_int(v.lval.len);
|
||||||
cent_type_error("'LONGITVDO' requires a list");
|
if (v.type == CENT_STR) return cent_int((long)strlen(v.sval));
|
||||||
return cent_int(v.lval.len);
|
cent_type_error("'LONGITVDO' requires a list or string");
|
||||||
|
return cent_null(); /* unreachable; silences warning */
|
||||||
}
|
}
|
||||||
|
|
||||||
CentValue cent_fortis_numerus(CentValue lo, CentValue hi) {
|
CentValue cent_fortis_numerus(CentValue lo, CentValue hi) {
|
||||||
|
|||||||
3
tests.py
3
tests.py
@@ -388,6 +388,9 @@ builtin_tests = [
|
|||||||
("CVM FORS\nFORTIS_NVMERVS(I, X)", Program([ModuleCall("FORS")], [ExpressionStatement(BuiltIn("FORTIS_NVMERVS", [Numeral("I"), Numeral("X")]))]), ValInt(3)),
|
("CVM FORS\nFORTIS_NVMERVS(I, X)", Program([ModuleCall("FORS")], [ExpressionStatement(BuiltIn("FORTIS_NVMERVS", [Numeral("I"), Numeral("X")]))]), ValInt(3)),
|
||||||
("AVDI()", Program([], [ExpressionStatement(BuiltIn("AVDI", []))]), ValStr("hello"), "", ["hello"]),
|
("AVDI()", Program([], [ExpressionStatement(BuiltIn("AVDI", []))]), ValStr("hello"), "", ["hello"]),
|
||||||
("LONGITVDO([I, II, III])", Program([], [ExpressionStatement(BuiltIn("LONGITVDO", [DataArray([Numeral("I"), Numeral("II"), Numeral("III")])]))]), ValInt(3)),
|
("LONGITVDO([I, II, III])", Program([], [ExpressionStatement(BuiltIn("LONGITVDO", [DataArray([Numeral("I"), Numeral("II"), Numeral("III")])]))]), ValInt(3)),
|
||||||
|
("LONGITVDO([])", Program([], [ExpressionStatement(BuiltIn("LONGITVDO", [DataArray([])]))]), ValInt(0)),
|
||||||
|
('LONGITVDO("salve")', Program([], [ExpressionStatement(BuiltIn("LONGITVDO", [String("salve")]))]), ValInt(5)),
|
||||||
|
('LONGITVDO("")', Program([], [ExpressionStatement(BuiltIn("LONGITVDO", [String("")]))]), ValInt(0)),
|
||||||
("CVM FORS\nFORTIS_ELECTIONIS([I, II, III])", Program([ModuleCall("FORS")], [ExpressionStatement(BuiltIn("FORTIS_ELECTIONIS", [DataArray([Numeral("I"), Numeral("II"), Numeral("III")])]))]), ValInt(1)),
|
("CVM FORS\nFORTIS_ELECTIONIS([I, II, III])", Program([ModuleCall("FORS")], [ExpressionStatement(BuiltIn("FORTIS_ELECTIONIS", [DataArray([Numeral("I"), Numeral("II"), Numeral("III")])]))]), ValInt(1)),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user