generators/iterators, raise/try/except, and slot-based object layout

- VM refactor: resumable CAT_VM_Frame (ip/sp/locals/handlers)
- yield/next/generators: calling a yield-function returns a generator
- for..in over any iterator, ends on explicit exhaustion status
- raise/try/except: structured error values, nearest-handler unwinding
- slots: C-declared member layout (offsetof), PyTypeObject/tp_members style
- File now exposes path/mode/closed via slots
- examples: generators.cat, errors.cat, slots.cat; 40/40 tests
This commit is contained in:
Minus committed 2026-11-16 01:48:47 +00:00
1 parent 52d118211f
commit 3c20496c78
19 files changed
+978 -99

No files matched your search

+7
View File
@@ -58,6 +58,12 @@ enum CAT_BYTECODE_Op {
CAT_BYTECODE_OP_DUP, /* duplicate top of stack */
CAT_BYTECODE_OP_GETIDX, /* pop idx, obj -> push obj[idx] */
CAT_BYTECODE_OP_SETIDX, /* pop val, idx, obj -> obj[idx]=val */
CAT_BYTECODE_OP_YIELD, /* suspend a generator, yielding top */
CAT_BYTECODE_OP_NEXT, /* pop it -> push next(it) or nil */
CAT_BYTECODE_OP_TRYSETUP, /* A: handler target addr */
CAT_BYTECODE_OP_TRYEND, /* pop the innermost handler */
CAT_BYTECODE_OP_RAISE, /* pop value -> raise it */
CAT_BYTECODE_OP_FORNEXT, /* A: exit target; pop it -> push next or jump */
};
/* One instruction: opcode + three integer operands. */
@@ -88,6 +94,7 @@ typedef struct CAT_BYTECODE_Function {
int nprotos, capprotos;
int nlocals; /* number of local slots */
int nparams; /* number of parameters */
int is_generator; /* contains yield: calls produce a generator */
} CAT_BYTECODE_Function;
CAT_BYTECODE_Function *cat_bytecode_function_new(const char *name);