From 0d199fedd7cec055aece0488683d4e8fcc09988d Mon Sep 17 00:00:00 2001 From: Maxwell Jeffress Date: Tue, 14 Jul 2026 11:35:54 +1000 Subject: [PATCH] fix the clanker's code --- src/New/Bytecode.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/src/New/Bytecode.c b/src/New/Bytecode.c index 4b0a854..d5e93cb 100644 --- a/src/New/Bytecode.c +++ b/src/New/Bytecode.c @@ -419,22 +419,38 @@ static inline GroundSize doOffsets(GroundProgram* gp, GroundState* state, Ground // Resolve the value variable GroundArg* valueArg = &inst->args.at[inst->args.len - 1]; - GroundVariable* valueItem = NULL; - HASH_FIND_STR(state->variables, valueArg->as.ref->string, valueItem); - if (valueItem == NULL) { - valueItem = malloc(sizeof(GroundVariable)); - if (valueItem == NULL) { + if (valueArg->type == GroundArg_Value) { + GroundVariable* item = malloc(sizeof(GroundVariable)); + if (item == NULL) { Ground.Log.Error("malloc failed in Ground.New.Bytecode -> doOffsets"); Ground.Flags.error = true; return 0; } - valueItem->value = Ground.New.Value.Int(0); - strncpy(valueItem->name, valueArg->as.ref->string, 2047); - valueItem->_offset = size++; - HASH_ADD_STR(state->variables, name, valueItem); + item->value = Ground.Copy.Value(&valueArg->as.value); + if (Ground.Flags.error) return 0; + item->_offset = size++; + snprintf(item->name, sizeof(item->name) - 1, "_._.ground_internal_constant_%zu", item->_offset); + HASH_ADD_STR(state->variables, name, item); + valueArg->_offset = item->_offset; + newInst.args.at[gbiSize - 1] = item->_offset; + } else { + valueArg->_offset = item->_offset; + GroundVariable* valueItem = NULL; + HASH_FIND_STR(state->variables, valueArg->as.ref->string, valueItem); + if (valueItem == NULL) { + valueItem = malloc(sizeof(GroundVariable)); + if (valueItem == NULL) { + Ground.Log.Error("malloc failed in Ground.New.Bytecode -> doOffsets"); + Ground.Flags.error = true; + return 0; + } + valueItem->value = Ground.New.Value.Int(0); + strncpy(valueItem->name, valueArg->as.ref->string, 2047); + valueItem->_offset = size++; + HASH_ADD_STR(state->variables, name, valueItem); + } + newInst.args.at[gbiSize - 1] = valueItem->_offset; } - newInst.args.at[gbiSize - 1] = valueItem->_offset; - gbp->at[i] = newInst; gbp->len++;