1 /*
2  * This file is part of DGD, https://github.com/dworkin/dgd
3  * Copyright (C) 1993-2010 Dworkin B.V.
4  * Copyright (C) 2010-2012 DGD Authors (see the commit log for details)
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as
8  * published by the Free Software Foundation, either version 3 of the
9  * License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 typedef struct _node_ {
21     char type;			/* type of node */
22     char flags;			/* bitflags */
23     unsigned short mod;		/* modifier */
24     unsigned short line;	/* line number */
25     string *class;		/* object class */
26     union {
27 	Int number;		/* numeric value */
28 	unsigned short fhigh;	/* high word of float */
29 	string *string;		/* string value */
30 	char *ptr;		/* character pointer */
31 	struct _node_ *left;	/* left child */
32     } l;
33     union {
34 	Int number;		/* numeric value */
35 	Uint flow;		/* low longword of float */
36 	struct _node_ *right;	/* right child */
37     } r;
38 } node;
39 
40 # define NFLT_GET(n, f)	((f).high = (n)->l.fhigh, (f).low = (n)->r.flow)
41 # define NFLT_PUT(n, f)	((n)->l.fhigh = (f).high, (n)->r.flow = (f).low)
42 # define NFLT_ISZERO(n)	FLT_ISZERO((n)->l.fhigh, (n)->r.flow)
43 # define NFLT_ISONE(n)	FLT_ISONE((n)->l.fhigh, (n)->r.flow)
44 # define NFLT_ISMONE(n)	FLT_ISMONE((n)->l.fhigh, (n)->r.flow)
45 # define NFLT_ONE(n)	FLT_ONE((n)->l.fhigh, (n)->r.flow)
46 # define NFLT_ABS(n)	FLT_ABS((n)->l.fhigh, (n)->r.flow)
47 # define NFLT_NEG(n)	FLT_NEG((n)->l.fhigh, (n)->r.flow)
48 
49 # define F_CONST	0x01	/* constant expression */
50 # define F_SIDEFX	0x02	/* expression has side effect */
51 # define F_ENTRY	0x04	/* (first) statement has case/default entry */
52 # define F_REACH	0x08	/* statement block has case/default entry */
53 # define F_BREAK	0x10	/* break */
54 # define F_CONTINUE	0x20	/* continue */
55 # define F_RETURN	0x40	/* return */
56 # define F_END		(F_BREAK | F_CONTINUE | F_RETURN)
57 # define F_FLOW		(F_ENTRY | F_REACH | F_END)
58 # define F_VARARGS	0x04	/* varargs in parameter list */
59 # define F_ELLIPSIS	0x08	/* ellipsis in parameter list */
60 
61 extern void  node_init	(int);
62 extern node *node_new	(unsigned int);
63 extern node *node_int	(Int);
64 extern node *node_float	(xfloat*);
65 extern node *node_nil	(void);
66 extern node *node_str	(string*);
67 extern node *node_var	(unsigned int, int);
68 extern node *node_type	(int, string*);
69 extern node *node_fcall	(int, string*, char*, Int);
70 extern node *node_mon	(int, int, node*);
71 extern node *node_bin	(int, int, node*, node*);
72 extern void  node_toint	(node*, Int);
73 extern void  node_tostr	(node*, string*);
74 extern void  node_free	(void);
75 extern void  node_clear	(void);
76 
77 # define N_ADD			  1
78 # define N_ADD_INT		  2
79 # define N_ADD_FLOAT		  3
80 # define N_ADD_EQ		  4
81 # define N_ADD_EQ_INT		  5
82 # define N_ADD_EQ_FLOAT		  6
83 # define N_ADD_EQ_1		  7
84 # define N_ADD_EQ_1_INT		  8
85 # define N_ADD_EQ_1_FLOAT	  9
86 # define N_AGGR			 10
87 # define N_AND			 11
88 # define N_AND_INT		 12
89 # define N_AND_EQ		 13
90 # define N_AND_EQ_INT		 14
91 # define N_ASSIGN		 15
92 # define N_BLOCK		 16
93 # define N_BREAK		 17
94 # define N_CASE			 18
95 # define N_CAST			 19
96 # define N_CATCH		 20
97 # define N_COMMA		 21
98 # define N_COMPOUND		 22
99 # define N_CONTINUE		 23
100 # define N_DIV			 24
101 # define N_DIV_INT		 25
102 # define N_DIV_FLOAT		 26
103 # define N_DIV_EQ		 27
104 # define N_DIV_EQ_INT		 28
105 # define N_DIV_EQ_FLOAT		 29
106 # define N_DO			 30
107 # define N_ELSE			 31
108 # define N_EQ			 32
109 # define N_EQ_INT		 33
110 # define N_EQ_FLOAT		 34
111 # define N_FAKE			 35
112 # define N_FLOAT		 36
113 # define N_FOR			 37
114 # define N_FOREVER		 38
115 # define N_FUNC			 39
116 # define N_GE			 40
117 # define N_GE_INT		 41
118 # define N_GE_FLOAT		 42
119 # define N_GLOBAL		 43
120 # define N_GT			 44
121 # define N_GT_INT		 45
122 # define N_GT_FLOAT		 46
123 # define N_IF			 47
124 # define N_INDEX		 48
125 # define N_INSTANCEOF		 49
126 # define N_INT			 50
127 # define N_LAND			 51
128 # define N_LE			 52
129 # define N_LE_INT		 53
130 # define N_LE_FLOAT		 54
131 # define N_LOCAL		 55
132 # define N_LOR			 56
133 # define N_LSHIFT		 57
134 # define N_LSHIFT_INT		 58
135 # define N_LSHIFT_EQ		 59
136 # define N_LSHIFT_EQ_INT	 60
137 # define N_LT			 61
138 # define N_LT_INT		 62
139 # define N_LT_FLOAT		 63
140 # define N_LVALUE		 64
141 # define N_MOD			 65
142 # define N_MOD_INT		 66
143 # define N_MOD_EQ		 67
144 # define N_MOD_EQ_INT		 68
145 # define N_MULT			 69
146 # define N_MULT_INT		 70
147 # define N_MULT_FLOAT		 71
148 # define N_MULT_EQ		 72
149 # define N_MULT_EQ_INT		 73
150 # define N_MULT_EQ_FLOAT	 74
151 # define N_NE			 75
152 # define N_NE_INT		 76
153 # define N_NE_FLOAT		 77
154 # define N_NIL			 78
155 # define N_NOT			 79
156 # define N_OR			 80
157 # define N_OR_INT		 81
158 # define N_OR_EQ		 82
159 # define N_OR_EQ_INT		 83
160 # define N_PAIR			 84
161 # define N_POP			 85
162 # define N_QUEST		 86
163 # define N_RANGE		 87
164 # define N_RETURN		 88
165 # define N_RLIMITS		 89
166 # define N_RSHIFT		 90
167 # define N_RSHIFT_INT		 91
168 # define N_RSHIFT_EQ		 92
169 # define N_RSHIFT_EQ_INT	 93
170 # define N_SPREAD		 94
171 # define N_STR			 95
172 # define N_SUB			 96
173 # define N_SUB_INT		 97
174 # define N_SUB_FLOAT		 98
175 # define N_SUB_EQ		 99
176 # define N_SUB_EQ_INT		100
177 # define N_SUB_EQ_FLOAT		101
178 # define N_SUB_EQ_1		102
179 # define N_SUB_EQ_1_INT		103
180 # define N_SUB_EQ_1_FLOAT	104
181 # define N_SUM			105
182 # define N_SUM_EQ		106
183 # define N_SWITCH_INT		107
184 # define N_SWITCH_RANGE		108
185 # define N_SWITCH_STR		109
186 # define N_TOFLOAT		110
187 # define N_TOINT		111
188 # define N_TOSTRING		112
189 # define N_TST			113
190 # define N_TYPE			114
191 # define N_VAR			115
192 # define N_XOR			116
193 # define N_XOR_INT		117
194 # define N_XOR_EQ		118
195 # define N_XOR_EQ_INT		119
196 # define N_MIN_MIN		120
197 # define N_MIN_MIN_INT		121
198 # define N_MIN_MIN_FLOAT	122
199 # define N_PLUS_PLUS		123
200 # define N_PLUS_PLUS_INT	124
201 # define N_PLUS_PLUS_FLOAT	125
202 extern int nil_node;
203