object initialisation

This commit is contained in:
2026-07-08 12:06:18 +10:00
parent b507d79804
commit 6929f055de
4 changed files with 50 additions and 55 deletions

View File

@@ -156,6 +156,11 @@ static void doStruct(GroundProgram* program, GroundProgram* newProgram, GroundSt
// If we know the value type now, add it to the instruction
if (instruction->args.at[1].type == GroundArg_Value) {
field->value = Ground.Copy.Value(&instruction->args.at[1].as.value);
HASH_ADD_STR(gs.fields, name, field);
// set &field $value -> &field 2 $value
Ground.Instruction.append(&output, Ground.Copy.Arg(&instruction->args.at[0]));
Ground.Instruction.append(&output, (GroundArg) {.type = GroundArg_DirectRef, ._offset = 2});
Ground.Instruction.append(&output, Ground.Copy.Arg(&instruction->args.at[1]));
break;
}
@@ -178,29 +183,21 @@ static void doStruct(GroundProgram* program, GroundProgram* newProgram, GroundSt
snprintf(field->name, 2047, "%s", instruction->args.at[0].as.ref->string);
// If we know the type now, add it to the instruction
if (strcmp(field->name, "int") == 0) {
char* typeName = instruction->args.at[1].as.ref->string;
if (strcmp(typeName, "int") == 0) {
field->value = Ground.New.Value.Int(0);
break;
}
if (strcmp(field->name, "double") == 0) {
} else if (strcmp(typeName, "double") == 0) {
field->value = Ground.New.Value.Double(0.0);
break;
}
if (strcmp(field->name, "string") == 0) {
} else if (strcmp(typeName, "string") == 0) {
field->value = Ground.New.Value.String(Ground.New.String(""));
break;
}
if (strcmp(field->name, "char") == 0) {
} else if (strcmp(typeName, "char") == 0) {
field->value = Ground.New.Value.Char(0);
break;
}
if (strcmp(field->name, "bool") == 0) {
} else if (strcmp(typeName, "bool") == 0) {
field->value = Ground.New.Value.Bool(false);
break;
}
if (strcmp(field->name, "function") == 0) {
} else if (strcmp(typeName, "function") == 0) {
field->value = Ground.New.Value.Function(Ground.New.Function(state));
break;
} else {
field->value = Ground.New.Value.Int(0);
}
HASH_ADD_STR(gs.fields, name, field);
@@ -229,7 +226,7 @@ static void doStruct(GroundProgram* program, GroundProgram* newProgram, GroundSt
newProgram->len--;
// Add 3 to signal addition of closure
Ground.Instruction.append(&output, (GroundArg) {.type = GroundArg_DirectRef, ._offset = 1});
Ground.Instruction.append(&output, (GroundArg) {.type = GroundArg_DirectRef, ._offset = 3});
break;
}
case GroundInstruction_ENDSTRUCT: {