mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-07 13:33:22 +00:00
Use constant nimCoroutines instead of defined(nimCoroutines)
Variable
This commit is contained in:
@@ -16,8 +16,11 @@
|
||||
## -d:nimCoroutinesSetjmp Use setjmp backend.
|
||||
## -d:nimCoroutinesSetjmpBundled Use bundled setjmp implementation.
|
||||
|
||||
when not defined(nimCoroutines) and not defined(nimdoc):
|
||||
{.error: "Coroutines require -d:nimCoroutines".}
|
||||
when not nimCoroutines and not defined(nimdoc):
|
||||
when defined(noNimCoroutines):
|
||||
{.error: "Coroutines can not be used with -d:noNimCoroutines"}
|
||||
else:
|
||||
{.error: "Coroutines require -d:nimCoroutines".}
|
||||
|
||||
import os
|
||||
import macros
|
||||
|
||||
@@ -2462,6 +2462,23 @@ template accumulateResult*(iter: untyped) =
|
||||
# we have to compute this here before turning it off in except.nim anyway ...
|
||||
const NimStackTrace = compileOption("stacktrace")
|
||||
|
||||
template coroutinesSupportedPlatform(): bool =
|
||||
when defined(sparc) or defined(ELATE) or compileOption("gc", "v2") or
|
||||
defined(boehmgc) or defined(gogc) or defined(nogc) or defined(gcStack) or
|
||||
defined(gcMarkAndSweep):
|
||||
false
|
||||
else:
|
||||
true
|
||||
|
||||
when defined(nimCoroutines):
|
||||
when not coroutinesSupportedPlatform():
|
||||
{.error: "Coroutines are not supported on this architecture and/or garbage collector.".}
|
||||
const nimCoroutines* = true
|
||||
elif defined(noNimCoroutines):
|
||||
const nimCoroutines* = false
|
||||
else:
|
||||
const nimCoroutines* = false
|
||||
|
||||
{.push checks: off.}
|
||||
# obviously we cannot generate checking operations here :-)
|
||||
# because it would yield into an endless recursion
|
||||
|
||||
@@ -64,14 +64,14 @@ type
|
||||
maxPause: int64 # max measured GC pause in nanoseconds
|
||||
|
||||
GcStack {.final, pure.} = object
|
||||
when defined(nimCoroutines):
|
||||
when nimCoroutines:
|
||||
prev: ptr GcStack
|
||||
next: ptr GcStack
|
||||
maxStackSize: int # Used to track statistics because we can not use
|
||||
# GcStat.maxStackSize when multiple stacks exist.
|
||||
bottom: pointer
|
||||
|
||||
when withRealTime or defined(nimCoroutines):
|
||||
when withRealTime or nimCoroutines:
|
||||
pos: pointer # Used with `withRealTime` only for code clarity, see GC_Step().
|
||||
when withRealTime:
|
||||
bottomSaved: pointer
|
||||
@@ -79,7 +79,7 @@ type
|
||||
GcHeap {.final, pure.} = object # this contains the zero count and
|
||||
# non-zero count table
|
||||
stack: GcStack
|
||||
when defined(nimCoroutines):
|
||||
when nimCoroutines:
|
||||
activeStack: ptr GcStack # current executing coroutine stack.
|
||||
cycleThreshold: int
|
||||
when useCellIds:
|
||||
@@ -827,7 +827,7 @@ proc collectCTBody(gch: var GcHeap) =
|
||||
let t0 = getticks()
|
||||
sysAssert(allocInv(gch.region), "collectCT: begin")
|
||||
|
||||
when defined(nimCoroutines):
|
||||
when nimCoroutines:
|
||||
for stack in gch.stack.items():
|
||||
gch.stat.maxStackSize = max(gch.stat.maxStackSize, stack.stackSize())
|
||||
else:
|
||||
@@ -948,7 +948,7 @@ when not defined(useNimRtl):
|
||||
"[GC] zct capacity: " & $gch.zct.cap & "\n" &
|
||||
"[GC] max cycle table size: " & $gch.stat.cycleTableSize & "\n" &
|
||||
"[GC] max pause time [ms]: " & $(gch.stat.maxPause div 1000_000) & "\n"
|
||||
when defined(nimCoroutines):
|
||||
when nimCoroutines:
|
||||
result = result & "[GC] number of stacks: " & $gch.stack.len & "\n"
|
||||
for stack in items(gch.stack):
|
||||
result = result & "[GC] stack " & stack.bottom.repr & "[GC] max stack size " & cast[pointer](stack.maxStackSize).repr & "\n"
|
||||
|
||||
@@ -109,7 +109,7 @@ else:
|
||||
proc len(stack: var GcStack): int = 1
|
||||
|
||||
proc stackSize(stack: ptr GcStack): int {.noinline.} =
|
||||
when defined(nimCoroutines):
|
||||
when nimCoroutines:
|
||||
var pos = stack.pos
|
||||
else:
|
||||
var pos {.volatile.}: pointer
|
||||
@@ -127,7 +127,7 @@ proc stackSize(): int {.noinline.} =
|
||||
for stack in gch.stack.items():
|
||||
result = result + stack.stackSize()
|
||||
|
||||
when defined(nimCoroutines):
|
||||
when nimCoroutines:
|
||||
proc setPosition(stack: ptr GcStack, position: pointer) =
|
||||
stack.pos = position
|
||||
stack.maxStackSize = max(stack.maxStackSize, stack.stackSize())
|
||||
@@ -198,7 +198,7 @@ else:
|
||||
const stackIncreases = false
|
||||
|
||||
{.push stack_trace: off.}
|
||||
when defined(nimCoroutines):
|
||||
when nimCoroutines:
|
||||
proc GC_addStack(bottom: pointer) {.cdecl, exportc.} =
|
||||
# c_fprintf(stdout, "GC_addStack: %p;\n", bottom)
|
||||
var stack = gch.stack.append()
|
||||
@@ -219,7 +219,7 @@ when defined(nimCoroutines):
|
||||
when not defined(useNimRtl):
|
||||
proc setStackBottom(theStackBottom: pointer) =
|
||||
# Initializes main stack of the thread.
|
||||
when defined(nimCoroutines):
|
||||
when nimCoroutines:
|
||||
if gch.stack.next == nil:
|
||||
# Main stack was not initialized yet
|
||||
gch.stack.next = addr(gch.stack)
|
||||
@@ -257,7 +257,7 @@ proc isOnStack(p: pointer): bool =
|
||||
result = a <=% x and x <=% b
|
||||
|
||||
when defined(sparc): # For SPARC architecture.
|
||||
when defined(nimCoroutines):
|
||||
when nimCoroutines:
|
||||
{.error: "Nim coroutines are not supported on this platform."}
|
||||
|
||||
template forEachStackSlot(gch, gcMark: untyped) {.dirty.} =
|
||||
|
||||
Reference in New Issue
Block a user