le objects now go to the the bytecode

This commit is contained in:
2026-07-05 18:25:49 +10:00
parent 05733c693c
commit 820fd618a3
2 changed files with 67 additions and 4 deletions

View File

@@ -305,8 +305,17 @@ struct GroundBytecodeFunction {
// Only for native function
GroundType* returnType;
};
struct GroundBytecodeStruct {};
struct GroundBytecodeObject {};
struct GroundBytecodeStruct {
GroundBytecodeValue* values;
size_t size;
size_t capacity;
};
struct GroundBytecodeObject {
GroundBytecodeValue* values;
size_t size;
size_t capacity;
};
struct GroundBytecodeValue {
union {

View File

@@ -52,6 +52,60 @@ static inline GroundBytecodeFunction doFunction(GroundFunction* function) {
return bf;
}
static inline GroundBytecodeStruct doStruct(GroundStruct* gs) {
GroundBytecodeStruct gbs = {
.values = malloc(sizeof(GroundBytecodeValue) * 16),
.capacity = 16,
.size = 0
};
GroundObjectField *s, *tmp;
HASH_ITER(hh, gs->fields, s, tmp) {
if (gbs.size >= gbs.capacity) {
GroundBytecodeValue* tmp = malloc(sizeof(GroundBytecodeValue) * gbs.capacity * 2);
if (tmp == NULL) {
Ground.Log.Error("malloc failedd in Ground.New.BytecodeValue -> doStruct");
Ground.Flags.error = true;
return gbs;
}
gbs.values = tmp;
gbs.capacity *= 2;
}
gbs.values[gbs.size] = Ground.New.BytecodeValue(s->value);
gbs.size++;
}
return gbs;
}
static inline GroundBytecodeObject doObject(GroundObject* go) {
GroundBytecodeObject gbo = {
.values = malloc(sizeof(GroundBytecodeValue) * 16),
.capacity = 16,
.size = 0
};
GroundObjectField *s, *tmp;
HASH_ITER(hh, go->fields, s, tmp) {
if (gbo.size >= gbo.capacity) {
GroundBytecodeValue* tmp = malloc(sizeof(GroundBytecodeValue) * gbo.capacity * 2);
if (tmp == NULL) {
Ground.Log.Error("malloc failedd in Ground.New.BytecodeValue -> doStruct");
Ground.Flags.error = true;
return gbo;
}
gbo.values = tmp;
gbo.capacity *= 2;
}
gbo.values[gbo.size] = Ground.New.BytecodeValue(s->value);
gbo.size++;
}
return gbo;
}
GroundBytecodeValue _GroundNewBytecodeValue(GroundValue value) {
GroundBytecodeValue bv = {
@@ -89,11 +143,11 @@ GroundBytecodeValue _GroundNewBytecodeValue(GroundValue value) {
break;
}
case GroundType_Struct: {
// TODO - convert to bytecode struct
bv.as.Struct = doStruct(&value.as.Struct);
break;
}
case GroundType_Object: {
// TODO - convert to bytecode object
bv.as.Object = doObject(&value.as.Object);
break;
}
case GroundType_CoreType: {