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 { struct GroundArg {
enum GroundArgType type; enum GroundArgType type;
union { union {
const char* ref; char* ref;
GroundValue value; GroundValue value;
} as; } as;

View File

@@ -21,6 +21,11 @@ sources = files(
'src/Free/Struct.c', 'src/Free/Struct.c',
'src/Free/Value.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/appendInstruction.c',
'src/Function/appendArg.c', 'src/Function/appendArg.c',

View File

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

View File

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

BIN
test/test

Binary file not shown.

View File

@@ -1,15 +1,29 @@
#include <ground.h> #include <ground.h>
#include <stdio.h>
int main() { int main() {
GroundProgram program = Ground.New.Program(); GroundProgram program = Ground.New.Program();
printf(Ground.Flags.error ? "true\n" : "false\n");
GroundState state = {NULL, NULL, NULL}; GroundState state = {NULL, NULL, NULL};
GroundInstruction instruction = Ground.New.Instruction(GroundInstruction_ADD);
printf(Ground.Flags.error ? "true\n" : "false\n"); // Instruction 1: CREATELABEL start
Ground.Instruction.append(&instruction, Ground.New.Arg.Value(Ground.New.Value.Int(2))); GroundInstruction label_inst = Ground.New.Instruction(GroundInstruction_CREATELABEL);
printf(Ground.Flags.error ? "true\n" : "false\n"); Ground.Instruction.append(&label_inst, Ground.New.Arg.LabelRef("start"));
Ground.Instruction.append(&instruction, Ground.New.Arg.Value(Ground.New.Value.Int(2))); Ground.Program.append(&program, label_inst);
printf(Ground.Flags.error ? "true\n" : "false\n");
// 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); 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;
}
} }