diff --git a/centvrion/ast_nodes.py b/centvrion/ast_nodes.py index d750cfc..b70509c 100644 --- a/centvrion/ast_nodes.py +++ b/centvrion/ast_nodes.py @@ -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) diff --git a/centvrion/compiler/emit_expr.py b/centvrion/compiler/emit_expr.py index 979c4b7..65e487c 100644 --- a/centvrion/compiler/emit_expr.py +++ b/centvrion/compiler/emit_expr.py @@ -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) diff --git a/centvrion/compiler/runtime/cent_runtime.c b/centvrion/compiler/runtime/cent_runtime.c index 58ac326..2db9b65 100644 --- a/centvrion/compiler/runtime/cent_runtime.c +++ b/centvrion/compiler/runtime/cent_runtime.c @@ -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)) { diff --git a/centvrion/compiler/runtime/cent_runtime.h b/centvrion/compiler/runtime/cent_runtime.h index 276910d..2ce7ee0 100644 --- a/centvrion/compiler/runtime/cent_runtime.h +++ b/centvrion/compiler/runtime/cent_runtime.h @@ -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 */ diff --git a/centvrion/lexer.py b/centvrion/lexer.py index d8773c8..7a4bfd9 100644 --- a/centvrion/lexer.py +++ b/centvrion/lexer.py @@ -35,6 +35,7 @@ builtin_tokens = [("BUILTIN", i) for i in [ "AVDI_NVMERVS", "AVDI", "DICE", + "EVERRO", "FORTIS_NVMERVS", "FORTIS_ELECTIONIS", "LONGITVDO" diff --git a/tests.py b/tests.py index da05bdc..6f31204 100644 --- a/tests.py +++ b/tests.py @@ -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):