bug fixes

This commit is contained in:
2026-07-03 10:29:21 +10:00
parent c78426ef88
commit a06d3ba55d
4 changed files with 16 additions and 11 deletions

View File

@@ -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;
}

View File

@@ -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);
}
}

View File

@@ -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++;
}

View File

@@ -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