aboutsummaryrefslogtreecommitdiff
path: root/include/kpl/value.h
blob: e0bf0c7a6299859eddb9e06fe48a7b6c32de3e0d (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
/*
 * KPL value definitions
 */

#pragma once

#define _KPL_VALUE8 \
    uint8_t u8; \
    int8_t i8

typedef union {
    _KPL_VALUE8;
} kpl_value8;

#define _KPL_VALUE16 \
    uint16_t u16; \
    int16_t i16

typedef union {
   _KPL_VALUE8;
   _KPL_VALUE16;
} kpl_value16;

typedef uint8_t kpl_utf8[4];

#define _KPL_VALUE32 \
    kpl_utf8 utf8; \
    uint32_t u32; \
    int32_t i32; \
    float f32

typedef union {
    _KPL_VALUE8;
    _KPL_VALUE16;
    _KPL_VALUE32;
} kpl_value32;

typedef union {
    _KPL_VALUE8;
    _KPL_VALUE16;
    _KPL_VALUE32;
    uint64_t u64;
    int64_t i64;
    double f64;
    void *ptr;
} kpl_value64;

typedef struct {
    kpl_value64 value;
    int64_t tag;
} kpl_result;

typedef struct {
    void *async, *sync;
} kpl_function;

/*
 * Must match the type of c main return
 * if code != KPL_EXIT_CODE_SUCCESS then return code
 */
typedef enum : int32_t {
    KPL_EXIT_CODE_SUCCESS       = 0,
    KPL_EXIT_CODE_ERROR         = 1,
    KPL_EXIT_CODE_HELP          = 2,
    KPL_EXIT_CODE_IO_ERROR      = 3,
    KPL_EXIT_CODE_THREAD_ERROR  = 4
} kpl_exit_code;