summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/puzzles/puzzle.c4
-rw-r--r--src/puzzles/puzzle.h2
-rw-r--r--src/scenes/puzzleScene.c1
-rw-r--r--src/scenes/resultView.c2
-rw-r--r--src/ui_elements/TextEditor.c1
-rw-r--r--src/wren_inter/wren_inter.c97
-rw-r--r--src/wren_inter/wren_inter.h3
7 files changed, 6 insertions, 104 deletions
diff --git a/src/puzzles/puzzle.c b/src/puzzles/puzzle.c
index 286057b..fad3f00 100644
--- a/src/puzzles/puzzle.c
+++ b/src/puzzles/puzzle.c
@@ -181,7 +181,7 @@ SubmitionResult *PrepareResult(SubmitionResult *self,
enum PUZZLE_TEST_RESULT result) {
if (vm == NULL || self == NULL) return self;
self->result = result;
- self->stdout = GetMachineOutput(vm);
+ self->stdout_sb = GetMachineOutput(vm);
InterpreterFreeMachine(vm);
return self;
}
@@ -216,6 +216,6 @@ SubmitionResult *SubmitSolution(Puzzle *self, char *script) {
}
void FreeSunmitionResult(SubmitionResult *res) {
- if (res->stdout != NULL) free(res->stdout);
+ if (res->stdout_sb != NULL) free(res->stdout_sb);
free(res);
}
diff --git a/src/puzzles/puzzle.h b/src/puzzles/puzzle.h
index 181c0ae..28ab6ca 100644
--- a/src/puzzles/puzzle.h
+++ b/src/puzzles/puzzle.h
@@ -49,7 +49,7 @@ void FreePuzzle(Puzzle *self);
Puzzle *GetTestPuzzle();
typedef struct {
- char *stdout;
+ char *stdout_sb;
enum PUZZLE_TEST_RESULT result;
} SubmitionResult;
diff --git a/src/scenes/puzzleScene.c b/src/scenes/puzzleScene.c
index 4bf5b60..feeada8 100644
--- a/src/scenes/puzzleScene.c
+++ b/src/scenes/puzzleScene.c
@@ -117,6 +117,7 @@ Scene *CreatePuzzleScene(Puzzle *puzzle) {
puzzleSceneData *data = malloc(sizeof(puzzleSceneData));
data->PuzzlePtr = puzzle;
+ data->scroll = 0;
TextAreaDisplayParams *EditorDisplayParams = malloc(sizeof(TextAreaDisplayParams));
if (EditorDisplayParams != NULL) {
diff --git a/src/scenes/resultView.c b/src/scenes/resultView.c
index c63967a..f3735ed 100644
--- a/src/scenes/resultView.c
+++ b/src/scenes/resultView.c
@@ -58,7 +58,7 @@ bool drawResultView(void *self) {
Rectangle body = GetResultViewBodyRect(data->scroll_up);
DrawRecBordered(body, WHITE, data->value->result == RESULT_OK ? COLORSCHEME_GREEN : COLORSCHEME_ORANGE, BORDER);
- DrawTextInRec(body, data->value->stdout,
+ DrawTextInRec(body, data->value->stdout_sb,
GetMainFont(), 20, COLORSCHEME_BROWN, 3, &data->scroll);
return true;
}
diff --git a/src/ui_elements/TextEditor.c b/src/ui_elements/TextEditor.c
index 13a13a6..e114080 100644
--- a/src/ui_elements/TextEditor.c
+++ b/src/ui_elements/TextEditor.c
@@ -99,6 +99,7 @@ TextArea *CreateTextArea(TextAreaDisplayParams *DisplayParams) {
}
outp->StartNode = start_node;
+ outp->CursorPosition = (Vector2){ 0, 0 };
outp->CurrentNode = start_node;
outp->NodeLenth = 1;
outp->DisplayParams = DisplayParams;
diff --git a/src/wren_inter/wren_inter.c b/src/wren_inter/wren_inter.c
index 868b2fe..4b72633 100644
--- a/src/wren_inter/wren_inter.c
+++ b/src/wren_inter/wren_inter.c
@@ -78,100 +78,3 @@ void InterpreterFreeMachine(WrenVM *vm) {
if (sb != NULL && sb->val != NULL) free(sb);
wrenFreeVM(vm);
}
-
-// ========== Async ==========
-
-typedef struct {
- // The data that you want to access in the worker
- void *data;
- // Toggle this to true when the task is finished
- bool is_done;
-} Task;
-
-bool RunWithCancellation(Task *task, void *(*runner) (void *), int timeout);
-
-#if defined(unix) || defined(__unix__) || defined(__unix)
-
-#include <threads.h>
-#include <pthread.h>
-#include <unistd.h>
-
-// Returns false if the process was aborted
-bool RunWithCancellation(Task *task, void *(*runner) (void *), int timeout) {
- pthread_t thread_id;
- if (pthread_create(&thread_id, NULL, runner, &task) != 0) {
- TraceLog(LOG_ERROR, "Failed to create a pthread");
- return RESULT_INIT_ERROR;
- }
-
- int elapsed = 0;
- while (!task->is_done && elapsed < timeout) {
- sleep(1);
- elapsed += 1;
- }
-
- if (!task->is_done) {
- pthread_cancel(thread_id);
- pthread_join(thread_id, NULL);
- return false;
- }
-
- return true;
-}
-
-#endif
-
-// The task that the interpreter would need to run. Made for async reasons
-typedef struct {
- WrenVM *vm;
- const char *module;
- const char *script;
- WrenInterpretResult result;
- bool is_done;
-} wrenTask;
-
-// Runs the wrenTask asynchronously
-// FIX: Inject the cancellation parameters inside the worker thread definition
-void *wren_worker(void *arg) {
- int old_type;
- pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &old_type); //
-
- Task *task_raw = (Task*)arg;
- wrenTask *task = (wrenTask*)task_raw->data;
- task->result = wrenInterpret(task->vm, task->module, task->script);
- task_raw->is_done = true;
- return NULL;
-}
-
-
-enum PUZZLE_TEST_RESULT wrenInterpretLimited(WrenVM* vm, const char* module,
- const char* script, int sMax) {
-
- wrenTask *data = malloc(sizeof(wrenTask));
- data->vm = vm;
- data->module = module;
- data->script = script;
- data->result = 0;
-
- Task *task = malloc(sizeof(Task));
- task->is_done = false;
- task->data = data;
-
- if (!RunWithCancellation(task, wren_worker, sMax)) {
- return RESULT_TIMEOUT;
- }
-
- WrenInterpretResult interpret_res = data->result;
-
- free(data);
- free(task);
-
- switch (interpret_res) {
- case WREN_RESULT_COMPILE_ERROR:
- return RESULT_COMPTIME_ERR;
- case WREN_RESULT_RUNTIME_ERROR:
- return RESULT_RUNTIME_ERR;
- default: break;
- }
- return RESULT_OK;
-}
diff --git a/src/wren_inter/wren_inter.h b/src/wren_inter/wren_inter.h
index a84323f..358dc1d 100644
--- a/src/wren_inter/wren_inter.h
+++ b/src/wren_inter/wren_inter.h
@@ -17,8 +17,5 @@ enum PUZZLE_TEST_RESULT {
WrenVM *InterpreterPrepareMachine();
char *GetMachineOutput(WrenVM *vm);
void InterpreterFreeMachine(WrenVM *vm);
-// Runs the machine and returns
-enum PUZZLE_TEST_RESULT wrenInterpretLimited(WrenVM *vm, const char *module,
- const char *script, int sMax);
#endif // WREN_INTER_H