Rev 2455 | Rev 4851 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2455 | Rev 2460 | ||
---|---|---|---|
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
- | |
2 | ;; ;; |
- | |
3 | ;; Copyright (C) KolibriOS team 2004-2011. All rights reserved. ;; |
- | |
4 | ;; Distributed under terms of the GNU General Public License ;; |
- | |
5 | ;; ;; |
- | |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
- | |
7 | 1 | ; Macroinstructions for defining data structures |
|
8 | ; Macroinstructions for defining data structures |
2 | |
9 | 3 | macro struct name |
|
10 | macro struct name |
4 | { virtual at 0 |
11 | { virtual at 0 |
5 | fields@struct equ name |
12 | fields@struct equ name |
6 | match child parent, name \{ fields@struct equ child,fields@\#parent \} |
13 | match child parent, name \{ fields@struct equ child,fields@\#parent \} |
7 | sub@struct equ |
14 | sub@struct equ |
8 | struc db [val] \{ \common define field@struct .,db, |
15 | struc db [val] \{ \common define field@struct .,db, |
9 | fields@struct equ fields@struct,field@struct \} |
16 | fields@struct equ fields@struct,field@struct \} |
10 | struc dw [val] \{ \common define field@struct .,dw, |
17 | struc dw [val] \{ \common define field@struct .,dw, |
11 | fields@struct equ fields@struct,field@struct \} |
18 | fields@struct equ fields@struct,field@struct \} |
12 | struc du [val] \{ \common define field@struct .,du, |
19 | struc du [val] \{ \common define field@struct .,du, |
13 | fields@struct equ fields@struct,field@struct \} |
20 | fields@struct equ fields@struct,field@struct \} |
14 | struc dd [val] \{ \common define field@struct .,dd, |
21 | struc dd [val] \{ \common define field@struct .,dd, |
15 | fields@struct equ fields@struct,field@struct \} |
22 | fields@struct equ fields@struct,field@struct \} |
16 | struc dp [val] \{ \common define field@struct .,dp, |
23 | struc dp [val] \{ \common define field@struct .,dp, |
17 | fields@struct equ fields@struct,field@struct \} |
24 | fields@struct equ fields@struct,field@struct \} |
18 | struc dq [val] \{ \common define field@struct .,dq, |
25 | struc dq [val] \{ \common define field@struct .,dq, |
19 | fields@struct equ fields@struct,field@struct \} |
26 | fields@struct equ fields@struct,field@struct \} |
20 | struc dt [val] \{ \common define field@struct .,dt, |
27 | struc dt [val] \{ \common define field@struct .,dt, |
21 | fields@struct equ fields@struct,field@struct \} |
28 | fields@struct equ fields@struct,field@struct \} |
22 | struc rb count \{ define field@struct .,db,count dup (?) |
29 | struc rb count \{ define field@struct .,db,count dup (?) |
23 | fields@struct equ fields@struct,field@struct \} |
30 | fields@struct equ fields@struct,field@struct \} |
24 | struc rw count \{ define field@struct .,dw,count dup (?) |
31 | struc rw count \{ define field@struct .,dw,count dup (?) |
25 | fields@struct equ fields@struct,field@struct \} |
32 | fields@struct equ fields@struct,field@struct \} |
26 | struc rd count \{ define field@struct .,dd,count dup (?) |
33 | struc rd count \{ define field@struct .,dd,count dup (?) |
27 | fields@struct equ fields@struct,field@struct \} |
34 | fields@struct equ fields@struct,field@struct \} |
28 | struc rp count \{ define field@struct .,dp,count dup (?) |
35 | struc rp count \{ define field@struct .,dp,count dup (?) |
29 | fields@struct equ fields@struct,field@struct \} |
36 | fields@struct equ fields@struct,field@struct \} |
30 | struc rq count \{ define field@struct .,dq,count dup (?) |
37 | struc rq count \{ define field@struct .,dq,count dup (?) |
31 | fields@struct equ fields@struct,field@struct \} |
38 | fields@struct equ fields@struct,field@struct \} |
32 | struc rt count \{ define field@struct .,dt,count dup (?) |
39 | struc rt count \{ define field@struct .,dt,count dup (?) |
33 | fields@struct equ fields@struct,field@struct \} |
40 | fields@struct equ fields@struct,field@struct \} |
34 | macro db [val] \{ \common \local anonymous |
41 | macro db [val] \{ \common \local anonymous |
35 | define field@struct anonymous,db, |
42 | define field@struct anonymous,db, |
36 | fields@struct equ fields@struct,field@struct \} |
43 | fields@struct equ fields@struct,field@struct \} |
37 | macro dw [val] \{ \common \local anonymous |
44 | macro dw [val] \{ \common \local anonymous |
38 | define field@struct anonymous,dw, |
45 | define field@struct anonymous,dw, |
39 | fields@struct equ fields@struct,field@struct \} |
46 | fields@struct equ fields@struct,field@struct \} |
40 | macro du [val] \{ \common \local anonymous |
47 | macro du [val] \{ \common \local anonymous |
41 | define field@struct anonymous,du, |
48 | define field@struct anonymous,du, |
42 | fields@struct equ fields@struct,field@struct \} |
49 | fields@struct equ fields@struct,field@struct \} |
43 | macro dd [val] \{ \common \local anonymous |
50 | macro dd [val] \{ \common \local anonymous |
44 | define field@struct anonymous,dd, |
51 | define field@struct anonymous,dd, |
45 | fields@struct equ fields@struct,field@struct \} |
52 | fields@struct equ fields@struct,field@struct \} |
46 | macro dp [val] \{ \common \local anonymous |
53 | macro dp [val] \{ \common \local anonymous |
47 | define field@struct anonymous,dp, |
54 | define field@struct anonymous,dp, |
48 | fields@struct equ fields@struct,field@struct \} |
55 | fields@struct equ fields@struct,field@struct \} |
49 | macro dq [val] \{ \common \local anonymous |
56 | macro dq [val] \{ \common \local anonymous |
50 | define field@struct anonymous,dq, |
57 | define field@struct anonymous,dq, |
51 | fields@struct equ fields@struct,field@struct \} |
58 | fields@struct equ fields@struct,field@struct \} |
52 | macro dt [val] \{ \common \local anonymous |
59 | macro dt [val] \{ \common \local anonymous |
53 | define field@struct anonymous,dt, |
60 | define field@struct anonymous,dt, |
54 | fields@struct equ fields@struct,field@struct \} |
61 | fields@struct equ fields@struct,field@struct \} |
55 | macro rb count \{ \local anonymous |
62 | macro rb count \{ \local anonymous |
56 | define field@struct anonymous,db,count dup (?) |
63 | define field@struct anonymous,db,count dup (?) |
57 | fields@struct equ fields@struct,field@struct \} |
64 | fields@struct equ fields@struct,field@struct \} |
58 | macro rw count \{ \local anonymous |
65 | macro rw count \{ \local anonymous |
59 | define field@struct anonymous,dw,count dup (?) |
66 | define field@struct anonymous,dw,count dup (?) |
60 | fields@struct equ fields@struct,field@struct \} |
67 | fields@struct equ fields@struct,field@struct \} |
61 | macro rd count \{ \local anonymous |
68 | macro rd count \{ \local anonymous |
62 | define field@struct anonymous,dd,count dup (?) |
69 | define field@struct anonymous,dd,count dup (?) |
63 | fields@struct equ fields@struct,field@struct \} |
70 | fields@struct equ fields@struct,field@struct \} |
64 | macro rp count \{ \local anonymous |
71 | macro rp count \{ \local anonymous |
65 | define field@struct anonymous,dp,count dup (?) |
72 | define field@struct anonymous,dp,count dup (?) |
66 | fields@struct equ fields@struct,field@struct \} |
73 | fields@struct equ fields@struct,field@struct \} |
67 | macro rq count \{ \local anonymous |
74 | macro rq count \{ \local anonymous |
68 | define field@struct anonymous,dq,count dup (?) |
75 | define field@struct anonymous,dq,count dup (?) |
69 | fields@struct equ fields@struct,field@struct \} |
76 | fields@struct equ fields@struct,field@struct \} |
70 | macro rt count \{ \local anonymous |
77 | macro rt count \{ \local anonymous |
71 | define field@struct anonymous,dt,count dup (?) |
78 | define field@struct anonymous,dt,count dup (?) |
72 | fields@struct equ fields@struct,field@struct \} |
79 | fields@struct equ fields@struct,field@struct \} |
73 | macro union \{ fields@struct equ fields@struct,,union,< |
80 | macro union \{ fields@struct equ fields@struct,,union,< |
74 | sub@struct equ union \} |
81 | sub@struct equ union \} |
75 | macro struct \{ fields@struct equ fields@struct,,substruct,< |
82 | macro struct \{ fields@struct equ fields@struct,,substruct,< |
76 | sub@struct equ substruct \} } |
83 | sub@struct equ substruct \} } |
77 | |
84 | 78 | macro ends |
|
85 | macro ends |
79 | { match , sub@struct \{ restruc db,dw,du,dd,dp,dq,dt |
86 | { match , sub@struct \{ restruc db,dw,du,dd,dp,dq,dt |
80 | restruc rb,rw,rd,rp,rq,rt |
87 | restruc rb,rw,rd,rp,rq,rt |
81 | purge db,dw,du,dd,dp,dq,dt |
88 | purge db,dw,du,dd,dp,dq,dt |
82 | purge rb,rw,rd,rp,rq,rt |
89 | purge rb,rw,rd,rp,rq,rt |
83 | purge union,struct |
90 | purge union,struct |
84 | match name tail,fields@struct, \\{ if $ |
91 | match name tail,fields@struct, \\{ if $ |
85 | display 'Error: definition of ',\\`name,' contains illegal instructions.',0Dh,0Ah |
92 | display 'Error: definition of ',\\`name,' contains illegal instructions.',0Dh,0Ah |
86 | err |
93 | err |
87 | end if \\} |
94 | end if \\} |
88 | match name=,fields,fields@struct \\{ fields@struct equ |
95 | match name=,fields,fields@struct \\{ fields@struct equ |
89 | make@struct name,fields |
96 | make@struct name,fields |
90 | define fields@\\#name fields \\} |
97 | define fields@\\#name fields \\} |
91 | end virtual \} |
98 | end virtual \} |
92 | match any, sub@struct \{ fields@struct equ fields@struct> \} |
99 | match any, sub@struct \{ fields@struct equ fields@struct> \} |
93 | restore sub@struct } |
100 | restore sub@struct } |
94 | |
101 | 95 | macro make@struct name,[field,type,def] |
|
102 | macro make@struct name,[field,type,def] |
96 | { common |
103 | { common |
97 | local define |
104 | local define |
98 | define equ name |
105 | define equ name |
99 | forward |
106 | forward |
100 | local sub |
107 | local sub |
101 | match , field \{ make@substruct type,name,sub def |
108 | match , field \{ make@substruct type,name,sub def |
102 | define equ define,.,sub, \} |
109 | define equ define,.,sub, \} |
103 | match any, field \{ define equ define,.#field,type, |
110 | match any, field \{ define equ define,.#field,type, |
104 | common |
111 | common |
105 | match fields, define \{ define@struct fields \} } |
112 | match fields, define \{ define@struct fields \} } |
106 | |
113 | 107 | macro define@struct name,[field,type,def] |
|
114 | macro define@struct name,[field,type,def] |
108 | { common |
115 | { common |
109 | virtual |
116 | virtual |
110 | db `name |
117 | db `name |
111 | load initial@struct byte from 0 |
118 | load initial@struct byte from 0 |
112 | if initial@struct = '.' |
119 | if initial@struct = '.' |
113 | display 'Error: name of structure should not begin with a dot.',0Dh,0Ah |
120 | display 'Error: name of structure should not begin with a dot.',0Dh,0Ah |
114 | err |
121 | err |
115 | end if |
122 | end if |
116 | end virtual |
123 | end virtual |
117 | local list |
124 | local list |
118 | list equ |
125 | list equ |
119 | forward |
126 | forward |
120 | if ~ field eq . |
127 | if ~ field eq . |
121 | name#field type def |
128 | name#field type def |
122 | sizeof.#name#field = $ - name#field |
129 | sizeof.#name#field = $ - name#field |
123 | else |
130 | else |
124 | label name#.#type |
131 | label name#.#type |
125 | rb sizeof.#type |
132 | rb sizeof.#type |
126 | end if |
133 | end if |
127 | local value |
134 | local value |
128 | match any, list \{ list equ list, \} |
135 | match any, list \{ list equ list, \} |
129 | list equ list |
136 | list equ list |
130 | common |
137 | common |
131 | sizeof.#name = $ |
138 | sizeof.#name = $ |
132 | restruc name |
139 | restruc name |
133 | match values, list \{ |
140 | match values, list \{ |
134 | struc name value \\{ \\local \\..base |
141 | struc name value \\{ \\local \\..base |
135 | match any, fields@struct \\\{ fields@struct equ fields@struct,.,name, |
142 | match any, fields@struct \\\{ fields@struct equ fields@struct,.,name, |
136 | match , fields@struct \\\{ label \\..base |
143 | match , fields@struct \\\{ label \\..base |
137 | forward |
144 | forward |
138 | match , value \\\\{ field type def \\\\} |
145 | match , value \\\\{ field type def \\\\} |
139 | match any, value \\\\{ field type value |
146 | match any, value \\\\{ field type value |
140 | if ~ field eq . |
147 | if ~ field eq . |
141 | rb sizeof.#name#field - ($-field) |
148 | rb sizeof.#name#field - ($-field) |
142 | end if \\\\} |
149 | end if \\\\} |
143 | common label . at \\..base \\\} |
150 | common label . at \\..base \\\} |
144 | \\} |
151 | \\} |
145 | macro name value \\{ |
152 | macro name value \\{ |
146 | match any, fields@struct \\\{ \\\local anonymous |
153 | match any, fields@struct \\\{ \\\local anonymous |
147 | fields@struct equ fields@struct,anonymous,name, |
154 | fields@struct equ fields@struct,anonymous,name, |
148 | match , fields@struct \\\{ |
155 | match , fields@struct \\\{ |
149 | forward |
156 | forward |
150 | match , value \\\\{ type def \\\\} |
157 | match , value \\\\{ type def \\\\} |
151 | match any, value \\\\{ \\\\local ..field |
158 | match any, value \\\\{ \\\\local ..field |
152 | ..field = $ |
159 | ..field = $ |
153 | type value |
160 | type value |
154 | if ~ field eq . |
161 | if ~ field eq . |
155 | rb sizeof.#name#field - ($-..field) |
162 | rb sizeof.#name#field - ($-..field) |
156 | end if \\\\} |
163 | end if \\\\} |
157 | common \\\} \\} \} } |
164 | common \\\} \\} \} } |
158 | |
165 | 159 | macro enable@substruct |
|
166 | macro enable@substruct |
160 | { macro make@substruct substruct,parent,name,[field,type,def] |
167 | { macro make@substruct substruct,parent,name,[field,type,def] |
161 | \{ \common |
168 | \{ \common |
162 | \local define |
169 | \local define |
163 | define equ parent,name |
170 | define equ parent,name |
164 | \forward |
171 | \forward |
165 | \local sub |
172 | \local sub |
166 | match , field \\{ match any, type \\\{ enable@substruct |
173 | match , field \\{ match any, type \\\{ enable@substruct |
167 | make@substruct type,parent,sub def |
174 | make@substruct type,parent,sub def |
168 | purge make@substruct |
175 | purge make@substruct |
169 | define equ define,.,sub, \\\} \\} |
176 | define equ define,.,sub, \\\} \\} |
170 | match any, field \\{ define equ define,.\#field,type, |
177 | match any, field \\{ define equ define,.\#field,type, |
171 | \common |
178 | \common |
172 | match fields, define \\{ define@\#substruct fields \\} \} } |
179 | match fields, define \\{ define@\#substruct fields \\} \} } |
173 | |
180 | 174 | enable@substruct |
|
181 | enable@substruct |
175 | |
182 | 176 | macro define@union parent,name,[field,type,def] |
|
183 | macro define@union parent,name,[field,type,def] |
177 | { common |
184 | { common |
178 | virtual at parent#.#name |
185 | virtual at parent#.#name |
179 | forward |
186 | forward |
180 | if ~ field eq . |
187 | if ~ field eq . |
181 | virtual at parent#.#name |
188 | virtual at parent#.#name |
182 | parent#field type def |
189 | parent#field type def |
183 | sizeof.#parent#field = $ - parent#field |
190 | sizeof.#parent#field = $ - parent#field |
184 | end virtual |
191 | end virtual |
185 | if sizeof.#parent#field > $ - parent#.#name |
192 | if sizeof.#parent#field > $ - parent#.#name |
186 | rb sizeof.#parent#field - ($ - parent#.#name) |
193 | rb sizeof.#parent#field - ($ - parent#.#name) |
187 | end if |
194 | end if |
188 | else |
195 | else |
189 | virtual at parent#.#name |
196 | virtual at parent#.#name |
190 | label parent#.#type |
197 | label parent#.#type |
191 | type def |
198 | type def |
192 | end virtual |
199 | end virtual |
193 | label name#.#type at parent#.#name |
200 | label name#.#type at parent#.#name |
194 | if sizeof.#type > $ - parent#.#name |
201 | if sizeof.#type > $ - parent#.#name |
195 | rb sizeof.#type - ($ - parent#.#name) |
202 | rb sizeof.#type - ($ - parent#.#name) |
196 | end if |
203 | end if |
197 | end if |
204 | end if |
198 | common |
205 | common |
199 | sizeof.#name = $ - parent#.#name |
206 | sizeof.#name = $ - parent#.#name |
200 | end virtual |
207 | end virtual |
201 | struc name [value] \{ \common |
208 | struc name [value] \{ \common |
202 | label .\#name |
209 | label .\#name |
203 | last@union equ |
210 | last@union equ |
204 | forward |
211 | forward |
205 | match any, last@union \\{ virtual at .\#name |
212 | match any, last@union \\{ virtual at .\#name |
206 | field type def |
213 | field type def |
207 | end virtual \\} |
214 | end virtual \\} |
208 | match , last@union \\{ match , value \\\{ field type def \\\} |
215 | match , last@union \\{ match , value \\\{ field type def \\\} |
209 | match any, value \\\{ field type value \\\} \\} |
216 | match any, value \\\{ field type value \\\} \\} |
210 | last@union equ field |
217 | last@union equ field |
211 | common rb sizeof.#name - ($ - .\#name) \} |
218 | common rb sizeof.#name - ($ - .\#name) \} |
212 | macro name [value] \{ \common \local ..anonymous |
219 | macro name [value] \{ \common \local ..anonymous |
213 | ..anonymous name value \} } |
220 | ..anonymous name value \} } |
214 | |
221 | 215 | macro define@substruct parent,name,[field,type,def] |
|
222 | macro define@substruct parent,name,[field,type,def] |
216 | { common |
223 | { common |
217 | virtual at parent#.#name |
224 | virtual at parent#.#name |
218 | forward |
225 | forward |
219 | if ~ field eq . |
226 | if ~ field eq . |
220 | parent#field type def |
227 | parent#field type def |
221 | sizeof.#parent#field = $ - parent#field |
228 | sizeof.#parent#field = $ - parent#field |
222 | else |
229 | else |
223 | label parent#.#type |
230 | label parent#.#type |
224 | rb sizeof.#type |
231 | rb sizeof.#type |
225 | end if |
232 | end if |
226 | common |
233 | common |
227 | sizeof.#name = $ - parent#.#name |
234 | sizeof.#name = $ - parent#.#name |
228 | end virtual |
235 | end virtual |
229 | struc name value \{ |
236 | struc name value \{ |
230 | label .\#name |
237 | label .\#name |
231 | forward |
238 | forward |
232 | match , value \\{ field type def \\} |
239 | match , value \\{ field type def \\} |
233 | match any, value \\{ field type value |
240 | match any, value \\{ field type value |
234 | if ~ field eq . |
241 | if ~ field eq . |
235 | rb sizeof.#parent#field - ($-field) |
242 | rb sizeof.#parent#field - ($-field) |
236 | end if \\} |
243 | end if \\} |
237 | common \} |
244 | common \} |
238 | macro name value \{ \local ..anonymous |
245 | macro name value \{ \local ..anonymous |
239 | ..anonymous name \} } |
246 | ..anonymous name \} } |
240 | > |
247 | > |
241 | > |
248 | > |
- |