8
8
import std/ os
9
9
import std/ fenv
10
10
when defined(js) or not (defined(Py_FORCE_UTF8_FS_ENCODING) or defined(windows)):
11
- from std/ strutils import toLowerAscii
11
+ import std/ strutils # toLowerAscii startsWith
12
12
when defined(nimPreviewSlimSystem):
13
13
import std/ assertions
14
14
@@ -48,13 +48,13 @@ when not weirdTarget and not defined(windows):
48
48
49
49
proc getPlatform(): string =
50
50
when defined(js):
51
- template inString(jo: JsObject): string =
52
- $ (jo.to(cstring ))
53
51
when defined(nodejs):
54
- return require(" os" ).platform().inString
52
+ proc `os.platform` (): cstring {.importjs:
53
+ " require('os').platform()" .}
54
+ return `os.platform`().`$ `
55
55
else :
56
- let navigator{.importcpp. }: JsObject
57
- result = navigator.platform.inString .toLowerAscii
56
+ let ` navigator.platform`{.importjs: " navigator.platform " . }: cstring
57
+ result = ` navigator.platform`.`$` .toLowerAscii
58
58
result =
59
59
if result .startsWith " win32" : " win32"
60
60
elif result .startsWith " linux" : " linux"
@@ -78,11 +78,14 @@ proc getPlatform(): string =
78
78
# XXX: haiku, netbsd ok ?
79
79
hostOS & uname_release_major()
80
80
81
- const platform* : PyStr =
82
- str getPlatform()
83
- # # .. note:: the value is standalone for bare system
84
- # # and haiku/netbsd appended with major version instead of "unknown".
85
- # # In short, this won't be "unknown" as Python does.
81
+ when defined(js):
82
+ let platform* = str getPlatform()
83
+ else :
84
+ const platform* : PyStr =
85
+ str getPlatform()
86
+ # # .. note:: the value is standalone for bare system
87
+ # # and haiku/netbsd appended with major version instead of "unknown".
88
+ # # In short, this won't be "unknown" as Python does.
86
89
87
90
when not weirdTarget:
88
91
when not defined(pylibSysNoStdio):
@@ -132,15 +135,15 @@ const
132
135
#rounds: 1
133
136
) ## float_info.rounds is defined as a `getter`, see `rounds`_
134
137
135
- when not defined(nimscript) :
138
+ when not weirdTarget :
136
139
let fiRound = fegetround().int
137
140
template rounds*(fi: typeof(float_info)): int =
138
141
## not available when nimscript
139
142
bind fiRound
140
143
fiRound
141
144
else:
142
145
template rounds*(fi: typeof(float_info)): int =
143
- {.error: "not available for nimscript/compile-time".}
146
+ {.error: "not available for nimscript/JavaScript/ compile-time".}
144
147
145
148
func int2hex(x: int ): int =
146
149
## 10 -> 0x10
@@ -216,6 +219,14 @@ else:
216
219
217
220
when defined(nimscript):
218
221
template executable* : PyStr = str getCurrentCompilerExe()
222
+ elif defined(js):
223
+ const execPathJs =
224
+ when defined(nodejs): " process.execPath"
225
+ else : " typeof Deno === 'undefined' ? '' : Deno.execPath()"
226
+ let execPath{.importjs: execPathJs.}: cstring
227
+ template executable* : PyStr =
228
+ bind execPath
229
+ str execPath
219
230
else :
220
231
template executable* : PyStr =
221
232
# # .. note:: when nimscript, this is path of `Nim`;
0 commit comments