summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorRokas Kupstys <rokups@zoho.com>2017-02-18 17:17:44 +0200
committerRokas Kupstys <rokups@zoho.com>2017-02-20 17:24:19 +0200
commitf80ddbbcc6a599f2a17275f2cca4d268f7f1fc63 (patch)
tree4ea21d3c77c699e2a1d6916646c272f9d1df8376 /lib
parent9f8863169a2ebf25e80b3fb75b96bb7710a416f2 (diff)
downloadNim-f80ddbbcc6a599f2a17275f2cca4d268f7f1fc63.tar.gz
Use constant nimCoroutines instead of defined(nimCoroutines)
Variable
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/coro.nim7
-rw-r--r--lib/system.nim17
-rw-r--r--lib/system/gc.nim10
-rw-r--r--lib/system/gc_common.nim10
4 files changed, 32 insertions, 12 deletions
diff --git a/lib/pure/coro.nim b/lib/pure/coro.nim
index 494d6c6dc..1eb5cacad 100644
--- a/lib/pure/coro.nim
+++ b/lib/pure/coro.nim
@@ -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
diff --git a/lib/system.nim b/lib/system.nim
index bab5369f1..bd1d029fc 100644
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -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
diff --git a/lib/system/gc.nim b/lib/system/gc.nim
index 551dae459..8db60ab0f 100644
--- a/lib/system/gc.nim
+++ b/lib/system/gc.nim
@@ -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"
diff --git a/lib/system/gc_common.nim b/lib/system/gc_common.nim
index 70fd3412f..e3b861fad 100644
--- a/lib/system/gc_common.nim
+++ b/lib/system/gc_common.nim
@@ -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.} =