summaryrefslogtreecommitdiff
path: root/src/puzzles
diff options
context:
space:
mode:
authorPhysick <96335032+DegustatorPonos@users.noreply.github.com>2026-08-03 00:46:21 +0500
committerPhysick <96335032+DegustatorPonos@users.noreply.github.com>2026-08-03 00:46:21 +0500
commit56f152cf57e0bd3491be74195905b863519d9fca (patch)
tree671022de4608efbeb7efa7278d9404e8ae9b5303 /src/puzzles
parentd1a1ebd54cabc6646f20f6b1b341751a2bf3c2ec (diff)
memory leak issues + qol stull
Diffstat (limited to 'src/puzzles')
-rw-r--r--src/puzzles/puzzle.c50
-rw-r--r--src/puzzles/puzzle.h8
2 files changed, 55 insertions, 3 deletions
diff --git a/src/puzzles/puzzle.c b/src/puzzles/puzzle.c
index 6d0a4a0..e14708f 100644
--- a/src/puzzles/puzzle.c
+++ b/src/puzzles/puzzle.c
@@ -5,6 +5,7 @@
#include <stdlib.h>
#include <string.h>
#include <wren.h>
+#include <stdbool.h>
static const char *USER_MODULE_NAME = "main";
@@ -37,12 +38,20 @@ Puzzle *GetTestPuzzle() {
return outp;
}
+void FreePuzzleIO(PuzzleIO *io) {
+ if (io->value != NULL)
+ free(io->value);
+}
+
void FreeTests(Test *Tests, size_t TestC) {
if (TestC == 0 || Tests == NULL) return;
for (size_t i = 0; i < TestC; i++) {
Test *t = &Tests[i];
if (t->RecieverName != NULL) free(t->RecieverName);
if (t->MainMethodSignature != NULL) free(t->MainMethodSignature);
+ for (size_t j = 0; j < t->argc; j++) {
+ FreePuzzleIO(&t->argv[j]);
+ }
if (t->argv != NULL) free(t->argv);
}
free(Tests);
@@ -362,3 +371,44 @@ void FreeSunmitionResult(SubmitionResult *res) {
if (res->stdout_sb != NULL) free(res->stdout_sb);
free(res);
}
+
+void PrintPuzzle(Puzzle *puzzle) {
+ printf("Puzzle name: %s\n", puzzle->Name);
+ printf("Puzzle description: %s\n", puzzle->Description);
+ printf("Puzzle code: %s\n", puzzle->InitialCode);
+ printf("Puzzle TestC: %zu\n", puzzle->TestC);
+
+ for (int i = 0; i < puzzle->TestC; i++) {
+ Test t = puzzle->Tests[i];
+ printf("\nTest %d:\n", i);
+ printf("\tTest rec: %s\n", t.RecieverName);
+ printf("\tTest sig: %s\n", t.MainMethodSignature);
+ printf("\tTest argc: %zu\n", t.argc);
+ printf("\tArguments:\n");
+
+ for (int j = 0; j < t.argc; j++) {
+ PuzzleIO io = t.argv[j];
+ switch (io.type) {
+ case WREN_TYPE_BOOL:
+ printf("\t\t(bool)%s\n", *(bool *)io.value ? "true" : "false");
+ break;
+ case WREN_TYPE_NUM:
+ printf("\t\t(num)%f\n", *(float *)io.value);
+ break;
+ case WREN_TYPE_LIST:
+ printf("\t\t(list)NOT SUPPORTED\n");
+ break;
+ case WREN_TYPE_MAP:
+ printf("\t\t(list)NOT SUPPORTED\n");
+ break;
+ case WREN_TYPE_NULL:
+ printf("\t\t(null)\n");
+ break;
+ case WREN_TYPE_STRING:
+ printf("\t\t(string)%s\n", (char *)io.value);
+ break;
+ default: break;
+ }
+ }
+ }
+}
diff --git a/src/puzzles/puzzle.h b/src/puzzles/puzzle.h
index 20193ca..70c6cad 100644
--- a/src/puzzles/puzzle.h
+++ b/src/puzzles/puzzle.h
@@ -56,11 +56,9 @@ typedef struct {
Test *Tests;
} Puzzle;
-Puzzle *ReadPuzzleFromFile(const char *path);
-
-void FreePuzzle(Puzzle *self);
/// A prebuilt puzzle. Used for debuging
Puzzle *GetTestPuzzle();
+Puzzle *ReadPuzzleFromFile(const char *path);
typedef struct {
char *stdout_sb;
@@ -70,6 +68,10 @@ typedef struct {
// Don't put anything in out_res, it will be overriten.
// The stdout of the VM will be there
SubmitionResult *SubmitSolution(Puzzle *self, char *script);
+
+void PrintPuzzle(Puzzle *puzzle);
+
void FreeSunmitionResult(SubmitionResult *res);
+void FreePuzzle(Puzzle *self);
#endif // PUZZLE_H