harec

[hare] Hare compiler, written in C11 for POSIX OSs
Log | Files | Refs | README | LICENSE

commit fc9f3b57f210fe1ab9080e46be17d30064712f8a
parent e185444e916ee170913344bd29e34659b8ec636e
Author: Bor Grošelj Simić <bgs@turminal.net>
Date:   Sun, 20 Nov 2022 13:20:42 +0100

allow dependencies between command line defines in forward order

`harec -D A:int=5 -D B:int=A+2` is now valid, but
`harec -D B:int=A+2 -D A:int=5` isn't

Signed-off-by: Bor Grošelj Simić <bgs@turminal.net>

Diffstat:
Msrc/check.c | 16++++++----------
Msrc/main.c | 7+++----
2 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/src/check.c b/src/check.c @@ -4195,19 +4195,12 @@ check_internal(struct type_store *ts, // sub-scopes for each declaration, expression-list, etc. // Put defines into a temporary scope (-D on the command line) - struct scope *def_scope = NULL; - scope_push(&def_scope, SCOPE_UNIT); - ctx.unit = def_scope; + ctx.scope = NULL; + ctx.unit = scope_push(&ctx.scope, SCOPE_UNIT); for (struct ast_global_decl *def = defines; def; def = def->next) { scan_const(&ctx, def); } - ctx.unit = NULL; - - struct scopes *subunit_scopes = NULL; - struct scopes **next = &subunit_scopes; - struct scope *su_scope = NULL; - struct identifiers **inext = &unit->imports; - + struct scope *def_scope = ctx.scope; ctx.scope = NULL; ctx.unit = scope_push(&ctx.scope, SCOPE_UNIT); @@ -4216,6 +4209,9 @@ check_internal(struct type_store *ts, // A scope gets us: // a) duplicate detection for free // b) a way to find declaration's definition when it's refered to + struct scopes *subunit_scopes = NULL, **next = &subunit_scopes; + struct scope *su_scope = NULL; + struct identifiers **inext = &unit->imports; for (const struct ast_subunit *su = &aunit->subunits; su; su = su->next) { su_scope = NULL; diff --git a/src/main.c b/src/main.c @@ -92,7 +92,7 @@ main(int argc, char *argv[]) bool is_test = false; struct unit unit = {0}; struct lexer lexer; - struct ast_global_decl *defines = NULL, *def; + struct ast_global_decl *defines = NULL, **next_def = &defines; int c; while ((c = getopt(argc, argv, "D:ho:Tt:N:")) != -1) { @@ -101,9 +101,8 @@ main(int argc, char *argv[]) target = optarg; break; case 'D': - def = parse_define(argv[0], optarg); - def->next = defines; - defines = def; + *next_def = parse_define(argv[0], optarg); + next_def = &(*next_def)->next; break; case 'o': output = optarg;