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