Прикреплённый файл «mmlabel.py»

Загрузка

   1 #!/usr/bin/env python3
   2 import sys
   3 from pathlib import Path
   4 
   5 
   6 def annotate(text, labels={}, cellsize=56):
   7     address, prog = 0, False
   8     for line in text.split('\n'):
   9         length, words = 0, line.split(';')[0].split()
  10         match words:
  11             case ['.code']:
  12                 prog = True
  13             case ['.code', addr]:
  14                 prog = True
  15                 address = eval(addr)
  16             case [directive, *_] if directive.startswith('.'):
  17                 prog = False
  18             case [label, *cells] if prog:
  19                 if label.startswith('_'):
  20                     labels[label] = address
  21                     length = len("".join(cells))
  22                     line = " " * len(label) + line[len(label):]
  23                 else:
  24                     length = len("".join(words))
  25         yield address, prog, line
  26         address += length * 4 // cellsize
  27 
  28 
  29 def replace(annotext, labels, asize=4):
  30     for addr, prog, line in ann:
  31         words = line.split(";")
  32         if words:
  33             for label, address in labels.items():
  34                 words[0] = words[0].replace(label, f"{address:0{asize}x}")
  35         yield ";".join(words)
  36 
  37 
  38 if __name__ == "__main__":
  39     labels = {}
  40     if len(sys.argv) > 1:
  41         source = Path(sys.argv[1]).read_text()
  42     else:
  43         source = sys.stdin.read()
  44     if '.mm-3' in source:
  45         cellsize = 56
  46     elif '.mm-2' in source:
  47         cellsize = 40
  48     elif '.mm-1' in source:
  49         cellsize = 24
  50     elif '.mm-m' in source or 'mm-r' in source:
  51         cellsize = 16
  52     else:
  53         cellsize = 8
  54 
  55     ann = [*annotate(source, labels, cellsize)]
  56     res = "\n".join(replace(ann, labels, 4))
  57     if len(sys.argv) > 2:
  58         Path(sys.argv[2]).write_text(res)
  59     else:
  60         sys.stdout.write(res)
  61     if len(sys.argv) > 3:
  62         print(labels, file=sys.stderr)

Прикреплённые файлы

Для ссылки на прикреплённый файл в тексте страницы напишите attachment:имяфайла, как показано ниже в списке файлов. Не используйте URL из ссылки «[получить]», так как он чисто внутренний и может измениться.
 Все файлы | Выбранные файлы: удалить переместить на страницу скопировать на страницу

Вам нельзя прикреплять файлы к этой странице.