annotate old-trunk/lwasm/old/lwval.h @ 377:55ed7d06b136

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