Просмотр исходного кода

Fixed assembly int 2 bytes

Now separated to 2 types of integers, signed and unsigned.
Min 6 лет назад
Родитель
Сommit
c0c6784846
1 измененных файлов с 15 добавлено и 6 удалено
  1. 15 6
      tools/asm_compiler.py

+ 15 - 6
tools/asm_compiler.py

@@ -13,6 +13,8 @@ args_re = re.compile("(?:^|,)(?=[^\"]|(\")?)\"?((?(1)[^\"]*|[^,\"]*))\"?(?=,|$)"
 func_re = re.compile("^([\w$#@~.?]+)\s*([|^<>+\-*/%@]{1,2})\s*([\w$#@~.?]+)$", re.IGNORECASE)
 func_re = re.compile("^([\w$#@~.?]+)\s*([|^<>+\-*/%@]{1,2})\s*([\w$#@~.?]+)$", re.IGNORECASE)
 secs_re = re.compile("^([\d]+)x([\d]+)x([\d]+)$", re.IGNORECASE)
 secs_re = re.compile("^([\d]+)x([\d]+)x([\d]+)$", re.IGNORECASE)
 
 
+MAX_INT_BYTES = 12
+
 def args2operands(args):
 def args2operands(args):
     operands = ['"' + a[1] + '"' if a[0] == '"' else a[1] for a in args_re.findall(args or '') if a[1]]
     operands = ['"' + a[1] + '"' if a[0] == '"' else a[1] for a in args_re.findall(args or '') if a[1]]
     return operands
     return operands
@@ -120,14 +122,16 @@ class Compiler:
         s = s.strip()
         s = s.strip()
         typ = ""
         typ = ""
         # Decimal numbers
         # Decimal numbers
-        if s.isnumeric():
+        if (s.startswith('+') or s.startswith('-')) and s[1:].isnumeric():
             typ = 'int'
             typ = 'int'
+        elif s.isnumeric():
+            typ = 'uint'
         elif s.endswith('d') and s[:-1].isnumeric():
         elif s.endswith('d') and s[:-1].isnumeric():
             s = s[:-1]
             s = s[:-1]
-            typ = 'int'
+            typ = 'uint'
         elif s.startswith('0d') and s[2:].isnumeric():
         elif s.startswith('0d') and s[2:].isnumeric():
             s = s[2:]
             s = s[2:]
-            typ = 'int'
+            typ = 'uint'
 
 
         # Hexadecimal numbers
         # Hexadecimal numbers
         elif s.startswith('0') and s.endswith('h') and match(hex_re, s[1:-1]):
         elif s.startswith('0') and s.endswith('h') and match(hex_re, s[1:-1]):
@@ -164,10 +168,15 @@ class Compiler:
             typ = 'string'
             typ = 'string'
 
 
         # Convert with limits
         # Convert with limits
-        if typ == 'int':
+        if typ == 'uint':
             numb = int(s)
             numb = int(s)
-            for i in range(1, 9):
-                if -2 ** (i * 7) < i < 2 ** (i * 8):
+            for i in range(1, MAX_INT_BYTES+1):
+                if numb < 2 ** (i * 8):
+                    return numb.to_bytes(i, self.order)
+        elif typ == 'int':
+            numb = int(s)
+            for i in range(1, MAX_INT_BYTES+1):
+                if -2 ** (i * 7) < numb < 2 ** (i * 7):
                     return numb.to_bytes(i, self.order)
                     return numb.to_bytes(i, self.order)
         elif typ == 'hex':
         elif typ == 'hex':
             numb = int(s, 16)
             numb = int(s, 16)