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