- Create optional with ~ instead of ?. return io::EOF?; becomes return io::EOF~.

- Deprecated use of `?` to create optional.
This commit is contained in:
Christoffer Lerno
2026-01-20 16:10:28 +01:00
parent 5390ca6250
commit cdabe8fd9e
159 changed files with 710 additions and 707 deletions

View File

@@ -88,7 +88,7 @@ fn int? decode(String in, char* out, int* invalid_char_index = null)
if (c == ERR)
{
if (invalid_char_index) *invalid_char_index = i;
return INVALID_CHARACTER?;
return INVALID_CHARACTER~;
}

View File

@@ -9,7 +9,7 @@ faultdef INTEPRET_FAILED;
fn void? print_error_type_at(usz pos, String err)
{
io::printfn("Error at %s: %s", pos, err);
return INTEPRET_FAILED?;
return INTEPRET_FAILED~;
}
fn void? brainf(String program)

View File

@@ -29,7 +29,7 @@ fn void? Summary.print(Summary* s, OutStream out)
fn Doc? read_doc(String url)
{
if (url.contains("fail")) return BAD_READ?;
if (url.contains("fail")) return BAD_READ~;
if (url.contains("head-missing")) return { };
if (url.contains("title-missing")) return { .head = maybe::value{Head}({}) };
if (url.contains("title-empty")) return { .head = maybe::value{Head}({ .title = maybe::value{String}("")}) };
@@ -52,7 +52,7 @@ fn Summary read_and_build_summary(String url)
fn bool? is_title_non_empty(Doc doc)
{
String? title = doc.head.get().title.get();
if (catch title) return TITLE_MISSING?;
if (catch title) return TITLE_MISSING~;
return title.len > 0;
}

View File

@@ -36,7 +36,7 @@ fn Resource? prep_out(String out_name, String[] prep_names)
@open_with(name; Resource reader)
{
io::printfn("use %s", reader.name);
// if (true) return WELCOME_TO_YOUR_DOOM?;
// if (true) return WELCOME_TO_YOUR_DOOM~;
}!;
}
return writer;

View File

@@ -18,8 +18,8 @@ int err_count = 0;
fn int? ask_guess(int high)
{
io::printf("Guess a number between 1 and %d: ", high);
String text = io::treadline() ?? FAILED_TO_READ?!;
return text.to_int() ?? NOT_AN_INT?;
String text = io::treadline() ?? FAILED_TO_READ~!;
return text.to_int() ?? NOT_AN_INT~;
}
fn int? ask_guess_multi(int high)

View File

@@ -35,17 +35,17 @@ fn void Map.init(Map *map, uint capacity = 128)
fn Type? Map.valueForKey(Map *map, Key key)
{
if (!map.map) return faults::KEY_NOT_FOUND?;
if (!map.map) return faults::KEY_NOT_FOUND~;
uint hash = key.hash();
usz pos = hash & map.mod;
Entry* entry = &map.map[pos];
if (!entry) return faults::KEY_NOT_FOUND?;
if (!entry) return faults::KEY_NOT_FOUND~;
while (entry)
{
if (entry.hash == hash && entry.key == key) return entry.value;
entry = entry.next;
}
return faults::KEY_NOT_FOUND?;
return faults::KEY_NOT_FOUND~;
}
fn Type? Map.set(Map *map, Key key, Type value) @maydiscard
@@ -67,7 +67,7 @@ fn Type? Map.set(Map *map, Key key, Type value) @maydiscard
entry.value = value;
entry.hash = hash;
entry.key = key;
return faults::KEY_NOT_FOUND?;
return faults::KEY_NOT_FOUND~;
}
if (entry.hash == hash && entry.key == key)
{
@@ -87,7 +87,7 @@ fn Type? Map.set(Map *map, Key key, Type value) @maydiscard
new.next = null;
new.used = true;
entry.next = new;
return faults::KEY_NOT_FOUND?;
return faults::KEY_NOT_FOUND~;
}
}

View File

@@ -74,7 +74,7 @@ fn String? read_next(String* remaining)
}
// If it's a zero length token, return an optional result.
if (!len) return NO_MORE_TOKENS?;
if (!len) return NO_MORE_TOKENS~;
// Otherwise create a slice from the pointer start and length.
return (String)ptr_start[:len];

View File

@@ -6,7 +6,7 @@ faultdef NOPE;
fn int? eventually_succeed()
{
static int i = 0;
if (i++ < 3) return NOPE?;
if (i++ < 3) return NOPE~;
return i * 3;
}
@@ -24,7 +24,7 @@ macro @retry(#function, int retries = 3)
}
return result;
} while (retries-- > 0);
return e?;
return e~;
}
fn void main()