From 6d35acbe6014a773b74b1abe1fa6ac04f5a6349a Mon Sep 17 00:00:00 2001 From: Maxwell Jeffress Date: Tue, 16 Jun 2026 20:08:21 +1000 Subject: [PATCH] Fix a couple things --- include/ground.h | 2 +- meson.build | 5 ++ src/Instruction/execute.c | 152 ++++++++++++++++++++++++++++---------- src/Internal/run.c | 2 +- test/test | Bin 16056 -> 16056 bytes test/test.c | 30 ++++++-- 6 files changed, 143 insertions(+), 48 deletions(-) diff --git a/include/ground.h b/include/ground.h index 9570494..5f11ca2 100644 --- a/include/ground.h +++ b/include/ground.h @@ -143,7 +143,7 @@ enum GroundArgType { struct GroundArg { enum GroundArgType type; union { - const char* ref; + char* ref; GroundValue value; } as; diff --git a/meson.build b/meson.build index 7b82d26..9d9d940 100644 --- a/meson.build +++ b/meson.build @@ -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', diff --git a/src/Instruction/execute.c b/src/Instruction/execute.c index bbc716e..76fe8c5 100644 --- a/src/Instruction/execute.c +++ b/src/Instruction/execute.c @@ -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; diff --git a/src/Internal/run.c b/src/Internal/run.c index cad53b6..b37cdff 100644 --- a/src/Internal/run.c +++ b/src/Internal/run.c @@ -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; diff --git a/test/test b/test/test index 173b36e0adb3a291eebad6e6a32c22a50d2f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roundProgram 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; + } }