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
|
#ifndef LITERAL_H
#define LITERAL_H
typedef struct value *value_t;
struct literal {
enum literal_type {
LITERAL_STRING,
LITERAL_NUM_INT,
LITERAL_NUM_FLOAT
} type;
union {
char *string;
long num_int;
float num_float;
};
};
// struct pair {
// };
// struct proc {
// };
struct value {
enum value_type {
VALUE_SYMBOL,
VALUE_LITERAL,
VALUE_PAIR,
VALUE_LIST,
VALUE_PROC,
VALUE_TYPES
} type;
int references;
union {
char *symbol;
struct literal literal;
// struct pair pair;
// struct pari list;
// struct proc_t proc;
};
};
// try to save data as a literal
// returns a value_t on success and NULL on fail
// ret is set to: 0 on sucess, > 0 on fail (data isnt this type),
// and < 0 on error
value_t value_create(enum value_type type, void *data, int *ret);
// returns a value_t on success
value_t value_copy(value_t value);
// destroys a value
void value_destroy(value_t value);
// copy a string version of the value the buf[buf_sz]
// returns buf on success
char *value_string(value_t value, char *buf, size_t buf_sz);
#endif
|