From 99cf6e8eca2e3d29874b8b80e8c4312cd1bc87ba Mon Sep 17 00:00:00 2001 From: dx Date: Fri, 22 May 2020 19:13:15 +0100 Subject: ~compile_lines -> compile_file, shuffle I've redid the compiler to use a FILE object pointer, which means that we can leave error checking for FILES on the main program. Furthermore, I've removed the use of the array_t type with a two pass system. One pass is done for the number of lines (along with potentially other diagnostics), another is done for the actual compilation. This means at runtime we have an understanding about the size of the file and can optimize for it. Also, we have a single memory block to assign to, where we know the size of the array. --- Converter/includes/compiler.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'Converter/includes') diff --git a/Converter/includes/compiler.h b/Converter/includes/compiler.h index 8d84b71..4540164 100644 --- a/Converter/includes/compiler.h +++ b/Converter/includes/compiler.h @@ -2,6 +2,7 @@ #define __COMPILER_H_ #include +#include #include typedef char *string; @@ -15,7 +16,9 @@ int find_string(string src, string query, size_t sz_src, size_t sz_query); /* Check if a given character is a text token*/ bool is_token(char c); -/* Given a file, get the lines */ -char **get_lines(char *filename); +/* Given a file, get number of lines */ +int nlines(FILE *fp); +/* Given a file, compile the lines */ +string *compile_file(FILE *fp, string filename, int nlines); #endif // __COMPILER_H_ -- cgit v1.2.3-13-gbd6f