From 9fcd22a03b9fe3aa5659d4b544fc3ccc59730031 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Tue, 3 Dec 2024 00:22:14 +0000 Subject: Simplify build system RELEASE and DEBUG builds have differing build flags, triggered by setting RELEASE variable. No longer doing object based compilation because: + gcc is fast enough without it + stale code compilation bugs are annoying + having one output binary to clean-up is just easier when switching build-types --- main.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index c8e16ea..58357c8 100644 --- a/main.c +++ b/main.c @@ -15,7 +15,6 @@ #define MEMORY_DEFAULT 30000 -#define DEBUG 0 #define MIN_MEM_DUMP 64 typedef struct @@ -23,7 +22,7 @@ typedef struct size_t dp; uint8_t memory[MEMORY_DEFAULT]; -#if DEBUG +#ifdef DEBUG size_t dp_max; #endif } machine_t; @@ -62,13 +61,13 @@ void interpret(machine_t *cpu, node_t *ast, size_t num) i = node.loop_ref; break; } -#if DEBUG +#ifdef DEBUG if (cpu->dp > cpu->dp_max) cpu->dp_max = cpu->dp + 1; #endif } -#if DEBUG +#ifdef DEBUG if (cpu->dp_max < MIN_MEM_DUMP) cpu->dp_max = MIN_MEM_DUMP; #endif @@ -90,9 +89,9 @@ int main(int argc, char *argv[]) return 1; } - char *filepath, *file_data; - buffer_t *buffer; - struct PResult res; + char *filepath = NULL, *file_data = NULL; + buffer_t *buffer = NULL; + struct PResult res = {0}; machine_t machine = {0}; @@ -101,7 +100,7 @@ int main(int argc, char *argv[]) filepath = argv[i]; FILE *handle = fopen(filepath, "r"); -#if DEBUG +#ifdef DEBUG printf("[DEBUG]: Attempting to open file handle to %s\n", filepath); #endif if (!handle) @@ -111,12 +110,12 @@ int main(int argc, char *argv[]) } file_data = fread_all(handle); fclose(handle); -#if DEBUG +#ifdef DEBUG printf("[DEBUG]: Read data from file %s\n", filepath); #endif buffer = buffer_init_str(filepath, file_data, strlen(file_data)); -#if DEBUG +#ifdef DEBUG puts("[DEBUG]: Initialised buffer"); #endif res = parse_buffer(buffer); @@ -126,7 +125,7 @@ int main(int argc, char *argv[]) goto error; } -#if DEBUG +#ifdef DEBUG char *str = ast_to_str(res.nodes, res.size); printf("[DEBUG]: Parsed buffer (%lu nodes parsed)\n\t[DEBUG]: Out=%s\n", res.size, str); @@ -135,7 +134,7 @@ int main(int argc, char *argv[]) interpret(&machine, res.nodes, res.size); -#if DEBUG +#ifdef DEBUG printf("[DEBUG]: Finished interpreting, memory:"); for (size_t i = 0; i < machine.dp_max; ++i) { -- cgit v1.2.3-13-gbd6f