Add specific lib code for Nintendo Switch

This commit is contained in:
Joey Yakimowich-Payne 2018-06-19 17:11:22 +09:00
commit 8a0bff973f
7 changed files with 40 additions and 8 deletions

View file

@ -819,7 +819,8 @@ iterator walkDir*(dir: string; relative=false): tuple[kind: PathComponent, path:
y = dir / y
var k = pcFile
when defined(linux) or defined(macosx) or defined(bsd) or defined(genode):
when defined(linux) or defined(macosx) or
defined(bsd) or defined(genode) or defined(nintendoswitch):
if x.d_type != DT_UNKNOWN:
if x.d_type == DT_DIR: k = pcDir
if x.d_type == DT_LNK:
@ -1285,7 +1286,7 @@ elif defined(windows):
elif not defined(createNimRtl) and
not(defined(posix) and appType == "lib") and
not defined(genode):
not defined(genode) and not defined(nintendoswitch):
# On Posix, there is no portable way to get the command line from a DLL.
var
cmdCount {.importc: "cmdCount".}: cint
@ -1439,7 +1440,7 @@ proc getAppFilename*(): string {.rtl, extern: "nos$1", tags: [ReadIOEffect].} =
result = getApplAux("/proc/self/exe")
elif defined(solaris):
result = getApplAux("/proc/" & $getpid() & "/path/a.out")
elif defined(genode):
elif defined(genode) or defined(nintendoswitch):
raiseOSError(OSErrorCode(-1), "POSIX command line not supported")
elif defined(freebsd) or defined(dragonfly):
result = getApplFreebsd()

View file

@ -312,6 +312,8 @@ else:
include ioselects/ioselectors_poll # need to replace it with event ports
elif defined(genode):
include ioselects/ioselectors_select # TODO: use the native VFS layer
elif defined(nintendoswitch):
include ioselects/ioselectors_select
else:
include ioselects/ioselectors_poll

View file

@ -45,7 +45,7 @@ when defined(windows):
SIGTERM = cint(15)
elif defined(macosx) or defined(linux) or defined(freebsd) or
defined(openbsd) or defined(netbsd) or defined(solaris) or
defined(dragonfly):
defined(dragonfly) or defined(nintendoswitch):
const
SIGABRT = cint(6)
SIGFPE = cint(8)

View file

@ -167,6 +167,24 @@ elif defined(genode):
proc nimGetProcAddr(lib: LibHandle, name: cstring): ProcAddr {.
error: "nimGetProcAddr not implemented".}
elif defined(nintendoswitch):
proc nimUnloadLibrary(lib: LibHandle) =
stderr.rawWrite("nimUnLoadLibrary not implemented")
stderr.rawWrite("\n")
quit(1)
proc nimLoadLibrary(path: string): LibHandle =
stderr.rawWrite("nimLoadLibrary not implemented")
stderr.rawWrite("\n")
quit(1)
proc nimGetProcAddr(lib: LibHandle, name: cstring): ProcAddr =
stderr.rawWrite("nimGetProAddr not implemented")
stderr.write(name)
stderr.rawWrite("\n")
quit(1)
else:
{.error: "no implementation for dyncalls".}

View file

@ -31,13 +31,14 @@ type
vm, ## Some Virtual machine: Nim's VM or JavaScript
avr, ## AVR based processor
msp430, ## TI MSP430 microcontroller
riscv64 ## RISC-V 64-bit processor
riscv64, ## RISC-V 64-bit processor
armv8a57 ## Arm Cortex A57 64-bit processor for Nintendo Switch
OsPlatform* {.pure.} = enum ## the OS this program will run on.
none, dos, windows, os2, linux, morphos, skyos, solaris,
irix, netbsd, freebsd, openbsd, aix, palmos, qnx, amiga,
atari, netware, macos, macosx, haiku, android, js, nimVM,
standalone
standalone, nintendoswitch
const
targetOS* = when defined(windows): OsPlatform.windows
@ -64,6 +65,7 @@ const
elif defined(js): OsPlatform.js
elif defined(nimVM): OsPlatform.nimVM
elif defined(standalone): OsPlatform.standalone
elif defined(nintendoswitch): OsPlatform.nintendoswitch
else: OsPlatform.none
## the OS this program will run on.
@ -86,5 +88,6 @@ const
elif defined(avr): CpuPlatform.avr
elif defined(msp430): CpuPlatform.msp430
elif defined(riscv64): CpuPlatform.riscv64
elif defined(armv8a57): CpuPlatform.armv8a57
else: CpuPlatform.none
## the CPU this program will run on.

View file

@ -419,7 +419,7 @@ proc setStdIoUnbuffered() =
when declared(stdout):
proc echoBinSafe(args: openArray[string]) {.compilerProc.} =
# flockfile deadlocks some versions of Android 5.x.x
when not defined(windows) and not defined(android):
when not defined(windows) and not defined(android) and not defined(nintendoswitch):
proc flockfile(f: File) {.importc, noDecl.}
proc funlockfile(f: File) {.importc, noDecl.}
flockfile(stdout)
@ -428,7 +428,7 @@ when declared(stdout):
const linefeed = "\n" # can be 1 or more chars
discard c_fwrite(linefeed.cstring, linefeed.len, 1, stdout)
discard c_fflush(stdout)
when not defined(windows) and not defined(android):
when not defined(windows) and not defined(android) and not defined(nintendoswitch):
funlockfile(stdout)
{.pop.}

View file

@ -185,6 +185,14 @@ else:
abi: array[56 div sizeof(clong), clong]
ThreadVarSlot {.importc: "pthread_key_t",
header: "<sys/types.h>".} = distinct cuint
elif defined(nintendoswitch):
type
SysThread* {.importc: "pthread_t",
header: "<sys/types.h>" .} = distinct cuint
Pthread_attr {.importc: "pthread_attr_t",
header: "<sys/types.h>".} = object
ThreadVarSlot {.importc: "pthread_key_t",
header: "<sys/types.h>".} = distinct cuint
else:
type
SysThread* {.importc: "pthread_t", header: "<sys/types.h>".} = object