Skip to content

Commit 1a712c8

Browse files
committed
fix(Lib/platform): machine() result fixed for some arch; closes #48
1 parent b32671a commit 1a712c8

File tree

1 file changed

+43
-5
lines changed

1 file changed

+43
-5
lines changed

src/pylib/Lib/platform.nim

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,50 @@
33
import ./private/platformInfo
44
import ../pystring/strimpl
55
export strimpl
6-
import std/strutils
76

87
proc version*(): PyStr = str `platform.version`()
98

10-
func python_implementation*(): PyStr = str "PyNim"
11-
func system*(): PyStr = str `platform.system`
12-
const machineS = str hostCPU.toUpperAscii()
13-
func machine*(): PyStr = machineS
9+
func python_implementation*(): PyStr{.inline.} = str "PyNim"
10+
func system*(): PyStr{.inline.} = str `platform.system`
11+
12+
const machineS = hostCPU
13+
#[ doc says:
14+
15+
```
16+
Possible values:
17+
"i386", "amd64",
18+
"powerpc", "powerpc64", "powerpc64el",
19+
20+
"alpha", "sparc", "loongarch64".
21+
"mips", "mipsel", "mips64", "mips64el",
22+
"arm", "arm64", "riscv32", "riscv64",
23+
```
24+
]#
25+
# refer to compiler/platform.nim,
26+
# there're more
27+
28+
# compiler/semfold.nim
29+
# proc getConstExpr(m: PSym, n: PNode; idgen: IdGenerator; g: ModuleGraph): PNode
30+
# of mHostCPU: result = newStrNodeT(platform.CPU[g.config.target.targetCPU].name.toLowerAscii, n, g)
31+
32+
when defined(windows):
33+
import std/strutils
34+
template winNormMachine(machine): string =
35+
case machine
36+
of "i386": "x86"
37+
of "alpha": "Alpha"
38+
elif machine.startsWith"powerpc": "PowerPC"
39+
elif machine.startsWith"mips": "MIPS"
40+
#elif machine.startsWith"arm": machine.toUpperAscii
41+
else: # including ia64, arm[64], amd64
42+
machine
43+
44+
func machine*(): PyStr{.inline.} =
45+
when defined(windows):
46+
winNormMachine machineS
47+
else:
48+
case machineS
49+
of "amd64": "x86_64"
50+
of "arm64": "aarch64"
51+
else: machineS
1452

0 commit comments

Comments
 (0)