commit 7feb69aa9fcd5bee19f34b55b6837d3b3a523a4d
parent db7cd9f02a0e7d80f5637cf6322542536fc94033
Author: walther chen <walther.chen@gmail.com>
Date:   Sun, 16 Mar 2025 21:34:50 +0700

update c3 to 0.7.0 dev

Diffstat:
Mc3/brainz.c3 | 14+++++++-------
Mc3/opt0.c3 | 12++++++------
Mjustfile | 2+-
3 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/c3/brainz.c3 b/c3/brainz.c3 @@ -9,13 +9,13 @@ fn int main(String[] args) { io::eprintn("Please provide source path"); } String source_path = args[1]; - char[]! src = file::load_new(source_path); + char[]? src = file::load_new(source_path); if (catch err = src) { io::eprintfn("Error reading source file"); return 1; } - Program! program = parse(src); + Program? program = parse(src); if (catch err = program) { io::eprintfn("Error parsing program: %s", err); return 1; @@ -33,12 +33,12 @@ fn int main(String[] args) { return 0; } -def Program = char[]; +alias Program = char[]; -fn Program! parse(char[] src, Allocator alloc = allocator::heap()) { +fn Program? parse(char[] src, Allocator alloc = allocator::heap()) { @pool(alloc) { - List(<char>) instructions; - instructions.temp_init(); + List{char} instructions; + instructions.tinit(); foreach (c : src) { switch (c) { @@ -54,6 +54,6 @@ fn Program! parse(char[] src, Allocator alloc = allocator::heap()) { default: {}; } } - return instructions.to_new_array(alloc); + return instructions.to_array(alloc); }; } diff --git a/c3/opt0.c3 b/c3/opt0.c3 @@ -1,7 +1,7 @@ module brainz::opt0; import std::io; -fn void! interpret( +fn void? interpret( Program program, char[] memory, InStream rdr = io::stdin(), @@ -42,7 +42,7 @@ fn void! interpret( if (bracket_nesting != 0) { io::eprintfn("unmatched '[' at pc=%d", saved_pc); - return InterpretError.UNMATCHED_LBRACKET?; + return UNMATCHED_LBRACKET?; } case ']': // jumps to previous matching ']' if curr data != 0 @@ -65,17 +65,17 @@ fn void! interpret( if (bracket_nesting != 0) { io::eprintfn("unmatched ']' at pc=%d", saved_pc); - return InterpretError.UNMATCHED_RBRACKET?; + return UNMATCHED_RBRACKET?; } default: - return InterpretError.UNREACHABLE_CHAR?; + return UNREACHABLE_CHAR?; } pc += 1; } } -fault InterpretError { +faultdef UNMATCHED_LBRACKET, UNMATCHED_RBRACKET, UNREACHABLE_CHAR, -} +; diff --git a/justfile b/justfile @@ -2,5 +2,5 @@ bench-factor: werk build -Dprofile=release && \ zig build -Doptimize=ReleaseFast && \ hyperfine \ - 'echo 179424691 | zig-out/bin/og fixtures/factor.bf' \ + 'echo 179424691 | zig-out/bin/opt2 fixtures/factor.bf' \ 'echo 179424691 | target/brainz-c3 fixtures/factor.bf'