summaryrefslogtreecommitdiffstats
path: root/private/os2/os2ses/struc.inc
blob: f76dd9280bf0b45cacd5efa964ff5a66afc7f066 (plain) (blame)
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
;;	SCCSID = @(#)struc.inc	12.1 88/03/18
;;STRUC.INC--Stucture Macro Library
;;Version 2.20		08/08/86
;;Written by Eric C. Rasmussen

        if      @Version GE 600
        option  nokeyword: <.if, .elseif, .else, .endif, .while>
        endif

if1
$noconj equ	0
$and		equ	1
$or		equ	2
$short		equ	3
$near		equ	4
$andor		=	0
$temp		=	0
$temp2		=	0
$dist		=	0

$notype		equ	10
$conjif		equ	11
$iftype		equ	12
$elsetype	equ	13
$whiletype	equ	14
$conjwhile	equ	15
$repeattype	equ	16
$conjuntil	equ	17
$fortype	equ	18
$conjleave	equ	19

$StrucErr macro text
					Structure error -- text
endm

j	macro
endm
jn	macro
endm

jbuild	macro	j1,j2
	j1	macro	tgt
		.xcref	j1
					j2 tgt
	endm
endm

irp	x,<<jeq,je>,<jlt,jl>,<jgt,jg>,<jneq,jne>,<jnlt,jnl>,<jngt,jng>,<jnpe,jpo>,<jnpo,jpe>>
	jbuild	x
endm
irp	x,<<jzero,jz>,<jnzero,jnz>,<jnonzero,jnz>,<jnnonzero,jz>,<jand,jnz>,<jnand,jz>,<jnnand,jnz>>
	jbuild	x
endm
irp	x,<a,ae,b,be,c,e,g,ge,l,le,o,p,s,z,cxz>
	jbuild	jnn&x,j&x
endm

jncxz	macro	tgt
	local	skip
					jcxz skip
					jmp short tgt
skip:
endm

purge	jbuild

$getconj macro	p1,p2
	$andor	= $noconj
	irp	parm,<p1,p2>
		ifnb	<&parm>
			irp	x,<and,AND,or,OR>
				ifidn	<parm>,<x>
					$andor = $&&&x
					exitm
				endif
			endm
		endif
	endm
endm

$getdist macro	p1,p2
	irp	parm,<p1,p2>
		ifnb	<parm>
			irp	x,<short,SHORT,near,NEAR>
				ifidn	<parm>,<x>
					$dist = $&&&x
					exitm
				endif
			endm
		endif
	endm
endm


$poke	macro	num,value
	$st&num = value
.xcref	$st&num
endm

$peek	macro	sym,num
	sym	= $st&num
endm

$push	macro	value
	$st	= $st+1
	$poke	%$st,value
endm

$pop	macro	sym
	$peek	sym,%$st
	$st	= $st-1
endm

$labl	macro	num
$l&num:
endm

$cjump	macro	lnum,tf,cond
	local	skip
	if	$dist eq $short
		ifb	<cond>
					jmp short $l&lnum
		else
			ifidn <tf>,<f>
					jn&cond $l&lnum
			else
					j&cond $l&lnum
			endif
		endif
	else
		ifnb	<cond>
			ifidn <tf>,<f>
					j&cond skip
			else
					jn&cond skip
			endif
		endif
					jmp $l&lnum
		ifnb		<cond>
skip:
		endif
	endif
endm


$cloop	macro	lnum,cond
					loop&cond $l&lnum
endm

$test	macro	tgt,a1,a2,a3,a4,x1
	ifb	<a1>
		$StrucErr <invalid condition>
	else
	ifb	<a2>
		$cjump	%&tgt,a1
	else
	ifb	<a3>
		ifdif	<a1>,<zero>
		ifdif	<a1>,<nonzero>
		ifdif	<a1>,<ZERO>
		ifdif	<a1>,<NONZERO>
			$StrucErr	<invalid condition>
			exitm
		endif
		endif
		endif
		endif
					or a2,a2
		$cjump	%&tgt,a1
	else
	ifb	<a4>
					cmp a1,a3
		$cjump	%&tgt,a2
	else
	ifb	<x1>
		ifdif	<a1>,<bit>
		ifdif	<a1>,<BIT>
			$StrucErr	<invalid condition>
			exitm
		endif
		endif
					test a2,a4
		$cjump	%&tgt,a3
	else
		$StrucErr	<invalid condition>
	endif
	endif
	endif
	endif
	endif
endm

$toptest macro	args,ntype,ctype,p4,p5
	$getconj p4,p5
	$dist = $defdist
	$getdist p4,p5
	if	$andor eq $noconj
		$test	<$sn-1,f>,args
		$pop	$temp
		if	 $orfound
			$labl  %$temp
		endif
		$push	ntype
	else
		if	$andor eq $and
			$test	<$sn-1,f>,args
		else
			$orfound = 1
			$test	<$sn,t>,args
		endif
		$push	ctype
	endif
endm
;;*****************************************************************************
.if	macro	tst,p2,p3
	$peek	$temp,%$st
	if	$temp eq $conjif
		$pop	$temp
	else
		$push	$elseiffound
		$elseiffound = 0
		$orfound = 0
		$sn	= $sn+1
		$push	$sn
		$sn	= $sn+1
		$push	$sn
		$sn	= $sn+1
		$push	$sn
	endif
	$toptest <tst>,$iftype,$conjif,p2,p3
endm
;;*****************************************************************************
.then	macro
	$peek	$temp,%$st
	if	$temp ne $iftype
		$StrucErr <then without if>
	endif
endm
;;*****************************************************************************
.elseif macro	tst,p2,p3
	$pop	$temp
	if	$temp ne $iftype
		$StrucErr <elseif without if>
		exitm
	endif
	$elseiffound = 1
	$orfound = 0
	$pop	$temp
	$peek	$temp2,%$st
	$dist	= $near
	$cjump	%$temp2
	$labl	%$temp
	$sn	= $sn+1
	$push	$sn
	$sn	= $sn+1
	$push	$sn
	$toptest <tst>,$iftype,$conjif,p2,p3
endm
;;*****************************************************************************
.else	macro	dist
	$pop	$temp
	if	$temp ne $iftype
		$StrucErr <else without if>
		exitm
	endif
	$sn	= $sn+1
	$dist	= $defdist
	$getdist dist
	$cjump	%$sn
	$pop	$temp
	$labl	%$temp
	$push	$sn
	$push	$elsetype
endm
;;*****************************************************************************
.endif	macro
	$pop	$temp
	if	$temp ne $iftype
		if	$temp ne $elsetype
			$StrucErr <endif without if>
			exitm
		endif
	endif
	$pop	$temp
	$labl	%$temp
	$pop	$temp
	if	$elseiffound
		$labl	 %$temp
	endif
	$pop	$elseiffound
endm
;;*****************************************************************************
.while	macro	tst,p2,p3
	$peek	$temp,%$st
	if	$temp eq $conjwhile
		$pop		$temp
	else
		$push $endloop
		$orfound = 0
		$sn = $sn + 1
		$push $sn
		$labl %$sn
		$sn = $sn + 2
		$push $sn
		$endloop = $sn - 1
	endif
	$toptest <tst>,$whiletype,$conjwhile,p2,p3
endm
;;*****************************************************************************
.endwhile macro
	$pop	$temp
	if	$temp ne $whiletype
		$StrucErr <endwhile without while>
		exitm
	endif
	$pop	$temp
	$dist	= $near
	$cjump	%$temp
	$labl	%$temp+1
	$pop	$endloop
endm
;;*****************************************************************************
;OS2SS-.repeat macro
;OS2SS-	$push	$endloop
;OS2SS-	$push	$leavefound
;OS2SS-	$sn	= $sn+1
;OS2SS-	$labl	%$sn
;OS2SS-	$push	$sn
;OS2SS-	$push	$repeattype
;OS2SS-	$sn	= $sn+1
;OS2SS-	$endloop = $sn
;OS2SS-	$leavefound = 0
;OS2SS-endm
;;*****************************************************************************
;OS2SS-.until	macro	tst,p2,p3
;OS2SS-	$until_2 p2,p3,tst
;OS2SS-endm
;OS2SS-$until_2 macro	p2,p3,a1,a2,a3,a4,x1
;OS2SS-	$pop	$temp
;OS2SS-	if	$temp ne $repeattype
;OS2SS-		if	$temp ne $conjuntil
;OS2SS-			$StrucErr <until without repeat>
;OS2SS-			exitm
;OS2SS-		endif
;OS2SS-	else
;OS2SS-		$orfound = 0
;OS2SS-	endif
;OS2SS-	$dist	= $defdist
;OS2SS-	$getdist p2,p3
;OS2SS-	$getconj p2,p3
;OS2SS-
;OS2SS-	if	$andor eq $noconj
;OS2SS-		$pop	$temp
;OS2SS-		ifb	<a1>
;OS2SS-			$dist	= $near
;OS2SS-			$cjump	%$temp,f
;OS2SS-		else
;OS2SS-			$test	<$temp,f>,<a1>,<a2>,<a3>,<a4>,<x1>
;OS2SS-		endif
;OS2SS-		if	$orfound or $leavefound
;OS2SS-			$labl %$temp+1
;OS2SS-		endif
;OS2SS-		$pop	$leavefound
;OS2SS-		$pop	$endloop
;OS2SS-	else
;OS2SS-		$peek $temp,%$st
;OS2SS-		if	$andor eq $and
;OS2SS-			$test <$temp,f>,<a1>,<a2>,<a3>,<a4>,<x1>
;OS2SS-		else
;OS2SS-			$orfound = 1
;OS2SS-			$test <$temp+1,t>,<a1>,<a2>,<a3>,<a4>,<x1>
;OS2SS-		endif
;OS2SS-		$push $conjuntil
;OS2SS-	endif
;OS2SS-endm
;;*****************************************************************************
;OS2SS-.loop	macro	cond
;OS2SS-	$pop	$temp
;OS2SS-	if	$temp ne $repeattype
;OS2SS-		$StrucErr <loop without repeat>
;OS2SS-		exitm
;OS2SS-	endif
;OS2SS-	$pop	$temp
;OS2SS-	$cloop	%$temp,cond
;OS2SS-	if	$leavefound
;OS2SS-		$labl %$temp+1
;OS2SS-	endif
;OS2SS-	$pop	$leavefound
;OS2SS-	$pop	$endloop
;OS2SS-endm
;;*****************************************************************************
;OS2SS-.for	macro	index,equals,start,to,stop,by,step,dist
;OS2SS-					mov index,start
;OS2SS-	$push	$endloop
;OS2SS-	$sn	= $sn+1
;OS2SS-	$push	$sn
;OS2SS-	$labl	%$sn
;OS2SS-	$sn	= $sn+1
;OS2SS-	$endloop = $sn
;OS2SS-					cmp index,stop
;OS2SS-	$dist	= $defdist
;OS2SS-	ifb	<step>
;OS2SS-		$push 1
;OS2SS-		$getdist by
;OS2SS-		$cjump %$sn,t,gt
;OS2SS-	else
;OS2SS-		$getdist dist
;OS2SS-		$push %(step)
;OS2SS-		if	step lt 0
;OS2SS-			$cjump %$sn,t,lt
;OS2SS-		else
;OS2SS-			$cjump %$sn,t,gt
;OS2SS-		endif
;OS2SS-	endif
;OS2SS-	$push	$fortype
;OS2SS-endm
;;*****************************************************************************
;OS2SS-.next	macro	index
;OS2SS-	$pop	$temp
;OS2SS-	if	$temp ne $fortype
;OS2SS-		$StrucErr <next without for>
;OS2SS-		exitm
;OS2SS-	endif
;OS2SS-	$pop	$temp
;OS2SS-	if	$temp eq 1
;OS2SS-					inc index
;OS2SS-	else
;OS2SS-		if	$temp eq -1
;OS2SS-					dec index
;OS2SS-		else
;OS2SS-					add index,$temp
;OS2SS-		endif
;OS2SS-	endif
;OS2SS-	$pop	$temp
;OS2SS-	$dist	= $near
;OS2SS-	$cjump	%$temp
;OS2SS-	$labl	%$temp+1
;OS2SS-	$pop	$endloop
;OS2SS-endm
;;*****************************************************************************
;OS2SS-.leave	macro	tst,p2,p3
;OS2SS-	$leave_2 p2,p3,tst
;OS2SS-endm
;OS2SS-$leave_2 macro	p2,p3,a1,a2,a3,a4,x1
;OS2SS-	ife	$endloop
;OS2SS-		$StrucErr <leave outside a loop>
;OS2SS-		exitm
;OS2SS-	endif
;OS2SS-	$leavefound = 1
;OS2SS-	$peek	$temp,%$st
;OS2SS-	if	$temp eq $conjleave
;OS2SS-		$pop		$temp
;OS2SS-	else
;OS2SS-		$orfound = 0
;OS2SS-		$sn = $sn + 1
;OS2SS-	endif
;OS2SS-	$dist	= 0
;OS2SS-	$getdist <a1>
;OS2SS-	if	$dist
;OS2SS-		$cjump %$endloop
;OS2SS-		if	$orfound
;OS2SS-			$labl %$sn
;OS2SS-		endif
;OS2SS-	else
;OS2SS-		$dist	= $defdist
;OS2SS-		$getdist p2,p3
;OS2SS-		$getconj p2,p3
;OS2SS-
;OS2SS-		if	$andor eq $noconj
;OS2SS-			ifb	<a1>
;OS2SS-				$cjump	%$endloop,t
;OS2SS-			else
;OS2SS-				$test <$endloop,t>,<a1>,<a2>,<a3>,<a4>,<x1>
;OS2SS-			endif
;OS2SS-			if	$orfound
;OS2SS-				$labl %$sn
;OS2SS-			endif
;OS2SS-		else
;OS2SS-			if	$andor eq $and
;OS2SS-				$orfound = 1
;OS2SS-				$test  <$sn,f>,<a1>,<a2>,<a3>,<a4>,<x1>
;OS2SS-			else
;OS2SS-				$test  <$endloop,t>,<a1>,<a2>,<a3>,<a4>,<x1>
;OS2SS-			endif
;OS2SS-			$push $conjleave
;OS2SS-		endif
;OS2SS-	endif
;OS2SS-endm
;;*****************************************************************************
else
	$pop	 $temp
	if	 $temp ne $notype
		 $StrucErr <open structure(s)>
	endif
.xcref $noconj,$and,$or,$short,$near,$andor,$temp,$temp2,$dist
.xcref $notype,$conjif,$iftype,$elsetype,$whiletype,$conjwhile
.xcref $repeattype,$conjuntil,$fortype,$conjleave,jncxz
.xcref jeq,jgt,jlt,jneq,jngt,jnlt,jnna,jnnae,jnnb,jnnbe,jnnc,jnncxz
.xcref jnne,jnng,jnnge,jnnl,jnnle,jnno,jnnp,jnns,jnnz,jnpe,jnpo,jbuild
.xcref $getconj,$getdist,$poke,$peek,$push,$pop,$labl,$cjump,$cloop,$test
;OS2SS-.xcref $toptest,$leave_2,$until_2,$strucerr,j,jn,jand,jnand,jnnand
.xcref $toptest,$strucerr,j,jn,jand,jnand,jnnand
.xcref jnnonzero,jnonzero,jnzero,jzero
.xcref $st,$sn,$orfound,$elseiffound,$endloop,$leavefound,$defdist
endif
$st		= 0
$sn		= 0
$orfound	= 0
$elseiffound	= 0
$endloop	= 0
$leavefound	= 0
$defdist	= $short
$push	%$notype