From d3cf79e3e7ebacbc50f4dde508b28d4f9d46e3fe Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Fri, 22 Jun 2018 10:47:37 +0900 Subject: [PATCH] Add more defined sections for nintendo switch --- lib/pure/dynlib.nim | 22 ++++++++++++++++++++++ lib/pure/os.nim | 31 +++++++++++++++++++------------ lib/pure/ospaths.nim | 2 +- lib/pure/times.nim | 4 ++-- lib/system/threads.nim | 2 +- 5 files changed, 45 insertions(+), 16 deletions(-) diff --git a/lib/pure/dynlib.nim b/lib/pure/dynlib.nim index 5bd06f6fb..d030ad532 100644 --- a/lib/pure/dynlib.nim +++ b/lib/pure/dynlib.nim @@ -137,6 +137,28 @@ when defined(posix): proc symAddr(lib: LibHandle, name: cstring): pointer = return dlsym(lib, name) +elif defined(nintendoswitch): + # + # ========================================================================= + # Nintendo switch DevkitPro sdk does not have these. Raise an error if called. + # ========================================================================= + # + + proc dlclose(lib: LibHandle) = + raise newException(OSError, "dlclose not implemented on Nintendo Switch!") + proc dlopen(path: cstring, mode: int): LibHandle = + raise newException(OSError, "dlopen not implemented on Nintendo Switch!") + proc dlsym(lib: LibHandle, name: cstring): pointer = + raise newException(OSError, "dlsym not implemented on Nintendo Switch!") + proc loadLib(path: string, global_symbols=false): LibHandle = + raise newException(OSError, "loadLib not implemented on Nintendo Switch!") + proc loadLib(): LibHandle = + raise newException(OSError, "loadLib not implemented on Nintendo Switch!") + proc unloadLib(lib: LibHandle) = + raise newException(OSError, "unloadLib not implemented on Nintendo Switch!") + proc symAddr(lib: LibHandle, name: cstring): pointer = + raise newException(OSError, "symAddr not implemented on Nintendo Switch!") + elif defined(windows) or defined(dos): # # ======================================================================= diff --git a/lib/pure/os.nim b/lib/pure/os.nim index 90c52657c..e81f87e0a 100644 --- a/lib/pure/os.nim +++ b/lib/pure/os.nim @@ -21,7 +21,7 @@ import when defined(windows): import winlean -elif defined(posix): +elif defined(posix) or defined(nintendoswitch): import posix proc toTime(ts: Timespec): times.Time {.inline.} = @@ -187,7 +187,7 @@ proc findExe*(exe: string, followSymlinks: bool = true; proc getLastModificationTime*(file: string): times.Time {.rtl, extern: "nos$1".} = ## Returns the `file`'s last modification time. - when defined(posix): + when defined(posix) or defined(nintendoswitch): var res: Stat if stat(file, res) < 0'i32: raiseOSError(osLastError()) result = res.st_mtim.toTime @@ -200,7 +200,7 @@ proc getLastModificationTime*(file: string): times.Time {.rtl, extern: "nos$1".} proc getLastAccessTime*(file: string): times.Time {.rtl, extern: "nos$1".} = ## Returns the `file`'s last read or write access time. - when defined(posix): + when defined(posix) or defined(nintendoswitch): var res: Stat if stat(file, res) < 0'i32: raiseOSError(osLastError()) result = res.st_atim.toTime @@ -217,7 +217,7 @@ proc getCreationTime*(file: string): times.Time {.rtl, extern: "nos$1".} = ## **Note:** Under POSIX OS's, the returned time may actually be the time at ## which the file's attribute's were last modified. See ## `here `_ for details. - when defined(posix): + when defined(posix) or defined(nintendoswitch): var res: Stat if stat(file, res) < 0'i32: raiseOSError(osLastError()) result = res.st_ctim.toTime @@ -231,7 +231,7 @@ proc getCreationTime*(file: string): times.Time {.rtl, extern: "nos$1".} = proc fileNewer*(a, b: string): bool {.rtl, extern: "nos$1".} = ## Returns true if the file `a` is newer than file `b`, i.e. if `a`'s ## modification time is later than `b`'s. - when defined(posix): + when defined(posix) or defined(nintendoswitch): # If we don't have access to nanosecond resolution, use '>=' when not StatHasNanoseconds: result = getLastModificationTime(a) >= getLastModificationTime(b) @@ -446,7 +446,7 @@ proc getFilePermissions*(filename: string): set[FilePermission] {. ## retrieves file permissions for `filename`. `OSError` is raised in case of ## an error. On Windows, only the ``readonly`` flag is checked, every other ## permission is available in any case. - when defined(posix): + when defined(posix) or defined(nintendoswitch): var a: Stat if stat(filename, a) < 0'i32: raiseOSError(osLastError()) result = {} @@ -478,7 +478,7 @@ proc setFilePermissions*(filename: string, permissions: set[FilePermission]) {. ## sets the file permissions for `filename`. `OSError` is raised in case of ## an error. On Windows, only the ``readonly`` flag is changed, depending on ## ``fpUserWrite``. - when defined(posix): + when defined(posix) or defined(nintendoswitch): var p = 0'i32 if fpUserRead in permissions: p = p or S_IRUSR if fpUserWrite in permissions: p = p or S_IWUSR @@ -645,7 +645,7 @@ proc execShellCmd*(command: string): int {.rtl, extern: "nos$1", ## the process has finished. To execute a program without having a ## shell involved, use the `execProcess` proc of the `osproc` ## module. - when defined(posix): + when defined(posix) or defined(nintendoswitch): result = c_system(command) shr 8 else: result = c_system(command) @@ -739,7 +739,7 @@ type pcLinkToDir ## path refers to a symbolic link to a directory -when defined(posix): +when defined(posix) or defined(nintendoswitch): proc getSymlinkFileKind(path: string): PathComponent = # Helper function. var s: Stat @@ -911,7 +911,7 @@ proc rawCreateDir(dir: string): bool = result = false else: raiseOSError(osLastError()) - elif defined(posix): + elif defined(posix) or defined(nintendoswitch): let res = mkdir(dir, 0o777) if res == 0'i32: result = true @@ -1284,9 +1284,16 @@ elif defined(windows): if i < ownArgv.len and i >= 0: return TaintedString(ownArgv[i]) raise newException(IndexError, "invalid index") +elif defined(nintendoswitch): + proc paramStr*(i: int): TaintedString {.tags: [ReadIOEffect].} = + raise newException(OSError, "paramStr is not implemented on Nintendo Switch") + + proc paramCount*(): int {.tags: [ReadIOEffect].} = + raise newException(OSError, "paramCount is not implemented on Nintendo Switch") + elif not defined(createNimRtl) and not(defined(posix) and appType == "lib") and - not defined(genode) and not defined(nintendoswitch): + not defined(genode): # On Posix, there is no portable way to get the command line from a DLL. var cmdCount {.importc: "cmdCount".}: cint @@ -1649,7 +1656,7 @@ proc isHidden*(path: string): bool = proc setLastModificationTime*(file: string, t: times.Time) = ## Sets the `file`'s last modification time. `OSError` is raised in case of ## an error. - when defined(posix): + when defined(posix) or defined(nintendoswitch): let unixt = posix.Time(t.toUnix) let micro = convert(Nanoseconds, Microseconds, t.nanosecond) var timevals = [Timeval(tv_sec: unixt, tv_usec: micro), diff --git a/lib/pure/ospaths.nim b/lib/pure/ospaths.nim index c0d3ef512..905a65925 100644 --- a/lib/pure/ospaths.nim +++ b/lib/pure/ospaths.nim @@ -597,7 +597,7 @@ proc quoteShellPosix*(s: string): string {.noSideEffect, rtl, extern: "nosp$1".} else: return "'" & s.replace("'", "'\"'\"'") & "'" -when defined(windows) or defined(posix): +when defined(windows) or defined(posix) or defined(nintendoswitch): proc quoteShell*(s: string): string {.noSideEffect, rtl, extern: "nosp$1".} = ## Quote ``s``, so it can be safely passed to shell. when defined(windows): diff --git a/lib/pure/times.nim b/lib/pure/times.nim index 7cecc31ab..a5dc42c37 100644 --- a/lib/pure/times.nim +++ b/lib/pure/times.nim @@ -61,7 +61,7 @@ when defined(JS): system.inc(a, b) {.pop.} -when defined(posix): +when defined(posix) or defined(nintendoswitch): import posix type CTime = posix.Time @@ -2031,7 +2031,7 @@ when not defined(JS): ## on the hardware/OS). ## ## ``getTime`` should generally be prefered over this proc. - when defined(posix): + when defined(posix) or defined(nintendoswitch): var a: Timeval gettimeofday(a) result = toBiggestFloat(a.tv_sec.int64) + toFloat(a.tv_usec)*0.00_0001 diff --git a/lib/system/threads.nim b/lib/system/threads.nim index df145628b..3bfaa1dc2 100644 --- a/lib/system/threads.nim +++ b/lib/system/threads.nim @@ -176,7 +176,7 @@ else: else: type Time = int - when defined(linux) and defined(amd64) and defined(nintendoswitch): + when (defined(linux) or defined(nintendoswitch)) and defined(amd64): type SysThread* {.importc: "pthread_t", header: "" .} = distinct culong