-
Notifications
You must be signed in to change notification settings - Fork 2
/
EXPCONDS.INC
184 lines (158 loc) · 7.5 KB
/
EXPCONDS.INC
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
; -[*]-----------------------------------------------------------------------
; Useful macros for F-Code for advanced executing control
; Version 1.0
; Copyright (c) 1996 by Alexander Demin
; ---------------------------------------------------------------------------
; ---------------------------------------------------------------------------
; Compile true conditional jump
; Warning: If Cond='@', compile the unconditional jump
;
TrueCondJumps MACRO Cond:REQ, Way:REQ
IfIdn <&Cond>, <EQ> ; =
ofJz &Way
ElseIfIdn <&Cond>, <NE> ; <>
ofJnz &Way
ElseIfIdn <&Cond>, <LE> ; <=
ofJle &Way
ElseIfIdn <&Cond>, <LT> ; <
ofJlt &Way
ElseIfIdn <&Cond>, <GE> ; >=
ofJge &Way
ElseIfIdn <&Cond>, <GT> ; >
ofJgt &Way
ElseIfIdn <&Cond>, <@> ; Jump
ofJmp &Way
Else ; Error in condition
Err "Incorrect condition &Cond"
EndIf
ENDM
; ---------------------------------------------------------------------------
; Compile inversed conditional jump
; Warning: If Cond='@', compile the unconditional jump
;
NotCondJumps MACRO Cond:REQ, Way:REQ
IfIdn <&Cond>, <EQ> ; =
ofJnz &Way
ElseIfIdn <&Cond>, <NE> ; <>
ofJz &Way
ElseIfIdn <&Cond>, <LE> ; <=
ofJgt &Way
ElseIfIdn <&Cond>, <LT> ; <
ofJge &Way
ElseIfIdn <&Cond>, <GE> ; >=
ofJlt &Way
ElseIfIdn <&Cond>, <GT> ; >
ofJle &Way
ElseIfIdn <&Cond>, <@> ; Jump
ofJmp &Way
Else ; Error in condition
Err "Incorrect condition &Cond"
EndIf
ENDM
; ---------------------------------------------------------------------------
; Start $If construction
$If MACRO Cond:REQ, IfCnt:REQ
Local Way
Way CatStr <@@if_>, <&IfCnt>
NotCondJumps Cond, Way ; Compile inversed
ENDM ; jump
; ---------------------------------------------------------------------------
; Make $Else way in $If contruction
$Else MACRO IfCnt:REQ
Local Way, ElseWay
Way CatStr <@@if_>, <&IfCnt>
ElseWay CatStr <@@else_>, <&IfCnt>
ofJmp &ElseWay
&Way: ENDM
; ---------------------------------------------------------------------------
; Finish $If construction
; If there was $Else-way -> Tag=1, otherwise -> Tag=0
$Endif MACRO IfCnt:REQ, Tag:REQ
Local Way
If Tag EQ 1 ; Is there $Else-way ?
Way CatStr <@@else_>, <&IfCnt> ; Finish $Else
Else
Way CatStr <@@if_>, <&IfCnt> ; Finish $If
EndIf
&Way: ENDM
; ---------------------------------------------------------------------------
; Start $Do construnction
$Do MACRO DoCnt:REQ
Local Way
Way CatStr <@@do_>, <&DoCnt>
&Way: ENDM
; ---------------------------------------------------------------------------
; Break $Do construction
$ExitDo MACRO Cond:REQ, DoCnt:REQ
Local Exit
Exit CatStr <@@exit_do_>, <&DoCnt>
TrueCondJumps Cond, Exit ; Compile conditional
ENDM ; jump
; ---------------------------------------------------------------------------
; Go to the next $Do iteration
$ContDo MACRO Cond:REQ, DoCnt:REQ
Local Cont
Cont CatStr <@@cont_do_>, <&DoCnt>
TrueCondJumps Cond, Cont ; Compile conditional
ENDM ; jump
; ---------------------------------------------------------------------------
; Finish $Do contruction
$EndDo MACRO Cond:REQ, DoCnt:REQ
Local Way, Cont, Exit
Way CatStr <@@do_>, <&DoCnt> ; Loop-label
Cont CatStr <@@cont_do_>, <&DoCnt> ; Continue-label
Exit CatStr <@@exit_do_>, <&DoCnt> ; Exit-label
&Cont: TrueCondJumps Cond, Way ; Compile conditional
&Exit: ENDM ; jump
; ---------------------------------------------------------------------------
; Start $For construnction
; Warning: When using format with non-blanked arguments, both arguments
; must be present
$For MACRO ForCnt:REQ, AStart, AEnd
Local Way
Way CatStr <@@for_>, <&ForCnt>
IfNB <&AStart> ; What's calling format ?
ofDo AStart, AEnd ; Immediate format
Else
osDo ; In-stack format
EndIf
&Way: ENDM
; ---------------------------------------------------------------------------
; Break $For construction
$ExitFor MACRO Cond:REQ, ForCnt:REQ
Local Exit
Exit CatStr <@@exit_for_>, <&ForCnt>
TrueCondJumps Cond, Exit
ENDM
; ---------------------------------------------------------------------------
; Go to the next $For iteration
$ContFor MACRO Cond:REQ, ForCnt:REQ
Local Cont
Cont CatStr <@@cont_for_>, <&ForCnt>
TrueCondJumps Cond, Cont
ENDM
; ---------------------------------------------------------------------------
; Finish $For construnction with Step
; Warning: If Delta is absent, Delta must be in the data-stack
$Step MACRO ForCnt:REQ, Delta
Local Way, Nearly, Cont, Exit
Cont CatStr <@@cont_for_>, <&ForCnt>
Exit CatStr <@@exit_for_>, <&ForCnt>
Way CatStr <@@for_>, <&ForCnt>
IfNB <&Delta> ; Is Delta present ?
&Cont: ofStep &Way, Delta
Else
&Cont: ofPush &Way ; Delta Addr
osSwap ; Addr Delta
osStep
EndIf
&Exit: ENDM
; ---------------------------------------------------------------------------
; Finish $For construction w/o Step
$Loop MACRO ForCnt:REQ
Local Way, Nearly, Cont, Exit
Cont CatStr <@@cont_for_>, <&ForCnt>
Exit CatStr <@@exit_for_>, <&ForCnt>
Way CatStr <@@for_>, <&ForCnt>
&Cont: ofLoop &Way
&Exit: ENDM