|
11 | 11 |
|
12 | 12 | import os |
13 | 13 | import re |
14 | | -import sys |
15 | 14 | from pathlib import Path |
16 | 15 | from typing import TextIO |
17 | 16 |
|
18 | 17 | # regex for exported labels |
19 | 18 | export_re = re.compile(r"^\s*Export_(\w+)\s*:\s*(;.*)?$") |
20 | 19 |
|
21 | 20 |
|
| 21 | +PAGE2_BEGIN = """ |
| 22 | +.section page2 |
| 23 | +.logical * + $2000 |
| 24 | +""" |
| 25 | + |
| 26 | +PAGE2_END = """ |
| 27 | +.endlogical |
| 28 | +.send page2 |
| 29 | +""" |
| 30 | + |
| 31 | + |
22 | 32 | def main(*, module_name: str, build_dir: Path, page: int = 1) -> None: |
23 | 33 | """Generate a single assembly build file for the specified module.""" |
24 | 34 | if not build_dir.exists(): |
@@ -59,26 +69,28 @@ def process_source(path: Path, out: TextIO, *, page: int = 1) -> list[str]: |
59 | 69 | if page == 2: |
60 | 70 | normalized = " ".join(line.split()) |
61 | 71 | if normalized == ".section code": |
62 | | - out.write("\t\t.section page2\n") |
63 | | - out.write("\t\t.logical * + $2000\n") |
| 72 | + out.write(PAGE2_BEGIN) |
64 | 73 | continue |
65 | 74 | elif normalized == ".send code": |
66 | | - out.write("\t\t.here\n") |
67 | | - out.write("\t\t.send page2\n") |
| 75 | + out.write(PAGE2_END) |
68 | 76 | continue |
69 | 77 |
|
70 | 78 | out.write(f"{line.rstrip()}\n") |
71 | 79 |
|
72 | 80 | return exports |
73 | 81 |
|
74 | 82 |
|
75 | | -def dump_exports(build_dir: Path, module_name: str, exports: list[str], *, page: int = 1) -> None: |
| 83 | +def dump_exports( |
| 84 | + build_dir: Path, module_name: str, exports: list[str], *, page: int = 1 |
| 85 | +) -> None: |
76 | 86 | """Save module exports to the corresponding `.exports` file.""" |
77 | 87 | if not exports: |
78 | 88 | return |
79 | 89 |
|
80 | 90 | suffix = "_p2" if page == 2 else "" |
81 | | - with open(build_dir / (module_name + suffix + ".exports"), "w", encoding="utf-8") as out: |
| 91 | + with open( |
| 92 | + build_dir / (module_name + suffix + ".exports"), "w", encoding="utf-8" |
| 93 | + ) as out: |
82 | 94 | for export in exports: |
83 | 95 | out.write(f"{export}\n") |
84 | 96 |
|
@@ -109,8 +121,12 @@ def collect_sources(module_name: str) -> list[Path]: |
109 | 121 |
|
110 | 122 | parser = argparse.ArgumentParser(description="Build module assembly file") |
111 | 123 | parser.add_argument("module_name", help="Name of the module to build") |
112 | | - parser.add_argument("build_dir", nargs="?", default=".build", help="Build output directory") |
113 | | - parser.add_argument("--page", type=int, default=1, choices=[1, 2], help="Module page (1 or 2)") |
| 124 | + parser.add_argument( |
| 125 | + "build_dir", nargs="?", default=".build", help="Build output directory" |
| 126 | + ) |
| 127 | + parser.add_argument( |
| 128 | + "--page", type=int, default=1, choices=[1, 2], help="Module page (1 or 2)" |
| 129 | + ) |
114 | 130 | args = parser.parse_args() |
115 | 131 |
|
116 | 132 | main( |
|
0 commit comments