66# Copyleft (k) 2008, by Jose M. Rodriguez-Rosa
77# (a.k.a. Boriel, http://www.boriel.com)
88#
9- # This module contains 8 bit boolean, arithmetic and
9+ # This module contains float (FP) boolean, arithmetic and
1010# comparison intermediate-code translations
1111# --------------------------------------------------------------
1212
1313from typing import List
1414
15- from .common import is_float , _f_ops , is_int , runtime_call
16- from .runtime import Labels as RuntimeLabel
17- from .runtime import RUNTIME_LABELS
15+ from src .arch .z80 .backend .common import is_float , _f_ops , is_int , runtime_call , Quad
16+ from src .arch .z80 .backend .runtime import Labels as RuntimeLabel , RUNTIME_LABELS
1817
1918# -----------------------------------------------------
2019# Floating Point operators
@@ -29,21 +28,25 @@ def _float(op):
2928 return fp .immediate_float (float (op ))
3029
3130
32- def _fpop ():
31+ def _fpop () -> List [ str ] :
3332 """Returns the pop sequence of a float"""
34- output = ["pop af" , "pop de" , "pop bc" ]
35-
36- return output
33+ return [
34+ "pop af" ,
35+ "pop de" ,
36+ "pop bc" ,
37+ ]
3738
3839
39- def _fpush ():
40+ def _fpush () -> List [ str ] :
4041 """Returns the push sequence of a float"""
41- output = ["push bc" , "push de" , "push af" ]
42-
43- return output
42+ return [
43+ "push bc" ,
44+ "push de" ,
45+ "push af" ,
46+ ]
4447
4548
46- def _float_oper (op1 , op2 = None ):
49+ def _float_oper (op1 , op2 = None ) -> List [ str ] :
4750 """Returns pop sequence for floating point operands
4851 1st operand in A DE BC, 2nd operand remains in the stack
4952
@@ -137,7 +140,7 @@ def _float_oper(op1, op2=None):
137140# -----------------------------------------------------
138141
139142
140- def __float_binary (ins , label : str ) -> List [str ]:
143+ def __float_binary (ins : Quad , label : str ) -> List [str ]:
141144 assert label in RUNTIME_LABELS
142145
143146 op1 , op2 = tuple (ins .quad [2 :])
@@ -147,7 +150,7 @@ def __float_binary(ins, label: str) -> List[str]:
147150 return output
148151
149152
150- def _addf (ins ) :
153+ def _addf (ins : Quad ) -> List [ str ] :
151154 """Add 2 float values. The result is pushed onto the stack."""
152155 op1 , op2 = tuple (ins .quad [2 :])
153156
@@ -162,7 +165,7 @@ def _addf(ins):
162165 return __float_binary (ins , RuntimeLabel .ADDF )
163166
164167
165- def _subf (ins ) :
168+ def _subf (ins : Quad ) -> List [ str ] :
166169 """Subtract 2 float values. The result is pushed onto the stack."""
167170 op1 , op2 = tuple (ins .quad [2 :])
168171
@@ -175,7 +178,7 @@ def _subf(ins):
175178 return __float_binary (ins , RuntimeLabel .SUBF )
176179
177180
178- def _mulf (ins ) :
181+ def _mulf (ins : Quad ) -> List [ str ] :
179182 """Multiply 2 float values. The result is pushed onto the stack."""
180183 op1 , op2 = tuple (ins .quad [2 :])
181184
@@ -190,7 +193,7 @@ def _mulf(ins):
190193 return __float_binary (ins , RuntimeLabel .MULF )
191194
192195
193- def _divf (ins ) :
196+ def _divf (ins : Quad ) -> List [ str ] :
194197 """Divide 2 float values. The result is pushed onto the stack."""
195198 op1 , op2 = tuple (ins .quad [2 :])
196199
@@ -203,12 +206,12 @@ def _divf(ins):
203206 return __float_binary (ins , RuntimeLabel .DIVF )
204207
205208
206- def _modf (ins ) :
209+ def _modf (ins : Quad ) -> List [ str ] :
207210 """Reminder of div. 2 float values. The result is pushed onto the stack."""
208211 return __float_binary (ins , RuntimeLabel .MODF )
209212
210213
211- def _powf (ins ) :
214+ def _powf (ins : Quad ) -> List [ str ] :
212215 """Exponentiation of 2 float values. The result is pushed onto the stack."""
213216 op1 , op2 = tuple (ins .quad [2 :])
214217
@@ -230,7 +233,7 @@ def __bool_binary(ins, label: str) -> List[str]:
230233 return output
231234
232235
233- def _ltf (ins ) :
236+ def _ltf (ins : Quad ) -> List [ str ] :
234237 """Compares & pops top 2 operands out of the stack, and checks
235238 if the 1st operand < 2nd operand (top of the stack).
236239 Pushes 0 if False, 1 if True.
@@ -240,7 +243,7 @@ def _ltf(ins):
240243 return __bool_binary (ins , RuntimeLabel .LTF )
241244
242245
243- def _gtf (ins ) :
246+ def _gtf (ins : Quad ) -> List [ str ] :
244247 """Compares & pops top 2 operands out of the stack, and checks
245248 if the 1st operand > 2nd operand (top of the stack).
246249 Pushes 0 if False, 1 if True.
@@ -250,7 +253,7 @@ def _gtf(ins):
250253 return __bool_binary (ins , RuntimeLabel .GTF )
251254
252255
253- def _lef (ins ) :
256+ def _lef (ins : Quad ) -> List [ str ] :
254257 """Compares & pops top 2 operands out of the stack, and checks
255258 if the 1st operand <= 2nd operand (top of the stack).
256259 Pushes 0 if False, 1 if True.
@@ -260,7 +263,7 @@ def _lef(ins):
260263 return __bool_binary (ins , RuntimeLabel .LEF )
261264
262265
263- def _gef (ins ) :
266+ def _gef (ins : Quad ) -> List [ str ] :
264267 """Compares & pops top 2 operands out of the stack, and checks
265268 if the 1st operand >= 2nd operand (top of the stack).
266269 Pushes 0 if False, 1 if True.
@@ -270,7 +273,7 @@ def _gef(ins):
270273 return __bool_binary (ins , RuntimeLabel .GEF )
271274
272275
273- def _eqf (ins ) :
276+ def _eqf (ins : Quad ) -> List [ str ] :
274277 """Compares & pops top 2 operands out of the stack, and checks
275278 if the 1st operand == 2nd operand (top of the stack).
276279 Pushes 0 if False, 1 if True.
@@ -280,7 +283,7 @@ def _eqf(ins):
280283 return __bool_binary (ins , RuntimeLabel .EQF )
281284
282285
283- def _nef (ins ) :
286+ def _nef (ins : Quad ) -> List [ str ] :
284287 """Compares & pops top 2 operands out of the stack, and checks
285288 if the 1st operand != 2nd operand (top of the stack).
286289 Pushes 0 if False, 1 if True.
@@ -290,7 +293,7 @@ def _nef(ins):
290293 return __bool_binary (ins , RuntimeLabel .NEF )
291294
292295
293- def _orf (ins ) :
296+ def _orf (ins : Quad ) -> List [ str ] :
294297 """Compares & pops top 2 operands out of the stack, and checks
295298 if the 1st operand || 2nd operand (top of the stack).
296299 Pushes 0 if False, 1 if True.
@@ -300,7 +303,7 @@ def _orf(ins):
300303 return __bool_binary (ins , RuntimeLabel .ORF )
301304
302305
303- def _xorf (ins ) :
306+ def _xorf (ins : Quad ) -> List [ str ] :
304307 """Compares & pops top 2 operands out of the stack, and checks
305308 if the 1st operand ~~ 2nd operand (top of the stack).
306309 Pushes 0 if False, 1 if True.
@@ -310,7 +313,7 @@ def _xorf(ins):
310313 return __bool_binary (ins , RuntimeLabel .XORF )
311314
312315
313- def _andf (ins ) :
316+ def _andf (ins : Quad ) -> List [ str ] :
314317 """Compares & pops top 2 operands out of the stack, and checks
315318 if the 1st operand && 2nd operand (top of the stack).
316319 Pushes 0 if False, 1 if True.
@@ -320,31 +323,31 @@ def _andf(ins):
320323 return __bool_binary (ins , RuntimeLabel .ANDF )
321324
322325
323- def _notf (ins ) :
326+ def _notf (ins : Quad ) -> List [ str ] :
324327 """Negates top of the stack (48 bits)"""
325328 output = _float_oper (ins .quad [2 ])
326329 output .append (runtime_call (RuntimeLabel .NOTF ))
327330 output .append ("push af" )
328331 return output
329332
330333
331- def _negf (ins ) :
334+ def _negf (ins : Quad ) -> List [ str ] :
332335 """Changes sign of top of the stack (48 bits)"""
333336 output = _float_oper (ins .quad [2 ])
334337 output .append (runtime_call (RuntimeLabel .NEGF ))
335338 output .extend (_fpush ())
336339 return output
337340
338341
339- def _absf (ins ) :
342+ def _absf (ins : Quad ) -> List [ str ] :
340343 """Absolute value of top of the stack (48 bits)"""
341344 output = _float_oper (ins .quad [2 ])
342345 output .append ("res 7, e" ) # Just resets the sign bit!
343346 output .extend (_fpush ())
344347 return output
345348
346349
347- def _loadf (ins ) :
350+ def _loadf (ins : Quad ) -> List [ str ] :
348351 """Loads a floating point value from a memory address.
349352 If 2nd arg. start with '*', it is always treated as
350353 an indirect value.
@@ -354,7 +357,7 @@ def _loadf(ins):
354357 return output
355358
356359
357- def _storef (ins ) :
360+ def _storef (ins : Quad ) -> List [ str ] :
358361 """Stores a floating point value into a memory address."""
359362 output = _float_oper (ins .quad [2 ])
360363
@@ -388,7 +391,7 @@ def _storef(ins):
388391 return output
389392
390393
391- def _jzerof (ins ) :
394+ def _jzerof (ins : Quad ) -> List [ str ] :
392395 """Jumps if top of the stack (40bit, float) is 0 to arg(1)"""
393396 value = ins .quad [1 ]
394397 if is_float (value ):
@@ -407,7 +410,7 @@ def _jzerof(ins):
407410 return output
408411
409412
410- def _jnzerof (ins ) :
413+ def _jnzerof (ins : Quad ) -> List [ str ] :
411414 """Jumps if top of the stack (40bit, float) is != 0 to arg(1)"""
412415 value = ins .quad [1 ]
413416 if is_float (value ):
@@ -426,7 +429,7 @@ def _jnzerof(ins):
426429 return output
427430
428431
429- def _jgezerof (ins ) :
432+ def _jgezerof (ins : Quad ) -> List [ str ] :
430433 """Jumps if top of the stack (40bit, float) is >= 0 to arg(1)"""
431434 value = ins .quad [1 ]
432435 if is_float (value ):
@@ -440,22 +443,22 @@ def _jgezerof(ins):
440443 return output
441444
442445
443- def _retf (ins ) :
446+ def _retf (ins : Quad ) -> List [ str ] :
444447 """Returns from a procedure / function a Floating Point (40bits) value"""
445448 output = _float_oper (ins .quad [1 ])
446449 output .append ("#pragma opt require a,bc,de" )
447450 output .append ("jp %s" % str (ins .quad [2 ]))
448451 return output
449452
450453
451- def _paramf (ins ) :
454+ def _paramf (ins : Quad ) -> List [ str ] :
452455 """Pushes 40bit (float) param into the stack"""
453456 output = _float_oper (ins .quad [1 ])
454457 output .extend (_fpush ())
455458 return output
456459
457460
458- def _fparamf (ins ) :
461+ def _fparamf (ins : Quad ) -> List [ str ] :
459462 """Passes a floating point as a __FASTCALL__ parameter.
460463 This is done by popping out of the stack for a
461464 value, or by loading it from memory (indirect)
0 commit comments