catscript: núcleo C, stdlib (TOML), família de arquivos e front-end self-hosted

- Modelo de objetos Cat_Value + vtable (interfaces abstratas)
- VM de bytecode, sem GIL (VM por-thread, nativas como valores)
- Stdlib com TOML embutido (toml_parse/toml_encode)
- Família de arquivos: AbstractFile (abstrata), File::open, StringIO, BytesIO
- Front-end (lexer/parser/checker/compiler) implementado em catscript
- cpk (cat package manager) como primeiro programa; manifest package.toml
- Type hints advisory, inclusive DynSized() e sentinel_sized<...>
- 25/25 testes passando (make test)
This commit is contained in:
Minus committed 2026-11-16 01:27:44 +00:00
commit 52d118211f
69 files changed
+6938

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
-- tests/selfhost_compile.cat -- drives the FULL self-hosted front-end:
-- lexer -> parser -> checker -> compiler (all written in catscript),
-- then runs the resulting bytecode via the C runtime's bc_run.
--
-- This proves the front-end is self-hosted: given catscript source text,
-- the catscript programs compile it to bytecode and execute it.
dofile("src/catscript/lexer.cat")
dofile("src/catscript/parser.cat")
dofile("src/catscript/checker.cat")
dofile("src/catscript/compiler.cat")
function selfhost_compile(src)
local toks = lexer_tokenize(src)
local pr = par_parse(toks)
if not pr.ok then
return { ok = false, err = pr.err }
end
local chk = chk_check(pr)
local chunk = cmp_compile(pr)
return { ok = true, chunk = chunk, diags = chk.diags }
end
local src = "local x = 40\nlocal y = 2\nprint(\"sum =\", x + y)\nfunction sq(n)\n return n * n\nend\nprint(\"sq =\", sq(7))\n"
local r = selfhost_compile(src)
if not r.ok then
print("compile error: " .. r.err)
else
print("compiled ok (" .. tostring(len(r.chunk.code)) .. " instrs)")
local i = 1
while i <= len(r.diags) do
print("diag: " .. r.diags[i])
i = i + 1
end
bc_run(r.chunk)
end