* beneficial refactoring; use system.Endianness * closes #18433
This commit is contained in:
parent
15fdcd0c4d
commit
b3aca78e22
3 changed files with 42 additions and 6 deletions
|
|
@ -592,8 +592,8 @@ proc isDefined*(conf: ConfigRef; symbol: string): bool =
|
||||||
result = conf.target.targetOS == osNintendoSwitch
|
result = conf.target.targetOS == osNintendoSwitch
|
||||||
of "freertos", "lwip":
|
of "freertos", "lwip":
|
||||||
result = conf.target.targetOS == osFreeRTOS
|
result = conf.target.targetOS == osFreeRTOS
|
||||||
of "littleendian": result = CPU[conf.target.targetCPU].endian == platform.littleEndian
|
of "littleendian": result = CPU[conf.target.targetCPU].endian == littleEndian
|
||||||
of "bigendian": result = CPU[conf.target.targetCPU].endian == platform.bigEndian
|
of "bigendian": result = CPU[conf.target.targetCPU].endian == bigEndian
|
||||||
of "cpu8": result = CPU[conf.target.targetCPU].bit == 8
|
of "cpu8": result = CPU[conf.target.targetCPU].bit == 8
|
||||||
of "cpu16": result = CPU[conf.target.targetCPU].bit == 16
|
of "cpu16": result = CPU[conf.target.targetCPU].bit == 16
|
||||||
of "cpu32": result = CPU[conf.target.targetCPU].bit == 32
|
of "cpu32": result = CPU[conf.target.targetCPU].bit == 32
|
||||||
|
|
|
||||||
|
|
@ -196,13 +196,11 @@ type
|
||||||
cpuSparc64, cpuMips64, cpuMips64el, cpuRiscV32, cpuRiscV64, cpuEsp, cpuWasm32
|
cpuSparc64, cpuMips64, cpuMips64el, cpuRiscV32, cpuRiscV64, cpuEsp, cpuWasm32
|
||||||
|
|
||||||
type
|
type
|
||||||
TEndian* = enum
|
TInfoCPU* = tuple[name: string, intSize: int, endian: Endianness,
|
||||||
littleEndian, bigEndian
|
|
||||||
TInfoCPU* = tuple[name: string, intSize: int, endian: TEndian,
|
|
||||||
floatSize, bit: int]
|
floatSize, bit: int]
|
||||||
|
|
||||||
const
|
const
|
||||||
EndianToStr*: array[TEndian, string] = ["littleEndian", "bigEndian"]
|
EndianToStr*: array[Endianness, string] = ["littleEndian", "bigEndian"]
|
||||||
CPU*: array[succ(low(TSystemCPU))..high(TSystemCPU), TInfoCPU] = [
|
CPU*: array[succ(low(TSystemCPU))..high(TSystemCPU), TInfoCPU] = [
|
||||||
(name: "i386", intSize: 32, endian: littleEndian, floatSize: 64, bit: 32),
|
(name: "i386", intSize: 32, endian: littleEndian, floatSize: 64, bit: 32),
|
||||||
(name: "m68k", intSize: 32, endian: bigEndian, floatSize: 64, bit: 32),
|
(name: "m68k", intSize: 32, endian: bigEndian, floatSize: 64, bit: 32),
|
||||||
|
|
|
||||||
38
tests/arc/tfuncobj.nim
Normal file
38
tests/arc/tfuncobj.nim
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
discard """
|
||||||
|
outputsub: '''f1
|
||||||
|
f2
|
||||||
|
f3'''
|
||||||
|
cmd: "nim c --gc:orc $file"
|
||||||
|
valgrind: true
|
||||||
|
"""
|
||||||
|
|
||||||
|
type
|
||||||
|
FuncObj = object
|
||||||
|
fn: proc (env: pointer) {.cdecl.}
|
||||||
|
env: pointer
|
||||||
|
|
||||||
|
proc `=destroy`(x: var FuncObj) =
|
||||||
|
GC_unref(cast[RootRef](x.env))
|
||||||
|
|
||||||
|
proc `=copy`(x: var FuncObj, y: FuncObj) {.error.}
|
||||||
|
|
||||||
|
# bug #18433
|
||||||
|
|
||||||
|
proc main =
|
||||||
|
var fs: seq[FuncObj]
|
||||||
|
|
||||||
|
proc wrap(p: proc()) =
|
||||||
|
proc closeOver() = p()
|
||||||
|
let env = rawEnv closeOver
|
||||||
|
GC_ref(cast[RootRef](env))
|
||||||
|
fs.add(FuncObj(fn: cast[proc(env: pointer){.cdecl.}](rawProc closeOver), env: env))
|
||||||
|
|
||||||
|
wrap(proc() {.closure.} = echo "f1")
|
||||||
|
wrap(proc() {.closure.} = echo "f2")
|
||||||
|
wrap(proc() {.closure.} = echo "f3")
|
||||||
|
|
||||||
|
for a in fs:
|
||||||
|
a.fn(a.env)
|
||||||
|
|
||||||
|
main()
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue