aboutsummaryrefslogtreecommitdiff
path: root/include/program.h
blob: 2fcdb07f0a1a0c6081a572f441fe243028480425 (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
#ifndef TSL_PROGRAM_H
#define TSL_PROGRAM_H

#include "std/buffer.h"
#include "std_gc/hash_map.h"
#include "string_view.h"
#include "value.h"

typedef enum {
    TSL_STACK_VALUE_TYPE_NUMBER,
    TSL_STACK_VALUE_TYPE_BOOL,
    TSL_STACK_VALUE_TYPE_STRING,
    TSL_STACK_VALUE_TYPE_NULL,
    TSL_STACK_VALUE_TYPE_FUNCTION,
    TSL_STACK_VALUE_TYPE_VARIABLE_NAME,
    TSL_STACK_VALUE_TYPE_VARIABLE,
    TSL_STACK_VALUE_TYPE_LIST,
    TSL_STACK_VALUE_TYPE_MAP,
    TSL_STACK_VALUE_TYPE_INDEX
} TslStackValueType;

typedef struct {
    union {
        int integer;
        double number;
        TslBool boolean;
        TslStringView str;
        TslValue variable;
    } data;
    TslStackValueType type;
} TslStackValue;

typedef struct {
    TslBuffer /*TslBytecode*/ function_bytecode_list;
    /* Allocated with GC and is the root object of the program. When this is deallocated, the whole program is deallocated */
    TslHashMap /*TslStringView, TslValue*/ *variables;
    TslBuffer /*TslStackValue*/ stack_values;
} TslProgram;

typedef enum {
    TSL_PROGRAM_RESULT_ERR,
    TSL_PROGRAM_RESULT_OK
} TslProgramResult;

void tsl_program_init(TslProgram *self);
void tsl_program_deinit(TslProgram *self);

TslProgramResult tsl_program_run(TslProgram *self);

#endif /* TSL_PROGRAM_H */