le objects now go to the the bytecode
This commit is contained in:
@@ -305,8 +305,17 @@ struct GroundBytecodeFunction {
|
|||||||
// Only for native function
|
// Only for native function
|
||||||
GroundType* returnType;
|
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 {
|
struct GroundBytecodeValue {
|
||||||
union {
|
union {
|
||||||
|
|||||||
@@ -52,6 +52,60 @@ static inline GroundBytecodeFunction doFunction(GroundFunction* function) {
|
|||||||
return bf;
|
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 _GroundNewBytecodeValue(GroundValue value) {
|
||||||
|
|
||||||
GroundBytecodeValue bv = {
|
GroundBytecodeValue bv = {
|
||||||
@@ -89,11 +143,11 @@ GroundBytecodeValue _GroundNewBytecodeValue(GroundValue value) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case GroundType_Struct: {
|
case GroundType_Struct: {
|
||||||
// TODO - convert to bytecode struct
|
bv.as.Struct = doStruct(&value.as.Struct);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case GroundType_Object: {
|
case GroundType_Object: {
|
||||||
// TODO - convert to bytecode object
|
bv.as.Object = doObject(&value.as.Object);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case GroundType_CoreType: {
|
case GroundType_CoreType: {
|
||||||
|
|||||||
Reference in New Issue
Block a user