remove nil/null: absence is an error, empty object is the only no-value

- 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
This commit is contained in:
Minus committed 2026-11-16 04:08:24 +00:00
1 parent e0bf102f2a
commit d29b0706c9
36 files changed
+257 -244

No files matched your search

+3 -3
View File
@@ -20,7 +20,7 @@
enum CAT_BYTECODE_Op {
CAT_BYTECODE_OP_NOP = 0,
CAT_BYTECODE_OP_CONST, /* A: index into consts[] */
CAT_BYTECODE_OP_NIL, /* push nil */
CAT_BYTECODE_OP_EMPTY, /* push the empty object */
CAT_BYTECODE_OP_TRUE, /* push true */
CAT_BYTECODE_OP_FALSE, /* push false */
CAT_BYTECODE_OP_GETLOCAL, /* A: local slot -> stack */
@@ -49,7 +49,7 @@ enum CAT_BYTECODE_Op {
CAT_BYTECODE_OP_JUMPIF, /* A: target; pop cond */
CAT_BYTECODE_OP_JUMPIFNOT, /* A: target; pop cond */
CAT_BYTECODE_OP_RETURN, /* pop -> return */
CAT_BYTECODE_OP_RETURN0, /* return nil */
CAT_BYTECODE_OP_RETURN0, /* return the empty object */
CAT_BYTECODE_OP_POP, /* discard top */
CAT_BYTECODE_OP_PRINT, /* pop, print */
CAT_BYTECODE_OP_CLOSURE, /* A: index into protos[] */
@@ -59,7 +59,7 @@ enum CAT_BYTECODE_Op {
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_NEXT, /* pop it -> push next(it) or empty */
CAT_BYTECODE_OP_TRYSETUP, /* A: handler target addr */
CAT_BYTECODE_OP_TRYEND, /* pop the innermost handler */
CAT_BYTECODE_OP_RAISE, /* pop value -> raise it */