summary refs log tree commit diff stats
path: root/compiler/options.nim
Commit message (Expand)AuthorAgeFilesLines
* + added nimsuggest support for exception inlay hints (#23202)Nikolay Nikolov2024-03-151-0/+2
* Update copyright year 2024 (#23144)ringabout2023-12-311-1/+1
* add switch, warning, and `bind` support for new generic injection behavior (#...metagn2023-12-221-0/+1
* Show proper error message if trying to run a Nim file in a directory that doe...Jake Leahy2023-12-021-1/+4
* enable vtable implementation for C++ and make it an experimental feature (#23...ringabout2023-11-301-1/+2
* nimsuggest: Added optional command line option '--clientProcessId:XXX' (#22969)Nikolay Nikolov2023-11-241-0/+1
* IC: progress and refactorings (#22961)Andreas Rumpf2023-11-201-10/+12
* Inlay hints support (#22896)Nikolay Nikolov2023-11-041-1/+17
* prepare for the enforcement of `std` prefix (#22873)ringabout2023-10-291-5/+6
* NIR: store sizes, alignments and offsets in the type graph; beginning… (#22...Andreas Rumpf2023-10-161-5/+8
* fixes #22763; nimcache in nim.cfg uses the relative path to the config file (...ringabout2023-09-281-0/+3
* Instantiates generics in the module that uses it (#22513)Juan M Gómez2023-09-091-0/+3
* replaces `doAssert false` with `raiseAssert` for unreachable branches, which ...ringabout2023-08-101-1/+1
* use strictdefs for compiler (#22365)ringabout2023-08-061-1/+4
* Allow `libffi` to work via `koch boot` (#22322)awr12023-08-031-1/+1
* Add experimental inferGenericTypes switch (#22317)SirOlaf2023-08-031-1/+2
* implemented 'push quirky' switch for fine grained control over the ex… (#22...Andreas Rumpf2023-07-231-0/+1
* adds nimbasePattern compiler option (#22144)Juan M Gómez2023-06-241-0/+1
* fixes #22065; do not search path for relative imports (#22073)ringabout2023-06-131-1/+6
* Remove Deprecated Nimfix (#22062)Juan Carlos2023-06-101-1/+0
* clean up SOME pending/xxx/issue link comments (#21826)metagn2023-05-111-8/+0
* Remove LineTooLong (#21819)Juan Carlos2023-05-111-0/+1
* adds an experimental `mm:atomicArc` switch (#21798)ringabout2023-05-081-0/+1
* int64/uint64 as bigint in JS (#21613)metagn2023-04-111-1/+3
* remove useVersion (#21626)metagn2023-04-081-3/+0
* Add support for NuttX RTOS. (#21372)Century Systems2023-02-161-1/+3
* Change the default stdlib location for Linux packaging (#21328)Gabriel Huber2023-02-121-10/+12
* fixes #19396; Nimdoc hide nonexported fields (#21305)ringabout2023-02-011-0/+4
* Implemented basic macro expand functionality (#20579)Ivan Yonchovski2023-01-271-1/+13
* docgen: implement cross-document links (#20990)Andrey Makarov2023-01-041-0/+2
* fixes #20906; update copyright year [backport 1.6] (#21210)ringabout2023-01-011-1/+1
* less verbose type mismatch messages (#21191)ringabout2022-12-281-0/+1
* remove implicitDeref feature enum (#21075)ringabout2022-12-121-2/+1
* stdlib organization & documentation improvements (#20971)metagn2022-12-061-1/+2
* Add `--genCDeps` for better integration with CMake (#20950)Jaremy Creechley2022-11-291-0/+1
* implemented strictCaseObjects (#20608)Andreas Rumpf2022-10-211-1/+2
* fixes #19162; enable `strictEffects` for v2 (#19380)ringabout2022-10-151-0/+2
* Make rstgen work with gcsafe (#20534)ringabout2022-10-101-1/+1
* Automatic dereferencing is removed (#20531)ringabout2022-10-101-1/+1
* DAA and 'out' parameters (#20506)Andreas Rumpf2022-10-061-1/+2
* Fix/improve handling of forward declarations in nimsuggest (#20493)Ivan Yonchovski2022-10-061-1/+2
* Unicode Operators are no longer experimental (#20444)ringabout2022-09-281-2/+2
* defaults to ORC (#19972)ringabout2022-09-231-1/+1
* overloadable enums no longer experimental (#20298)metagn2022-09-051-1/+1
* Implement type command (#19944)Ivan Yonchovski2022-07-151-1/+3
* Improve Markdown code blocks & start moving docs to Markdown style (#19954)Andrey Makarov2022-07-151-0/+2
* fix #18735; genDepend broken for duplicate module names in separate folders (...flywind2022-07-121-1/+1
* Initial implementation of nimsuggest v3 (#19826)Ivan Yonchovski2022-06-131-2/+11
* remove noop option `gc:v2` (#19810)flywind2022-06-101-1/+0
* Refactor and doc package handling, module name mangling (#19821)quantimnot2022-05-301-5/+2
55' href='#n55'>55 56 57 58 59 60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
                              


                      

                                  





                                                                           
 



                                                             
 



                                                              

                     

                                         
 
      

                       





























                                                                       
                         

                          
                         
 

                                                                      

                                                              

                                           

                                                   

        

                                                       


















                                                                           





                                                                           
 









                                                                      
                                                           









                                                                          
               
import std/private/threadtypes

when defined(windows):
  type
    ThreadVarSlot = distinct int32

  proc threadVarAlloc(): ThreadVarSlot {.
    importc: "TlsAlloc", stdcall, header: "<windows.h>".}
  proc threadVarSetValue(dwTlsIndex: ThreadVarSlot, lpTlsValue: pointer) {.
    importc: "TlsSetValue", stdcall, header: "<windows.h>".}
  proc tlsGetValue(dwTlsIndex: ThreadVarSlot): pointer {.
    importc: "TlsGetValue", stdcall, header: "<windows.h>".}

  proc getLastError(): uint32 {.
    importc: "GetLastError", stdcall, header: "<windows.h>".}
  proc setLastError(x: uint32) {.
    importc: "SetLastError", stdcall, header: "<windows.h>".}

  proc threadVarGetValue(dwTlsIndex: ThreadVarSlot): pointer =
    let realLastError = getLastError()
    result = tlsGetValue(dwTlsIndex)
    setLastError(realLastError)

elif defined(genode):
  const
    GenodeHeader = "genode_cpp/threads.h"

  type
    ThreadVarSlot = int

  proc threadVarAlloc(): ThreadVarSlot = 0

  proc offMainThread(): bool {.
    importcpp: "Nim::SysThread::offMainThread",
    header: GenodeHeader.}

  proc threadVarSetValue(value: pointer) {.
    importcpp: "Nim::SysThread::threadVarSetValue(@)",
    header: GenodeHeader.}

  proc threadVarGetValue(): pointer {.
    importcpp: "Nim::SysThread::threadVarGetValue()",
    header: GenodeHeader.}

  var mainTls: pointer

  proc threadVarSetValue(s: ThreadVarSlot, value: pointer) {.inline.} =
    if offMainThread():
      threadVarSetValue(value);
    else:
      mainTls = value

  proc threadVarGetValue(s: ThreadVarSlot): pointer {.inline.} =
    if offMainThread():
      threadVarGetValue();
    else:
      mainTls

else:
  when not (defined(macosx) or defined(haiku)):
    {.passl: "-pthread".}

  when not defined(haiku):
    {.passc: "-pthread".}

  when (defined(linux) or defined(nintendoswitch)) and defined(amd64):
    type
      ThreadVarSlot {.importc: "pthread_key_t",
                    header: "<sys/types.h>".} = distinct cuint
  elif defined(openbsd) and defined(amd64):
    type
      ThreadVarSlot {.importc: "pthread_key_t",
                     header: "<pthread.h>".} = cint
  else:
    type
      ThreadVarSlot {.importc: "pthread_key_t",
                     header: "<sys/types.h>".} = object

  proc pthread_getspecific(a1: ThreadVarSlot): pointer {.
    importc: "pthread_getspecific", header: pthreadh.}
  proc pthread_key_create(a1: ptr ThreadVarSlot,
                          destruct: proc (x: pointer) {.noconv.}): int32 {.
    importc: "pthread_key_create", header: pthreadh.}
  proc pthread_key_delete(a1: ThreadVarSlot): int32 {.
    importc: "pthread_key_delete", header: pthreadh.}

  proc pthread_setspecific(a1: ThreadVarSlot, a2: pointer): int32 {.
    importc: "pthread_setspecific", header: pthreadh.}

  proc threadVarAlloc(): ThreadVarSlot {.inline.} =
    discard pthread_key_create(addr(result), nil)
  proc threadVarSetValue(s: ThreadVarSlot, value: pointer) {.inline.} =
    discard pthread_setspecific(s, value)
  proc threadVarGetValue(s: ThreadVarSlot): pointer {.inline.} =
    result = pthread_getspecific(s)


when emulatedThreadVars:
  # the compiler generates this proc for us, so that we can get the size of
  # the thread local var block; we use this only for sanity checking though
  proc nimThreadVarsSize(): int {.noconv, importc: "NimThreadVarsSize".}



when emulatedThreadVars:
  var globalsSlot: ThreadVarSlot

  when not defined(useNimRtl):
    var mainThread: GcThread

  proc GetThreadLocalVars(): pointer {.compilerRtl, inl.} =
    result = addr(cast[PGcThread](threadVarGetValue(globalsSlot)).tls)

  proc initThreadVarsEmulation() {.compilerproc, inline.} =
    when not defined(useNimRtl):
      globalsSlot = threadVarAlloc()
      when declared(mainThread):
        threadVarSetValue(globalsSlot, addr(mainThread))

when not defined(useNimRtl):
  when emulatedThreadVars:
    if nimThreadVarsSize() > sizeof(ThreadLocalStorage):
      c_fprintf(cstderr, """too large thread local storage size requested,
use -d:\"nimTlsSize=X\" to setup even more or stop using unittest.nim""")
      rawQuit 1