annotate lwlib/lw_expr.h @ 347:1649bc7bda5a

Some data oriented pseudo ops added
author lost@starbug
date Sat, 27 Mar 2010 20:16:24 -0600
parents a82c55070624
children 34dfc9747f23
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
334
f2173d18c73f Checkpoint
lost
parents:
diff changeset
1 /*
f2173d18c73f Checkpoint
lost
parents:
diff changeset
2 lwexpr.h
f2173d18c73f Checkpoint
lost
parents:
diff changeset
3
f2173d18c73f Checkpoint
lost
parents:
diff changeset
4 Copyright © 2010 William Astle
f2173d18c73f Checkpoint
lost
parents:
diff changeset
5
f2173d18c73f Checkpoint
lost
parents:
diff changeset
6 This file is part of LWTOOLS.
f2173d18c73f Checkpoint
lost
parents:
diff changeset
7
f2173d18c73f Checkpoint
lost
parents:
diff changeset
8 LWTOOLS is free software: you can redistribute it and/or modify it under the
f2173d18c73f Checkpoint
lost
parents:
diff changeset
9 terms of the GNU General Public License as published by the Free Software
f2173d18c73f Checkpoint
lost
parents:
diff changeset
10 Foundation, either version 3 of the License, or (at your option) any later
f2173d18c73f Checkpoint
lost
parents:
diff changeset
11 version.
f2173d18c73f Checkpoint
lost
parents:
diff changeset
12
f2173d18c73f Checkpoint
lost
parents:
diff changeset
13 This program is distributed in the hope that it will be useful, but WITHOUT
f2173d18c73f Checkpoint
lost
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f2173d18c73f Checkpoint
lost
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
f2173d18c73f Checkpoint
lost
parents:
diff changeset
16 more details.
f2173d18c73f Checkpoint
lost
parents:
diff changeset
17
f2173d18c73f Checkpoint
lost
parents:
diff changeset
18 You should have received a copy of the GNU General Public License along with
f2173d18c73f Checkpoint
lost
parents:
diff changeset
19 this program. If not, see <http://www.gnu.org/licenses/>.
f2173d18c73f Checkpoint
lost
parents:
diff changeset
20 */
f2173d18c73f Checkpoint
lost
parents:
diff changeset
21
f2173d18c73f Checkpoint
lost
parents:
diff changeset
22 #ifndef ___lw_expr_h_seen___
f2173d18c73f Checkpoint
lost
parents:
diff changeset
23 #define ___lw_expr_h_seen___
f2173d18c73f Checkpoint
lost
parents:
diff changeset
24
f2173d18c73f Checkpoint
lost
parents:
diff changeset
25
f2173d18c73f Checkpoint
lost
parents:
diff changeset
26 enum
f2173d18c73f Checkpoint
lost
parents:
diff changeset
27 {
f2173d18c73f Checkpoint
lost
parents:
diff changeset
28 lw_expr_type_oper, // operator term
f2173d18c73f Checkpoint
lost
parents:
diff changeset
29 lw_expr_type_int, // integer
f2173d18c73f Checkpoint
lost
parents:
diff changeset
30 lw_expr_type_var, // a "variable" (string for the name)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
31 lw_expr_type_special // a "special" reference (user defined)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
32 };
f2173d18c73f Checkpoint
lost
parents:
diff changeset
33
f2173d18c73f Checkpoint
lost
parents:
diff changeset
34 enum
f2173d18c73f Checkpoint
lost
parents:
diff changeset
35 {
f2173d18c73f Checkpoint
lost
parents:
diff changeset
36 lw_expr_oper_plus = 1, // addition
f2173d18c73f Checkpoint
lost
parents:
diff changeset
37 lw_expr_oper_minus, // subtraction
f2173d18c73f Checkpoint
lost
parents:
diff changeset
38 lw_expr_oper_times, // multiplication
f2173d18c73f Checkpoint
lost
parents:
diff changeset
39 lw_expr_oper_divide, // division
f2173d18c73f Checkpoint
lost
parents:
diff changeset
40 lw_expr_oper_mod, // modulus
f2173d18c73f Checkpoint
lost
parents:
diff changeset
41 lw_expr_oper_intdiv, // integer division
f2173d18c73f Checkpoint
lost
parents:
diff changeset
42 lw_expr_oper_bwand, // bitwise and
f2173d18c73f Checkpoint
lost
parents:
diff changeset
43 lw_expr_oper_bwor, // bitwise or
f2173d18c73f Checkpoint
lost
parents:
diff changeset
44 lw_expr_oper_bwxor, // bitwise xor
f2173d18c73f Checkpoint
lost
parents:
diff changeset
45 lw_expr_oper_and, // boolean and
f2173d18c73f Checkpoint
lost
parents:
diff changeset
46 lw_expr_oper_or, // boolean or
f2173d18c73f Checkpoint
lost
parents:
diff changeset
47 lw_expr_oper_neg, // unary negation, 2's complement
346
a82c55070624 Added expression parsing infrastructure and misc fixes
lost@starbug
parents: 342
diff changeset
48 lw_expr_oper_com, // unary 1's complement
a82c55070624 Added expression parsing infrastructure and misc fixes
lost@starbug
parents: 342
diff changeset
49 lw_expr_oper_none = 0
334
f2173d18c73f Checkpoint
lost
parents:
diff changeset
50 };
f2173d18c73f Checkpoint
lost
parents:
diff changeset
51
f2173d18c73f Checkpoint
lost
parents:
diff changeset
52 #ifdef ___lw_expr_c_seen___
f2173d18c73f Checkpoint
lost
parents:
diff changeset
53
f2173d18c73f Checkpoint
lost
parents:
diff changeset
54 typedef struct lw_expr_priv * lw_expr_t;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
55
f2173d18c73f Checkpoint
lost
parents:
diff changeset
56 struct lw_expr_opers
f2173d18c73f Checkpoint
lost
parents:
diff changeset
57 {
f2173d18c73f Checkpoint
lost
parents:
diff changeset
58 lw_expr_t p;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
59 struct lw_expr_opers *next;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
60 };
f2173d18c73f Checkpoint
lost
parents:
diff changeset
61
f2173d18c73f Checkpoint
lost
parents:
diff changeset
62 struct lw_expr_priv
f2173d18c73f Checkpoint
lost
parents:
diff changeset
63 {
f2173d18c73f Checkpoint
lost
parents:
diff changeset
64 int type; // type of term
f2173d18c73f Checkpoint
lost
parents:
diff changeset
65 int value; // integer value
f2173d18c73f Checkpoint
lost
parents:
diff changeset
66 void *value2; // misc pointer value
f2173d18c73f Checkpoint
lost
parents:
diff changeset
67 struct lw_expr_opers *operands; // ptr to list of operands (for operators)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
68 };
f2173d18c73f Checkpoint
lost
parents:
diff changeset
69
346
a82c55070624 Added expression parsing infrastructure and misc fixes
lost@starbug
parents: 342
diff changeset
70 typedef lw_expr_t lw_expr_fn_t(int t, void *ptr, void *priv);
a82c55070624 Added expression parsing infrastructure and misc fixes
lost@starbug
parents: 342
diff changeset
71 typedef lw_expr_t lw_expr_fn2_t(char *var, void *priv);
a82c55070624 Added expression parsing infrastructure and misc fixes
lost@starbug
parents: 342
diff changeset
72 typedef lw_expr_t lw_expr_fn3_t(char **p, void *priv);
334
f2173d18c73f Checkpoint
lost
parents:
diff changeset
73
f2173d18c73f Checkpoint
lost
parents:
diff changeset
74 #else /* def ___lw_expr_c_seen___ */
f2173d18c73f Checkpoint
lost
parents:
diff changeset
75
f2173d18c73f Checkpoint
lost
parents:
diff changeset
76 typedef void * lw_expr_t;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
77
f2173d18c73f Checkpoint
lost
parents:
diff changeset
78 extern lw_expr_t lwexpr_create(void);
337
04c80c51b16a Checkpoint development
lost
parents: 335
diff changeset
79 extern void lw_expr_destroy(lw_expr_t E);
334
f2173d18c73f Checkpoint
lost
parents:
diff changeset
80 extern lw_expr_t lw_expr_copy(lw_expr_t E);
f2173d18c73f Checkpoint
lost
parents:
diff changeset
81 extern void lw_expr_add_operand(lw_expr_t E, lw_expr_t O);
f2173d18c73f Checkpoint
lost
parents:
diff changeset
82 extern lw_expr_t lw_expr_build(int exprtype, ...);
f2173d18c73f Checkpoint
lost
parents:
diff changeset
83 extern void lw_expr_print(lw_expr_t E);
f2173d18c73f Checkpoint
lost
parents:
diff changeset
84 extern int lw_expr_compare(lw_expr_t E1, lw_expr_t E2);
346
a82c55070624 Added expression parsing infrastructure and misc fixes
lost@starbug
parents: 342
diff changeset
85 extern void lw_expr_simplify(lw_expr_t E, void *priv);
337
04c80c51b16a Checkpoint development
lost
parents: 335
diff changeset
86
346
a82c55070624 Added expression parsing infrastructure and misc fixes
lost@starbug
parents: 342
diff changeset
87 typedef lw_expr_t lw_expr_fn_t(int t, void *ptr, void *priv);
a82c55070624 Added expression parsing infrastructure and misc fixes
lost@starbug
parents: 342
diff changeset
88 typedef lw_expr_t lw_expr_fn2_t(char *var, void *priv);
a82c55070624 Added expression parsing infrastructure and misc fixes
lost@starbug
parents: 342
diff changeset
89 typedef lw_expr_t lw_expr_fn3_t(char **p, void *priv);
342
7b4123dce741 Added basic symbol registration
lost@starbug
parents: 337
diff changeset
90
7b4123dce741 Added basic symbol registration
lost@starbug
parents: 337
diff changeset
91 extern void lw_expr_set_special_handler(lw_expr_fn_t *fn);
7b4123dce741 Added basic symbol registration
lost@starbug
parents: 337
diff changeset
92 extern void lw_expr_set_var_handler(lw_expr_fn2_t *fn);
346
a82c55070624 Added expression parsing infrastructure and misc fixes
lost@starbug
parents: 342
diff changeset
93 extern void lw_expr_set_term_parser(lw_expr_fn3_t *fn);
a82c55070624 Added expression parsing infrastructure and misc fixes
lost@starbug
parents: 342
diff changeset
94
a82c55070624 Added expression parsing infrastructure and misc fixes
lost@starbug
parents: 342
diff changeset
95 extern lw_expr_t lw_expr_parse(char **p, void *priv);
347
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents: 346
diff changeset
96 extern int lw_expr_istype(lw_expr_t e, int t);
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents: 346
diff changeset
97 extern int lw_expr_intval(lw_expr_t e);
334
f2173d18c73f Checkpoint
lost
parents:
diff changeset
98
f2173d18c73f Checkpoint
lost
parents:
diff changeset
99 #endif /* def ___lw_expr_c_seen___ */
f2173d18c73f Checkpoint
lost
parents:
diff changeset
100
f2173d18c73f Checkpoint
lost
parents:
diff changeset
101 #endif /* ___lw_expr_h_seen___ */