summary refs log tree commit diff stats
path: root/tests/system/tdollars.nim
Commit message (Collapse)AuthorAgeFilesLines
* Replacement PR for https://github.com/nim-lang/Nim/pull/23779 that (#23793)c-blake2024-07-071-1/+1
| | | | | | | makes new hash the default, with an opt-out (& js-no-big-int) define. Also update changelog (& fix one typo). Only really expect the chronos hash-order sensitive test to fail until they merge that PR and tag a new release.
* fixes testament matrix doesn't work with other backends which left many JS ↵ringabout2024-05-141-3/+3
| | | | | | tests untested (#23592) Targets are not changes, which means the C binary is actually tested for JS backend
* clean up SOME pending/xxx/issue link comments (#21826)metagn2023-05-111-2/+1
| | | | | * clean up SOME pending/xxx/issue link comments * great
* stdlib tests now check refc too (#21664)ringabout2023-04-211-1/+1
| | | | | | | | | | | * stdlib tests now check refc too * typo * fixes line numbers * disable cpp * do not touch
* int64/uint64 as bigint in JS (#21613)metagn2023-04-111-4/+6
| | | | | | | | | | | * int64/uint64 as bigint in JS * fix CI * convert to compile option * fix lie * smaller diff, changelog entry
* remove exception (#18906)flywind2021-10-221-0/+7
|
* improvements to `addInt` and `$` for integer types (#18592)Timothee Cour2021-08-191-27/+54
| | | | | | | | * improvements to $(SomeInteger) and addInt * remove mIntToStr, mInt64ToStr * improvements * fix tests/pragmas/tinjectstmt.nim; the diff is harmless, cgen code is identical with -d:danger or debug mode * rm tests/system/tstrmantle.nim * revert compiler/jsgen.nim for -d:nimVersion140
* Ref #12700 add testcase (#17096)flywind2021-02-191-1/+9
| | | | | | | * fix js unsigned integer * better * ref #12700 add testcase
* fix stringify unsigned integer in JS and JS VM (#17086)flywind2021-02-181-0/+28
| | | | | * fix js unsigned integer * better
* [backport:1.4] JS cstring null fixes (#16979)hlaaftana2021-02-111-1/+24
| | | | | * [backport:1.4] JS cstring null fixes * fix JS move string * make it look cleaner
* follow #16505 move and active tests (#16508)flywind2020-12-301-0/+26
| | | | | * fix printing negative zero in JS backend * move tests
* fix #14350, cstrings in JS init as null (#14355)hlaaftana2020-05-151-0/+7
| | | | * fix #14350, cstrings in JS init as null
* `$` now works for unsigned intergers with `nim js` (#14122)Timothee Cour2020-04-271-0/+72
* $(unsigned) now works for js * move NimMajor+friends closer to NimVersion according as per reviewer feedback
881ec3'>^
d5cc2085e ^
4d4b3b1c0 ^
405b86068





8b2a9401a ^
405b86068









8d7a45f20 ^




405b86068
ff5b446df ^
8d7a45f20 ^
405b86068
ff5b446df ^
405b86068

8098e2a42 ^

ff5b446df ^
405b86068

ff5b446df ^
450a3e317 ^



72f804671 ^


003601472 ^

405b86068
ff5b446df ^
405b86068
286f16630 ^
405b86068
8b2a9401a ^
405b86068




e75e42191 ^



ff5b446df ^
e84834db7 ^
e75e42191 ^


ff5b446df ^
e84834db7 ^
405b86068
2df9b442c ^

405b86068

405b86068
ff5b446df ^
2df9b442c ^
405b86068
ff5b446df ^

405b86068
ff5b446df ^
2df9b442c ^
e8bc19f79 ^
572b7c37a ^

40f4fe997 ^

572b7c37a ^
40f4fe997 ^



e8bc19f79 ^
40f4fe997 ^
d23eb7984 ^
40f4fe997 ^











06cd15663 ^
e8bc19f79 ^

405b86068
7e351fc7f ^

8aa5991be ^

7e351fc7f ^
8aa5991be ^

7e351fc7f ^
8aa5991be ^

7e351fc7f ^
141b76e36 ^
559a7615a ^
003601472 ^

d5cc2085e ^
559a7615a ^

003601472 ^

d5cc2085e ^
559a7615a ^


003601472 ^


d5cc2085e ^
559a7615a ^
439aa2d04 ^
405b86068
67a30d837 ^
f9d8d6ce0 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200

 
                                  
                                         




                                                   
                                                                       
                                                                             

                                                                            
 

                         
     
                               
 

                                                 

                                   
                        
                                                            























                                                                               
            
 
                                                                              
                                                 


                                        
            
 





                                                              
                    









                                                                             




                                                                 
 
                                                               
                                                      
                                    
                                                        

                                    

                                                          
                                         

                
                                                



                                                          


                                 

                               
 
                                                                
                             
                                         
 
                                      




                                                                           



                                                  
                                                                    
                                                                               


                                                   
                                                                    
                                                                   
 

                                                              

                                                               
 
                                         
                                      
 

                                                  
 
                                                                
                                                        
                            

                                               

                      
                                    



                                     
                            
                   
                        











                                                
                                                                                   

                              
 

                     

                                                   
 

                                                 
 

                                                                
 
                                                                     
                                         

                                                        
              

                                                

                                                      
              


                                                                


                                                     
              
 
     
                                             
 
       
#
#
#            Nim's Runtime Library
#        (c) Copyright 2012 Andreas Rumpf
#
#    See the file "copying.txt", included in this
#    distribution, for details about the copyright.
#

# This file implements the ability to call native procs from libraries.
# It is not possible to do this in a platform independent way, unfortunately.
# However, the interface has been designed to take platform differences into
# account and been ported to all major platforms.

{.push stack_trace: off.}

const
  NilLibHandle: LibHandle = nil

proc nimLoadLibraryError(path: string) =
  # carefully written to avoid memory allocation:
  const prefix = "could not load: "
  cstderr.rawWrite(prefix)
  cstderr.rawWrite(path)
  when not defined(nimDebugDlOpen) and not defined(windows):
    cstderr.rawWrite("\n(compile with -d:nimDebugDlOpen for more information)")
  when defined(windows):
    const badExe = "\n(bad format; library may be wrong architecture)"
    let loadError = GetLastError()
    if loadError == ERROR_BAD_EXE_FORMAT:
      cstderr.rawWrite(badExe)
    when defined(guiapp):
      # Because console output is not shown in GUI apps, display the error as a
      # message box instead:
      var
        msg: array[1000, char]
        msgLeft = msg.len - 1 # leave (at least) one for nullchar
        msgIdx = 0
      copyMem(msg[msgIdx].addr, prefix.cstring, prefix.len)
      msgLeft -= prefix.len
      msgIdx += prefix.len
      let pathLen = min(path.len, msgLeft)
      copyMem(msg[msgIdx].addr, path.cstring, pathLen)
      msgLeft -= pathLen
      msgIdx += pathLen
      if loadError == ERROR_BAD_EXE_FORMAT and msgLeft >= badExe.len:
        copyMem(msg[msgIdx].addr, badExe.cstring, badExe.len)
      discard MessageBoxA(nil, msg[0].addr, nil, 0)
  cstderr.rawWrite("\n")
  rawQuit(1)

proc procAddrError(name: cstring) {.compilerproc, nonReloadable, hcrInline.} =
  # carefully written to avoid memory allocation:
  cstderr.rawWrite("could not import: ")
  cstderr.rawWrite(name)
  cstderr.rawWrite("\n")
  rawQuit(1)

# this code was inspired from Lua's source code:
# Lua - An Extensible Extension Language
# Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil
# http://www.lua.org
# mailto:info@lua.org

when defined(posix):
  #
  # =========================================================================
  # This is an implementation based on the dlfcn interface.
  # The dlfcn interface is available in Linux, SunOS, Solaris, IRIX, FreeBSD,
  # NetBSD, AIX 4.2, HPUX 11, and probably most other Unix flavors, at least
  # as an emulation layer on top of native functions.
  # =========================================================================
  #

  # c stuff:
  when defined(linux) or defined(macosx):
    const RTLD_NOW = cint(2)
  else:
    var
      RTLD_NOW {.importc: "RTLD_NOW", header: "<dlfcn.h>".}: cint

  proc dlclose(lib: LibHandle) {.importc, header: "<dlfcn.h>".}
  proc dlopen(path: cstring, mode: cint): LibHandle {.
      importc, header: "<dlfcn.h>".}
  proc dlsym(lib: LibHandle, name: cstring): ProcAddr {.
      importc, header: "<dlfcn.h>".}

  proc dlerror(): cstring {.importc, header: "<dlfcn.h>".}

  proc nimUnloadLibrary(lib: LibHandle) =
    dlclose(lib)

  proc nimLoadLibrary(path: string): LibHandle =
    let flags =
      when defined(globalSymbols): RTLD_NOW or RTLD_GLOBAL
      else: RTLD_NOW
    result = dlopen(path, flags)
    when defined(nimDebugDlOpen):
      let error = dlerror()
      if error != nil:
        cstderr.rawWrite(error)
        cstderr.rawWrite("\n")

  proc nimGetProcAddr(lib: LibHandle, name: cstring): ProcAddr =
    result = dlsym(lib, name)
    if result == nil: procAddrError(name)

elif defined(windows) or defined(dos):
  #
  # =======================================================================
  # Native Windows Implementation
  # =======================================================================
  #
  when defined(cpp):
    type
      THINSTANCE {.importc: "HINSTANCE".} = object
        x: pointer
    proc getProcAddress(lib: THINSTANCE, name: cstring): ProcAddr {.
        importcpp: "(void*)GetProcAddress(@)", header: "<windows.h>", stdcall.}
  else:
    type
      THINSTANCE {.importc: "HINSTANCE".} = pointer
    proc getProcAddress(lib: THINSTANCE, name: cstring): ProcAddr {.
        importc: "GetProcAddress", header: "<windows.h>", stdcall.}

  proc freeLibrary(lib: THINSTANCE) {.
      importc: "FreeLibrary", header: "<windows.h>", stdcall.}
  proc winLoadLibrary(path: cstring): THINSTANCE {.
      importc: "LoadLibraryA", header: "<windows.h>", stdcall.}

  proc nimUnloadLibrary(lib: LibHandle) =
    freeLibrary(cast[THINSTANCE](lib))

  proc nimLoadLibrary(path: string): LibHandle =
    result = cast[LibHandle](winLoadLibrary(path))

  proc nimGetProcAddr(lib: LibHandle, name: cstring): ProcAddr =
    result = getProcAddress(cast[THINSTANCE](lib), name)
    if result != nil: return
    const decoratedLength = 250
    var decorated: array[decoratedLength, char]
    decorated[0] = '_'
    var m = 1
    while m < (decoratedLength - 5):
      if name[m - 1] == '\x00': break
      decorated[m] = name[m - 1]
      inc(m)
    decorated[m] = '@'
    for i in countup(0, 50):
      var k = i * 4
      if k div 100 == 0:
        if k div 10 == 0:
          m = m + 1
        else:
          m = m + 2
      else:
        m = m + 3
      decorated[m + 1] = '\x00'
      while true:
        decorated[m] = chr(ord('0') + (k %% 10))
        dec(m)
        k = k div 10
        if k == 0: break
      result = getProcAddress(cast[THINSTANCE](lib), cast[cstring](addr decorated))
      if result != nil: return
    procAddrError(name)

elif defined(genode):

  proc nimUnloadLibrary(lib: LibHandle) =
    raiseAssert("nimUnloadLibrary not implemented")

  proc nimLoadLibrary(path: string): LibHandle =
    raiseAssert("nimLoadLibrary not implemented")

  proc nimGetProcAddr(lib: LibHandle, name: cstring): ProcAddr =
    raiseAssert("nimGetProcAddr not implemented")

elif defined(nintendoswitch) or defined(freertos) or defined(zephyr):
  proc nimUnloadLibrary(lib: LibHandle) =
    cstderr.rawWrite("nimUnLoadLibrary not implemented")
    cstderr.rawWrite("\n")
    rawQuit(1)

  proc nimLoadLibrary(path: string): LibHandle =
    cstderr.rawWrite("nimLoadLibrary not implemented")
    cstderr.rawWrite("\n")
    rawQuit(1)


  proc nimGetProcAddr(lib: LibHandle, name: cstring): ProcAddr =
    cstderr.rawWrite("nimGetProAddr not implemented")
    cstderr.rawWrite(name)
    cstderr.rawWrite("\n")
    rawQuit(1)

else:
  {.error: "no implementation for dyncalls".}

{.pop.}