Begin work on reworked extern instruction

This commit is contained in:
2026-07-04 17:53:14 +10:00
parent 3204613c6f
commit 7c29048397
4 changed files with 100 additions and 3 deletions

View File

@@ -78,10 +78,10 @@ static inline void doLabels(GroundProgram* program, GroundState* state) {
static inline GroundSize doOffsets(GroundProgram* gp, GroundState* state, GroundBytecodeProgram* gbp) {
GroundSize size = 0;
// Add size of state
// Add size of state and assign offsets to pre-existing variables
GroundVariable *s, *tmp;
HASH_ITER(hh, state->variables, s, tmp) {
size++;
s->_offset = size++;
}
for (GroundSize i = 0; i < gp->len; i++) {
@@ -175,6 +175,61 @@ GroundBytecode _GroundNewBytecode(GroundProgram* program, GroundState* state) {
return bytecode;
}
// Add core types to state
for (unsigned int i = 0; i < (unsigned int)GroundType_Object; i++) {
GroundVariable* var = malloc(sizeof(GroundVariable));
if (var == NULL) {
Ground.Log.Error("malloc failed in Ground.New.Bytecode");
Ground.Flags.error = true;
return bytecode;
}
var->value = (GroundValue) {
.type = {GroundType_CoreType},
.as.CoreType = (enum GroundTypeType) i
};
switch ((enum GroundTypeType) i) {
case GroundType_Int: {
sprintf(var->name, "int");
break;
}
case GroundType_Double: {
sprintf(var->name, "double");
break;
}
case GroundType_Char: {
sprintf(var->name, "char");
break;
}
case GroundType_Bool: {
sprintf(var->name, "bool");
break;
}
case GroundType_String: {
sprintf(var->name, "string");
break;
}
case GroundType_List: {
sprintf(var->name, "list");
break;
}
case GroundType_Function: {
sprintf(var->name, "function");
break;
}
case GroundType_Struct: {
sprintf(var->name, "struct");
break;
}
default: break; // unreachable (in theory)
}
HASH_ADD_STR(state->variables, name, var);
}
state->_size += (unsigned int)GroundType_Object + 1;
// Precompute some really cool stuff
doLabels(program, state);
if (Ground.Flags.error) return bytecode;