This commit is contained in:
2026-06-21 16:13:00 +10:00
parent ff98aa63b4
commit b2f6883e62
10 changed files with 351 additions and 42 deletions

View File

@@ -72,12 +72,6 @@ static inline void doLabels(GroundProgram* program, GroundState* state) {
}
static inline void addToGroundBytecodeProgram(GroundBytecodeProgram* program, GroundBytecodeInstruction inst) {
if (program->len + 1 >= program->capacity) {
}
}
/*
* Assigns an offset to each variable referenced.
*/
@@ -111,6 +105,7 @@ static inline GroundSize doOffsets(GroundProgram* gp, GroundState* state, Ground
item->_offset = size++;
snprintf(item->name, sizeof(item->name) - 1, "_._.ground_internal_constant_%zu", item->_offset);
HASH_ADD_STR(state->variables, name, item);
arg->_offset = item->_offset;
continue;
}
@@ -131,7 +126,6 @@ static inline GroundSize doOffsets(GroundProgram* gp, GroundState* state, Ground
}
arg->_offset = item->_offset;
size++;
}
// Convert to GroundBytecodeInstruction
@@ -142,7 +136,11 @@ static inline GroundSize doOffsets(GroundProgram* gp, GroundState* state, Ground
.args.capacity = gp->at[i].args.len
};
if (inst.args.at == NULL) {}
if (inst.args.at == NULL) {
Ground.Log.Error("malloc failed in Ground.Internal.run()");
Ground.Flags.error = true;
return 0;
}
for (GroundSize j = 0; j < gp->at[i].args.len; j++) {
inst.args.at[j] = gp->at[i].args.at[j]._offset;
@@ -196,12 +194,10 @@ GroundBytecode _GroundNewBytecode(GroundProgram* program, GroundState* state) {
GroundVariable *s, *tmp;
// Copy constants into heap
GroundSize i = 0;
// Copy constants into heap at their assigned offsets
HASH_ITER(hh, state->variables, s, tmp) {
bytecode.heap.heap[i] = Ground.Copy.Value(&s->value);
bytecode.heap.heap[s->_offset] = Ground.Copy.Value(&s->value);
if (Ground.Flags.error) return bytecode;
i++;
}