Skip to content

Commit

Permalink
feat: main can omit args
Browse files Browse the repository at this point in the history
  • Loading branch information
giann committed Jan 25, 2025
1 parent c3f2915 commit c7ef841
Show file tree
Hide file tree
Showing 12 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion examples/2048.buzz
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ object Game {
}
}

fun main(_: [str]) > void {
fun main() > void {
final game = Game.init();

game.addNewTile();
Expand Down
2 changes: 1 addition & 1 deletion examples/sdl.buzz
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
2 changes: 1 addition & 1 deletion examples/voronoi-diagram.buzz
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/Parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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.?))
Expand All @@ -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,
},
Expand Down
2 changes: 1 addition & 1 deletion tests/bench/005-k-nucleoide.buzz
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/bench/007-fib.buzz
Original file line number Diff line number Diff line change
Expand Up @@ -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)}");
}
2 changes: 1 addition & 1 deletion tests/bench/008-for.buzz
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion tests/manual/002-error.buzz
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fun main(_: [str]) > void !> any {
fun main() > void !> any {
throw "wat!";
}
2 changes: 1 addition & 1 deletion tests/manual/003-io.buzz
Original file line number Diff line number Diff line change
@@ -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("> ");
Expand Down
2 changes: 1 addition & 1 deletion tests/manual/004-os.buzz
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "os";

fun main(_: [str]) > void {
fun main() > void {
os\exit(12);
}
2 changes: 1 addition & 1 deletion tests/manual/005-tcp-client.buzz
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tests/manual/006-http-client.buzz
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit c7ef841

Please sign in to comment.