diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-09-17 15:17:13 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-09-17 15:17:13 -0400 |
| commit | aaa51fc734dde35ab8109bad04e478cdf4fff950 (patch) | |
| tree | 94b8d8e0d38ae055ff6aa009763c63c1b1b92c48 /environment.c | |
| parent | 2d5c8c3124dfe82c983bc91b62ed4b69be3fc647 (diff) | |
Perform topological ordering when compiling typedefs so users don't need
to think about ordering their definitions.
Diffstat (limited to 'environment.c')
| -rw-r--r-- | environment.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/environment.c b/environment.c index 8ae4611c..0c2a1d3b 100644 --- a/environment.c +++ b/environment.c @@ -3,11 +3,12 @@ #include <stdlib.h> #include <signal.h> +#include "cordhelpers.h" +#include "environment.h" +#include "stdlib/datatypes.h" #include "stdlib/tables.h" #include "stdlib/text.h" #include "stdlib/util.h" -#include "cordhelpers.h" -#include "environment.h" #include "typecheck.h" type_t *TEXT_TYPE = NULL; @@ -421,11 +422,9 @@ env_t *load_module_env(env_t *env, ast_t *ast) module_env->namespace_bindings = module_env->locals; Table$str_set(module_env->imports, name, module_env); - for (ast_list_t *stmt = Match(ast, Block)->statements; stmt; stmt = stmt->next) - prebind_statement(module_env, stmt->ast); - - for (ast_list_t *stmt = Match(ast, Block)->statements; stmt; stmt = stmt->next) - bind_statement(module_env, stmt->ast); + ast_list_t *statements = Match(ast, Block)->statements; + visit_topologically(statements, (Closure_t){.fn=(void*)prebind_statement, .userdata=module_env}); + visit_topologically(statements, (Closure_t){.fn=(void*)bind_statement, .userdata=module_env}); return module_env; } |
