-
Notifications
You must be signed in to change notification settings - Fork 4
/
_jou_startup.jou
48 lines (42 loc) · 1.37 KB
/
_jou_startup.jou
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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]