Add compiler #14

Merged
max merged 13 commits from unstable into master 2026-01-21 15:53:20 +11:00
2 changed files with 40 additions and 2 deletions
Showing only changes of commit c6762a7966 - Show all commits

View File

@@ -1,4 +1,3 @@
#include "lexer.h"
#include "parser.h"
#include "interpreter.h"
#include "types.h"
@@ -68,11 +67,34 @@ GroundValue groundCreateValue(GroundValueType type, ...) {
return createListGroundValue(va_arg(args, List));
break;
}
default: {
case FUNCTION: {
return createFunctionGroundValue(va_arg(args, GroundFunction*));
break;
}
case STRUCTVAL: {
GroundValue gv;
gv.type = STRUCTVAL;
gv.data.structVal = malloc(sizeof(GroundStruct));
*gv.data.structVal = va_arg(args, GroundStruct);
return gv;
}
case CUSTOM: {
// FIXME do this later lmao
return createNoneGroundValue();
break;
}
case ERROR: {
return createErrorGroundValue(va_arg(args, GroundError));
break;
}
case NONE: {
return createNoneGroundValue();
break;
}
}
return createNoneGroundValue();
va_end(args);
}
@@ -90,3 +112,18 @@ void groundPrintProgram(GroundProgram* program) {
GroundProgram groundParseFile(const char* code) {
return parseFile(code);
}
GroundStruct groundCreateStruct() {
GroundStruct gs;
gs.size = 0;
gs.fields = malloc(sizeof(GroundStructField));
return gs;
}
void groundAddValueToScope(GroundScope* gs, const char* name, GroundValue value) {
addVariable(gs->variables, name, value);
}
void groundAddFieldToStruct(GroundStruct* gstruct, char* name, GroundValue field) {
addFieldToStruct(gstruct, name, field);
}

View File

@@ -42,6 +42,7 @@ GroundFunction* parseFunction(GroundProgram* in, size_t errorOffset);
GroundValue interpretGroundProgram(GroundProgram* in, GroundScope* inScope);
GroundValue interpretGroundInstruction(GroundInstruction inst, GroundScope* scope);
void addVariable(GroundVariable **head, const char *id, GroundValue data);