Updated grammar. Removal of elif. Removal of ':' ';' in some ct statements. Empty faults is now an error. Remove "define" for types. Remove "private". Better errors on incorrect bitstruct syntax. Introduction of wildcard type rather than optional wildcard. Removal of scaled vector type. mkdir and rmdir. Disallow define @Foo() = { @inline }. Add handling for @optreturn and change it to @return!. Restrict interface style functions. Updated x64 ABI. stdlib updates to string. Removed deprecated functions. Update how variadics are implemented. Extended error messages. x86 ABI fixes. Shift check fixes. '!' and '?' are flipped. No trailing ',' allowed in functions. Fix to string parsing. Allow l suffix. Simplifying flatpath. any replaces variant, anyfault replaces anyerr. Allow getting the underlying type of anyfault. De-duplicate string constants. Fix of readme. Extended list. Fix of "(MyEnum)x + 1". Clock and DateTime types. Fixes to array concat.

This commit is contained in:
Christoffer Lerno
2023-03-23 14:49:51 +01:00
committed by Christoffer Lerno
parent d14e778232
commit 809321e20c
270 changed files with 8777 additions and 7237 deletions

View File

@@ -3,11 +3,11 @@ import libc;
import std::io;
struct Doc { Head *head; }
struct Head { VarString* title; }
struct Head { DString* title; }
struct Summary
{
VarString* title;
DString* title;
bool ok;
}
@@ -44,7 +44,7 @@ fn bool contains(String haystack, String needle)
macro @dupe(value)
{
$typeof(&value) temp = malloc_checked($typeof(value))?;
$typeof(&value) temp = malloc_checked($typeof(value))!;
*temp = value;
return temp;
}
@@ -56,11 +56,11 @@ fault ReadError
fn Doc! readDoc(String url)
{
if (contains(url, "fail")) return ReadError.BAD_READ!;
if (contains(url, "fail")) return ReadError.BAD_READ?;
if (contains(url, "head-missing")) return { .head = null };
if (contains(url, "title-missing")) return { @dupe(Head { .title = null }) };
if (contains(url, "title-empty")) return { @dupe(Head { .title = @dupe((VarString)null) }) };
VarString str;
if (contains(url, "title-empty")) return { @dupe(Head { .title = @dupe((DString)null) }) };
DString str;
str.printf("Title of %s", url);
return { @dupe(Head { .title = @dupe(str) }) };
}
@@ -96,9 +96,9 @@ fault TitleResult
fn bool! isTitleNonEmpty(Doc doc)
{
if (!doc.head) return TitleResult.TITLE_MISSING!;
VarString* head = doc.head.title;
if (!head) return TitleResult.TITLE_MISSING!;
if (!doc.head) return TitleResult.TITLE_MISSING?;
DString* head = doc.head.title;
if (!head) return TitleResult.TITLE_MISSING?;
return head.len() > 0;
}
@@ -133,7 +133,7 @@ fn void main()
bool! has_title = readWhetherTitleNonEmpty(url);
// This looks a bit less than elegant, but as you see it's mostly due to having to
// use printf here.
io::printf(" Has title: %s vs %s\n", bool_to_string(has_title) ?? (catch? has_title).nameof, has_title ?? false);
io::printf(" Has title: %s vs %s\n", bool_to_string(has_title) ?? (@catchof(has_title)).nameof, has_title ?? false);
};
dynamic_arena.reset();
}

View File

@@ -0,0 +1,52 @@
import std::io;
struct Resource
{
String name;
}
fault Error
{
WELCOME_TO_YOUR_DOOM
}
fn Resource! resource_init(String name)
{
io::printfn("open %s", name);
return { name };
}
fn void Resource.deinit(Resource this) => io::printfn("close %s", this.name);
macro void! @open_with(String name; @body(Resource resource))
{
Resource resource = resource_init(name)!;
defer {
io::printn("Using open_with to close");
resource.deinit();
}
@body(resource);
}
fn Resource! prep_out(String out_name, String[] prep_names)
{
Resource writer = resource_init(out_name)!; // Rethrow the optional result
defer catch writer.deinit();
foreach (name : prep_names)
{
@open_with(name; Resource reader)
{
io::printfn("use %s", reader.name);
// if (true) return Error.WELCOME_TO_YOUR_DOOM?;
}!;
}
return writer;
}
fn void! main()
{
Resource writer = prep_out("out", String[] { "a", "b"})!;
defer writer.deinit();
io::printn("use out");
}

View File

@@ -23,10 +23,10 @@ int err_count = 0;
fn int! askGuess(int high)
{
libc::printf("Guess a number between 1 and %d: ", high);
String text = readLine()?;
String text = readLine()!;
char* end = null;
int value = (int)libc::strtol(text.ptr, &end, 10);
if (end && end[0] >= ' ') return InputResult.NOT_AN_INT!;
if (end && end[0] >= ' ') return InputResult.NOT_AN_INT?;
return value;
}
@@ -34,7 +34,7 @@ fn String! readLine()
{
char* chars = tmalloc(1024);
isz loaded = getline(&chars, &&(usz)1023, libc::stdin());
if (loaded < 0) return InputResult.FAILED_TO_READ!;
if (loaded < 0) return InputResult.FAILED_TO_READ?;
chars[loaded] = 0;
return (String)chars[0..(loaded - 1)];
}
@@ -44,7 +44,7 @@ fn int! askGuessMulti(int high)
while (true)
{
int! result = askGuess(high);
if (catch? result == InputResult.NOT_AN_INT)
if (@catchof(result) == InputResult.NOT_AN_INT)
{
libc::printf("I didn't understand that.\n");
err_count++;
@@ -59,7 +59,7 @@ fn void! Game.play(Game *game)
{
while (!game.done)
{
int guess = askGuessMulti(game.high)?;
int guess = askGuessMulti(game.high)!;
game.report(guess);
game.update(guess);
}