From 8b5ccf4edc630c64483ad931f6c58ea87b5f0135 Mon Sep 17 00:00:00 2001 From: igor Date: Fri, 19 Dec 2025 15:48:42 +0100 Subject: [PATCH] commit --- a.out | Bin 9128 -> 0 bytes main.py | 29 ++++++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) delete mode 100755 a.out diff --git a/a.out b/a.out deleted file mode 100755 index 692068c06232a80da3913784ee2f2a7e6dea0e98..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 9128 zcmeI2U2GKB700iQ7Yt6an?Q)wLbX9lHA2{>F{AZlyL5r@ldbf_dGm!y+@tZ@mTY@iqv*-_ z#OqC6fw}^91?mda6{ssvSD>yyU4gm+bp`4Q)D`%DRKOTr`F*&7CEU-9(L25lH?m3r z{=6PTDH7dRoMye$6w^m0n>BZOYy-e>2#FRx#B{eQRxV4sURoC0KM%*7m_G7lbI?j7 z3j!H%>qPy1#uDjb}ky%EZWZ>+L(g?P@FdkC)KpD03R|(plxQ6YSYuKK@hV8j)*q-%mT1ga$w|mUX z1*xD0H1{KIu+KH5*M`_w zizrB;;|9*DNNe@jHxWK?RNHqpeBc;V?g{ugt=;-A9_oMhTj={~7-s@zPxvKp~n z6xJpNv9R|49Vl-Y0Oh;E6MoCvhYvTt?LRMkb07mmn2e0!2Uwarqjg-=I!?oL=N{8W zzGLCX_X5}5iLqvA4R;#s44#gI&dU9(1YOQ+o zi)B!N8Wh3Ig+0droZP<@D1?JYs(4O^<8l^q=Q{vTHQlfXnm{)08@hYma8L47mOvFa zRN$CC?Ewk|PYdM1QkMNT=vQ96RIOItgYuFTr^!BgS8l@FYXJ`!vvOtI6`1&2xJhTk zmAwIgkt%;cx6Qan0(%#dP zoWfg(vzy|4ro1g7zD(g!;_DQ?iuhKAuOs@XE5sjD z_yyu+g*W5xUC`kZh2KJa-qPCqqr`7h_^LVhUBr78|2Xmc6uyOcPT?uyuEMj#-&c5% zbJ%pWHveId_u$68>rZp=KYP5_^Tp27bMU_t-xIC%KLk7iI?Ml0mBC)-e0H8k=HLg3 ztMOT?Xl2uP4kWEyd$KUV%z~4&o%USb%vqSW3kEM%) z0;TOd_3}G2wqS*!Br!Yh2xNAGBlU9@S)F3v!@}I@#X~cR19&|%1C?Z& zsRHH?Pbo7q>7MZP%x$M&Z%AAdD^-`$Y^4vdJv z-uFCc9l|tX>{jUEUrg{i5|@0>M#a$kz6Y7r`M5T`^=4hIw+Ixa@0;LvSv2^;weV^c n4a1KjytRp8v+ieNFsT@Ez2J2t3=|h`zJeQr>o(DNcXj>`0hVL| diff --git a/main.py b/main.py index 25b4950..67d7f71 100644 --- a/main.py +++ b/main.py @@ -15,6 +15,7 @@ import ctypes import mmap import subprocess import sys +import shutil import textwrap from dataclasses import dataclass, field from pathlib import Path @@ -2292,7 +2293,6 @@ class Compiler: self.parser = Parser(self.dictionary, self.reader) self.assembler = Assembler(self.dictionary) - def compile_source(self, source: str) -> Emission: tokens = self.reader.tokenize(source) module = self.parser.parse(tokens, source) @@ -2344,14 +2344,32 @@ def run_linker(obj_path: Path, exe_path: Path, debug: bool = False) -> None: def cli(argv: Sequence[str]) -> int: parser = argparse.ArgumentParser(description="L2 compiler driver") - parser.add_argument("source", type=Path, help="input .sl file") + parser.add_argument("source", type=Path, nargs="?", default=None, help="input .sl file (optional when --clean is used)") parser.add_argument("-o", dest="output", type=Path, default=Path("a.out")) parser.add_argument("--emit-asm", action="store_true", help="stop after generating asm") parser.add_argument("--temp-dir", type=Path, default=Path("build")) parser.add_argument("--debug", action="store_true", help="compile with debug info") - + parser.add_argument("--run", action="store_true", help="run the built binary after successful build") + parser.add_argument("--dbg", action="store_true", help="launch gdb on the built binary after successful build") + parser.add_argument("--clean", action="store_true", help="remove the temp build directory and exit") + args = parser.parse_args(argv) + if args.clean: + try: + if args.temp_dir.exists(): + shutil.rmtree(args.temp_dir) + print(f"[info] removed {args.temp_dir}") + else: + print(f"[info] {args.temp_dir} does not exist") + except Exception as exc: + print(f"[error] failed to remove {args.temp_dir}: {exc}") + return 1 + return 0 + + if args.source is None: + parser.error("the following arguments are required: source") + compiler = Compiler() emission = compiler.compile_file(args.source) @@ -2367,6 +2385,11 @@ def cli(argv: Sequence[str]) -> int: run_nasm(asm_path, obj_path, debug=args.debug) run_linker(obj_path, args.output, debug=args.debug) print(f"[info] built {args.output}") + exe_path = Path(args.output).resolve() + if args.dbg: + subprocess.run(["gdb", str(exe_path)]) + elif args.run: + subprocess.run([str(exe_path)]) return 0