🐐 EVERRO

This commit is contained in:
Nikolaj
2026-04-13 11:18:46 +02:00
parent ffc60f8a06
commit 675e3ecc9d
6 changed files with 15 additions and 0 deletions

View File

@@ -899,6 +899,9 @@ class BuiltIn(Node):
if not isinstance(params[0], ValList):
raise CentvrionError("LONGITVDO requires an array")
return vtable, ValInt(len(params[0].value()))
case "EVERRO":
print("\033[2J\033[H", end="", flush=True)
return vtable, ValNul()
case _:
raise NotImplementedError(self.builtin)

View File

@@ -187,6 +187,10 @@ def _emit_builtin(node, ctx):
lines.append("break;")
lines.append(f"CentValue {tmp} = cent_null();")
case "EVERRO":
lines.append("cent_everro();")
lines.append(f"CentValue {tmp} = cent_null();")
case _:
raise NotImplementedError(node.builtin)

View File

@@ -458,6 +458,11 @@ void cent_dice(CentValue v) {
fputc('\n', stdout);
}
void cent_everro(void) {
fputs("\033[2J\033[H", stdout);
fflush(stdout);
}
CentValue cent_avdi(void) {
char *buf = cent_arena_alloc(cent_arena, 1024);
if (!fgets(buf, 1024, stdin)) {

View File

@@ -174,6 +174,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_everro(void); /* EVERRO */
/* ------------------------------------------------------------------ */
/* Array helpers */

View File

@@ -35,6 +35,7 @@ builtin_tokens = [("BUILTIN", i) for i in [
"AVDI_NVMERVS",
"AVDI",
"DICE",
"EVERRO",
"FORTIS_NVMERVS",
"FORTIS_ELECTIONIS",
"LONGITVDO"

View File

@@ -117,6 +117,7 @@ output_tests = [
("DICE(\"a\", \"b\")", Program([], [ExpressionStatement(BuiltIn("DICE", [String("a"), String("b")]))]), ValStr("a b"), "a b\n"),
("DICE(\"line one\")\nDICE(\"line two\")", Program([], [ExpressionStatement(BuiltIn("DICE", [String("line one")])), ExpressionStatement(BuiltIn("DICE", [String("line two")]))]), ValStr("line two"), "line one\nline two\n"),
("DICE(DICE(II))", Program([], [ExpressionStatement(BuiltIn("DICE", [BuiltIn("DICE", [Numeral("II")])]))]), ValStr("II"), "II\nII\n"),
("EVERRO()", Program([], [ExpressionStatement(BuiltIn("EVERRO", []))]), ValNul(), "\033[2J\033[H"),
]
class TestOutput(unittest.TestCase):