A second backend that lowers each bytecode instruction to a machine-code
call into a runtime helper, with control flow as real branches.
- cat/backend/x86_64_glue.c: one helper per opcode, mirroring cat/vm.c
exactly (frame lifecycle, arith, cmp, attr/idx, call/callmethod, is,
next/fornext, try/raise). Helpers use the SysV convention (f in rdi,
a/b/c in rsi/rdx/rcx) and return 0/1/-1.
- cat/backend/x86_64.c: emits AT&T assembly (one labelled block per
instruction, one call per helper, real jumps for JUMP/JUMPIF/JUMPIFNOT/
FORNEXT/RETURN, an .Lonerror block that resumes try handlers), plus a
small generated _main.c that rebuilds the bytecode and boots the VM.
Builds with as + cc linked against libcatscript.a.
- generators are not lowered: their prototype carries no nat_entry, so
the VM runs them (their bytecode is rebuilt by the generated main), and
the emitted code simply falls back to the interpreter.
- cat_vm_exec_closure dispatches to a prototype's nat_entry when present.
- tests: native-vs-interpreter equivalence check. Suite 155 -> 156.
Verified: hello, control, classes, generators, arith, errors, text, oop,
slots, reflect, toml, files, ffi all match the interpreter natively.
- cat/backend/backend.h: the CAT_BACKEND_Backend contract (name,
description, native flag, emit(), compile()).
- cat/backend/registry.c: the single table of targets; cat_backend_find/
default/count/at. Adding a backend = one file + one line here.
- cat/backend/c.c: exposes cat_backend_c_backend(); body unchanged.
- cat/backend/x86_64.c: the native x86-64 backend descriptor (lowering
stubbed for now).
- main.c: --backend <name> --emit/--build, --list-backends; --emit-c and
--build stay as shortcuts for the default (c) backend.
- Makefile: build the new files. Suite 151 -> 155.
- new cat/backend/c.{h,c}: lower a compiled CAT_BYTECODE_Function to a
self-contained C translation unit that rebuilds the bytecode and runs
it on the catscript runtime. The tree is emitted in pre-order with
forward declarations; constants (int/float/text/bool) are recreated by
the matching constructors; jumps keep their absolute targets.
- Makefile: also build libcatscript.a (all objects but main.o) so an AOT
program links the runtime without clashing on `main`.
- main.c: `--emit-c <file>` prints the generated C; `--build <file> <out>`
emits it, invokes the system `cc`, and produces the executable.
- tests/aot.cat + suite: the native binary's stdout must equal the
interpreter's (arithmetic, recursion, objects, interfaces, `is`,
concat, comparisons). Suite 151 -> 152.
The backend is faithful by construction: it lowers the very bytecode the
interpreter runs, so native output matches the interpreter exactly
(including current language quirks, e.g. upvalues and `try`/`catch`).
First slice of the static-typing foundation (traits/generics/Sized()
will build on it). Typing stays structural and permissive: an unknown
or opaque name is never a rejection, so existing programs keep working.
- new module cat/types/type.{h,c}: compile-time-only descriptors
(int/float/bool/text/empty/object/function/list/memory/any + interned
named/opaque types), with equal/assignable/join and int->float widening.
- compiler: skip_type_hint -> parse_type_hint, which returns the type of
the first identifier in a hint (the rest of a balanced hint is still
consumed and ignored, so `cbyte[sentinel_sized<0>]` parses).
- `local NAME : T = <literal>` is checked: assigning a known concrete
literal of the wrong kind to a known concrete type raises at compile
time ("line N: cannot assign text to int"). Unknown/opaque names and
non-literal expressions stay permissive.
- FuncCtx tracks a declared/inferred type per local slot.
- tests/types.cat + suite block: ok hints, int->float widening, opaque
names accepted, and a wrong assignment rejected. Suite 136 -> 140.
To bind GLFW and Vulkan, the FFI needs to pass *structs*, not just
scalars. This adds the memory-safe foundation for that.
- cat/types/memory.{h,c}: the `memory` type -- an owned byte buffer
with named accessors (u8..u64, i8..i64, f32, f64, text, set_text,
ptr, size, fill, copy). Every access is bounds-checked and raises
an error instead of corrupting memory. `ptr` exposes the address for
an FFI call; values outlive the call, so the pointer stays valid.
- ffi.c: a `memory` value where a pointer is expected now passes its
buffer address -- the bridge that lets structs reach native code.
- lexer: 0x/0b/0o integer literals (0xAB), with `_` separators.
- stdlib: `memory(n)` constructor as a global.
- tests/memory.cat: reads/writes, zeroing, fill, out-of-bounds raising
(119 total, all green).
Proved live: glfwGetVersion(major,minor,rev) called through catscript
FFI + memory -> 3, 4, 0 (GLFW 3.4).
- delete the nil type; catscript has no nil and no null
- add the empty object (Object with no members), exposed as the global
'empty'; it is a shared immutable singleton
- 'nil' is no longer a keyword: it is an undefined global, which raises
- undefined global -> error (consistent with a missing attribute)
- only 'false' is falsy (numbers/objects are truthy); booleans kept
- OP_NIL -> OP_EMPTY; compiler, VM, stdlib, toml, ffi, generator, file,
list, selector, value all migrated
- rename the table type to Object
- std/ front-end and examples/tests migrated to 'empty'
- 84/84 tests
- new list type (iterable, indexable) backing attributes()
- attributes(obj): member names of a table/object, follows __index
inheritance, includes native and slot members (like Python dir())
- help(obj): prints the value's _doc_ documentation, else its type
and attributes
- natives carry an optional _doc_ string (cat_types_native_new_doc);
stdlib builtins documented
- len() handles lists
- examples/reflect.cat + 8 assertions wired into run_tests.sh (77 total)
- 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)