From 1e3fb8a2c0cca385d65c52679411b118b5fb4641 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 24 Nov 2024 16:18:21 -0500 Subject: [PATCH] Rename "NULL" to "NONE" --- compile.c | 34 +++++++++++++++++----------------- docs/arrays.md | 4 ++-- docs/booleans.md | 2 +- docs/integers.md | 6 +++--- docs/iterators.md | 2 +- docs/metamethods.md | 2 +- docs/moments.md | 4 ++-- docs/nums.md | 2 +- docs/optionals.md | 8 ++++---- docs/paths.md | 4 ++-- docs/reductions.md | 2 +- docs/tables.md | 4 ++-- docs/text.md | 8 ++++---- parse.c | 4 ++-- stdlib/arrays.c | 4 ++-- stdlib/bools.c | 2 +- stdlib/bytes.h | 2 +- stdlib/integers.c | 4 ++-- stdlib/integers.h | 8 ++++---- stdlib/moments.c | 4 ++-- stdlib/optionals.c | 4 ++-- stdlib/optionals.h | 14 +++++++------- stdlib/paths.c | 22 +++++++++++----------- stdlib/patterns.c | 6 +++--- stdlib/patterns.h | 2 +- stdlib/shell.c | 12 ++++++------ stdlib/stdlib.c | 4 ++-- stdlib/text.c | 4 ++-- test/arrays.tm | 4 ++-- test/nums.tm | 8 ++++---- test/optionals.tm | 30 +++++++++++++++--------------- test/paths.tm | 4 ++-- test/reductions.tm | 4 ++-- test/tables.tm | 6 +++--- test/text.tm | 14 +++++++------- tomo.c | 4 ++-- 36 files changed, 126 insertions(+), 126 deletions(-) diff --git a/compile.c b/compile.c index 0b19e48..46ee822 100644 --- a/compile.c +++ b/compile.c @@ -422,7 +422,7 @@ CORD check_null(type_t *t, CORD value) else if (t->tag == TableType || t->tag == SetType) return CORD_all("((", value, ").entries.length < 0)"); else if (t->tag == BoolType) - return CORD_all("((", value, ") == NULL_BOOL)"); + return CORD_all("((", value, ") == NONE_BOOL)"); else if (t->tag == TextType) return CORD_all("((", value, ").length < 0)"); else if (t->tag == IntType || t->tag == ByteType || t->tag == StructType) @@ -1862,28 +1862,28 @@ CORD compile_null(type_t *t) if (t == THREAD_TYPE) return "NULL"; switch (t->tag) { - case BigIntType: return "NULL_INT"; + case BigIntType: return "NONE_INT"; case IntType: { switch (Match(t, IntType)->bits) { - case TYPE_IBITS8: return "NULL_INT8"; - case TYPE_IBITS16: return "NULL_INT16"; - case TYPE_IBITS32: return "NULL_INT32"; - case TYPE_IBITS64: return "NULL_INT64"; + case TYPE_IBITS8: return "NONE_INT8"; + case TYPE_IBITS16: return "NONE_INT16"; + case TYPE_IBITS32: return "NONE_INT32"; + case TYPE_IBITS64: return "NONE_INT64"; default: errx(1, "Invalid integer bit size"); } break; } - case BoolType: return "NULL_BOOL"; - case ByteType: return "NULL_BYTE"; - case ArrayType: return "NULL_ARRAY"; - case TableType: return "NULL_TABLE"; - case SetType: return "NULL_TABLE"; + case BoolType: return "NONE_BOOL"; + case ByteType: return "NONE_BYTE"; + case ArrayType: return "NONE_ARRAY"; + case TableType: return "NONE_TABLE"; + case SetType: return "NONE_TABLE"; case ChannelType: return "NULL"; - case TextType: return "NULL_TEXT"; + case TextType: return "NONE_TEXT"; case CStringType: return "NULL"; - case MomentType: return "NULL_MOMENT"; + case MomentType: return "NONE_MOMENT"; case PointerType: return CORD_all("((", compile_type(t), ")NULL)"); - case ClosureType: return "NULL_CLOSURE"; + case ClosureType: return "NONE_CLOSURE"; case NumType: return "nan(\"null\")"; case StructType: return CORD_all("((", compile_type(Type(OptionalType, .type=t)), "){.is_null=yes})"); case EnumType: { @@ -3245,12 +3245,12 @@ CORD compile(env_t *env, ast_t *ast) CORD code = CORD_all( "({ // Reduction:\n", compile_declaration(item_t, "prev"), ";\n" - "OptionalBool_t result = NULL_BOOL;\n" + "OptionalBool_t result = NONE_BOOL;\n" ); ast_t *comparison = WrapAST(ast, BinaryOp, .op=op, .lhs=FakeAST(InlineCCode, .code="prev", .type=item_t), .rhs=item); body->__data.InlineCCode.code = CORD_all( - "if (result == NULL_BOOL) {\n" + "if (result == NONE_BOOL) {\n" " prev = ", compile(body_scope, item), ";\n" " result = yes;\n" "} else {\n" @@ -3439,7 +3439,7 @@ CORD compile(env_t *env, ast_t *ast) "values.data += ", CORD_asprintf("%zu", offset), ";\n" "values; })"); } else if (streq(f->field, "fallback")) { - return CORD_all("({ Table_t *_fallback = (", compile_to_pointer_depth(env, f->fielded, 0, false), ").fallback; _fallback ? *_fallback : NULL_TABLE; })"); + return CORD_all("({ Table_t *_fallback = (", compile_to_pointer_depth(env, f->fielded, 0, false), ").fallback; _fallback ? *_fallback : NONE_TABLE; })"); } code_err(ast, "There is no '%s' field on tables", f->field); } diff --git a/docs/arrays.md b/docs/arrays.md index b69ae25..c1886d4 100644 --- a/docs/arrays.md +++ b/docs/arrays.md @@ -366,7 +366,7 @@ The index of the first occurrence or `!Int` if not found. = 2 : Int? >> [10, 20, 30, 40, 50]:find(9999) -= NULL : Int? += NONE : Int? ``` --- @@ -396,7 +396,7 @@ item matches. >> [4, 5, 6]:find(func(i:&Int): i:is_prime()) = 5 : Int? >> [4, 6, 8]:find(func(i:&Int): i:is_prime()) -= NULL : Int? += NONE : Int? ``` --- diff --git a/docs/booleans.md b/docs/booleans.md index 3537e3e..d2a22d5 100644 --- a/docs/booleans.md +++ b/docs/booleans.md @@ -33,5 +33,5 @@ func parse(text: Text -> Bool?) >> Bool.parse("no") = no : Bool? >> Bool.parse("???") -= NULL : Bool? += NONE : Bool? ``` diff --git a/docs/integers.md b/docs/integers.md index d995d13..213aa1b 100644 --- a/docs/integers.md +++ b/docs/integers.md @@ -171,7 +171,7 @@ func parse(text: Text -> Int?) **Returns:** The integer represented by the text. If the given text contains a value outside of the representable range or if the entire text can't be parsed as an integer, -`NULL` will be returned. +`NONE` will be returned. **Example:** ```tomo @@ -182,11 +182,11 @@ of the representable range or if the entire text can't be parsed as an integer, # Can't parse: >> Int.parse("asdf") -= NULL : Int? += NONE : Int? # Outside valid range: >> Int8.parse("9999999") -= NULL : Int8? += NONE : Int8? ``` --- diff --git a/docs/iterators.md b/docs/iterators.md index ee777cf..064af9c 100644 --- a/docs/iterators.md +++ b/docs/iterators.md @@ -22,7 +22,7 @@ successively gets one line from a file at a time until the file is exhausted: >> iter() = "line three" : Text? >> iter() -= NULL : Text? += NONE : Text? for line in (./test.txt):each_line(): pass diff --git a/docs/metamethods.md b/docs/metamethods.md index ca2eccc..a3f73b5 100644 --- a/docs/metamethods.md +++ b/docs/metamethods.md @@ -6,7 +6,7 @@ behavior that is required for all types: - `func as_text(obj:&T?, colorize=no, type:&TypeInfo_t -> Text)`: a method to convert the type to a string. If `colorize` is `yes`, then the method should include ANSI escape codes for syntax highlighting. If the `obj` pointer is - `NULL`, a string representation of the type will be returned instead. + `NONE`, a string representation of the type will be returned instead. - `func compare(x:&T, y:&T, type:&TypeInfo_t -> Int32)`: Return an integer representing the result of comparing `x` and `y`, where negative numbers mean `x` is less diff --git a/docs/moments.md b/docs/moments.md index 6e2ac23..84b71d0 100644 --- a/docs/moments.md +++ b/docs/moments.md @@ -523,7 +523,7 @@ Returns a `Moment` object representing the current date and time. **Description:** Return a new `Moment` object parsed from the given string in the given format, -or `NULL` if the value could not be successfully parsed. +or `NONE` if the value could not be successfully parsed. **Signature:** ```tomo @@ -539,7 +539,7 @@ func parse(text: Text, format: Text = "%Y-%m-%dT%H:%M:%S%z" -> Moment?) **Returns:** If the text was successfully parsed according to the given format, return a -`Moment` representing that information. Otherwise, return `NULL`. +`Moment` representing that information. Otherwise, return `NONE`. **Example:** ```tomo diff --git a/docs/nums.md b/docs/nums.md index 0b55f71..acf195d 100644 --- a/docs/nums.md +++ b/docs/nums.md @@ -583,7 +583,7 @@ func parse(text: Text -> Num?) - `text`: The text containing the number. **Returns:** -The number represented by the text or `NULL` if the entire text can't be parsed +The number represented by the text or `NONE` if the entire text can't be parsed as a number. **Example:** diff --git a/docs/optionals.md b/docs/optionals.md index bb2aecf..584625f 100644 --- a/docs/optionals.md +++ b/docs/optionals.md @@ -63,7 +63,7 @@ x = !Int ## Type Inference -For convenience, null values can also be written as `NULL` for any type in +For convenience, null values can also be written as `NONE` for any type in situations where the compiler knows what type of optional value is expected: - When assigning to a variable that has already been declared as optional. @@ -74,12 +74,12 @@ Here are some examples: ```tomo x := 5? -x = NULL +x = NONE func doop(arg:Int?)->Text?: - return NULL + return NONE -doop(NULL) +doop(NONE) ``` Non-null values can also be automatically promoted to optional values without diff --git a/docs/paths.md b/docs/paths.md index b2dfe38..f2b4452 100644 --- a/docs/paths.md +++ b/docs/paths.md @@ -495,7 +495,7 @@ raised. = "Hello" : Text? >> (./nosuchfile.xxx):read() -= NULL : Text? += NONE : Text? ``` --- @@ -524,7 +524,7 @@ returned. = [72[B], 101[B], 108[B], 108[B], 111[B]] : [Byte]? >> (./nosuchfile.xxx):read() -= NULL : [Byte]? += NONE : [Byte]? ``` --- diff --git a/docs/reductions.md b/docs/reductions.md index 2ed6879..d68b388 100644 --- a/docs/reductions.md +++ b/docs/reductions.md @@ -22,7 +22,7 @@ nums := [:Int] sum := (+: nums) >> sum -= NULL : Int? += NONE : Int? >> sum or 0 = 0 diff --git a/docs/tables.md b/docs/tables.md index 6a6c700..6cbe859 100644 --- a/docs/tables.md +++ b/docs/tables.md @@ -50,7 +50,7 @@ was found or error if it wasn't: >> t:get("x") = 1 : Int? >> t:get("????") -= NULL : Int? += NONE : Int? >> t:get("x")! = 1 ``` @@ -190,7 +190,7 @@ The value associated with the key or null if the key is not found. = 1 : Int? >> t:get("????") -= NULL : Int? += NONE : Int? >> t:get("A")! = 1 : Int diff --git a/docs/text.md b/docs/text.md index 15b08d9..d67f0a7 100644 --- a/docs/text.md +++ b/docs/text.md @@ -3,7 +3,7 @@ `Text` is Tomo's datatype to represent text. The name `Text` is used instead of "string" because Tomo text represents immutable, normalized unicode data with fast indexing that has an implementation that is efficient for concatenation. -These are _not_ C-style NULL-terminated character arrays. GNU libunistring is +These are _not_ C-style NUL-terminated character arrays. GNU libunistring is used for full Unicode functionality (grapheme cluster counts, capitalization, etc.). @@ -695,9 +695,9 @@ containing information about the match. **Example:** ```tomo >> " #one #two #three ":find($/#{id}/, start=-999) -= NULL : Match? += NONE : Match? >> " #one #two #three ":find($/#{id}/, start=999) -= NULL : Match? += NONE : Match? >> " #one #two #three ":find($/#{id}/) = Match(text="#one", index=2, captures=["one"]) : Match? >> " #one #two #three ":find("{id}", start=6) @@ -887,7 +887,7 @@ or a null value otherwise. **Example:** ```tomo >> "hello world":matches($/{id}/) -= NULL : [Text]? += NONE : [Text]? >> "hello world":matches($/{id} {id}/) = ["hello", "world"] : [Text]? diff --git a/parse.c b/parse.c index bc25e89..b1d9f73 100644 --- a/parse.c +++ b/parse.c @@ -53,7 +53,7 @@ int op_tightness[] = { static const char *keywords[] = { "yes", "xor", "while", "when", "use", "unless", "struct", "stop", "skip", "return", "or", "not", "no", "mod1", "mod", "pass", "lang", "inline", "in", "if", - "func", "for", "extern", "enum", "else", "do", "defer", "and", "_min_", "_max_", + "func", "for", "extern", "enum", "else", "do", "defer", "and", "NONE", "_min_", "_max_", NULL, }; @@ -1532,7 +1532,7 @@ PARSER(parse_lambda) { PARSER(parse_null) { const char *start = pos; - if (match_word(&pos, "NULL")) + if (match_word(&pos, "NONE")) return NewAST(ctx->file, start, pos, Null, .type=NULL); if (!match(&pos, "!")) return NULL; type_ast_t *type = parse_type(ctx, pos); diff --git a/stdlib/arrays.c b/stdlib/arrays.c index 8814f31..4db3d2d 100644 --- a/stdlib/arrays.c +++ b/stdlib/arrays.c @@ -222,7 +222,7 @@ public Int_t Array$find(Array_t arr, void *item, const TypeInfo_t *type) if (generic_equal(item, arr.data + i*arr.stride, item_type)) return I(i+1); } - return NULL_INT; + return NONE_INT; } public Int_t Array$first(Array_t arr, Closure_t predicate) @@ -232,7 +232,7 @@ public Int_t Array$first(Array_t arr, Closure_t predicate) if (is_good(arr.data + i*arr.stride, predicate.userdata)) return I(i+1); } - return NULL_INT; + return NONE_INT; } public void Array$sort(Array_t *arr, Closure_t comparison, int64_t padded_item_size) diff --git a/stdlib/bools.c b/stdlib/bools.c index 9a2c8cd..50cd3f4 100644 --- a/stdlib/bools.c +++ b/stdlib/bools.c @@ -35,7 +35,7 @@ PUREFUNC public OptionalBool_t Bool$parse(Text_t text) || Text$equal_ignoring_case(text, Text("0"))) { return no; } else { - return NULL_BOOL; + return NONE_BOOL; } } diff --git a/stdlib/bytes.h b/stdlib/bytes.h index ef5c072..8c14ef1 100644 --- a/stdlib/bytes.h +++ b/stdlib/bytes.h @@ -35,6 +35,6 @@ typedef struct { bool is_null:1; } OptionalByte_t; -#define NULL_BYTE ((OptionalByte_t){.is_null=true}) +#define NONE_BYTE ((OptionalByte_t){.is_null=true}) // vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 diff --git a/stdlib/integers.c b/stdlib/integers.c index 3b95c99..baf1b0c 100644 --- a/stdlib/integers.c +++ b/stdlib/integers.c @@ -303,7 +303,7 @@ public Int_t Int$power(Int_t base, Int_t exponent) public OptionalInt_t Int$sqrt(Int_t i) { if (Int$compare_value(i, I(0)) < 0) - return NULL_INT; + return NONE_INT; mpz_t result; mpz_init_set_int(result, i); mpz_sqrt(result, result); @@ -327,7 +327,7 @@ public Int_t Int$from_str(const char *str) { result = mpz_init_set_str(i, str, 10); } if (result != 0) - return NULL_INT; + return NONE_INT; return Int$from_mpz(i); } diff --git a/stdlib/integers.h b/stdlib/integers.h index 7bda639..0c4b87f 100644 --- a/stdlib/integers.h +++ b/stdlib/integers.h @@ -79,10 +79,10 @@ DEFINE_INT_TYPE(int16_t, Int16, CONSTFUNC) DEFINE_INT_TYPE(int8_t, Int8, CONSTFUNC) #undef DEFINE_INT_TYPE -#define NULL_INT64 ((OptionalInt64_t){.is_null=true}) -#define NULL_INT32 ((OptionalInt32_t){.is_null=true}) -#define NULL_INT16 ((OptionalInt16_t){.is_null=true}) -#define NULL_INT8 ((OptionalInt8_t){.is_null=true}) +#define NONE_INT64 ((OptionalInt64_t){.is_null=true}) +#define NONE_INT32 ((OptionalInt32_t){.is_null=true}) +#define NONE_INT16 ((OptionalInt16_t){.is_null=true}) +#define NONE_INT8 ((OptionalInt8_t){.is_null=true}) #define Int64$abs(...) I64(labs(__VA_ARGS__)) #define Int32$abs(...) I32(abs(__VA_ARGS__)) diff --git a/stdlib/moments.c b/stdlib/moments.c index 955d5e9..848626c 100644 --- a/stdlib/moments.c +++ b/stdlib/moments.c @@ -14,7 +14,7 @@ #include "text.h" #include "util.h" -static OptionalText_t _local_timezone = NULL_TEXT; +static OptionalText_t _local_timezone = NONE_TEXT; #define WITH_TIMEZONE(tz, body) ({ if (tz.length >= 0) { \ OptionalText_t old_timezone = _local_timezone; \ @@ -220,7 +220,7 @@ public OptionalMoment_t Moment$parse(Text_t text, Text_t format) char *invalid = strptime(str, fmt, &info); if (!invalid || invalid[0] != '\0') - return NULL_MOMENT; + return NONE_MOMENT; long offset = info.tm_gmtoff; // Need to cache this because mktime() mutates it to local timezone >:( time_t t = mktime(&info); diff --git a/stdlib/optionals.c b/stdlib/optionals.c index 8c29522..2fb734f 100644 --- a/stdlib/optionals.c +++ b/stdlib/optionals.c @@ -18,7 +18,7 @@ public PUREFUNC bool is_null(const void *obj, const TypeInfo_t *non_optional_typ if (non_optional_type == &Int$info) return ((Int_t*)obj)->small == 0; else if (non_optional_type == &Bool$info) - return *((OptionalBool_t*)obj) == NULL_BOOL; + return *((OptionalBool_t*)obj) == NONE_BOOL; else if (non_optional_type == &Num$info) return isnan(*((Num_t*)obj)); else if (non_optional_type == &Num32$info) @@ -72,7 +72,7 @@ public Text_t Optional$as_text(const void *obj, bool colorize, const TypeInfo_t return Text$concat(generic_as_text(obj, colorize, type->OptionalInfo.type), Text("?")); if (is_null(obj, type->OptionalInfo.type)) - return colorize ? Text("\x1b[31mNULL\x1b[m") : Text("NULL"); + return colorize ? Text("\x1b[31mNONE\x1b[m") : Text("NONE"); return generic_as_text(obj, colorize, type->OptionalInfo.type); } diff --git a/stdlib/optionals.h b/stdlib/optionals.h index b532647..7d52375 100644 --- a/stdlib/optionals.h +++ b/stdlib/optionals.h @@ -16,13 +16,13 @@ #define OptionalText_t Text_t #define OptionalClosure_t Closure_t -#define NULL_ARRAY ((Array_t){.length=-1}) -#define NULL_BOOL ((OptionalBool_t)2) -#define NULL_INT ((OptionalInt_t){.small=0}) -#define NULL_TABLE ((OptionalTable_t){.entries.length=-1}) -#define NULL_CLOSURE ((OptionalClosure_t){.fn=NULL}) -#define NULL_TEXT ((OptionalText_t){.length=-1}) -#define NULL_MOMENT ((OptionalMoment_t){.tv_usec=-1}) +#define NONE_ARRAY ((Array_t){.length=-1}) +#define NONE_BOOL ((OptionalBool_t)2) +#define NONE_INT ((OptionalInt_t){.small=0}) +#define NONE_TABLE ((OptionalTable_t){.entries.length=-1}) +#define NONE_CLOSURE ((OptionalClosure_t){.fn=NULL}) +#define NONE_TEXT ((OptionalText_t){.length=-1}) +#define NONE_MOMENT ((OptionalMoment_t){.tv_usec=-1}) PUREFUNC bool is_null(const void *obj, const TypeInfo_t *non_optional_type); Text_t Optional$as_text(const void *obj, bool colorize, const TypeInfo_t *type); diff --git a/stdlib/paths.c b/stdlib/paths.c index 5649271..ee73647 100644 --- a/stdlib/paths.c +++ b/stdlib/paths.c @@ -209,7 +209,7 @@ public OptionalMoment_t Path$modified(Path_t path, bool follow_symlinks) { struct stat sb; int status = path_stat(path, follow_symlinks, &sb); - if (status != 0) return NULL_MOMENT; + if (status != 0) return NONE_MOMENT; return (Moment_t){.tv_sec=sb.st_mtime}; } @@ -217,7 +217,7 @@ public OptionalMoment_t Path$accessed(Path_t path, bool follow_symlinks) { struct stat sb; int status = path_stat(path, follow_symlinks, &sb); - if (status != 0) return NULL_MOMENT; + if (status != 0) return NONE_MOMENT; return (Moment_t){.tv_sec=sb.st_atime}; } @@ -225,7 +225,7 @@ public OptionalMoment_t Path$changed(Path_t path, bool follow_symlinks) { struct stat sb; int status = path_stat(path, follow_symlinks, &sb); - if (status != 0) return NULL_MOMENT; + if (status != 0) return NONE_MOMENT; return (Moment_t){.tv_sec=sb.st_ctime}; } @@ -271,11 +271,11 @@ public OptionalArray_t Path$read_bytes(Path_t path, OptionalInt_t count) path = Path$_expand_home(path); int fd = open(Text$as_c_string(path), O_RDONLY); if (fd == -1) - return NULL_ARRAY; + return NONE_ARRAY; struct stat sb; if (fstat(fd, &sb) != 0) - return NULL_ARRAY; + return NONE_ARRAY; int64_t const target_count = count.small ? Int_to_Int64(count, false) : INT64_MAX; if (target_count < 0) @@ -301,7 +301,7 @@ public OptionalArray_t Path$read_bytes(Path_t path, OptionalInt_t count) ssize_t just_read = read(fd, chunk, to_read); if (just_read < 0) { close(fd); - return NULL_ARRAY; + return NONE_ARRAY; } else if (just_read == 0) { if (errno == EAGAIN || errno == EINTR) continue; @@ -325,8 +325,8 @@ public OptionalArray_t Path$read_bytes(Path_t path, OptionalInt_t count) public OptionalText_t Path$read(Path_t path) { - Array_t bytes = Path$read_bytes(path, NULL_INT); - if (bytes.length < 0) return NULL_TEXT; + Array_t bytes = Path$read_bytes(path, NONE_INT); + if (bytes.length < 0) return NONE_TEXT; return Text$from_bytes(bytes); } @@ -511,14 +511,14 @@ static void _line_reader_cleanup(FILE **f) static Text_t _next_line(FILE **f) { - if (!f || !*f) return NULL_TEXT; + if (!f || !*f) return NONE_TEXT; char *line = NULL; size_t size = 0; ssize_t len = getline(&line, &size, *f); if (len <= 0) { _line_reader_cleanup(f); - return NULL_TEXT; + return NONE_TEXT; } while (len > 0 && (line[len-1] == '\r' || line[len-1] == '\n')) @@ -538,7 +538,7 @@ public OptionalClosure_t Path$by_line(Path_t path) FILE *f = fopen(Text$as_c_string(path), "r"); if (f == NULL) - return NULL_CLOSURE; + return NONE_CLOSURE; FILE **wrapper = GC_MALLOC(sizeof(FILE*)); *wrapper = f; diff --git a/stdlib/patterns.c b/stdlib/patterns.c index 97cade4..3bf2ebf 100644 --- a/stdlib/patterns.c +++ b/stdlib/patterns.c @@ -802,13 +802,13 @@ public OptionalMatch_t Text$find(Text_t text, Pattern_t pattern, Int_t from_inde if (first == 0) fail("Invalid index: 0"); if (first < 0) first = text.length + first + 1; if (first > text.length || first < 1) - return NULL_MATCH; + return NONE_MATCH; capture_t captures[MAX_BACKREFS] = {}; int64_t len = 0; int64_t found = _find(text, pattern, first-1, text.length-1, &len, captures); if (found == -1) - return NULL_MATCH; + return NONE_MATCH; Array_t capture_array = {}; for (int i = 0; captures[i].occupied; i++) { @@ -845,7 +845,7 @@ public OptionalArray_t Text$matches(Text_t text, Pattern_t pattern) capture_t captures[MAX_BACKREFS] = {}; int64_t match_len = match(text, 0, pattern, 0, captures, 0); if (match_len != text.length) - return NULL_ARRAY; + return NONE_ARRAY; Array_t capture_array = {}; for (int i = 0; captures[i].occupied; i++) { diff --git a/stdlib/patterns.h b/stdlib/patterns.h index 2b30a3a..641009a 100644 --- a/stdlib/patterns.h +++ b/stdlib/patterns.h @@ -21,7 +21,7 @@ typedef struct { } Match_t; typedef Match_t OptionalMatch_t; -#define NULL_MATCH ((OptionalMatch_t){.index=NULL_INT}) +#define NONE_MATCH ((OptionalMatch_t){.index=NONE_INT}) Text_t Text$replace(Text_t str, Pattern_t pat, Text_t replacement, Pattern_t backref_pat, bool recursive); Pattern_t Pattern$escape_text(Text_t text); diff --git a/stdlib/shell.c b/stdlib/shell.c index 68c6111..ec78f5e 100644 --- a/stdlib/shell.c +++ b/stdlib/shell.c @@ -50,7 +50,7 @@ public OptionalArray_t Shell$run_bytes(Shell_t command) const char *cmd_str = Text$as_c_string(command); FILE *prog = popen(cmd_str, "r"); if (!prog) - return NULL_ARRAY; + return NONE_ARRAY; size_t capacity = 256, len = 0; char *content = GC_MALLOC_ATOMIC(capacity); @@ -73,7 +73,7 @@ public OptionalArray_t Shell$run_bytes(Shell_t command) int status = pclose(prog); if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) - return NULL_ARRAY; + return NONE_ARRAY; return (Array_t){.data=content, .atomic=1, .stride=1, .length=len}; } @@ -82,7 +82,7 @@ public OptionalText_t Shell$run(Shell_t command) { Array_t bytes = Shell$run_bytes(command); if (bytes.length < 0) - return NULL_TEXT; + return NONE_TEXT; if (bytes.length > 0 && *(char*)(bytes.data + (bytes.length-1)*bytes.stride) == '\n') { --bytes.length; @@ -102,14 +102,14 @@ static void _line_reader_cleanup(FILE **f) static Text_t _next_line(FILE **f) { - if (!f || !*f) return NULL_TEXT; + if (!f || !*f) return NONE_TEXT; char *line = NULL; size_t size = 0; ssize_t len = getline(&line, &size, *f); if (len <= 0) { _line_reader_cleanup(f); - return NULL_TEXT; + return NONE_TEXT; } while (len > 0 && (line[len-1] == '\r' || line[len-1] == '\n')) @@ -128,7 +128,7 @@ public OptionalClosure_t Shell$by_line(Shell_t command) const char *cmd_str = Text$as_c_string(command); FILE *prog = popen(cmd_str, "r"); if (!prog) - return NULL_CLOSURE; + return NONE_CLOSURE; FILE **wrapper = GC_MALLOC(sizeof(FILE*)); *wrapper = prog; diff --git a/stdlib/stdlib.c b/stdlib/stdlib.c index 0e72dfc..5d51f65 100644 --- a/stdlib/stdlib.c +++ b/stdlib/stdlib.c @@ -96,9 +96,9 @@ static bool parse_single_arg(const TypeInfo_t *info, char *arg, void *dest) return !parsed.is_null; } else if (info == &Bool$info) { OptionalBool_t parsed = Bool$parse(Text$from_str(arg)); - if (parsed != NULL_BOOL) + if (parsed != NONE_BOOL) *(OptionalBool_t*)dest = parsed; - return parsed != NULL_BOOL; + return parsed != NONE_BOOL; } else if (info == &Num$info) { OptionalNum_t parsed = Num$parse(Text$from_str(arg)); if (!isnan(parsed)) diff --git a/stdlib/text.c b/stdlib/text.c index 69e54ff..8a05f96 100644 --- a/stdlib/text.c +++ b/stdlib/text.c @@ -678,7 +678,7 @@ public OptionalText_t Text$from_strn(const char *str, size_t len) return ret; } else { if (u8_check((uint8_t*)str, len) != NULL) - return NULL_TEXT; + return NONE_TEXT; ucs4_t buf[128]; size_t length = sizeof(buf)/sizeof(buf[0]); @@ -1330,7 +1330,7 @@ public OptionalText_t Text$from_codepoint_names(Array_t codepoint_names) const char *name_str = Text$as_c_string(*name); ucs4_t codepoint = unicode_name_character(name_str); if (codepoint == UNINAME_INVALID) - return NULL_TEXT; + return NONE_TEXT; Array$insert(&codepoints, &codepoint, I_small(0), sizeof(ucs4_t)); } return Text$from_codepoints(codepoints); diff --git a/test/arrays.tm b/test/arrays.tm index a6de26c..6f99f3f 100644 --- a/test/arrays.tm +++ b/test/arrays.tm @@ -166,9 +166,9 @@ func main(): >> ["a", "b", "c"]:find("b") = 2 : Int? >> ["a", "b", "c"]:find("XXX") - = NULL : Int? + = NONE : Int? >> [10, 20]:first(func(i:&Int): i:is_prime()) - = NULL : Int? + = NONE : Int? >> [4, 5, 6]:first(func(i:&Int): i:is_prime()) = 2 : Int? diff --git a/test/nums.tm b/test/nums.tm index 4e6d34a..9d3e9a6 100644 --- a/test/nums.tm +++ b/test/nums.tm @@ -23,9 +23,9 @@ func main(): = yes >> Num.NAN - = NULL : Num? + = NONE : Num? >> nan := Num.NAN - = NULL : Num? + = NONE : Num? >> nan == nan = yes >> nan < nan @@ -48,10 +48,10 @@ func main(): = -1 >> nan + 1 - = NULL : Num? + = NONE : Num? >> 0./0. - = NULL : Num? + = NONE : Num? >> Num.PI:cos()!:near(-1) = yes diff --git a/test/optionals.tm b/test/optionals.tm index 8efae41..84a4a9c 100644 --- a/test/optionals.tm +++ b/test/optionals.tm @@ -4,7 +4,7 @@ struct Struct(x:Int, y:Text): if should_i: return Struct(123, "hello") else: - return NULL + return NONE enum Enum(X, Y(y:Int)): func maybe(should_i:Bool->Enum?): @@ -100,7 +100,7 @@ func main(): >> yep := maybe_int(yes) = 123 : Int? >> nope := maybe_int(no) - = NULL : Int? + = NONE : Int? >> if yep: >> yep = 123 @@ -115,7 +115,7 @@ func main(): >> yep := maybe_int64(yes) = 123 : Int64? >> nope := maybe_int64(no) - = NULL : Int64? + = NONE : Int64? >> if yep: >> yep = 123 @@ -130,7 +130,7 @@ func main(): >> yep := maybe_array(yes) = [10, 20, 30] : [Int]? >> nope := maybe_array(no) - = NULL : [Int]? + = NONE : [Int]? >> if yep: >> yep = [10, 20, 30] @@ -145,7 +145,7 @@ func main(): >> yep := maybe_bool(yes) = no : Bool? >> nope := maybe_bool(no) - = NULL : Bool? + = NONE : Bool? >> if yep: >> yep = no @@ -160,7 +160,7 @@ func main(): >> yep := maybe_text(yes) = "Hello" : Text? >> nope := maybe_text(no) - = NULL : Text? + = NONE : Text? >> if yep: >> yep = "Hello" @@ -175,7 +175,7 @@ func main(): >> yep := maybe_num(yes) = 12.3 : Num? >> nope := maybe_num(no) - = NULL : Num? + = NONE : Num? >> if yep: >> yep = 12.3 @@ -190,7 +190,7 @@ func main(): >> yep := maybe_lambda(yes) = func() [optionals.tm:54] : func()? >> nope := maybe_lambda(no) - = NULL : func()? + = NONE : func()? >> if yep: >> yep = func() [optionals.tm:54] @@ -205,7 +205,7 @@ func main(): >> yep := Struct.maybe(yes) = Struct(x=123, y="hello") : Struct? >> nope := Struct.maybe(no) - = NULL : Struct? + = NONE : Struct? >> if yep: >> yep = Struct(x=123, y="hello") @@ -220,7 +220,7 @@ func main(): >> yep := Enum.maybe(yes) = Enum.Y(123) : Enum? >> nope := Enum.maybe(no) - = NULL : Enum? + = NONE : Enum? >> if yep: >> yep = Enum.Y(123) @@ -235,7 +235,7 @@ func main(): >> yep := maybe_c_string(yes) = CString("hi") : CString? >> nope := maybe_c_string(no) - = NULL : CString? + = NONE : CString? >> if yep: >> yep = CString("hi") @@ -250,7 +250,7 @@ func main(): >> yep := maybe_channel(yes) # No "=" test here because channels use addresses in the text version >> nope := maybe_channel(no) - = NULL : |:Int|? + = NONE : |:Int|? >> if yep: >> yep else: fail("Falsey: $yep") >> if nope: @@ -263,7 +263,7 @@ func main(): >> yep := maybe_thread(yes) # No "=" test here because threads use addresses in the text version >> nope := maybe_thread(no) - = NULL : Thread? + = NONE : Thread? >> if yep: >> yep else: fail("Falsey: $yep") >> if nope: @@ -284,9 +284,9 @@ func main(): >> (5? == 5?) = yes >> {!Int, !Int} - = {NULL} + = {NONE} >> [5?, !Int, !Int, 6?]:sorted() - = [NULL, NULL, 5, 6] + = [NONE, NONE, 5, 6] do: >> value := if var := 5?: diff --git a/test/paths.tm b/test/paths.tm index 62cecec..25cb4e5 100644 --- a/test/paths.tm +++ b/test/paths.tm @@ -36,9 +36,9 @@ func main(): fail("Couldn't read lines in $tmpfile") >> (./does-not-exist.xxx):read() - = NULL : Text? + = NONE : Text? >> (./does-not-exist.xxx):read_bytes() - = NULL : [Byte]? + = NONE : [Byte]? if lines := (./does-not-exist.xxx):by_line(): fail("I could read lines in a nonexistent file") else: diff --git a/test/reductions.tm b/test/reductions.tm index 23ccf09..26f3533 100644 --- a/test/reductions.tm +++ b/test/reductions.tm @@ -5,7 +5,7 @@ func main(): = 60 : Int? >> (+: [:Int]) - = NULL : Int? + = NONE : Int? >> (+: [10, 20, 30]) or 0 = 60 @@ -37,7 +37,7 @@ func main(): = yes >> (<=: [:Int]) - = NULL : Bool? + = NONE : Bool? >> (<=: [5, 4, 3, 2, 1])! = no diff --git a/test/tables.tm b/test/tables.tm index 85ce5e0..acda0eb 100644 --- a/test/tables.tm +++ b/test/tables.tm @@ -7,7 +7,7 @@ func main(): >> t:get("two") = 2 : Int? >> t:get("???") - = NULL : Int? + = NONE : Int? >> t:get("one")! = 1 >> t:get("???") or -1 @@ -22,7 +22,7 @@ func main(): >> t.length = 2 >> t.fallback - = NULL : {Text:Int}? + = NONE : {Text:Int}? >> t.keys = ["one", "two"] @@ -37,7 +37,7 @@ func main(): >> t2:get("three") = 3 : Int? >> t2:get("???") - = NULL : Int? + = NONE : Int? >> t2.length = 1 diff --git a/test/text.tm b/test/text.tm index cd00940..c6fb6ad 100644 --- a/test/text.tm +++ b/test/text.tm @@ -35,7 +35,7 @@ func main(): >> Text.from_bytes([:Byte 0x41, 0x6D, 0xC3, 0xA9, 0x6C, 0x69, 0x65])! = "Amélie" >> Text.from_bytes([Byte(0xFF)]) - = NULL : Text? + = NONE : Text? >> amelie2 := "Am$(\U65\U301)lie" >> amelie2:split() @@ -189,9 +189,9 @@ func main(): !! Test text:find() >> " one two three ":find($/{id}/, start=-999) - = NULL : Match? + = NONE : Match? >> " one two three ":find($/{id}/, start=999) - = NULL : Match? + = NONE : Match? >> " one two three ":find($/{id}/) = Match(text="one", index=2, captures=["one"]) : Match? >> " one two three ":find($/{id}/, start=5) @@ -222,7 +222,7 @@ func main(): = ["PENGUIN"] >> Text.from_codepoint_names(["not a valid name here buddy"]) - = NULL : Text? + = NONE : Text? >> "one two; three four":find_all($/; {..}/) = [Match(text="; three four", index=8, captures=["three four"])] @@ -249,11 +249,11 @@ func main(): >> "Hello":matches($/{id}/) = ["Hello"] : [Text]? >> "Hello":matches($/{lower}/) - = NULL : [Text]? + = NONE : [Text]? >> "Hello":matches($/{upper}/) - = NULL : [Text]? + = NONE : [Text]? >> "Hello...":matches($/{id}/) - = NULL : [Text]? + = NONE : [Text]? if matches := "hello world":matches($/{id} {id}/): >> matches diff --git a/tomo.c b/tomo.c index 3b46c83..e550175 100644 --- a/tomo.c +++ b/tomo.c @@ -30,8 +30,8 @@ #define run_cmd(...) ({ const char *_cmd = heap_strf(__VA_ARGS__); if (verbose) puts(_cmd); popen(_cmd, "w"); }) #define array_str(arr) Text$as_c_string(Text$join(Text(" "), arr)) -static OptionalArray_t files = NULL_ARRAY, - args = NULL_ARRAY; +static OptionalArray_t files = NONE_ARRAY, + args = NONE_ARRAY; static OptionalBool_t verbose = false, show_codegen = false, stop_at_transpile = false,