comparison src/ploki/val.h @ 4223:ac0403686959

<oerjan> rm -rf src/ploki; mv ploki src
author HackBot
date Fri, 20 Dec 2013 22:18:50 +0000
parents
children
comparison
equal deleted inserted replaced
4222:b0f3e267bb1e 4223:ac0403686959
1 #ifndef VAL_H_
2 #define VAL_H_
3
4 #include "config.h"
5 #include "IO.h"
6 #include "Str.h"
7 #include "kork.h"
8 #include "list.h"
9 #include "sub.h"
10
11 enum val_cont {
12 V_UNDEF = 0,
13 V_STR_K = 1,
14 V_NUM_K = V_STR_K << 1,
15 V_EXT_K = V_NUM_K << 1,
16 V_SUB_K = V_EXT_K << 1,
17 V_LIST_K = V_SUB_K << 1
18 };
19
20 struct val {
21 enum val_cont type;
22 union {
23 IO *ext;
24 struct sub *sub;
25 struct list *list;
26 } magic;
27 struct kork *ko;
28 double num;
29 };
30
31 void v_init(struct val *);
32 void v_end(struct val *);
33 int v_cmp_ls(struct val *, struct val *);
34 void v_ok_str(struct val *);
35 void v_ok_num(struct val *);
36 int v_true(const struct val *);
37 void v_iniset(struct val *, const struct val *);
38 void v_set(struct val *, const struct val *);
39 void v_set_n(struct val *, double);
40 void v_set_s(struct val *, const String *);
41 void v_set_m(struct val *, const void *, size_t);
42 void v_set_undef(struct val *);
43 void v_set_io(struct val *, IO *);
44 void v_set_sub(struct val *, struct sub *);
45 void v_cat(struct val *, struct val *);
46 void v_cat_s(struct val *, const String *);
47 void v_cat_m(struct val *, const void *, size_t);
48 void v_cat_c(struct val *, char);
49 struct val *v_undef(void);
50 void v_delete(struct val *);
51
52 const char *v_sptr(struct val *, size_t *);
53 struct kork *v_kork(struct val *);
54
55 #define V_STR_P(v) ((v)->type & V_STR_K)
56 #define V_NUM_P(v) ((v)->type & V_NUM_K)
57 #define V_EXT_P(v) ((v)->type & V_EXT_K)
58 #define V_SUB_P(v) ((v)->type & V_SUB_K)
59 #define V_LIST_P(v) ((v)->type & V_LIST_K)
60
61 #define V_STR(v) if (V_STR_P(v)); else v_ok_str(v)
62 #define V_NUM(v) if (V_NUM_P(v)); else v_ok_num(v)
63
64 #define V_xxx_OFF(v) \
65 do { \
66 if (V_EXT_P(v)) { \
67 io_decr((v)->magic.ext); \
68 (v)->type &= ~V_EXT_K; \
69 } else if (V_SUB_P(v)) { \
70 sub_decr((v)->magic.sub); \
71 (v)->type &= ~V_SUB_K; \
72 } else if (V_LIST_P(v)) { \
73 li_delete((v)->magic.list); \
74 (v)->type &= ~V_LIST_K; \
75 } \
76 } while (0)
77
78 #define RINT(x) ((x) + ((x) < 0.0 ? -.5 : .5))
79
80 #endif /* VAL_H_ */