Continue struct parsing work
This commit is contained in:
@@ -234,6 +234,11 @@ void groundAddNativeFunction(GroundScope* scope, char* name, NativeGroundFunctio
|
||||
addVariable(scope->variables, name, createFunctionGroundValue(gf));
|
||||
}
|
||||
|
||||
GroundStruct parseStruct(GroundProgram* in) {
|
||||
GroundStruct gstruct = createStruct();
|
||||
return gstruct;
|
||||
}
|
||||
|
||||
GroundValue interpretGroundProgram(GroundProgram* in, GroundScope* inScope) {
|
||||
GroundLabel* labels = NULL;
|
||||
GroundVariable* variables = NULL;
|
||||
@@ -246,7 +251,7 @@ GroundValue interpretGroundProgram(GroundProgram* in, GroundScope* inScope) {
|
||||
scope.labels = &labels;
|
||||
scope.variables = &variables;
|
||||
}
|
||||
// Preprocess all labels and functions
|
||||
// Preprocess all labels, structs and functions
|
||||
for (int i = 0; i < in->size; i++) {
|
||||
if (in->instructions[i].type == CREATELABEL) {
|
||||
addLabel(scope.labels, in->instructions[i].args.args[0].value.refName, i);
|
||||
@@ -290,6 +295,36 @@ GroundValue interpretGroundProgram(GroundProgram* in, GroundScope* inScope) {
|
||||
}
|
||||
addVariable(scope.variables, functionName, createFunctionGroundValue(function));
|
||||
}
|
||||
if (in->instructions[i].type == STRUCT) {
|
||||
if (in->instructions[i].args.length < 1) {
|
||||
runtimeError(TOO_FEW_ARGS, "Expecting 1 arg", &in->instructions[i], i);
|
||||
}
|
||||
if (in->instructions[i].args.length > 1) {
|
||||
runtimeError(TOO_MANY_ARGS, "Expecting 1 arg", &in->instructions[i], i);
|
||||
}
|
||||
if (in->instructions[i].args.args[0].type != TYPEREF) {
|
||||
runtimeError(ARG_TYPE_MISMATCH, "Expected arg 1 to be a typeref", &in->instructions[i], i);
|
||||
}
|
||||
char* name = in->instructions[i].args.args[0].value.refName;
|
||||
i++;
|
||||
|
||||
size_t counter = 1;
|
||||
GroundProgram gp;
|
||||
while (counter > 0) {
|
||||
if (i >= in->size) {
|
||||
runtimeError(PREMATURE_EOF, "Reached end of scope before struct definition ended", &in->instructions[i - 1], i - 1);
|
||||
}
|
||||
if (in->instructions[i].type == STRUCT) {
|
||||
counter++;
|
||||
}
|
||||
if (in->instructions[i].type == ENDSTRUCT) {
|
||||
counter--;
|
||||
}
|
||||
addInstructionToProgram(&gp, in->instructions[i]);
|
||||
}
|
||||
|
||||
GroundStruct gs = parseStruct(&gp);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < in->size; i++) {
|
||||
if (in->instructions[i].type == FUN) {
|
||||
|
||||
Reference in New Issue
Block a user