From 30825788e5dd71b274fd1fb7cb3f7fb356ebe6a9 Mon Sep 17 00:00:00 2001 From: Akuli Date: Wed, 6 Dec 2023 15:29:51 +0200 Subject: [PATCH] delete is_windows and is_macos functions --- self_hosted/bug_workaround.jou | 15 --------------- self_hosted/main.jou | 11 +++++------ self_hosted/paths.jou | 5 ++--- self_hosted/target.jou | 3 +-- tests/should_succeed/compiler_cli.jou | 26 ++++++-------------------- 5 files changed, 14 insertions(+), 46 deletions(-) delete mode 100644 self_hosted/bug_workaround.jou diff --git a/self_hosted/bug_workaround.jou b/self_hosted/bug_workaround.jou deleted file mode 100644 index bafb6e16..00000000 --- a/self_hosted/bug_workaround.jou +++ /dev/null @@ -1,15 +0,0 @@ -# TODO: delete this file - -if WINDOWS: - def is_windows() -> bool: - return True -else: - def is_windows() -> bool: - return False - -if MACOS: - def is_macos() -> bool: - return True -else: - def is_macos() -> bool: - return False diff --git a/self_hosted/main.jou b/self_hosted/main.jou index 889a4508..fd82e5ef 100644 --- a/self_hosted/main.jou +++ b/self_hosted/main.jou @@ -10,7 +10,6 @@ import "./target.jou" import "./create_llvm_ir.jou" import "./llvm.jou" import "./evaluate.jou" -import "./bug_workaround.jou" import "stdlib/mem.jou" import "stdlib/process.jou" import "stdlib/str.jou" @@ -173,7 +172,7 @@ class Compiler: def determine_automagic_files(self) -> void: self->automagic_files[0] = malloc(strlen(self->stdlib_path) + 40) sprintf(self->automagic_files[0], "%s/_assert_fail.jou", self->stdlib_path) - if is_windows(): + if WINDOWS: self->automagic_files[1] = malloc(strlen(self->stdlib_path) + 40) sprintf(self->automagic_files[1], "%s/_windows_startup.jou", self->stdlib_path) @@ -333,11 +332,11 @@ class Compiler: else: exe = strdup(self->args->output_file) - if is_windows() and not ends_with(exe, ".exe") and not ends_with(exe, ".EXE"): + if WINDOWS and not ends_with(exe, ".exe") and not ends_with(exe, ".EXE"): exe = realloc(exe, strlen(exe) + 10) strcat(exe, ".exe") - if is_windows(): + if WINDOWS: for i = 0; exe[i] != '\0'; i++: if exe[i] == '/': exe[i] = '\\' @@ -378,7 +377,7 @@ class Compiler: def link(self, object_files: byte**) -> byte*: exe = self->get_exe_file_path() - if is_windows(): + if WINDOWS: c_compiler = find_installation_directory() c_compiler = realloc(c_compiler, strlen(c_compiler) + 100) strcat(c_compiler, "\\mingw64\\bin\\gcc.exe") @@ -396,7 +395,7 @@ class Compiler: sprintf(&command[strlen(command)], " \"%s\"", object_files[i]) strcat(command, " -lm") - if is_windows(): + if WINDOWS: # windows strips outermost quotes for some reason, so let's quote it all one more time... memmove(&command[1], &command[0], strlen(command) + 1) command[0] = '"' diff --git a/self_hosted/paths.jou b/self_hosted/paths.jou index 7aaaa92c..30bf2fb6 100644 --- a/self_hosted/paths.jou +++ b/self_hosted/paths.jou @@ -2,7 +2,6 @@ import "stdlib/mem.jou" import "stdlib/str.jou" import "stdlib/io.jou" import "stdlib/process.jou" -import "./bug_workaround.jou" if WINDOWS: declare GetModuleFileNameA(hModule: void*, lpFilename: byte*, nSize: int) -> int @@ -79,7 +78,7 @@ def find_stdlib() -> byte*: memset(&checked, 0, sizeof checked) exedir = find_current_executable() - while is_windows() and strstr(exedir, "\\") != NULL: + while WINDOWS and strstr(exedir, "\\") != NULL: *strstr(exedir, "\\") = '/' for i = 0; i < sizeof checked / sizeof checked[0]; i++: @@ -136,7 +135,7 @@ def delete_slice(start: byte*, end: byte*) -> void: memmove(start, end, strlen(end) + 1) def simplify_path(path: byte*) -> void: - if is_windows(): + if WINDOWS: # Backslash to forward slash. for p = path; *p != '\0'; p++: if *p == '\\': diff --git a/self_hosted/target.jou b/self_hosted/target.jou index 8dbd7095..ec2b56a8 100644 --- a/self_hosted/target.jou +++ b/self_hosted/target.jou @@ -7,7 +7,6 @@ # will make the mess slightly less miserable to you. Just use the global # "target" variable, it contains everything you will ever need. -import "./bug_workaround.jou" import "./llvm.jou" import "stdlib/str.jou" import "stdlib/io.jou" @@ -34,7 +33,7 @@ def init_target() -> void: LLVMInitializeX86AsmParser() LLVMInitializeX86AsmPrinter() - if is_windows(): + if WINDOWS: # LLVM's default is x86_64-pc-windows-msvc target.triple = "x86_64-pc-windows-gnu" else: diff --git a/tests/should_succeed/compiler_cli.jou b/tests/should_succeed/compiler_cli.jou index 8a396f4d..0d1e2eee 100644 --- a/tests/should_succeed/compiler_cli.jou +++ b/tests/should_succeed/compiler_cli.jou @@ -3,23 +3,9 @@ import "stdlib/mem.jou" import "stdlib/process.jou" import "stdlib/io.jou" -# TODO: these shouldn't be needed -if WINDOWS: - def is_windows() -> bool: - return True -else: - def is_windows() -> bool: - return False -if MACOS: - def is_macos() -> bool: - return True -else: - def is_macos() -> bool: - return False - def run_jou(command: byte*) -> void: - if is_windows(): + if WINDOWS: jou_exe = "jou.exe" else: jou_exe = "./jou" @@ -78,7 +64,7 @@ def main() -> int: # Different working directory. # Output: Hello World - if is_windows(): + if WINDOWS: system("cd tests & ..\\jou.exe ../examples/hello.jou") else: system("cd tests && ../jou ../examples/hello.jou") @@ -86,14 +72,14 @@ def main() -> int: # Compile to an executable. # Output: Hello World run_jou("-o tmp/tests/hello.exe examples/hello.jou") - if is_windows(): + if WINDOWS: system("tmp\\tests\\hello.exe") else: system("tmp/tests/hello.exe") # Compiler in weird place # Output: error: cannot find the Jou standard library in /tmp/tests/stdlib - if is_windows(): + if WINDOWS: system("copy jou.exe tmp\\tests\\jou_executable.exe >nul") system("tmp\\tests\\jou_executable.exe") else: @@ -101,13 +87,13 @@ def main() -> int: system("tmp/tests/jou_executable") # Compile a GUI program - if not is_windows() and not is_macos(): + if not (WINDOWS or MACOS): ret = system("./jou -o /dev/null --linker-flags \"-lX11\" examples/x11_window.jou") assert ret == 0 # Compile a program with a memory leak. # Output: 100 bytes in 1 blocks are definitely lost in loss record 1 of 1 - if is_windows() or system("which valgrind >/dev/null 2>/dev/null") != 0: + if WINDOWS or system("which valgrind >/dev/null 2>/dev/null") != 0: # valgrind not available --> produce some fake output to pass the test puts("100 bytes in 1 blocks are definitely lost in loss record 1 of 1") else: