Fix a couple things

This commit is contained in:
2026-06-16 20:08:21 +10:00
parent 02b5a9cc54
commit 6d35acbe60
6 changed files with 143 additions and 48 deletions

View File

@@ -143,7 +143,7 @@ enum GroundArgType {
struct GroundArg {
enum GroundArgType type;
union {
const char* ref;
char* ref;
GroundValue value;
} as;

View File

@@ -21,6 +21,11 @@ sources = files(
'src/Free/Struct.c',
'src/Free/Value.c',
'src/Free/Arg.c',
'src/Free/Instruction.c',
'src/Free/Program.c',
'src/Free/State.c',
'src/Function/appendInstruction.c',
'src/Function/appendArg.c',

View File

@@ -137,13 +137,27 @@ int64_t _GroundInstructionExecute(GroundInstruction* instruction, GroundValue* h
Ground.Log.Warning("EXISTS is deprecated");
return -1;
}
SETLIST: {}
SETLISTAT: {}
GETLISTAT: {}
GETLISTSIZE: {}
LISTAPPEND: {}
GETSTRSIZE: {}
GETSTRCHARAT: {}
SETLIST: {
return -1;
}
SETLISTAT: {
return -1;
}
GETLISTAT: {
return -1;
}
GETLISTSIZE: {
return -1;
}
LISTAPPEND: {
return -1;
}
GETSTRSIZE: {
return -1;
}
GETSTRCHARAT: {
return -1;
}
ADD: {
GroundValue* final = &heap[instruction->args.at[2]._offset];
GroundValue* left = &instruction->args.at[0].as.value;
@@ -512,37 +526,99 @@ int64_t _GroundInstructionExecute(GroundInstruction* instruction, GroundValue* h
heap[instruction->args.at[1]._offset] = Ground.New.Value.Bool(!instruction->args.at[0].as.value.as.Bool);
return -1;
}
GREATER: {}
LESSER: {}
AND: {}
OR: {}
XOR: {}
NEG: {}
SHIFT: {}
STOI: {}
STOD: {}
ITOC: {}
CTOI: {}
TOSTRING: {}
FUN: {}
RETURN: {}
ENDFUN: {}
CALL: {}
CALLMETHOD: {}
STRUCT: {}
ENDSTRUCT: {}
INIT: {}
GETFIELD: {}
SETFIELD: {}
USE: {}
EXTERN: {}
CREATELABEL: {}
PAUSE: {}
DROP: {}
LICENSE: {}
ERRORCMD: {}
THROW: {}
CATCH: {}
GREATER: {
return -1;
}
LESSER: {
return -1;
}
AND: {
return -1;
}
OR: {
return -1;
}
XOR: {
return -1;
}
NEG: {
return -1;
}
SHIFT: {
return -1;
}
STOI: {
return -1;
}
STOD: {
return -1;
}
ITOC: {
return -1;
}
CTOI: {
return -1;
}
TOSTRING: {
return -1;
}
FUN: {
return -1;
}
RETURN: {
return -1;
}
ENDFUN: {
return -1;
}
CALL: {
return -1;
}
CALLMETHOD: {
return -1;
}
STRUCT: {
return -1;
}
ENDSTRUCT: {
return -1;
}
INIT: {
return -1;
}
GETFIELD: {
return -1;
}
SETFIELD: {
return -1;
}
USE: {
return -1;
}
EXTERN: {
return -1;
}
CREATELABEL: {
return -1;
}
PAUSE: {
return -1;
}
DROP: {
return -1;
}
LICENSE: {
return -1;
}
ERRORCMD: {
return -1;
}
THROW: {
return -1;
}
CATCH: {
return -1;
}
Ground.Log.Error("operation fell through in Ground.Instruction.execute()");
Ground.Flags.error = true;

View File

@@ -135,7 +135,7 @@ void _GroundInternalRun(GroundProgram* program, GroundState* state) {
break;
default:
if (status < program->len) {
i = status;
i = status - 1;
} else {
Ground.Log.Error("out of bounds jump in Ground.Internal.Run()");
Ground.Flags.error = true;

BIN
test/test

Binary file not shown.

View File

@@ -1,15 +1,29 @@
#include <ground.h>
#include <stdio.h>
int main() {
GroundProgram program = Ground.New.Program();
printf(Ground.Flags.error ? "true\n" : "false\n");
GroundState state = {NULL, NULL, NULL};
GroundInstruction instruction = Ground.New.Instruction(GroundInstruction_ADD);
printf(Ground.Flags.error ? "true\n" : "false\n");
Ground.Instruction.append(&instruction, Ground.New.Arg.Value(Ground.New.Value.Int(2)));
printf(Ground.Flags.error ? "true\n" : "false\n");
Ground.Instruction.append(&instruction, Ground.New.Arg.Value(Ground.New.Value.Int(2)));
printf(Ground.Flags.error ? "true\n" : "false\n");
// Instruction 1: CREATELABEL start
GroundInstruction label_inst = Ground.New.Instruction(GroundInstruction_CREATELABEL);
Ground.Instruction.append(&label_inst, Ground.New.Arg.LabelRef("start"));
Ground.Program.append(&program, label_inst);
// Instruction 2: JUMP start
GroundInstruction jump_inst = Ground.New.Instruction(GroundInstruction_JUMP);
Ground.Instruction.append(&jump_inst, Ground.New.Arg.LabelRef("start"));
Ground.Program.append(&program, jump_inst);
// Execute program
Ground.Program.execute(&program, &state);
printf(Ground.Flags.error ? "true\n" : "false\n");
if (Ground.Flags.error) {
printf("Error set during execution!\n");
Ground.Log.printErrors();
return 1;
} else {
printf("Success!\n");
return 0;
}
}