diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-10-11 14:21:35 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-10-11 14:21:35 -0400 |
| commit | 5b2acc934ee1cda4a514b617a56b43fc4ddf6a0f (patch) | |
| tree | feb31009ea5e8433694b11dfe9c9c59969bcdfcc | |
| parent | c74fba540448f1d4b1aec4de8f3d9ffc395fdde0 (diff) | |
Added Empty() struct
| -rw-r--r-- | CHANGES.md | 2 | ||||
| -rw-r--r-- | src/environment.c | 8 | ||||
| -rw-r--r-- | src/stdlib/datatypes.h | 3 | ||||
| -rw-r--r-- | src/stdlib/structs.c | 12 | ||||
| -rw-r--r-- | src/stdlib/structs.h | 2 | ||||
| -rw-r--r-- | src/stdlib/types.h | 1 |
6 files changed, 25 insertions, 3 deletions
@@ -29,6 +29,8 @@ arguments). - Added `table.with(other)`, `table.without(other)`, `table.intersection(other)`, and `table.difference(other)`. +- Added `Empty` for a built-in empty struct type and `EMPTY` for an instance of + the empty struct. - Added a `--format` flag to the `tomo` binary that autoformats your code (currently unstable, do not rely on it just yet). - Standardized text methods for Unicode encodings: diff --git a/src/environment.c b/src/environment.c index 3f07787e..ea390996 100644 --- a/src/environment.c +++ b/src/environment.c @@ -68,6 +68,8 @@ env_t *global_env(bool source_mapping) { PATH_TYPE_TYPE = declare_type(env, "enum PathType(Relative, Absolute, Home)"); PATH_TYPE = declare_type(env, "struct Path(type:PathType, components:[Text])"); + type_t *empty_type = declare_type(env, "struct Empty()"); + typedef struct { const char *name, *code, *type_str; } ns_entry_t; @@ -83,9 +85,10 @@ env_t *global_env(bool source_mapping) { Text_t typeinfo; List_t namespace; } global_types[] = { - MAKE_TYPE("Void", Type(VoidType), Text("Void_t"), Text("Void$info")), + MAKE_TYPE("Void", Type(VoidType), Text("void"), Text("Void$info")), MAKE_TYPE("Abort", Type(AbortType), Text("void"), Text("Abort$info")), - MAKE_TYPE("Memory", Type(MemoryType), Text("Memory_t"), Text("Memory$info")), + MAKE_TYPE("Memory", Type(MemoryType), Text("void"), Text("Memory$info")), + MAKE_TYPE("Empty", empty_type, Text("Empty$$type"), Text("Empty$$info")), MAKE_TYPE( // "Bool", Type(BoolType), Text("Bool_t"), Text("Bool$info"), {"parse", "Bool$parse", "func(text:Text, remainder:&Text? = none -> Bool?)"}), @@ -531,6 +534,7 @@ env_t *global_env(bool source_mapping) { {"exit", "tomo_exit", "func(message:Text?=none, code=Int32(1) -> Abort)"}, {"fail", "fail_text", "func(message:Text -> Abort)"}, {"sleep", "sleep_num", "func(seconds:Num)"}, + {"EMPTY", "EMPTY", "Empty"}, }; for (size_t i = 0; i < sizeof(global_vars) / sizeof(global_vars[0]); i++) { diff --git a/src/stdlib/datatypes.h b/src/stdlib/datatypes.h index fc665401..0ac97019 100644 --- a/src/stdlib/datatypes.h +++ b/src/stdlib/datatypes.h @@ -69,6 +69,9 @@ typedef struct table_s { struct table_s *fallback; } Table_t; +typedef struct Empty$$struct { +} Empty$$type; + typedef struct { void *fn, *userdata; } Closure_t; diff --git a/src/stdlib/structs.c b/src/stdlib/structs.c index 885b903c..89b5581b 100644 --- a/src/stdlib/structs.c +++ b/src/stdlib/structs.c @@ -6,6 +6,7 @@ #include "bools.h" #include "metamethods.h" #include "siphash.h" +#include "structs.h" #include "text.h" #include "util.h" @@ -214,3 +215,14 @@ void Struct$deserialize(FILE *in, void *outval, List_t *pointers, const TypeInfo } } } + +public +const TypeInfo_t Empty$$info = {.size = 0, + .align = 0, + .tag = StructInfo, + .metamethods = Struct$metamethods, + .StructInfo.name = "Empty", + .StructInfo.num_fields = 0}; + +public +const Empty$$type EMPTY = {}; diff --git a/src/stdlib/structs.h b/src/stdlib/structs.h index a582e9fb..83904377 100644 --- a/src/stdlib/structs.h +++ b/src/stdlib/structs.h @@ -15,6 +15,8 @@ PUREFUNC bool PackedData$equal(const void *x, const void *y, const TypeInfo_t *t PUREFUNC Text_t Struct$as_text(const void *obj, bool colorize, const TypeInfo_t *type); void Struct$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *type); void Struct$deserialize(FILE *in, void *outval, List_t *pointers, const TypeInfo_t *type); +extern const TypeInfo_t Empty$$info; +extern const Empty$$type EMPTY; #define Struct$metamethods \ { \ diff --git a/src/stdlib/types.h b/src/stdlib/types.h index bd2474fa..5cd622e7 100644 --- a/src/stdlib/types.h +++ b/src/stdlib/types.h @@ -91,7 +91,6 @@ struct TypeInfo_s { extern const TypeInfo_t Void$info; extern const TypeInfo_t Abort$info; -#define Void_t void Text_t Type$as_text(const void *typeinfo, bool colorize, const TypeInfo_t *type); |
