22# -*- coding: utf-8 -*-
33# vim: ts=4:et:sw=4
44
5- from src .libzxbasm .z80 import Opcode , Z80SET
5+ from src .libzxbasm .z80 import Z80SET
66from src .api .errors import Error
77import re
88
99# Reg. Exp. for counting N args in an asm mnemonic
1010ARGre = re .compile (r'\bN+\b' )
1111
12- Z80_re = {} # Reg. Expr dictionary to cache them
13-
1412Z80_8REGS = ('A' , 'B' , 'C' , 'D' , 'E' , 'H' , 'L' ,
1513 'IXh' , 'IYh' , 'IXl' , 'IYl' , 'I' , 'R' )
1614
2018 }
2119
2220
23- def num2bytes (x , bytes ):
21+ def num2bytes (x , bytes_ ):
2422 """ Returns x converted to a little-endian t-uple of bytes.
2523 E.g. num2bytes(255, 4) = (255, 0, 0, 0)
2624 """
2725 if not isinstance (x , int ): # If it is another "thing", just return ZEROs
28- return tuple ([0 ] * bytes )
26+ return tuple ([0 ] * bytes_ )
2927
30- x = x & ((2 << (bytes * 8 )) - 1 ) # mask the initial value
28+ x = x & ((2 << (bytes_ * 8 )) - 1 ) # mask the initial value
3129 result = ()
3230
33- for i in range (bytes ):
31+ for i in range (bytes_ ):
3432 result += (x & 0xFF ,)
3533 x >>= 8
3634
@@ -70,10 +68,9 @@ def __init__(self, current_size, asm):
7068 self .asm = asm
7169
7270
73- class AsmInstruction ( Opcode ) :
71+ class AsmInstruction :
7472 """ Derives from Opcode. This one checks for opcode validity.
7573 """
76-
7774 def __init__ (self , asm , arg = None ):
7875 """ Parses the given asm instruction and validates
7976 it against the Z80SET table. Raises InvalidMnemonicError
@@ -98,10 +95,11 @@ def __init__(self, asm, arg=None):
9895 self .comments = ''
9996
10097 asm = asm [0 ]
101- if asm .upper () not in Z80SET .keys ():
102- raise InvalidMnemonicError (asm )
10398
10499 self .mnemo = asm .upper ()
100+ if self .mnemo not in Z80SET .keys ():
101+ raise InvalidMnemonicError (asm )
102+
105103 Z80 = Z80SET [self .mnemo ]
106104
107105 self .asm = asm
@@ -125,7 +123,7 @@ def argval(self):
125123
126124 return self .arg
127125
128- def bytes (self ):
126+ def bytes (self ) -> bytearray :
129127 """ Returns a t-uple with instruction bytes (integers)
130128 """
131129 result = []
@@ -147,7 +145,7 @@ def bytes(self):
147145 if len (result ) != self .size :
148146 raise InternalMismatchSizeError (len (result ), self )
149147
150- return result
148+ return bytearray ( result )
151149
152150 def __str__ (self ):
153151 return self .asm
0 commit comments