-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
92 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# On many platforms, a call to the _jou_startup() function is inserted to | ||
# the start of main() in every Jou program. | ||
# | ||
# On Windows, the C "global variables" stdin, stdout and stderr are | ||
# actually macros: | ||
# | ||
# $ printf "#include <stdio.h>\nstdin\nstdout\nstderr\n" | x86_64-w64-mingw32-cpp | tail -3 | ||
# (__acrt_iob_func(0)) | ||
# (__acrt_iob_func(1)) | ||
# (__acrt_iob_func(2)) | ||
# | ||
# For simplicity, Jou redefines them as variables with the same | ||
# names and assigns the correct values to them. | ||
# | ||
# There seems to be a similar situation on most other platforms. | ||
# | ||
# We can't import FILE from io.jou here, because then we would be | ||
# trying to define a variable that already exists. | ||
if WINDOWS or MACOS or NETBSD: | ||
global stdin: void* | ||
global stdout: void* | ||
global stderr: void* | ||
|
||
if WINDOWS: | ||
declare __acrt_iob_func(index: int) -> void* | ||
|
||
def _jou_startup() -> None: | ||
stdin = __acrt_iob_func(0) | ||
stdout = __acrt_iob_func(1) | ||
stderr = __acrt_iob_func(2) | ||
|
||
if MACOS: | ||
declare global __stdinp: void* | ||
declare global __stdoutp: void* | ||
declare global __stderrp: void* | ||
|
||
def _jou_startup() -> None: | ||
stdin = __stdinp | ||
stdout = __stdoutp | ||
stderr = __stderrp | ||
|
||
if NETBSD: | ||
declare global __sF: byte[152][3] # sizeof(FILE) == 152 | ||
|
||
def _jou_startup() -> None: | ||
stdin = &__sF[0] | ||
stdout = &__sF[1] | ||
stderr = &__sF[2] |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,35 @@ | ||
# C's errno is actually a macro that expands to a function call. | ||
# See also _windows_startup.jou | ||
declare __errno_location() -> int* | ||
# The function name varies by platform. | ||
if WINDOWS: | ||
declare _errno() -> int* | ||
elif MACOS: | ||
declare __error() -> int* | ||
elif NETBSD: | ||
declare __errno() -> int* | ||
else: | ||
declare __errno_location() -> int* | ||
|
||
def set_errno(value: int) -> None: | ||
*__errno_location() = value | ||
|
||
def get_errno() -> int: | ||
return *__errno_location() | ||
# TODO: Ideally we would be able to place the if statements inside the functions. | ||
if WINDOWS: | ||
def set_errno(value: int) -> None: | ||
*_errno() = value | ||
def get_errno() -> int: | ||
return *_errno() | ||
elif MACOS: | ||
def set_errno(value: int) -> None: | ||
*__error() = value | ||
def get_errno() -> int: | ||
return *__error() | ||
elif NETBSD: | ||
def set_errno(value: int) -> None: | ||
*__errno() = value | ||
def get_errno() -> int: | ||
return *__errno() | ||
else: | ||
def set_errno(value: int) -> None: | ||
*__errno_location() = value | ||
def get_errno() -> int: | ||
return *__errno_location() | ||
|
||
# Convert an error code into a string. Do not modify or free() the returned string. | ||
declare strerror(errno_value: int) -> byte* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters