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
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* cat/types/empty.h -- the empty object (catscript has no nil/null).
|
||||
*
|
||||
* Naming rule: symbols here are cat_types_empty_* / CAT_TYPES_EMPTY_*.
|
||||
*
|
||||
* catscript has no `nil`/`null`. The value for "no value" is an empty
|
||||
* object: an `Object` with no members. It is a shared, immutable
|
||||
* singleton, so it is safe to compare by identity and needs no
|
||||
* allocation. Setting a member on it raises.
|
||||
*/
|
||||
#ifndef CAT_TYPES_EMPTY_H
|
||||
#define CAT_TYPES_EMPTY_H
|
||||
|
||||
#include "cat/value.h"
|
||||
|
||||
/* The canonical empty object (a singleton). */
|
||||
CAT_VALUE_Value *cat_types_empty(void);
|
||||
|
||||
CAT_VALUE_Vtable *cat_types_empty_vtable(void);
|
||||
|
||||
/* True if v is the empty object singleton. */
|
||||
int cat_types_empty_is(CAT_VALUE_Value *v);
|
||||
|
||||
#endif /* CAT_TYPES_EMPTY_H */
|
||||
@@ -51,10 +51,10 @@ enum {
|
||||
CAT_TYPES_FFI_RET_STRING
|
||||
};
|
||||
|
||||
/* Load a shared library by path; returns a Library value (nil on error). */
|
||||
/* Load a shared library by path; returns a Library value (empty on error). */
|
||||
CAT_VALUE_Value *cat_types_ffi_load(const char *path);
|
||||
|
||||
/* Bind a symbol with a signature; returns a Function value (nil on error). */
|
||||
/* Bind a symbol with a signature; returns a Function value (empty on error). */
|
||||
CAT_VALUE_Value *cat_types_ffi_bind(CAT_VALUE_Value *lib, const char *name,
|
||||
const char *sig);
|
||||
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* cat/types/nil.h -- the `nil` singleton value.
|
||||
*
|
||||
* Naming rule: symbols here are cat_types_nil_* / CAT_TYPES_NIL_*.
|
||||
* `nil` is falsy and participates in no arithmetic.
|
||||
*/
|
||||
#ifndef CAT_TYPES_NIL_H
|
||||
#define CAT_TYPES_NIL_H
|
||||
|
||||
#include "cat/value.h"
|
||||
|
||||
typedef struct CAT_TYPES_NIL_Nil {
|
||||
CAT_VALUE_Value base;
|
||||
} CAT_TYPES_NIL_Nil;
|
||||
|
||||
/* The one shared nil value (never freed by callers). */
|
||||
CAT_VALUE_Value *cat_types_nil_get(void);
|
||||
CAT_VALUE_Vtable *cat_types_nil_vtable(void);
|
||||
|
||||
#endif /* CAT_TYPES_NIL_H */
|
||||
Reference in new issue
Block a user