From bf36e8f06d414ca90e203e141b58ebc62d124b06 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Sat, 25 Jan 2025 14:42:00 +0100 Subject: [PATCH] feat: main can omit `args` --- examples/2048.buzz | 2 +- examples/sdl.buzz | 2 +- examples/voronoi-diagram.buzz | 2 +- src/Parser.zig | 6 +++--- tests/bench/005-k-nucleoide.buzz | 2 +- tests/bench/007-fib.buzz | 2 +- tests/bench/008-for.buzz | 2 +- tests/compile_errors/014-main-signature.buzz | 4 ++-- tests/manual/002-error.buzz | 2 +- tests/manual/003-io.buzz | 2 +- tests/manual/004-os.buzz | 2 +- tests/manual/005-tcp-client.buzz | 2 +- tests/manual/006-http-client.buzz | 2 +- 13 files changed, 16 insertions(+), 16 deletions(-) diff --git a/examples/2048.buzz b/examples/2048.buzz index 19cf6821..0abb4dd6 100644 --- a/examples/2048.buzz +++ b/examples/2048.buzz @@ -293,7 +293,7 @@ object Game { } } -fun main(_: [str]) > void { +fun main() > void { final game = Game.init(); game.addNewTile(); diff --git a/examples/sdl.buzz b/examples/sdl.buzz index a41b7ed2..60592c99 100644 --- a/examples/sdl.buzz +++ b/examples/sdl.buzz @@ -1,7 +1,7 @@ import "examples/sdl-wrapped" as _; // buzz -L/path/to/SDL2.dylib/so/dll examples/sdl.buzz -fun main(_: [str]) > int !> SDLError { +fun main() > int !> SDLError { final sdl = SDL.init([Subsystem.Video]); final window = Window.init( diff --git a/examples/voronoi-diagram.buzz b/examples/voronoi-diagram.buzz index 8bd6cdab..94508df4 100644 --- a/examples/voronoi-diagram.buzz +++ b/examples/voronoi-diagram.buzz @@ -66,7 +66,7 @@ fun generateVoronoi(renderer: Renderer, width: int, height: int, numCells: int) } } -fun main(_: [str]) > void !> SDLError { +fun main() > void !> SDLError { final width = 400; final height = 400; final numCells = 50; diff --git a/src/Parser.zig b/src/Parser.zig index 5245976c..bf05a346 100644 --- a/src/Parser.zig +++ b/src/Parser.zig @@ -6417,9 +6417,9 @@ fn funDeclaration(self: *Self) Error!Ast.Node.Index { const fun_def = fun_typedef.resolved_type.?.Function; if (is_main) { var signature_valid = true; - if (fun_def.parameters.count() != 1 or (fun_def.return_type.def_type != .Integer and fun_def.return_type.def_type != .Void)) { + if (fun_def.parameters.count() > 1 or (fun_def.return_type.def_type != .Integer and fun_def.return_type.def_type != .Void)) { signature_valid = false; - } else { + } else if (fun_def.parameters.count() > 0) { const first_param = fun_def.parameters.get(fun_def.parameters.keys()[0]); if (first_param == null or !(try self.parseTypeDefFrom("[str]")).eql(first_param.?)) @@ -6434,7 +6434,7 @@ fn funDeclaration(self: *Self) Error!Ast.Node.Index { self.reporter.reportErrorFmt( .main_signature, self.ast.tokens.get(self.ast.nodes.items(.location)[function_node]), - "Expected `main` signature to be `fun main([str] args) > void|int` got {s}", + "Expected `main` signature to be `fun main([ args: [str] ]) > void|int` got {s}", .{ main_def_str, }, diff --git a/tests/bench/005-k-nucleoide.buzz b/tests/bench/005-k-nucleoide.buzz index fff72722..af92cc29 100644 --- a/tests/bench/005-k-nucleoide.buzz +++ b/tests/bench/005-k-nucleoide.buzz @@ -53,7 +53,7 @@ fun frequency(sequence: str, k: int) > void { } // buzz tests/bench/005-k-nucleoide.buzz < tests/bench/reference/knucleotide-input.txt -fun main(_: [str]) > void { +fun main() > void { final sequence = readSequence() catch ""; frequency(sequence, k: 1); frequency(sequence, k: 2); diff --git a/tests/bench/007-fib.buzz b/tests/bench/007-fib.buzz index 54bbfd8c..c6c4973c 100644 --- a/tests/bench/007-fib.buzz +++ b/tests/bench/007-fib.buzz @@ -8,6 +8,6 @@ fun fibonnacci(n: int) > int { return fibonnacci(n - 2) + fibonnacci(n - 1); } -fun main(_: [str]) > void { +fun main() > void { std\print("{fibonnacci(30)}"); } diff --git a/tests/bench/008-for.buzz b/tests/bench/008-for.buzz index 5b1b7c8d..b127e657 100644 --- a/tests/bench/008-for.buzz +++ b/tests/bench/008-for.buzz @@ -1,6 +1,6 @@ import "std"; -fun main(_: [str]) > void { +fun main() > void { final list: mut [int] = mut []; foreach (i in 0..1_000_000) { diff --git a/tests/compile_errors/014-main-signature.buzz b/tests/compile_errors/014-main-signature.buzz index 96b2bdc3..70769952 100644 --- a/tests/compile_errors/014-main-signature.buzz +++ b/tests/compile_errors/014-main-signature.buzz @@ -1,2 +1,2 @@ -// Expected `main` signature to be `fun main([str] args) > void|int` got fun main() > void -fun main() > void {} +// Expected `main` signature to be `fun main([ args: [int] ]) > void|int` got fun main(args: int) > void +fun main(args: int) > void {} diff --git a/tests/manual/002-error.buzz b/tests/manual/002-error.buzz index a06eef9b..09b63de3 100644 --- a/tests/manual/002-error.buzz +++ b/tests/manual/002-error.buzz @@ -1,3 +1,3 @@ -fun main(_: [str]) > void !> any { +fun main() > void !> any { throw "wat!"; } diff --git a/tests/manual/003-io.buzz b/tests/manual/003-io.buzz index 8626fd78..3c4f074f 100644 --- a/tests/manual/003-io.buzz +++ b/tests/manual/003-io.buzz @@ -1,7 +1,7 @@ import "std"; import "io"; -fun main(_: [str]) > void !> any { +fun main() > void !> any { for (line: str? = ""; line != null; line = io\stdin.readLine()) { std\print("= {line}"); io\stdout.write("> "); diff --git a/tests/manual/004-os.buzz b/tests/manual/004-os.buzz index 811ace74..c911a52e 100644 --- a/tests/manual/004-os.buzz +++ b/tests/manual/004-os.buzz @@ -1,5 +1,5 @@ import "os"; -fun main(_: [str]) > void { +fun main() > void { os\exit(12); } diff --git a/tests/manual/005-tcp-client.buzz b/tests/manual/005-tcp-client.buzz index e030dbfb..66aec80a 100644 --- a/tests/manual/005-tcp-client.buzz +++ b/tests/manual/005-tcp-client.buzz @@ -1,7 +1,7 @@ import "std"; import "os"; -fun main(_: [str]) > void !> any { +fun main() > void !> any { final socket = os\Socket.connect( address: "127.0.0.1", port: 8080, diff --git a/tests/manual/006-http-client.buzz b/tests/manual/006-http-client.buzz index 5907edf1..30e41327 100644 --- a/tests/manual/006-http-client.buzz +++ b/tests/manual/006-http-client.buzz @@ -3,7 +3,7 @@ import "debug"; import "errors"; import "serialize"; -fun main(_: [str]) > void !> any { +fun main() > void !> any { final client = http\Client.init(); final request = mut http\Request{