🐐 SENATVS

This commit is contained in:
2026-04-21 15:49:53 +02:00
parent 861448cb04
commit f62a7dda1c
7 changed files with 66 additions and 1 deletions

View File

@@ -967,6 +967,16 @@ class BuiltIn(Node):
for _ in range(to_remove):
arr.pop(random.randint(0, len(arr) - 1))
return vtable, ValList(arr)
case "SENATVS":
if len(params) == 1 and isinstance(params[0], ValList):
items = params[0].value()
else:
items = params
for p in items:
if not isinstance(p, ValBool):
raise CentvrionError("SENATVS requires boolean arguments")
true_count = sum(1 for p in items if p.value())
return vtable, ValBool(true_count > len(items) / 2)
case "LONGITVDO":
if isinstance(params[0], (ValList, ValStr)):
return vtable, ValInt(len(params[0].value()))

View File

@@ -201,6 +201,14 @@ def _emit_builtin(node, ctx):
lines.append(f"cent_semen({param_vars[0]});")
lines.append(f"CentValue {tmp} = cent_null();")
case "SENATVS":
if param_vars:
arr_tmp = ctx.fresh_tmp() + "_arr"
lines.append(f"CentValue {arr_tmp}[] = {{{', '.join(param_vars)}}};")
lines.append(f"CentValue {tmp} = cent_senatus({arr_tmp}, {len(param_vars)});")
else:
lines.append(f"CentValue {tmp} = cent_senatus(NULL, 0);")
case "ERVMPE":
# break as expression (side-effecting; result is unused)
lines.append("break;")

View File

@@ -533,6 +533,21 @@ CentValue cent_fortis_electionis(CentValue lst) {
return lst.lval.items[rand() % lst.lval.len];
}
CentValue cent_senatus(CentValue *args, int n) {
/* Single array argument: unpack it */
if (n == 1 && args[0].type == CENT_LIST) {
n = args[0].lval.len;
args = args[0].lval.items;
}
int true_count = 0;
for (int i = 0; i < n; i++) {
if (args[i].type != CENT_BOOL)
cent_type_error("'SENATVS' requires boolean arguments");
if (args[i].bval) true_count++;
}
return cent_bool(true_count * 2 > n);
}
CentValue cent_decimatio(CentValue lst) {
if (lst.type != CENT_LIST)
cent_type_error("'DECIMATIO' requires a list");

View File

@@ -180,6 +180,7 @@ CentValue cent_fortis_electionis(CentValue lst); /* FORTIS_ELECTIONIS *
CentValue cent_decimatio(CentValue lst); /* DECIMATIO */
void cent_semen(CentValue seed); /* SEMEN */
void cent_everro(void); /* EVERRO */
CentValue cent_senatus(CentValue *args, int n); /* SENATVS */
/* ------------------------------------------------------------------ */
/* Array helpers */

View File

@@ -45,7 +45,8 @@ builtin_tokens = [("BUILTIN", i) for i in [
"FORTIS_NVMERVS",
"FORTIS_ELECTIONIS",
"LONGITVDO",
"SEMEN"
"SEMEN",
"SENATVS"
]]
data_tokens = [