From e3702f46f34fccdaad1230e51a2270d22fa4bfe7 Mon Sep 17 00:00:00 2001 From: Maxwell Jeffress Date: Sat, 31 Jan 2026 09:08:38 +1100 Subject: [PATCH] Command line arguments via CMDLINE_ARGS list var --- src/main.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/main.c b/src/main.c index 2bdd63e..582fca6 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,7 @@ #include "parser.h" #include "interpreter.h" #include "compiler.h" +#include "types.h" #include char* getFileContents(const char* filename) { @@ -40,19 +41,6 @@ char* getFileContents(const char* filename) { } int main(int argc, char** argv) { - /* - if (argc < 2) { - printf("Usage: ground [file]\n"); - exit(1); - } - char* file = getFileContents(argv[1]); - GroundProgram program = parseFile(file); - free(file); - char* compiled = compileGroundProgram(&program); - printf("%s\n", compiled); - interpretGroundProgram(&program, NULL); - */ - if (argc < 2) { printf("Usage: %s [-c] [--compile] [-h] [--help]\n", argv[0]); exit(1); @@ -60,7 +48,7 @@ int main(int argc, char** argv) { bool compile = false; char* fileName = NULL; - + List groundArgs = createList(); for (int i = 1; i < argc; i++) { if (strcmp("--compile", argv[i]) == 0 || strcmp("-c", argv[i]) == 0) { compile = true; @@ -73,7 +61,11 @@ int main(int argc, char** argv) { printf(" -h or --help: Shows this help message\n"); exit(0); } else { - fileName = argv[i]; + if (fileName == NULL) { + fileName = argv[i]; + } else { + appendToList(&groundArgs, createStringGroundValue(argv[i])); + } } } @@ -91,6 +83,14 @@ int main(int argc, char** argv) { char* compiled = compileGroundProgram(&program); printf("%s\n", compiled); } else { - interpretGroundProgram(&program, NULL); + GroundVariable* variables = NULL; + GroundLabel* labels = NULL; + + GroundScope scope; + scope.variables = &variables; + scope.labels = &labels; + scope.isMainScope = true; + addVariable(scope.variables, "CMDLINE_ARGS", createListGroundValue(groundArgs)); + interpretGroundProgram(&program, &scope); } }