aboutsummaryrefslogtreecommitdiff
path: root/typecheck.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-07-05 15:51:23 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-07-05 15:51:23 -0400
commita86dc05d366c0733b645763dd5c3e7396041bd7b (patch)
tree409af6b99d0bb828ca44b75202e170dea87389b9 /typecheck.c
parente51e6f840cb2414cad6e816aea7adea74ee8b1b8 (diff)
Cache AST parsings so we don't have to re-parse files
Diffstat (limited to 'typecheck.c')
-rw-r--r--typecheck.c18
1 files changed, 5 insertions, 13 deletions
diff --git a/typecheck.c b/typecheck.c
index 53946dc8..9a93211d 100644
--- a/typecheck.c
+++ b/typecheck.c
@@ -116,11 +116,8 @@ static env_t *load_module(env_t *env, ast_t *module_ast)
if (!resolved_path)
code_err(module_ast, "No such file exists: \"%s\"", path);
- file_t *f = load_file(resolved_path);
- if (!f) errx(1, "No such file: %s", resolved_path);
-
- ast_t *ast = parse_file(f, NULL);
- if (!ast) errx(1, "Could not compile!");
+ ast_t *ast = parse_file(resolved_path, NULL);
+ if (!ast) errx(1, "Could not compile file %s", resolved_path);
return load_module_env(env, ast);
} else if (module_ast->tag == Use) {
const char *libname = Match(module_ast, Use)->name;
@@ -147,11 +144,8 @@ static env_t *load_module(env_t *env, ast_t *module_ast)
const char *tm_path = resolve_path(line, resolved_path, ".");
if (!tm_path) errx(1, "Couldn't find library %s dependency: %s", libname, line);
- file_t *tm_f = load_file(tm_path);
- if (!tm_f) errx(1, "No such file: %s", tm_path);
-
- ast_t *ast = parse_file(tm_f, NULL);
- if (!ast) errx(1, "Could not compile!");
+ ast_t *ast = parse_file(tm_path, NULL);
+ if (!ast) errx(1, "Could not compile file %s", tm_path);
env_t *module_file_env = fresh_scope(module_env);
char *file_prefix = heap_str(file_base_name(line));
for (char *p = file_prefix; *p; p++) {
@@ -1101,9 +1095,7 @@ bool is_discardable(env_t *env, ast_t *ast)
type_t *get_file_type(env_t *env, const char *path)
{
- // auto info = get_file_info(env, path);
- file_t *f = load_file(path);
- ast_t *ast = parse_file(f, NULL);
+ ast_t *ast = parse_file(path, NULL);
if (!ast) compiler_err(NULL, NULL, NULL, "Couldn't parse file: %s", path);
arg_t *ns_fields = NULL;