Mercurial > hg-old > index.cgi
annotate lwasm/lwval.h @ 264:61d1db1dfe2a 2.6
Build manual for release
author | lost |
---|---|
date | Tue, 22 Dec 2009 05:27:32 +0000 |
parents | 427e268e876b |
children |
rev | line source |
---|---|
13
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
1 /* |
15 | 2 lwval.h |
13
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
3 Copyright © 2008 William Astle |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
4 |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
5 This file is part of LWASM. |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
6 |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
7 LWASM is free software: you can redistribute it and/or modify it under the |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
8 terms of the GNU General Public License as published by the Free Software |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
9 Foundation, either version 3 of the License, or (at your option) any later |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
10 version. |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
11 |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
12 This program is distributed in the hope that it will be useful, but WITHOUT |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
15 more details. |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
16 |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
17 You should have received a copy of the GNU General Public License along with |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
18 this program. If not, see <http://www.gnu.org/licenses/>. |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
19 */ |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
20 |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
21 /* |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
22 This file contains definitions associated with the expression evaluator used |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
23 by LWASM. |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
24 |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
25 The core of the entire expression handler is the opaque type LWVAL, pointers |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
26 to which are passed around to keep track of values. A value may be a simple |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
27 integer or it could be a more complex expression linked by operators or it |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
28 could be a polynomial expression. Simple integers are merely a degenerate |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
29 case of polynomials. |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
30 |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
31 The package understands the following operations: |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
32 |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
33 addition |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
34 subtraction |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
35 multiplication |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
36 division |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
37 modulus |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
38 parentheses |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
39 unary negation |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
40 unary "positive" |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
41 bitwise and |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
42 bitwise or |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
43 bitwise not (1's complement) |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
44 bitwise exclusive or |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
45 |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
46 Infix operators can be expressed as LWVAL <op> LWVAL. Thus, the order of |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
47 operations is only relevant when initially parsing the expression. The order |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
48 of evaluation is determined by what appears on either side of the <op> as |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
49 an LWVAL may be an expression. |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
50 */ |
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
51 |
15 | 52 #ifndef __lwval_h_seen__ |
53 #define __lwval_h_seen__ | |
13
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
54 |
14 | 55 typedef struct lwval LWVAL; |
13
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
56 |
15 | 57 struct lwval_dt_expr |
58 { | |
59 LWVAL *v1; // first value | |
60 LWVAL *v2; // second value | |
61 int op; // operator | |
62 }; | |
63 | |
14 | 64 union lwval_dt |
65 { | |
66 int lwval_int; // integer type data | |
67 char *lwval_var; // pointer to variable name | |
15 | 68 struct lwval_dt_expr expr; // expression |
14 | 69 }; |
70 | |
71 enum | |
72 { | |
15 | 73 LWVAL_TYPE_UNDEF, // undefined |
14 | 74 LWVAL_TYPE_NAN, // not a number |
75 LWVAL_TYPE_INT, // integer | |
76 LWVAL_TYPE_VAR, // variable (symbol) | |
77 LWVAL_TYPE_EXPR, // expression | |
15 | 78 LWVAL_TYPE_ERR // error |
14 | 79 }; |
80 | |
81 struct lwval | |
82 { | |
83 int lwval_type; // data type | |
84 union lwval_dt dt; // type specific stuff | |
85 }; | |
86 | |
15 | 87 #ifndef __lwval_c_seen__ |
16
4f14eae64d38
Made header less likely to conflict with other #defines
lost
parents:
15
diff
changeset
|
88 #define __lwval_extern__ extern |
14 | 89 #else |
16
4f14eae64d38
Made header less likely to conflict with other #defines
lost
parents:
15
diff
changeset
|
90 #define __lwval_extern__ |
14 | 91 #endif |
92 | |
16
4f14eae64d38
Made header less likely to conflict with other #defines
lost
parents:
15
diff
changeset
|
93 __lwval_extern__ LWVAL *lwval_construct_int(int value); |
4f14eae64d38
Made header less likely to conflict with other #defines
lost
parents:
15
diff
changeset
|
94 __lwval_extern__ LWVAL *lwval_construct_err(int errno); |
4f14eae64d38
Made header less likely to conflict with other #defines
lost
parents:
15
diff
changeset
|
95 __lwval_extern__ LWVAL *lwval_construct_nan(void); |
4f14eae64d38
Made header less likely to conflict with other #defines
lost
parents:
15
diff
changeset
|
96 __lwval_extern__ LWVAL *lwval_construct_expr(LWVAL *v1, LWVAL *v2, int op); |
4f14eae64d38
Made header less likely to conflict with other #defines
lost
parents:
15
diff
changeset
|
97 __lwval_extern__ LWVAL *lwval_construct_undef(void); |
4f14eae64d38
Made header less likely to conflict with other #defines
lost
parents:
15
diff
changeset
|
98 __lwval_extern__ void lwval_clear(LWVAL *value); |
4f14eae64d38
Made header less likely to conflict with other #defines
lost
parents:
15
diff
changeset
|
99 __lwval_extern__ void lwval_destroy(LWVAL *value); |
4f14eae64d38
Made header less likely to conflict with other #defines
lost
parents:
15
diff
changeset
|
100 __lwval_extern__ void lwval_dup(LWVAL *v1, LWVAL *v2); |
14 | 101 |
15 | 102 // operators - operate on v1 and v2 in order, result goes into |
103 // v1; return v1 | |
16
4f14eae64d38
Made header less likely to conflict with other #defines
lost
parents:
15
diff
changeset
|
104 __lwval_extern__ LWVAL *lwval_add(LWVAL *v1, LWVAL *v2); |
4f14eae64d38
Made header less likely to conflict with other #defines
lost
parents:
15
diff
changeset
|
105 __lwval_extern__ LWVAL *lwval_sub(LWVAL *v1, LWVAL *v2); |
4f14eae64d38
Made header less likely to conflict with other #defines
lost
parents:
15
diff
changeset
|
106 __lwval_extern__ LWVAL *lwval_mul(LWVAL *v1, LWVAL *v2); |
4f14eae64d38
Made header less likely to conflict with other #defines
lost
parents:
15
diff
changeset
|
107 __lwval_extern__ LWVAL *lwval_div(LWVAL *v1, LWVAL *v2); |
4f14eae64d38
Made header less likely to conflict with other #defines
lost
parents:
15
diff
changeset
|
108 __lwval_extern__ LWVAL *lwval_mod(LWVAL *v1, LWVAL *v2); |
4f14eae64d38
Made header less likely to conflict with other #defines
lost
parents:
15
diff
changeset
|
109 __lwval_extern__ LWVAL *lwval_neg(LWVAL *v1); |
4f14eae64d38
Made header less likely to conflict with other #defines
lost
parents:
15
diff
changeset
|
110 |
4f14eae64d38
Made header less likely to conflict with other #defines
lost
parents:
15
diff
changeset
|
111 #undef __lwval_extern__ |
13
05d4115b4860
Started work on new expression evaluator system and major code re-work for next release
lost
parents:
diff
changeset
|
112 |
15 | 113 #endif //__lwval_h_seen__ |