aboutsummaryrefslogtreecommitdiff
path: root/include/value.h
blob: 7dd6d28761d2c246245c15b98755b1cd938c082b (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
#ifndef TSL_VALUE_H
#define TSL_VALUE_H

#include "forward_decl.h"
#include <stddef.h>
#include <stdint.h>
#include "string_view.h"
#include "std_gc/list.h"
#include "std_gc/hash_map.h"

typedef enum {
    TSL_TYPE_NULL,
    TSL_TYPE_NUMBER,
    TSL_TYPE_STRING,
    TSL_TYPE_STRING_REF,
    TSL_TYPE_BOOL,
    TSL_TYPE_LIST,
    TSL_TYPE_MAP,
    TSL_TYPE_FUNCTION,
    TSL_TYPE_USERDATA
} TslType;

/* TODO: Support BigInt */
typedef double TslNumber;

typedef enum {
    TSL_FALSE,
    TSL_TRUE
} TslBool;

typedef struct {
    char *data;
    size_t size;
} TslString;

/* This is an index to the function */
typedef int TslFunction;

struct TslValue {
    union {
        TslNumber number;
        TslString *string;
        TslStringView string_ref;
        TslBool boolean;
        TslBool null;
        TslList *list;
        TslHashMap *map;
        TslFunction function;
        void *userdata;
    } data;
    uint8_t type;
};

uint64_t tsl_value_hash(const TslValue *value);
/* Returns 1 if equal, otherwise returns 0 */
int tsl_value_equals(const TslValue *lhs, const TslValue *rhs);

/* This should be called before setting/modifying the data of the value */
void tsl_value_clear(TslValue *self);

#endif /* TSL_VALUE_H */