🐐 DORMI

This commit is contained in:
2026-04-21 21:30:59 +02:00
parent 78b1dd7667
commit 108e69291d
7 changed files with 130 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
import re
import random
import time
from fractions import Fraction
from rply.token import BaseBox
@@ -1128,6 +1129,18 @@ class BuiltIn(Node):
ValFunc: "FVNCTIO", ValNul: "NVLLVS",
}
return vtable, ValStr(type_map[type(params[0])])
case "DORMI":
v = params[0]
if isinstance(v, ValNul):
seconds = 0
elif isinstance(v, ValInt):
seconds = v.value()
elif isinstance(v, ValFrac):
seconds = float(v.value())
else:
raise CentvrionError("DORMI requires a number or NVLLVS")
time.sleep(seconds)
return vtable, ValNul()
case _:
raise NotImplementedError(self.builtin)

View File

@@ -258,6 +258,10 @@ def _emit_builtin(node, ctx):
case "TYPVS":
lines.append(f"CentValue {tmp} = cent_typvs({param_vars[0]});")
case "DORMI":
lines.append(f"cent_dormi({param_vars[0]});")
lines.append(f"CentValue {tmp} = cent_null();")
case _:
raise NotImplementedError(node.builtin)

View File

@@ -559,6 +559,23 @@ CentValue cent_typvs(CentValue v) {
return cent_str("IGNOTA"); /* unreachable */
}
void cent_dormi(CentValue n) {
struct timespec ts;
if (n.type == CENT_NULL) {
ts.tv_sec = 0; ts.tv_nsec = 0;
} else if (n.type == CENT_INT) {
ts.tv_sec = n.ival; ts.tv_nsec = 0;
} else if (n.type == CENT_FRAC) {
long sec = n.fval.num / n.fval.den;
long rem = n.fval.num % n.fval.den;
ts.tv_sec = sec;
ts.tv_nsec = rem * 1000000000L / n.fval.den;
} else {
cent_type_error("'DORMI' requires a number or NVLLVS");
}
nanosleep(&ts, NULL);
}
CentValue cent_fortis_numerus(CentValue lo, CentValue hi) {
if (lo.type != CENT_INT || hi.type != CENT_INT)
cent_type_error("'FORTIS_NVMERVS' requires two integers");

View File

@@ -221,6 +221,7 @@ void cent_semen(CentValue seed); /* SEMEN */
void cent_everro(void); /* EVERRO */
CentValue cent_senatus(CentValue *args, int n); /* SENATVS */
CentValue cent_typvs(CentValue v); /* TYPVS */
void cent_dormi(CentValue n); /* DORMI */
/* ------------------------------------------------------------------ */
/* Array helpers */

View File

@@ -44,6 +44,7 @@ builtin_tokens = [("BUILTIN", i) for i in [
"CLAVES",
"DECIMATIO",
"DICE",
"DORMI",
"EVERRO",
"FORTIS_NVMERVS",
"FORTIS_ELECTIONIS",