aboutsummaryrefslogtreecommitdiffstats
path: root/src/asm_pass0.py
blob: a0ae56d500a8bb7fa29fef903fd01d26aff2ab33 (plain)
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
from dataclasses import dataclass
import os.path
from asm_ops import *
from asm_eval import *

@dataclass
class Result0Line:
  line_num: int
  src_file: str
  line: str

@dataclass
class Result0:
  lines: list[Result0Line]
  options: Options
  operations: OpExpansionDict

def pass_0(lines: list[str], file_name: str) -> Result0:
  options = Options()
  result_lines: list[Result0Line] = []
  operations: OpExpansionDict = default_expansions.copy()

  for (line_num, line) in enumerate(lines):
    line = line.split(";")[0].strip()
    if line == "": continue
    keyword, *args = line.lower().split()
    match keyword:
      case "@include":
        asm_file_name = args[0]
        path = os.path.join(os.path.dirname(file_name), asm_file_name + ".atk16")
        with open(path, "r") as f:
          for incl_line in f.readlines():
            result_lines.append(Result0Line(
              src_file=asm_file_name,
              line_num=line_num,
              line=incl_line
            ))

      case _:
        result_lines.append(Result0Line(
          src_file=file_name,
          line_num=line_num,
          line=line
        ))

  return Result0(
    operations=operations,
    options=options,
    lines=result_lines
  )