comparison src/ploki/expr.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 EXPR_H_
2 #define EXPR_H_
3
4 #include "config.h"
5 #include "Str.h"
6 #include "op.h"
7 #include "re.h"
8 #include "stack.h"
9 #include "strhash.h"
10 #include "val.h"
11 #include "variable.h"
12
13 #include <stddef.h>
14 #include <setjmp.h>
15
16 enum t_expr {
17 literE,
18 varE,
19 varhashE,
20 symbolE,
21 unopE,
22 binopE,
23 listE
24 };
25
26 enum t_func {
27 F_CALL = -1,
28 F_NUL,
29 F_ABS,
30 F_ACOS,
31 F_ASIN,
32 F_ATAN,
33 F_ATAN2,
34 F_CATCH,
35 F_CHR,
36 F_COS,
37 F_DEFINED,
38 F_EOF,
39 F_ERROR,
40 F_EXP,
41 F_FREEZE,
42 F_GETC,
43 F_GETENV,
44 F_GETS,
45 F_HANG,
46 F_INT,
47 F_IO,
48 F_LENGTH,
49 F_LOG,
50 F_LOG10,
51 F_LOWER,
52 F_MATCH,
53 F_MOEND,
54 F_MOSTART,
55 F_NEG,
56 F_NOT,
57 F_NUM,
58 F_OPEN,
59 F_OPENR,
60 F_OPENW,
61 F_ORD,
62 F_QUOTE,
63 F_RE_ESC,
64 F_REMOVE,
65 F_RENAME,
66 F_REVERSE,
67 F_SEEK,
68 F_SIN,
69 F_SQRT,
70 F_STR,
71 F_TAN,
72 F_TELL,
73 F_TYPEOF,
74 F_UPPER
75 };
76
77 enum t_symbol {
78 S_NUL,
79 S_ARG,
80 S_ARGC,
81 S_ARGV,
82 S_ERR,
83 S_EULER,
84 S_LUDOLF,
85 S_MATCH,
86 S_RAND,
87 S_RESULT,
88 S_STDIN,
89 S_STDOUT,
90 S_STDERR
91 };
92
93 enum t_binop {
94 B_AMPERSAND,
95 B_ANGLE,
96 B_BACKSPARK,
97 B_BRACELET,
98 B_DOUBLE_OH_SEVEN,
99 B_EMBRACE,
100 B_FLATWORM,
101 B_HALF_MESH,
102 B_HYBRID,
103 B_INTERSECTION,
104 B_RIGHT_ANGLE,
105 B_SHARK_FIN,
106 B_SLAT,
107 B_SPARK,
108 B_SPARK_SPOT,
109 B_SPIKE,
110 B_SPLAT,
111 B_SPOT,
112 B_SQIGGLE,
113 B_TAIL,
114 B_TWO_SPOT,
115 B_U_TURN,
116 B_U_TURN_BACK,
117 B_WORM,
118 B_XMATCH
119 };
120
121 struct expr {
122 enum t_expr type;
123 int op;
124 union {
125 t_vr_cookie tent;
126 struct val *val;
127 t_strhash *hash;
128 } v;
129 struct expr *right;
130 union {
131 struct expr *expr;
132 struct op *op;
133 t_regex *rx;
134 size_t bonus;
135 } left;
136 };
137
138 void expr_init(void);
139 void expr_end(void);
140
141 void free_expr(struct expr *);
142 struct expr *get_expr(struct op *);
143 struct expr *get_lval(struct op *);
144 struct expr *get_iobj(struct op *);
145
146 void eval_push(struct expr *);
147 void eval_into(struct expr *, struct val *);
148 struct val *eval_pop(void);
149 struct val *eval_expr(struct expr *);
150
151 ATTR_PURE
152 enum t_binop expr_binop(int);
153
154 void expr_pp(enum t_binop, struct val *, struct val *);
155
156 typedef struct {
157 jmp_buf buf;
158 size_t depth;
159 } t_context;
160
161 stack_declare(t_context, extern)
162 extern stack(t_context) Context;
163
164 #define OPERATORS "_+-*/%^[]<>=!{}:;&|~`'.,"
165 #define OPERATOR_P(c) strchr(OPERATORS, c)
166
167 #define TOLABEL(v) \
168 do { \
169 V_NUM(v); \
170 V_xxx_OFF(v); \
171 (v)->num = floor((v)->num + .5); \
172 (v)->type = V_NUM_K; \
173 v_ok_str(v); \
174 ko_grep(v->ko, isdigit); \
175 while (ko_at(v->ko, 0) == '0') { \
176 ko_shift(v->ko, 1); \
177 } \
178 (v)->type = V_STR_K; \
179 } while (0)
180
181 #endif /* EXPR_H_ */