public inbox for ~johnnyrichard/olang-devel@lists.sr.ht
 help / color / mirror / code / Atom feed
* [PATCH olang 0/2] Rename program to translation unit
@ 2024-09-23 11:43 Carlos Maniero
  2024-09-23 11:43 ` [PATCH olang 1/2] ast: rename " Carlos Maniero
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Carlos Maniero @ 2024-09-23 11:43 UTC (permalink / raw)
  To: ~johnnyrichard/olang-devel; +Cc: Carlos Maniero

We defined what we were calling program on the spec to translation unit.
Also the AST structure of a translation unit was changed to support
multiple declarations, yet it still only parsing one function.

Carlos Maniero (2):
  ast: rename program to translation unit
  ast: permit multi declarations on translation unit

 src/ast.c                   | 11 +++++++----
 src/ast.h                   | 12 ++++++------
 src/checker.c               |  9 +++++++--
 src/codegen_linux_aarch64.c | 28 ++++++++++++++++++++++------
 src/codegen_linux_aarch64.h |  2 +-
 src/codegen_linux_x86_64.c  | 28 ++++++++++++++++++++++------
 src/codegen_linux_x86_64.h  |  2 +-
 src/main.c                  | 10 +++++-----
 src/parser.c                |  8 ++++++--
 src/parser.h                |  2 +-
 src/pretty_print_ast.c      | 15 ++++++++++++---
 tests/unit/parser_test.c    | 27 +++++++++++++++++----------
 12 files changed, 107 insertions(+), 47 deletions(-)


base-commit: 761bd4304fe3df374d9ea77985bedde8edcdae46
-- 
2.34.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH olang 1/2] ast: rename program to translation unit
  2024-09-23 11:43 [PATCH olang 0/2] Rename program to translation unit Carlos Maniero
@ 2024-09-23 11:43 ` Carlos Maniero
  2024-09-23 11:43 ` [PATCH olang 2/2] ast: permit multi declarations on " Carlos Maniero
  2024-09-23 17:01 ` [PATCH olang 0/2] Rename program to translation unit Johnny Richard
  2 siblings, 0 replies; 5+ messages in thread
From: Carlos Maniero @ 2024-09-23 11:43 UTC (permalink / raw)
  To: ~johnnyrichard/olang-devel; +Cc: Carlos Maniero

That is the name we are calling it on the language spec and on
--dump-ast.

Signed-off-by: Carlos Maniero <carlos@maniero.me>
---
 src/ast.c                   |  8 ++++----
 src/ast.h                   | 10 +++++-----
 src/checker.c               |  4 ++--
 src/codegen_linux_aarch64.c |  8 ++++----
 src/codegen_linux_aarch64.h |  2 +-
 src/codegen_linux_x86_64.c  |  8 ++++----
 src/codegen_linux_x86_64.h  |  2 +-
 src/main.c                  | 10 +++++-----
 src/parser.c                |  4 ++--
 src/parser.h                |  2 +-
 src/pretty_print_ast.c      |  4 ++--
 tests/unit/parser_test.c    | 22 ++++++++++++----------
 12 files changed, 43 insertions(+), 41 deletions(-)

diff --git a/src/ast.c b/src/ast.c
index 7019316..f5fa483 100644
--- a/src/ast.c
+++ b/src/ast.c
@@ -23,15 +23,15 @@
 #include "string_view.h"
 
 ast_node_t *
-ast_new_program(arena_t *arena, ast_node_t *fn_def)
+ast_new_translation_unit(arena_t *arena, ast_node_t *fn_def)
 {
     ast_node_t *node = (ast_node_t *)arena_alloc(arena, sizeof(ast_node_t));
     assert(node);
 
-    node->kind = AST_NODE_PROGRAM;
-    ast_program_t *program = &node->as_program;
+    node->kind = AST_NODE_TRANSLATION_UNIT;
+    ast_translation_unit_t *translation_unit = &node->as_translation_unit;
 
-    program->fn = fn_def;
+    translation_unit->fn = fn_def;
 
     return node;
 }
diff --git a/src/ast.h b/src/ast.h
index df65e59..718c80f 100644
--- a/src/ast.h
+++ b/src/ast.h
@@ -29,7 +29,7 @@ typedef struct ast_node ast_node_t;
 
 typedef enum
 {
-    AST_NODE_PROGRAM,
+    AST_NODE_TRANSLATION_UNIT,
     AST_NODE_BLOCK,
     AST_NODE_FN_DEF,
     AST_NODE_VAR_DEF,
@@ -46,10 +46,10 @@ typedef struct ast_block
     list_t *nodes;
 } ast_block_t;
 
-typedef struct ast_program
+typedef struct ast_translation_unit
 {
     ast_node_t *fn;
-} ast_program_t;
+} ast_translation_unit_t;
 
 typedef struct ast_fn_definition
 {
@@ -133,7 +133,7 @@ typedef struct ast_node
     ast_node_kind_t kind;
     union
     {
-        ast_program_t as_program;
+        ast_translation_unit_t as_translation_unit;
         ast_fn_definition_t as_fn_def;
         ast_var_definition_t as_var_def;
         ast_binary_op_t as_bin_op;
@@ -146,7 +146,7 @@ typedef struct ast_node
 } ast_node_t;
 
 ast_node_t *
-ast_new_program(arena_t *arena, ast_node_t *fn_def);
+ast_new_translation_unit(arena_t *arena, ast_node_t *fn_def);
 
 ast_node_t *
 ast_new_node_fn_def(arena_t *arena, string_view_t id, string_view_t return_type, ast_node_t *block);
diff --git a/src/checker.c b/src/checker.c
index 090920c..e9bfacb 100644
--- a/src/checker.c
+++ b/src/checker.c
@@ -53,8 +53,8 @@ static void
 populate_scope(checker_t *checker, scope_t *scope, ast_node_t *ast)
 {
     switch (ast->kind) {
-        case AST_NODE_PROGRAM: {
-            populate_scope(checker, scope, ast->as_program.fn);
+        case AST_NODE_TRANSLATION_UNIT: {
+            populate_scope(checker, scope, ast->as_translation_unit.fn);
             return;
         }
 
diff --git a/src/codegen_linux_aarch64.c b/src/codegen_linux_aarch64.c
index 93dde4f..e8ae729 100644
--- a/src/codegen_linux_aarch64.c
+++ b/src/codegen_linux_aarch64.c
@@ -42,14 +42,14 @@ static void
 codegen_linux_aarch64_emit_function(FILE *out, ast_fn_definition_t *fn);
 
 void
-codegen_linux_aarch64_emit_program(FILE *out, ast_node_t *node)
+codegen_linux_aarch64_emit_translation_unit(FILE *out, ast_node_t *node)
 {
     codegen_linux_aarch64_emit_start_entrypoint(out);
 
-    assert(node->kind == AST_NODE_PROGRAM);
-    ast_program_t program = node->as_program;
+    assert(node->kind == AST_NODE_TRANSLATION_UNIT);
+    ast_translation_unit_t translation_unit = node->as_translation_unit;
 
-    ast_fn_definition_t fn = program.fn->as_fn_def;
+    ast_fn_definition_t fn = translation_unit.fn->as_fn_def;
 
     assert(string_view_eq_to_cstr(fn.id, "main"));
     codegen_linux_aarch64_emit_function(out, &fn);
diff --git a/src/codegen_linux_aarch64.h b/src/codegen_linux_aarch64.h
index fb88b64..03e2f46 100644
--- a/src/codegen_linux_aarch64.h
+++ b/src/codegen_linux_aarch64.h
@@ -20,6 +20,6 @@
 #include "ast.h"
 
 void
-codegen_linux_aarch64_emit_program(FILE *out, ast_node_t *prog);
+codegen_linux_aarch64_emit_translation_unit(FILE *out, ast_node_t *prog);
 
 #endif /* CODEGEN_LINUX_AARCH64_H */
diff --git a/src/codegen_linux_x86_64.c b/src/codegen_linux_x86_64.c
index a0d9d97..37d4575 100644
--- a/src/codegen_linux_x86_64.c
+++ b/src/codegen_linux_x86_64.c
@@ -55,15 +55,15 @@ codegen_linux_x86_64_init(codegen_x86_64_t *codegen, arena_t *arena, FILE *out)
 }
 
 void
-codegen_linux_x86_64_emit_program(codegen_x86_64_t *codegen, ast_node_t *node)
+codegen_linux_x86_64_emit_translation_unit(codegen_x86_64_t *codegen, ast_node_t *node)
 {
     codegen->label_index = 0;
     codegen_linux_x86_64_emit_start_entrypoint(codegen);
 
-    assert(node->kind == AST_NODE_PROGRAM);
-    ast_program_t program = node->as_program;
+    assert(node->kind == AST_NODE_TRANSLATION_UNIT);
+    ast_translation_unit_t translation_unit = node->as_translation_unit;
 
-    ast_fn_definition_t fn = program.fn->as_fn_def;
+    ast_fn_definition_t fn = translation_unit.fn->as_fn_def;
 
     assert(string_view_eq_to_cstr(fn.id, "main"));
     codegen_linux_x86_64_emit_function(codegen, &fn);
diff --git a/src/codegen_linux_x86_64.h b/src/codegen_linux_x86_64.h
index 803c080..a4137de 100644
--- a/src/codegen_linux_x86_64.h
+++ b/src/codegen_linux_x86_64.h
@@ -35,6 +35,6 @@ void
 codegen_linux_x86_64_init(codegen_x86_64_t *codegen, arena_t *arena, FILE *out);
 
 void
-codegen_linux_x86_64_emit_program(codegen_x86_64_t *codegen, ast_node_t *prog);
+codegen_linux_x86_64_emit_translation_unit(codegen_x86_64_t *codegen, ast_node_t *prog);
 
 #endif /* CODEGEN_X86_64_H */
diff --git a/src/main.c b/src/main.c
index 312b0c1..60b17bf 100644
--- a/src/main.c
+++ b/src/main.c
@@ -114,7 +114,7 @@ handle_dump_ast(cli_opts_t *opts)
     lexer_init(&lexer, file_content);
     parser_init(&parser, &lexer, &arena, opts->file_path);
 
-    ast_node_t *ast = parser_parse_program(&parser);
+    ast_node_t *ast = parser_parse_translation_unit(&parser);
 
     pretty_print_ast(ast);
 }
@@ -135,7 +135,7 @@ handle_codegen_linux(cli_opts_t *opts)
     lexer_init(&lexer, file_content);
     parser_init(&parser, &lexer, &arena, opts->file_path);
 
-    ast_node_t *ast = parser_parse_program(&parser);
+    ast_node_t *ast = parser_parse_translation_unit(&parser);
 
     checker_t *checker = checker_new(&arena);
     checker_check(checker, ast);
@@ -149,14 +149,14 @@ handle_codegen_linux(cli_opts_t *opts)
     if (!(opts->options & CLI_OPT_ARCH)) {
         codegen_x86_64_t codegen = { 0 };
         codegen_linux_x86_64_init(&codegen, &arena, out);
-        codegen_linux_x86_64_emit_program(&codegen, ast);
+        codegen_linux_x86_64_emit_translation_unit(&codegen, ast);
     } else {
         if (strcmp(opts->arch, "x86_64") == 0) {
             codegen_x86_64_t codegen = { 0 };
             codegen_linux_x86_64_init(&codegen, &arena, out);
-            codegen_linux_x86_64_emit_program(&codegen, ast);
+            codegen_linux_x86_64_emit_translation_unit(&codegen, ast);
         } else if (strcmp(opts->arch, "aarch64") == 0) {
-            codegen_linux_aarch64_emit_program(out, ast);
+            codegen_linux_aarch64_emit_translation_unit(out, ast);
         } else {
             fprintf(stderr, "error: architecture '%s' not supported\n", opts->arch);
             cli_print_usage(stderr, opts->compiler_path);
diff --git a/src/parser.c b/src/parser.c
index 3cae763..9332f6e 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -72,7 +72,7 @@ parser_init(parser_t *parser, lexer_t *lexer, arena_t *arena, char *file_path)
 }
 
 ast_node_t *
-parser_parse_program(parser_t *parser)
+parser_parse_translation_unit(parser_t *parser)
 {
     skip_line_feeds(parser->lexer);
     ast_node_t *fn = parser_parse_fn_definition(parser);
@@ -80,7 +80,7 @@ parser_parse_program(parser_t *parser)
         return NULL;
     }
 
-    return ast_new_program(parser->arena, fn);
+    return ast_new_translation_unit(parser->arena, fn);
 }
 
 static ast_binary_op_kind_t
diff --git a/src/parser.h b/src/parser.h
index 5bcef1d..31c0dc3 100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -33,6 +33,6 @@ void
 parser_init(parser_t *parser, lexer_t *lexer, arena_t *arena, char *file_path);
 
 ast_node_t *
-parser_parse_program(parser_t *parser);
+parser_parse_translation_unit(parser_t *parser);
 
 #endif /* PARSER_H */
diff --git a/src/pretty_print_ast.c b/src/pretty_print_ast.c
index 1d5576d..db646c5 100644
--- a/src/pretty_print_ast.c
+++ b/src/pretty_print_ast.c
@@ -112,11 +112,11 @@ static pretty_print_node_t *
 ast_node_to_pretty_print_node(ast_node_t *ast, arena_t *arena)
 {
     switch (ast->kind) {
-        case AST_NODE_PROGRAM: {
+        case AST_NODE_TRANSLATION_UNIT: {
             pretty_print_node_t *node = pretty_print_node_new(arena);
             node->name = "Translation_Unit";
 
-            pretty_print_node_t *fn_node = ast_node_to_pretty_print_node(ast->as_program.fn, arena);
+            pretty_print_node_t *fn_node = ast_node_to_pretty_print_node(ast->as_translation_unit.fn, arena);
             list_append(node->children, fn_node);
             return node;
         }
diff --git a/tests/unit/parser_test.c b/tests/unit/parser_test.c
index 8ad16b5..4e229be 100644
--- a/tests/unit/parser_test.c
+++ b/tests/unit/parser_test.c
@@ -27,7 +27,7 @@
 #define ARENA_CAPACITY (1024 * 1024)
 
 static MunitResult
-parse_program_test(const MunitParameter params[], void *user_data_or_fixture)
+parse_translation_unit_test(const MunitParameter params[], void *user_data_or_fixture)
 {
     arena_t arena = arena_new(ARENA_CAPACITY);
 
@@ -41,15 +41,15 @@ parse_program_test(const MunitParameter params[], void *user_data_or_fixture)
     parser_t parser;
     parser_init(&parser, &lexer, &arena, file_path);
 
-    ast_node_t *program_node = parser_parse_program(&parser);
-    assert_not_null(program_node);
-    assert_uint(program_node->kind, ==, AST_NODE_PROGRAM);
+    ast_node_t *translation_unit_node = parser_parse_translation_unit(&parser);
+    assert_not_null(translation_unit_node);
+    assert_uint(translation_unit_node->kind, ==, AST_NODE_TRANSLATION_UNIT);
 
-    ast_program_t program = program_node->as_program;
-    assert_not_null(program.fn);
-    assert_uint(program.fn->kind, ==, AST_NODE_FN_DEF);
+    ast_translation_unit_t translation_unit = translation_unit_node->as_translation_unit;
+    assert_not_null(translation_unit.fn);
+    assert_uint(translation_unit.fn->kind, ==, AST_NODE_FN_DEF);
 
-    ast_fn_definition_t fn = program.fn->as_fn_def;
+    ast_fn_definition_t fn = translation_unit.fn->as_fn_def;
     assert_memory_equal(fn.id.size, fn.id.chars, "main");
     assert_memory_equal(fn.return_type.size, fn.return_type.chars, "u32");
 
@@ -77,8 +77,10 @@ parse_program_test(const MunitParameter params[], void *user_data_or_fixture)
     return MUNIT_OK;
 }
 
-static MunitTest tests[] = { { "/parse_program", parse_program_test, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
-                             { NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL } };
+static MunitTest tests[] = {
+    { "/parse_translation_unit", parse_translation_unit_test, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
+    { NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }
+};
 
 static const MunitSuite suite = { "/parser", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE };
 
-- 
2.34.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH olang 2/2] ast: permit multi declarations on translation unit
  2024-09-23 11:43 [PATCH olang 0/2] Rename program to translation unit Carlos Maniero
  2024-09-23 11:43 ` [PATCH olang 1/2] ast: rename " Carlos Maniero
@ 2024-09-23 11:43 ` Carlos Maniero
  2024-09-23 11:44   ` [olang/patches/.build.yml] build success builds.sr.ht
  2024-09-23 17:01 ` [PATCH olang 0/2] Rename program to translation unit Johnny Richard
  2 siblings, 1 reply; 5+ messages in thread
From: Carlos Maniero @ 2024-09-23 11:43 UTC (permalink / raw)
  To: ~johnnyrichard/olang-devel; +Cc: Carlos Maniero

At this point the parser still parsing only a single function, but the
ast is ready to support multiple declarations.

Signed-off-by: Carlos Maniero <carlos@maniero.me>
---
 src/ast.c                   |  7 +++++--
 src/ast.h                   |  4 ++--
 src/checker.c               |  7 ++++++-
 src/codegen_linux_aarch64.c | 22 +++++++++++++++++++---
 src/codegen_linux_x86_64.c  | 22 +++++++++++++++++++---
 src/parser.c                |  6 +++++-
 src/pretty_print_ast.c      | 13 +++++++++++--
 tests/unit/parser_test.c    | 11 ++++++++---
 8 files changed, 75 insertions(+), 17 deletions(-)

diff --git a/src/ast.c b/src/ast.c
index f5fa483..bb74679 100644
--- a/src/ast.c
+++ b/src/ast.c
@@ -23,7 +23,7 @@
 #include "string_view.h"
 
 ast_node_t *
-ast_new_translation_unit(arena_t *arena, ast_node_t *fn_def)
+ast_new_translation_unit(arena_t *arena)
 {
     ast_node_t *node = (ast_node_t *)arena_alloc(arena, sizeof(ast_node_t));
     assert(node);
@@ -31,7 +31,10 @@ ast_new_translation_unit(arena_t *arena, ast_node_t *fn_def)
     node->kind = AST_NODE_TRANSLATION_UNIT;
     ast_translation_unit_t *translation_unit = &node->as_translation_unit;
 
-    translation_unit->fn = fn_def;
+    translation_unit->decls = (list_t *)arena_alloc(arena, sizeof(list_t));
+    assert(translation_unit->decls);
+
+    list_init(translation_unit->decls, arena);
 
     return node;
 }
diff --git a/src/ast.h b/src/ast.h
index 718c80f..6cfbfc0 100644
--- a/src/ast.h
+++ b/src/ast.h
@@ -48,7 +48,7 @@ typedef struct ast_block
 
 typedef struct ast_translation_unit
 {
-    ast_node_t *fn;
+    list_t *decls;
 } ast_translation_unit_t;
 
 typedef struct ast_fn_definition
@@ -146,7 +146,7 @@ typedef struct ast_node
 } ast_node_t;
 
 ast_node_t *
-ast_new_translation_unit(arena_t *arena, ast_node_t *fn_def);
+ast_new_translation_unit(arena_t *arena);
 
 ast_node_t *
 ast_new_node_fn_def(arena_t *arena, string_view_t id, string_view_t return_type, ast_node_t *block);
diff --git a/src/checker.c b/src/checker.c
index e9bfacb..814d052 100644
--- a/src/checker.c
+++ b/src/checker.c
@@ -54,7 +54,12 @@ populate_scope(checker_t *checker, scope_t *scope, ast_node_t *ast)
 {
     switch (ast->kind) {
         case AST_NODE_TRANSLATION_UNIT: {
-            populate_scope(checker, scope, ast->as_translation_unit.fn);
+            list_item_t *item = list_head(ast->as_translation_unit.decls);
+
+            while (item != NULL) {
+                populate_scope(checker, scope, (ast_node_t *)item->value);
+                item = list_next(item);
+            }
             return;
         }
 
diff --git a/src/codegen_linux_aarch64.c b/src/codegen_linux_aarch64.c
index e8ae729..d8187ab 100644
--- a/src/codegen_linux_aarch64.c
+++ b/src/codegen_linux_aarch64.c
@@ -49,10 +49,26 @@ codegen_linux_aarch64_emit_translation_unit(FILE *out, ast_node_t *node)
     assert(node->kind == AST_NODE_TRANSLATION_UNIT);
     ast_translation_unit_t translation_unit = node->as_translation_unit;
 
-    ast_fn_definition_t fn = translation_unit.fn->as_fn_def;
+    list_item_t *item = list_head(translation_unit.decls);
 
-    assert(string_view_eq_to_cstr(fn.id, "main"));
-    codegen_linux_aarch64_emit_function(out, &fn);
+    bool main_found = false;
+
+    while (item != NULL) {
+        ast_node_t *decl = (ast_node_t *)item->value;
+
+        if (decl->kind == AST_NODE_FN_DEF) {
+            ast_fn_definition_t fn = decl->as_fn_def;
+            codegen_linux_aarch64_emit_function(out, &fn);
+
+            main_found = main_found || string_view_eq_to_cstr(fn.id, "main");
+        } else {
+            assert(0 && "translation unit only supports function declarations");
+        }
+
+        item = list_next(item);
+    }
+
+    assert(main_found && "main function is required.");
 }
 
 static void
diff --git a/src/codegen_linux_x86_64.c b/src/codegen_linux_x86_64.c
index 37d4575..0173443 100644
--- a/src/codegen_linux_x86_64.c
+++ b/src/codegen_linux_x86_64.c
@@ -63,10 +63,26 @@ codegen_linux_x86_64_emit_translation_unit(codegen_x86_64_t *codegen, ast_node_t
     assert(node->kind == AST_NODE_TRANSLATION_UNIT);
     ast_translation_unit_t translation_unit = node->as_translation_unit;
 
-    ast_fn_definition_t fn = translation_unit.fn->as_fn_def;
+    list_item_t *item = list_head(translation_unit.decls);
 
-    assert(string_view_eq_to_cstr(fn.id, "main"));
-    codegen_linux_x86_64_emit_function(codegen, &fn);
+    bool main_found = false;
+
+    while (item != NULL) {
+        ast_node_t *decl = (ast_node_t *)item->value;
+
+        if (decl->kind == AST_NODE_FN_DEF) {
+            ast_fn_definition_t fn = decl->as_fn_def;
+            codegen_linux_x86_64_emit_function(codegen, &fn);
+
+            main_found = main_found || string_view_eq_to_cstr(fn.id, "main");
+        } else {
+            assert(0 && "translation unit only supports function declarations");
+        }
+
+        item = list_next(item);
+    }
+
+    assert(main_found && "main function is required.");
 }
 
 static void
diff --git a/src/parser.c b/src/parser.c
index 9332f6e..c79f3bd 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -80,7 +80,11 @@ parser_parse_translation_unit(parser_t *parser)
         return NULL;
     }
 
-    return ast_new_translation_unit(parser->arena, fn);
+    ast_node_t *translation_unit_node = ast_new_translation_unit(parser->arena);
+
+    list_append(translation_unit_node->as_translation_unit.decls, fn);
+
+    return translation_unit_node;
 }
 
 static ast_binary_op_kind_t
diff --git a/src/pretty_print_ast.c b/src/pretty_print_ast.c
index db646c5..8116e60 100644
--- a/src/pretty_print_ast.c
+++ b/src/pretty_print_ast.c
@@ -116,8 +116,17 @@ ast_node_to_pretty_print_node(ast_node_t *ast, arena_t *arena)
             pretty_print_node_t *node = pretty_print_node_new(arena);
             node->name = "Translation_Unit";
 
-            pretty_print_node_t *fn_node = ast_node_to_pretty_print_node(ast->as_translation_unit.fn, arena);
-            list_append(node->children, fn_node);
+            list_item_t *item = list_head(ast->as_translation_unit.decls);
+
+            while (item != NULL) {
+                ast_node_t *decl = (ast_node_t *)item->value;
+
+                pretty_print_node_t *fn_node = ast_node_to_pretty_print_node(decl, arena);
+                list_append(node->children, fn_node);
+
+                item = list_next(item);
+            }
+
             return node;
         }
         case AST_NODE_FN_DEF: {
diff --git a/tests/unit/parser_test.c b/tests/unit/parser_test.c
index 4e229be..a7c60d1 100644
--- a/tests/unit/parser_test.c
+++ b/tests/unit/parser_test.c
@@ -46,10 +46,15 @@ parse_translation_unit_test(const MunitParameter params[], void *user_data_or_fi
     assert_uint(translation_unit_node->kind, ==, AST_NODE_TRANSLATION_UNIT);
 
     ast_translation_unit_t translation_unit = translation_unit_node->as_translation_unit;
-    assert_not_null(translation_unit.fn);
-    assert_uint(translation_unit.fn->kind, ==, AST_NODE_FN_DEF);
 
-    ast_fn_definition_t fn = translation_unit.fn->as_fn_def;
+    assert_uint(list_size(translation_unit.decls), ==, 1);
+
+    ast_node_t *fn_node = (ast_node_t *)list_head(translation_unit.decls)->value;
+
+    assert_not_null(fn_node);
+    assert_uint(fn_node->kind, ==, AST_NODE_FN_DEF);
+
+    ast_fn_definition_t fn = fn_node->as_fn_def;
     assert_memory_equal(fn.id.size, fn.id.chars, "main");
     assert_memory_equal(fn.return_type.size, fn.return_type.chars, "u32");
 
-- 
2.34.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [olang/patches/.build.yml] build success
  2024-09-23 11:43 ` [PATCH olang 2/2] ast: permit multi declarations on " Carlos Maniero
@ 2024-09-23 11:44   ` builds.sr.ht
  0 siblings, 0 replies; 5+ messages in thread
From: builds.sr.ht @ 2024-09-23 11:44 UTC (permalink / raw)
  To: Carlos Maniero; +Cc: ~johnnyrichard/olang-devel

olang/patches/.build.yml: SUCCESS in 20s

[Rename program to translation unit][0] from [Carlos Maniero][1]

[0]: https://lists.sr.ht/~johnnyrichard/olang-devel/patches/55177
[1]: mailto:carlos@maniero.me

✓ #1335028 SUCCESS olang/patches/.build.yml https://builds.sr.ht/~johnnyrichard/job/1335028

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH olang 0/2] Rename program to translation unit
  2024-09-23 11:43 [PATCH olang 0/2] Rename program to translation unit Carlos Maniero
  2024-09-23 11:43 ` [PATCH olang 1/2] ast: rename " Carlos Maniero
  2024-09-23 11:43 ` [PATCH olang 2/2] ast: permit multi declarations on " Carlos Maniero
@ 2024-09-23 17:01 ` Johnny Richard
  2 siblings, 0 replies; 5+ messages in thread
From: Johnny Richard @ 2024-09-23 17:01 UTC (permalink / raw)
  To: Carlos Maniero; +Cc: ~johnnyrichard/olang-devel

Thanks. Applied!

To git.sr.ht:~johnnyrichard/olang
   a2d3a9c..d36d71c  main -> main


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-09-23 17:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-23 11:43 [PATCH olang 0/2] Rename program to translation unit Carlos Maniero
2024-09-23 11:43 ` [PATCH olang 1/2] ast: rename " Carlos Maniero
2024-09-23 11:43 ` [PATCH olang 2/2] ast: permit multi declarations on " Carlos Maniero
2024-09-23 11:44   ` [olang/patches/.build.yml] build success builds.sr.ht
2024-09-23 17:01 ` [PATCH olang 0/2] Rename program to translation unit Johnny Richard

Code repositories for project(s) associated with this public inbox

	https://git.johnnyrichard.com/olang.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox