From a06d3ba55db6290056f0afaf7ffb132da8964164 Mon Sep 17 00:00:00 2001 From: Maxwell Jeffress Date: Fri, 3 Jul 2026 10:29:21 +1000 Subject: [PATCH] bug fixes --- src/Copy/Function.c | 9 ++------- src/Free/Function.c | 2 +- src/Function/appendArg.c | 4 ++-- src/Program/preprocess.c | 12 +++++++++++- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/Copy/Function.c b/src/Copy/Function.c index 8401a8b..8962902 100644 --- a/src/Copy/Function.c +++ b/src/Copy/Function.c @@ -32,13 +32,8 @@ GroundFunction _GroundCopyFunction(GroundFunction* in) { return newFunction; } for (GroundSize i = 0; i < in->args.count; i++) { - if (newFunction.args.at == NULL) { - Ground.Log.Error("malloc failed in Ground.Copy.Function()"); - Ground.Flags.error = true; - return newFunction; - } - newFunction.args.at->as.id = Ground.Copy.Identifier(in->args.at[i].as.id); - } + newFunction.args.at[i].as.id = Ground.Copy.Identifier(in->args.at[i].as.id); + } return newFunction; } diff --git a/src/Free/Function.c b/src/Free/Function.c index c9c9962..c65ba12 100644 --- a/src/Free/Function.c +++ b/src/Free/Function.c @@ -6,7 +6,7 @@ void _GroundFreeFunction(GroundFunction* in) { free(in->program.ground); for (GroundSize i = 0; i < in->args.count; i++) { - free(in->args.at[i].as.id); + Ground.Free.Identifier(in->args.at[i].as.id); } } diff --git a/src/Function/appendArg.c b/src/Function/appendArg.c index d2028df..5489dc7 100644 --- a/src/Function/appendArg.c +++ b/src/Function/appendArg.c @@ -1,6 +1,6 @@ #include "../../include/ground.h" -void _GroundFunctionAppendArg(GroundFunction* function, GroundIdentifier* argName) { +void _GroundFunctionAppendArg(GroundFunction* function, const char* argName) { if (function->isNativeFunction) { Ground.Log.Error("Cannot add arg to native function in Ground.Function.appendArg()"); Ground.Flags.error = true; @@ -18,6 +18,6 @@ void _GroundFunctionAppendArg(GroundFunction* function, GroundIdentifier* argNam function->args.capacity *= 2; } - function->args.at[function->args.count].as.id = Ground.Copy.Identifier(argName); + function->args.at[function->args.count].as.id = Ground.New.Identifier(argName); function->args.count++; } diff --git a/src/Program/preprocess.c b/src/Program/preprocess.c index 8583bfc..ca2e4e0 100644 --- a/src/Program/preprocess.c +++ b/src/Program/preprocess.c @@ -14,7 +14,7 @@ GroundProgram _GroundProgramPreprocess(GroundProgram* program, GroundState* stat GroundInstruction* sig = &program->at[i]; char* id = sig->args.at[0].as.ref->string; - for (GroundSize j = 1; i < sig->args.len - 1; i++) { + for (GroundSize j = 1; j < sig->args.len; j++) { GroundArg* arg = &sig->args.at[j]; // Ignore type annotations, this can be taken care of in another function @@ -23,6 +23,16 @@ GroundProgram _GroundProgramPreprocess(GroundProgram* program, GroundState* stat } char* argId = arg->as.ref->string; Ground.Function.appendArg(&function, argId); + + GroundVariable* argVar = malloc(sizeof(GroundVariable)); + if (argVar == NULL) { + Ground.Flags.error = true; + Ground.Log.Error("malloc failed in Ground.Program.Preprocess"); + return newProgram; + } + snprintf(argVar->name, 2047, "%s", argId); + argVar->value = Ground.New.Value.Int(0); + HASH_ADD_STR(function.closure->variables, name, argVar); } // Add instructions to function