From 3f0b407cb313928ed9017f67dd04479b9ad50702 Mon Sep 17 00:00:00 2001 From: overflowerror Date: Sat, 18 May 2024 11:23:54 +0200 Subject: [PATCH] fix: macros with multiple arguments didn't work --- compiler/src/preprocessor.c | 15 +++++++++------ .../025c-preproc-macro-with-multiple-arguments.in | 5 +++++ ...025c-preproc-macro-with-multiple-arguments.out | 1 + 3 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 compiler/test/cases/025c-preproc-macro-with-multiple-arguments.in create mode 100644 compiler/test/cases/025c-preproc-macro-with-multiple-arguments.out diff --git a/compiler/src/preprocessor.c b/compiler/src/preprocessor.c index 2b89999..bbc9120 100644 --- a/compiler/src/preprocessor.c +++ b/compiler/src/preprocessor.c @@ -95,13 +95,16 @@ static void handle_macro_definition(void) { fprintf(stderr, "preprocessor: macro: , expected, got: %s\n", yytext); panic("preprocessor syntax error"); } - } else { - if (token != ID) { - fprintf(stderr, "preprocessor: macro: identifier expected, got: %s\n", yytext); - panic("preprocessor syntax error"); - } - list_add(macro->argument_list, yylval.id); + + token = yylex(); } + + if (token != ID) { + fprintf(stderr, "preprocessor: macro: identifier expected, got: %s\n", yytext); + panic("preprocessor syntax error"); + } + list_add(macro->argument_list, yylval.id); + is_first = false; } token = yylex(); diff --git a/compiler/test/cases/025c-preproc-macro-with-multiple-arguments.in b/compiler/test/cases/025c-preproc-macro-with-multiple-arguments.in new file mode 100644 index 0000000..732f1c1 --- /dev/null +++ b/compiler/test/cases/025c-preproc-macro-with-multiple-arguments.in @@ -0,0 +1,5 @@ +#macro test(a, b, c) { + print($a, $b, $c, '\n') +} + +test$('f', 'o', 'o'); diff --git a/compiler/test/cases/025c-preproc-macro-with-multiple-arguments.out b/compiler/test/cases/025c-preproc-macro-with-multiple-arguments.out new file mode 100644 index 0000000..4eb3318 --- /dev/null +++ b/compiler/test/cases/025c-preproc-macro-with-multiple-arguments.out @@ -0,0 +1 @@ +[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++<<<.>.>.>.