Subversion Repositories Kolibri OS

Rev

Rev 2460 | Rev 4851 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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