harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 6d44d0d3627ec216de16cbae7fb5a43049f58543
parent 298c24d8410b08bc089980d6f8c4c3f9942f1619
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sun, 13 Dec 2020 09:59:06 -0500

Initial riggings for type checker

Diffstat:
Mconfigure | 1+
Minclude/ast.h | 9++-------
Ainclude/check.h | 50++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/check.c | 40++++++++++++++++++++++++++++++++++++++++
Msrc/main.c | 9++++++---
5 files changed, 99 insertions(+), 10 deletions(-)

diff --git a/configure b/configure @@ -4,6 +4,7 @@ eval ". $srcdir/config.sh" harec() { genrules harec \ + src/check.c \ src/identifier.c \ src/lex.c \ src/main.c \ diff --git a/include/ast.h b/include/ast.h @@ -2,6 +2,7 @@ #define HARE_AST_H #include <stdbool.h> #include <stdint.h> +#include "check.h" #include "identifier.h" #include "types.h" @@ -125,15 +126,9 @@ struct ast_type_decl { struct ast_type_decl *next; }; -enum function_flags { - FN_FINI = 1 << 0, - FN_INIT = 1 << 1, - FN_TEST = 1 << 2, -}; - struct ast_function_decl { char *symbol; - uint32_t flags; // enum function_flags + uint32_t flags; // enum function_flags (check.h) struct identifier ident; struct ast_function_type prototype; struct ast_expression body; diff --git a/include/check.h b/include/check.h @@ -0,0 +1,50 @@ +#ifndef HARE_CHECK_H +#define HARE_CHECK_H +#include <stdbool.h> +#include <stdint.h> +#include "identifier.h" +#include "types.h" + +struct expression; + +enum function_flags { + FN_FINI = 1 << 0, + FN_INIT = 1 << 1, + FN_TEST = 1 << 2, +}; + +struct function_decl { + const struct type *type; + struct expression *body; + char *symbol; + uint32_t flags; // enum function_flags +}; + +enum declaration_type { + DECL_FUNC, + DECL_TYPE, + DECL_GLOBAL, + DECL_CONSTANT, +}; + +struct declaration { + enum declaration_type type; + struct identifier ident; + bool exported; +}; + +struct declarations { + struct declaration decl; + struct declarations *next; +}; + +struct unit { + struct identifier *ns; + struct declarations *declarations; +}; + +struct ast_unit; + +void check(const struct ast_unit *aunit, struct unit *unit); + +#endif diff --git a/src/check.c b/src/check.c @@ -0,0 +1,40 @@ +#include <assert.h> +#include "ast.h" +#include "check.h" +#include "types.h" +#include "type_store.h" + +struct context { + struct type_store store; +}; + +static void +scan_declarations(struct context *ctx, const struct ast_decls *decls) +{ + while (decls) { + const struct ast_decl *decl = &decls->decl; + switch (decl->decl_type) { + case AST_DECL_FUNC: + assert(0); // TODO + case AST_DECL_TYPE: + assert(0); // TODO + case AST_DECL_GLOBAL: + assert(0); // TODO + case AST_DECL_CONST: + assert(0); // TODO + } + decls = decls->next; + } +} + +void +check(const struct ast_unit *aunit, struct unit *unit) +{ + struct context ctx = {0}; + const struct ast_subunit *su = &aunit->subunits; + assert(su); // At least one is required + while (su) { + scan_declarations(&ctx, &su->decls); + su = su->next; + } +} diff --git a/src/main.c b/src/main.c @@ -1,5 +1,6 @@ #include <stdio.h> #include "ast.h" +#include "check.h" #include "lex.h" #include "parse.h" @@ -9,9 +10,11 @@ main(int argc, char *argv[]) struct lexer lexer; lex_init(&lexer, stdin); - struct ast_subunit subunit = {0}; - parse(&lexer, &subunit); - + struct ast_unit aunit = {0}; + parse(&lexer, &aunit.subunits); lex_finish(&lexer); + + struct unit unit = {0}; + check(&aunit, &unit); return 0; }