blob: 838b9d2b676e976422043f8ae22a0fd1329eceb1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
#include <stddef.h>
#include <wren.h>
#ifndef PUZZLE_H
enum PUZZLE_TEST_RESULT : char {
RESULT_OK = 0,
RESULT_WRONG_ANSWER,
RESULT_COMPTIME_NO_ENTRY,
RESULT_COMPTIME_ERR,
RESULT_RUNTIME_ERR,
// TODO: add async evaluation to prevent `while (true)` situation
RESULT_TIMEOUT,
RESULT_INIT_ERROR,
};
// This is a param that would be placed in a slot
// https://wren.io/embedding/slots-and-handles.html#writing-slots
typedef struct {
WrenType type;
// We store this value as void * to generalize. The downside of this approach
// is an extenciva allocation
void *value;
} PuzzleIO;
typedef struct {
// https://wren.io/embedding/calling-wren-from-c.html#setting-up-a-receiver
char *RecieverName;
// https://wren.io/embedding/calling-wren-from-c.html#getting-a-method-handle
char *MainMethodSignature;
size_t argc;
PuzzleIO *argv;
PuzzleIO ExpectedResult;
} Test;
/// The user submitted code should be evaluated by this point.
/// The entry point should be registered and the absence of the
/// Main method signatire will be concidered an error
enum PUZZLE_TEST_RESULT RunTest(Test *test, WrenVM *vm);
typedef struct {
char *Name;
char *Description;
char *InitialCode;
/// The tests that are accessible for an end user
size_t TestC;
Test *Tests;
} Puzzle;
// TODO
void ReadPuzzleFromFile(const char *path);
void FreePuzzle(Puzzle *self);
/// A prebuilt puzzle. Used for debuging
Puzzle *GetTestPuzzle();
typedef struct {
char *stdout;
enum PUZZLE_TEST_RESULT result;
} SubmitionResult;
// 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 FreeSunmitionResult(SubmitionResult *res);
#define PUZZLE_H
#endif // PUZZLE_H
|