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