🐐 SEMEN

This commit is contained in:
2026-04-21 14:24:48 +02:00
parent 4f67b1b2dc
commit ad46f189c0
8 changed files with 32 additions and 3 deletions

View File

@@ -920,6 +920,14 @@ class BuiltIn(Node):
if len(lst) == 0:
raise CentvrionError("FORTIS_ELECTIONIS: cannot select from an empty array")
return vtable, lst[random.randint(0, len(lst) - 1)]
case "SEMEN":
if "FORS" not in vtable["#modules"]:
raise CentvrionError("Cannot use 'SEMEN' without module 'FORS'")
seed = params[0].value()
if not isinstance(seed, int):
raise CentvrionError("SEMEN requires an integer seed")
random.seed(seed)
return vtable, ValNul()
case "LONGITVDO":
if isinstance(params[0], (ValList, ValStr)):
return vtable, ValInt(len(params[0].value()))

View File

@@ -186,6 +186,14 @@ def _emit_builtin(node, ctx):
else:
lines.append(f"CentValue {tmp} = cent_fortis_electionis({param_vars[0]});")
case "SEMEN":
if not ctx.has_module("FORS"):
lines.append('cent_runtime_error("FORS module required for SEMEN");')
lines.append(f"CentValue {tmp} = cent_null();")
else:
lines.append(f"cent_semen({param_vars[0]});")
lines.append(f"CentValue {tmp} = cent_null();")
case "ERVMPE":
# break as expression (side-effecting; result is unused)
lines.append("break;")

View File

@@ -533,6 +533,12 @@ CentValue cent_fortis_electionis(CentValue lst) {
return lst.lval.items[rand() % lst.lval.len];
}
void cent_semen(CentValue seed) {
if (seed.type != CENT_INT)
cent_type_error("'SEMEN' requires an integer seed");
srand((unsigned)seed.ival);
}
/* ------------------------------------------------------------------ */
/* Array helpers */
/* ------------------------------------------------------------------ */

View File

@@ -177,6 +177,7 @@ CentValue cent_avdi_numerus(void); /* AVDI_NVMERVS */
CentValue cent_longitudo(CentValue v); /* LONGITVDO */
CentValue cent_fortis_numerus(CentValue lo, CentValue hi); /* FORTIS_NVMERVS */
CentValue cent_fortis_electionis(CentValue lst); /* FORTIS_ELECTIONIS */
void cent_semen(CentValue seed); /* SEMEN */
void cent_everro(void); /* EVERRO */
/* ------------------------------------------------------------------ */

View File

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