🐐 SCRIPTA

This commit is contained in:
2026-04-21 22:00:19 +02:00
parent e61009b6ef
commit 80d430970a
9 changed files with 250 additions and 4 deletions

View File

@@ -1152,6 +1152,28 @@ class BuiltIn(Node):
raise CentvrionError("DORMI requires a number or NVLLVS")
time.sleep(seconds)
return vtable, ValNul()
case "LEGE":
if "SCRIPTA" not in vtable["#modules"]:
raise CentvrionError("Cannot use 'LEGE' without module 'SCRIPTA'")
path = make_string(params[0], magnvm, svbnvlla)
with open(path, "r") as f:
return vtable, ValStr(f.read())
case "SCRIBE":
if "SCRIPTA" not in vtable["#modules"]:
raise CentvrionError("Cannot use 'SCRIBE' without module 'SCRIPTA'")
path = make_string(params[0], magnvm, svbnvlla)
content = make_string(params[1], magnvm, svbnvlla)
with open(path, "w") as f:
f.write(content)
return vtable, ValNul()
case "ADIVNGE":
if "SCRIPTA" not in vtable["#modules"]:
raise CentvrionError("Cannot use 'ADIVNGE' without module 'SCRIPTA'")
path = make_string(params[0], magnvm, svbnvlla)
content = make_string(params[1], magnvm, svbnvlla)
with open(path, "a") as f:
f.write(content)
return vtable, ValNul()
case _:
raise NotImplementedError(self.builtin)

View File

@@ -265,6 +265,29 @@ def _emit_builtin(node, ctx):
lines.append(f"cent_dormi({param_vars[0]});")
lines.append(f"CentValue {tmp} = cent_null();")
case "LEGE":
if not ctx.has_module("SCRIPTA"):
lines.append('cent_runtime_error("SCRIPTA module required for LEGE");')
lines.append(f"CentValue {tmp} = cent_null();")
else:
lines.append(f"CentValue {tmp} = cent_lege({param_vars[0]});")
case "SCRIBE":
if not ctx.has_module("SCRIPTA"):
lines.append('cent_runtime_error("SCRIPTA module required for SCRIBE");')
lines.append(f"CentValue {tmp} = cent_null();")
else:
lines.append(f"cent_scribe({param_vars[0]}, {param_vars[1]});")
lines.append(f"CentValue {tmp} = cent_null();")
case "ADIVNGE":
if not ctx.has_module("SCRIPTA"):
lines.append('cent_runtime_error("SCRIPTA module required for ADIVNGE");')
lines.append(f"CentValue {tmp} = cent_null();")
else:
lines.append(f"cent_adivnge({param_vars[0]}, {param_vars[1]});")
lines.append(f"CentValue {tmp} = cent_null();")
case _:
raise NotImplementedError(node.builtin)

View File

@@ -576,6 +576,40 @@ void cent_dormi(CentValue n) {
nanosleep(&ts, NULL);
}
/* ---- SCRIPTA module ---- */
CentValue cent_lege(CentValue path) {
const char *p = cent_make_string(path);
FILE *f = fopen(p, "r");
if (!f) cent_runtime_error("LEGE: cannot open file");
fseek(f, 0, SEEK_END);
long len = ftell(f);
fseek(f, 0, SEEK_SET);
char *buf = cent_arena_alloc(cent_arena, len + 1);
fread(buf, 1, len, f);
buf[len] = '\0';
fclose(f);
return cent_str(buf);
}
void cent_scribe(CentValue path, CentValue content) {
const char *p = cent_make_string(path);
const char *c = cent_make_string(content);
FILE *f = fopen(p, "w");
if (!f) cent_runtime_error("SCRIBE: cannot open file");
fputs(c, f);
fclose(f);
}
void cent_adivnge(CentValue path, CentValue content) {
const char *p = cent_make_string(path);
const char *c = cent_make_string(content);
FILE *f = fopen(p, "a");
if (!f) cent_runtime_error("ADIVNGE: cannot open file");
fputs(c, f);
fclose(f);
}
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

@@ -223,6 +223,9 @@ CentValue cent_senatus(CentValue *args, int n); /* SENATVS */
CentValue cent_typvs(CentValue v); /* TYPVS */
void cent_dormi(CentValue n); /* DORMI */
CentValue cent_ordina(CentValue lst); /* ORDINA */
CentValue cent_lege(CentValue path); /* LEGE */
void cent_scribe(CentValue path, CentValue content); /* SCRIBE */
void cent_adivnge(CentValue path, CentValue content); /* ADIVNGE */
/* ------------------------------------------------------------------ */
/* Array helpers */

View File

@@ -52,7 +52,10 @@ builtin_tokens = [("BUILTIN", i) for i in [
"ORDINA",
"SEMEN",
"SENATVS",
"TYPVS"
"TYPVS",
"LEGE",
"SCRIBE",
"ADIVNGE"
]]
data_tokens = [
@@ -65,6 +68,7 @@ module_tokens = [("MODULE", i) for i in [
"FORS",
"FRACTIO",
"MAGNVM",
"SCRIPTA",
"SVBNVLLA"
]]