From 3a6d55f85ff2898c92072b6510adb4ee5ee1bfcf Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Tue, 4 Feb 2020 18:18:42 -0500 Subject: bug fixes --- main.c | 10 +++++----- toc.c | 2 +- types.c | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/main.c b/main.c index 09d6750..91b447e 100644 --- a/main.c +++ b/main.c @@ -25,7 +25,7 @@ make sure #export still works properly fix cgen_ident_to_str for unicode idents check for leaks --- -nice syntax for importing something into a namespace +nice syntax for #including something into a namespace run stuff at compile time without assigning it to a constant #compile_only declarations constants in structs @@ -77,13 +77,14 @@ int main(int argc, char **argv) { file.filename = in_filename; Location file_where = {0}; file_where.file = &file; - char *contents = read_entire_file(&main_allocr, in_filename, file_where); - + file.ctx = &err_ctx; + char *contents = read_file_contents(&main_allocr, in_filename, file_where); + if (!contents) return EXIT_FAILURE; + Identifiers idents; idents_create(&idents); Tokenizer t; file.contents = contents; - file.ctx = &err_ctx; tokr_create(&t, &idents, &err_ctx, &main_allocr); if (!tokenize_file(&t, &file)) { err_text_important(&err_ctx, "Errors occured during preprocessing.\n"); @@ -143,7 +144,6 @@ int main(int argc, char **argv) { block_exit(NULL, f.stmts); /* exit global scope */ - free(contents - 1); /* -1 because we put a 0 byte at the beginning */ allocr_free_all(&main_allocr); evalr_free(&ev); fclose(out); diff --git a/toc.c b/toc.c index bd94586..d60be8b 100644 --- a/toc.c +++ b/toc.c @@ -84,7 +84,7 @@ static size_t compiler_sizeof(Type *t); #include "copy.c" /* returns NULL on error */ -static char *read_entire_file(Allocator *a, const char *filename, Location where) { +static char *read_file_contents(Allocator *a, const char *filename, Location where) { FILE *in = fopen(filename, "r"); if (!in) { diff --git a/types.c b/types.c index fc88d82..cd5b688 100644 --- a/types.c +++ b/types.c @@ -2446,7 +2446,7 @@ static bool types_stmt(Typer *tr, Statement *s) { char *filename = eval_expr_as_cstr(tr, &s->inc.filename, "import filename"); if (!filename) return false; - char *contents = read_entire_file(tr->allocr, filename, s->where); + char *contents = read_file_contents(tr->allocr, filename, s->where); if (!contents) return false; Tokenizer tokr; -- cgit v1.2.3