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:
1 parent
e0bf102f2a
commit
d29b0706c9
36 files changed
+257
-244
No files matched your search
+4
-5
@@ -83,7 +83,7 @@ typedef struct CAT_IMPL_SetAttribute {
|
||||
CAT_ERROR_Error *err);
|
||||
} CAT_IMPL_SetAttribute;
|
||||
|
||||
/* Cat_ImplementsNext -- advance an iterator/generator: -> *out (nil ends). */
|
||||
/* Cat_ImplementsNext -- advance an iterator/generator: -> *out (status). */
|
||||
typedef struct CAT_IMPL_Next {
|
||||
int (*fn)(CAT_VALUE_Value *self, CAT_VALUE_Value **out,
|
||||
CAT_ERROR_Error *err);
|
||||
@@ -111,12 +111,11 @@ enum {
|
||||
CAT_VALUE_SLOT_DOUBLE, /* double member */
|
||||
CAT_VALUE_SLOT_TEXT, /* char * member */
|
||||
CAT_VALUE_SLOT_BOOL, /* int/bool member */
|
||||
CAT_VALUE_SLOT_NIL /* no storage; always reads nil */
|
||||
CAT_VALUE_SLOT_EMPTY /* no storage; always reads the empty object */
|
||||
};
|
||||
|
||||
/* Runtime kind tag: structural families the VM can test cheaply. */
|
||||
enum {
|
||||
CAT_VALUE_KIND_NIL,
|
||||
CAT_VALUE_KIND_BOOL, /* boolean family */
|
||||
CAT_VALUE_KIND_NUMBER, /* Cat_Number family */
|
||||
CAT_VALUE_KIND_TEXT, /* Cat_Text family */
|
||||
@@ -181,8 +180,8 @@ int cat_value_equal(CAT_VALUE_Value *a, CAT_VALUE_Value *b, int *out,
|
||||
|
||||
/* Advance an iterator/generator. Returns 0 and sets *out to the next
|
||||
* value, 1 when the iterator is exhausted (*out untouched), or -1 on
|
||||
* error. A separate exhaustion status (rather than a nil/sentinel
|
||||
* value) lets generators yield nil, false or 0 without ending the loop. */
|
||||
* error. A separate exhaustion status (rather than an empty/sentinel
|
||||
* value) lets generators yield false or 0 without ending the loop. */
|
||||
int cat_value_next(CAT_VALUE_Value *v, CAT_VALUE_Value **out,
|
||||
CAT_ERROR_Error *err);
|
||||
|
||||
|
||||
Reference in new issue
Block a user