diff --git a/porth.py b/porth.py index 5750ffa2..d51ec5ed 100755 --- a/porth.py +++ b/porth.py @@ -4,6 +4,7 @@ import sys import subprocess import shlex +import platform from os import path from typing import * from enum import Enum, auto @@ -955,14 +956,23 @@ def usage(compiler_name: str): basename = basename[:-len(porth_ext)] basedir = path.dirname(program_path) basepath = path.join(basedir, basename) - + print(f"{basepath=} {basedir=} {basename=}") print("[INFO] Generating %s" % (basepath + ".asm")) program = compile_file_to_program(program_path, include_paths); generate_nasm_linux_x86_64(program, basepath + ".asm") - cmd_call_echoed(["nasm", "-felf64", basepath + ".asm"]) - cmd_call_echoed(["ld", "-o", basepath, basepath + ".o"]) + if platform.system() == "Windows": # Pseudo Windows 10/11 support, requiring a wsl(version irelevant) installation with nasm and ld (gnu binutils) install on the default Distro + win_basepath = basepath.replace("\\", "/") + cmd_call_echoed(["wsl", "nasm", "-felf64", win_basepath + ".asm"]) + cmd_call_echoed(["wsl", "ld", "-o", win_basepath, win_basepath + ".o"]) + else: + cmd_call_echoed(["nasm", "-felf64", basepath + ".asm"]) + cmd_call_echoed(["ld", "-o", basepath, basepath + ".o"]) if run: - exit(cmd_call_echoed([basepath] + argv)) + if platform.system() == "Windows": # Pseudo Windows 10/11 support, requiring a wsl(version irelevant) installation with nasm and ld (gnu binutils) install on the default Distro + win_basepath = basepath.replace("\\", "/") + exit(cmd_call_echoed(["wsl", win_basepath] + argv)) + else: + exit(cmd_call_echoed([basepath] + argv)) elif subcommand == "help": usage(compiler_name) exit(0) diff --git a/test.py b/test.py index 074a0ef9..30920a8c 100755 --- a/test.py +++ b/test.py @@ -4,6 +4,7 @@ import os import subprocess import shlex +import platform def cmd_run_echoed(cmd, **kwargs): print("[CMD] %s" % " ".join(map(shlex.quote, cmd))) @@ -26,8 +27,10 @@ def test(folder): expected_output = None with open(txt_path, "rb") as f: expected_output = f.read() - - sim_output = cmd_run_echoed(["./porth.py", "sim", entry.path], capture_output=True).stdout + if platform.system() == "Windows": + sim_output = cmd_run_echoed(["wsl", "python3", "./porth.py", "sim", entry.path], capture_output=True).stdout.replace(b"\r\n", b"\n") # TODO: remove this dirty replace hack, it is needed since windows converts \n to \r\n + else: + sim_output = cmd_run_echoed(["./porth.py", "sim", entry.path], capture_output=True).stdout if sim_output != expected_output: sim_failed += 1 print("[ERROR] Unexpected simulation output") @@ -37,8 +40,12 @@ def test(folder): print(" %s" % sim_output) # exit(1) - cmd_run_echoed(["./porth.py", "com", entry.path]) - com_output = cmd_run_echoed([entry.path[:-len(porth_ext)]], capture_output=True).stdout + if platform.system() == "Windows": + cmd_run_echoed(["python", "./porth.py", "com", entry.path]) + com_output = cmd_run_echoed(["wsl", entry.path[:-len(porth_ext)]], capture_output=True).stdout.replace(b"\r\n", b"\n") # TODO: remove this dirty replace hack, it is needed since windows converts \n to \r\n + else: + cmd_run_echoed(["./porth.py", "com", entry.path]) + com_output = cmd_run_echoed([entry.path[:-len(porth_ext)]], capture_output=True).stdout if com_output != expected_output: com_failed += 1 print("[ERROR] Unexpected compilation output") @@ -56,7 +63,10 @@ def record(folder): for entry in os.scandir(folder): porth_ext = '.porth' if entry.is_file() and entry.path.endswith(porth_ext): - sim_output = cmd_run_echoed(["./porth.py", "sim", entry.path], capture_output=True).stdout + if platform.system() == "Windows": + sim_output = cmd_run_echoed(["python", "./porth.py", "sim", entry.path], capture_output=True).stdout.replace(b"\r\n", b"\n") # TODO: remove this dirty replace hack, it is needed since windows converts \n to \r\n + else: + sim_output = cmd_run_echoed(["./porth.py", "sim", entry.path], capture_output=True).stdout txt_path = entry.path[:-len(porth_ext)] + ".txt" print("[INFO] Saving output to %s" % txt_path) with open(txt_path, "wb") as txt_file: