Skip to content

Commit

Permalink
delete is_windows and is_macos functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Akuli committed Dec 6, 2023
1 parent 842a6b6 commit 3082578
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 46 deletions.
15 changes: 0 additions & 15 deletions self_hosted/bug_workaround.jou

This file was deleted.

11 changes: 5 additions & 6 deletions self_hosted/main.jou
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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] = '\\'
Expand Down Expand Up @@ -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")
Expand All @@ -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] = '"'
Expand Down
5 changes: 2 additions & 3 deletions self_hosted/paths.jou
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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++:
Expand Down Expand Up @@ -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 == '\\':
Expand Down
3 changes: 1 addition & 2 deletions self_hosted/target.jou
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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:
Expand Down
26 changes: 6 additions & 20 deletions tests/should_succeed/compiler_cli.jou
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -78,36 +64,36 @@ 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")

# 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 <joudir>/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:
system("cp jou tmp/tests/jou_executable")
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:
Expand Down

0 comments on commit 3082578

Please sign in to comment.