Start work on the interpreter

This commit is contained in:
2026-06-15 21:33:58 +10:00
parent 80140ed798
commit da75cf7590
3 changed files with 196 additions and 114 deletions

View File

@@ -4,7 +4,7 @@
#include <stdlib.h>
#include <uthash.h>
void doLabels(GroundProgram* program, GroundState* state) {
static inline void doLabels(GroundProgram* program, GroundState* state) {
for (size_t i = 0; i < program->len; i++) {
for (size_t j = 0; j < program->len; j++) {
@@ -70,7 +70,7 @@ void doLabels(GroundProgram* program, GroundState* state) {
/*
* Assigns an offset to each variable referenced.
*/
size_t doOffsets(GroundProgram* program, GroundState* state) {
static inline size_t doOffsets(GroundProgram* program, GroundState* state) {
size_t size = 0;
for (size_t i = 0; i < program->len; i++) {
for (size_t j = 0; j < program->at[i].args.len; j++) {
@@ -113,5 +113,28 @@ void _GroundInternalRun(GroundProgram* program, GroundState* state) {
size_t size = doOffsets(program, state);
if (Ground.Flags.error) return;
GroundValue* heap = malloc(sizeof(GroundValue) * size);
for (size_t i = 0; i < program->len; i++) {
GroundInstruction instruction = Ground.Copy.Instruction(&program->at[i]);
int64_t status = Ground.Instruction.execute(&instruction, heap);
switch (status) {
case -2:
return;
case -1:
break;
default:
if (status < program->len) {
i = status;
} else {
Ground.Log.Error("out of bounds jump in Ground.Internal.Run()");
Ground.Flags.error = true;
return;
}
}
// TODO: implement
// Ground.Free.Instruction(&instruction);
}
}