summary refs log tree commit diff stats
path: root/tests
ModeNameSize
d---------actiontable89log stats plain
d---------alias38log stats plain
d---------ambsym318log stats plain
d---------array283log stats plain
d---------assert169log stats plain
d---------assign258log stats plain
d---------astoverload45log stats plain
d---------async275log stats plain
-rw-r--r--benchmark.nim1293log stats plain blame
d---------benchmarks81log stats plain
d---------bind381log stats plain
d---------borrow85log stats plain
d---------caas1390log stats plain
d---------casestmt368log stats plain
d---------ccg47log stats plain
d---------ccgbugs205log stats plain
d---------closure644log stats plain
d---------cnstseq122log stats plain
d---------collections76log stats plain
d---------compiles41log stats plain
d---------concat39log stats plain
d---------concurrency44log stats plain
d---------constr80log stats plain
d---------constraints44log stats plain
d---------controlflow197log stats plain
d---------converter179log stats plain
d---------defaultprocparam98log stats plain
d---------deprecated43log stats plain
d---------destructor132log stats plain
d---------discard89log stats plain
d---------distinct82log stats plain
d---------dll166log stats plain
d---------effects441log stats plain
d---------enum367log stats plain
d---------exception631log stats plain
d---------exprs176log stats plain
d---------fields136log stats plain
d---------float156log stats plain
d---------friends80log stats plain
d---------gc523log stats plain
d---------generics1588log stats plain
d---------gensym85log stats plain
d---------global167log stats plain
d---------implicit91log stats plain
d---------init82log stats plain
d---------iter819log stats plain
-rw-r--r--js.html765log stats plain blame
-rw-r--r--js.nim576log stats plain blame
d---------js157log stats plain
d---------let73log stats plain
d---------lexer359log stats plain
d---------lookups83log stats plain
d---------macros1164log stats plain
d---------magics40log stats plain
d---------manyloc230log stats plain
d---------matrix160log stats plain
d---------metatype758log stats plain
d---------method360log stats plain
d---------misc2864log stats plain
-rw-r--r--mmaptest.nim1503log stats plain blame
d---------module316log stats plain
d---------modules164log stats plain
d---------namedparams89log stats plain
d---------namspc119log stats plain
d---------notnil199log stats plain
d---------objects436log stats plain
d---------objvariant217log stats plain
d---------openarray125log stats plain
d---------osproc72log stats plain
d---------overflw120log stats plain
d---------overload275log stats plain
d---------parallel537log stats plain
d---------parser259log stats plain
d---------pragmas80log stats plain
d---------proc82log stats plain
d---------procvar169log stats plain
d---------range292log stats plain
-rw-r--r--readme.txt315log stats plain blame
-rw-r--r--rectest.nim63log stats plain blame
d---------rodfiles655log stats plain
d---------seq236log stats plain
d---------sets153log stats plain
d---------showoff286log stats plain
d---------specialops39log stats plain
d---------static49log stats plain
-rw-r--r--stckovfl.nim144log stats plain blame
d---------stdlib1493log stats plain
d---------system229log stats plain
d---------table202log stats plain
d---------template903log stats plain
d---------testament267log stats plain
d---------testdata351log stats plain
d---------threads353log stats plain
d---------trmacros475log stats plain
d---------tuples92log stats plain
d---------typerel922log stats plain
d---------types330log stats plain
d---------usingstmt47log stats plain
d---------varres199log stats plain
d---------varstmt76log stats plain
d---------vm723log stats plain
b619fb83'>6ff8752be ^
0b4d5e45b ^

37229df7f ^
d29aa4c5a ^


90119066a ^
b4e25a637 ^

be4526362 ^
b4e25a637 ^



90119066a ^
















6ff8752be ^
202972dea ^




b4e25a637 ^
90119066a ^


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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306


                                          
                                         




                                                   




                                       
 
      



                                         

                         





                                                                   
                                                                   



                                                                   
                                              



                                                                     
                                                      



                                                                         
                                                                        
                                            
                                                                           
                                                                      
                                                                   


                                                                                
                                                                            
                                                  
                                                                        
                                                                               
                                                            
   
 
                                                          








                                            


                                                          
                             

                                                                             

                         

                                                                   
  





                                                                         
                                          

                                           
                                                                               
                     

                             


                                                                       

                        

                                                                              
 

                                                                               
     
                                                             

                               


                                           
                                                                           

                           
                               
                                            
                                                    
                      
                                  
                                
                                                           

                                   
                                
                                                    
  


                                                                         


                                               
                                 
                                           

                                    
                  
                                    
                                         
  
                         
                                        




                                         
                                                                                





                                            
                                                                             





                                                                               

                                                                           


















                                                            
                                         
                          
                 

                                      
                               



                           
                                                   


                             
                                                       

                                 
                     
 

                                                                               
                         
                        





















                                                                         
                                       
                
             










                                                                  
         














                                                                     
    


                              


                                                                               

                                                    
                          

                                                           
                                                        


                                                                         
 

                                        
                                           



                                               
















                                                                      
                                           




                                                               
                                 


                     
#
#
#         Maintenance program for Nimrod  
#        (c) Copyright 2014 Andreas Rumpf
#
#    See the file "copying.txt", included in this
#    distribution, for details about the copyright.
#

when defined(gcc) and defined(windows):
  when defined(x86):
    {.link: "icons/koch.res".}
  else:
    {.link: "icons/koch_icon.o".}

import
  os, strutils, parseopt, osproc, streams

when defined(withUpdate):
  import httpclient
when defined(haveZipLib):
  import zipfiles

const
  HelpText = """
+-----------------------------------------------------------------+
|         Maintenance program for Nimrod                          |
|             Version $1|
|             (c) 2014 Andreas Rumpf                              |
+-----------------------------------------------------------------+
Build time: $2, $3

Usage:
  koch [options] command [options for command]
Options:
  --help, -h               shows this help and quits
Possible Commands:
  boot [options]           bootstraps with given command line options
  install [dir]            installs to given directory
  clean                    cleans Nimrod project; removes generated files
  web                      generates the website
  csource [options]        builds the C sources for installation
  zip                      builds the installation ZIP package
  inno [options]           builds the Inno Setup installer (for Windows)
  tests [options]          run the testsuite
  update                   updates nimrod to the latest version from github
                           (compile koch with -d:withUpdate to enable)
  temp options             creates a temporary compiler for testing
Boot options:
  -d:release               produce a release version of the compiler
  -d:tinyc                 include the Tiny C backend (not supported on Windows)
  -d:useGnuReadline        use the GNU readline library for interactive mode
                           (not needed on Windows)
  -d:useFFI                build Nimrod with FFI support at compile time
  -d:nativeStacktrace      use native stack traces (only for Mac OS X or Linux)
  -d:noCaas                build Nimrod without CAAS support
"""

proc exe(f: string): string = return addFileExt(f, ExeExt)

proc exec(cmd: string) =
  echo(cmd)
  if execShellCmd(cmd) != 0: quit("FAILURE")

proc tryExec(cmd: string): bool = 
  echo(cmd)
  result = execShellCmd(cmd) == 0

const
  compileNimInst = "-d:useLibzipSrc tools/niminst/niminst"

proc csource(args: string) = 
  exec("nimrod cc $1 -r $3 --var:version=$2 csource compiler/nimrod.ini $1" %
       [args, NimrodVersion, compileNimInst])

proc zip(args: string) = 
  exec("nimrod cc -r $2 --var:version=$1 zip compiler/nimrod.ini" %
       [NimrodVersion, compileNimInst])
  
proc buildTool(toolname, args: string) = 
  exec("nimrod cc $# $#" % [args, toolname])
  copyFile(dest="bin"/ splitFile(toolname).name.exe, source=toolname.exe)

proc inno(args: string) =
  # make sure we have generated the c2nim and niminst executables:
  buildTool("tools/niminst/niminst", args)
  buildTool("tools/nimgrep", args)
  buildTool("compiler/c2nim/c2nim", args)  
  exec("tools" / "niminst" / "niminst --var:version=$# inno compiler/nimrod" % 
       NimrodVersion)

proc install(args: string) = 
  exec("nimrod cc -r $# --var:version=$# scripts compiler/nimrod.ini" %
       [compileNimInst, NimrodVersion])
  exec("sh ./install.sh $#" % args)

proc web(args: string) =
  exec(("nimrod cc -r tools/nimweb.nim web/nimrod --putenv:nimrodversion=$#" &
        " --path:$#") % [NimrodVersion, getCurrentDir()])

# -------------- boot ---------------------------------------------------------

const
  bootOptions = "" # options to pass to the bootstrap process

proc findStartNimrod: string = 
  # we try several things before giving up:
  # * bin/nimrod
  # * $PATH/nimrod
  # If these fail, we try to build nimrod with the "build.(sh|bat)" script.
  var nimrod = "nimrod".exe
  result = "bin" / nimrod
  if existsFile(result): return
  for dir in split(getEnv("PATH"), PathSep):
    if existsFile(dir / nimrod): return dir / nimrod
  when defined(Posix):
    const buildScript = "build.sh"
    if existsFile(buildScript): 
      if tryExec("./" & buildScript): return "bin" / nimrod
  else:
    const buildScript = "build.bat"
    if existsFile(buildScript): 
      if tryExec(buildScript): return "bin" / nimrod
  
  echo("Found no nimrod compiler and every attempt to build one failed!")
  quit("FAILURE")

proc safeRemove(filename: string) = 
  if existsFile(filename): removeFile(filename)

proc thVersion(i: int): string = 
  result = ("compiler" / "nimrod" & $i).exe

proc copyExe(source, dest: string) =
  safeRemove(dest)
  copyFile(dest=dest, source=source)
  inclFilePermissions(dest, {fpUserExec})
  
proc boot(args: string) =
  var output = "compiler" / "nimrod".exe
  var finalDest = "bin" / "nimrod".exe
  
  copyExe(findStartNimrod(), 0.thVersion)
  for i in 0..2:
    echo "iteration: ", i+1
    exec i.thVersion & " cc $# $# compiler" / "nimrod.nim" % [bootOptions, args]
    if sameFileContent(output, i.thVersion):
      copyExe(output, finalDest)
      echo "executables are equal: SUCCESS!"
      return
    copyExe(output, (i+1).thVersion)
  copyExe(output, finalDest)
  when not defined(windows): echo "[Warning] executables are still not equal"

# -------------- clean --------------------------------------------------------

const
  cleanExt = [
    ".ppu", ".o", ".obj", ".dcu", ".~pas", ".~inc", ".~dsk", ".~dpr",
    ".map", ".tds", ".err", ".bak", ".pyc", ".exe", ".rod", ".pdb", ".idb",
    ".idx"
  ]
  ignore = [
    ".bzrignore", "nimrod", "nimrod.exe", "koch", "koch.exe"
  ]

proc cleanAux(dir: string) = 
  for kind, path in walkDir(dir):
    case kind
    of pcFile:
      var (dir, name, ext) = splitFile(path)
      if ext == "" or cleanExt.contains(ext):
        if not ignore.contains(name):
          echo "removing: ", path
          removeFile(path)
    of pcDir:
      case splitPath(path).tail
      of "nimcache": 
        echo "removing dir: ", path
        removeDir(path)
      of "dist", ".git", "icons": discard
      else: cleanAux(path)
    else: discard

proc removePattern(pattern: string) = 
  for f in walkFiles(pattern): 
    echo "removing: ", f
    removeFile(f)

proc clean(args: string) = 
  if existsFile("koch.dat"): removeFile("koch.dat")
  removePattern("web/*.html")
  removePattern("doc/*.html")
  cleanAux(getCurrentDir())
  for kind, path in walkDir(getCurrentDir() / "build"):
    if kind == pcDir: 
      echo "removing dir: ", path
      removeDir(path)

# -------------- update -------------------------------------------------------

when defined(withUpdate):
  when defined(windows):
    {.warning: "Windows users: Make sure to run 'koch update' in Bash.".}

  proc update(args: string) =
    when defined(windows):
      echo("Windows users: Make sure to be running this in Bash. ",
           "If you aren't, press CTRL+C now.")

    var thisDir = getAppDir()
    var git = findExe("git")
    echo("Checking for git repo and git executable...")
    if existsDir(thisDir & "/.git") and git != "":
      echo("Git repo found!")
      # use git to download latest source
      echo("Checking for updates...")
      discard startCmd(git & " fetch origin master")
      var procs = startCmd(git & " diff origin/master master")
      var errcode = procs.waitForExit()
      var output = readLine(procs.outputStream)
      echo(output)
      if errcode == 0:
        if output == "":
          # No changes
          echo("No update. Exiting...")
          return
        else:
          echo("Fetching updates from repo...")
          var pullout = execCmdEx(git & " pull origin master")
          if pullout[1] != 0:
            quit("An error has occured.")
          else:
            if pullout[0].startsWith("Already up-to-date."):
              quit("No new changes fetched from the repo. " &
                   "Local branch must be ahead of it. Exiting...")
      else:
        quit("An error has occured.")
      
    else:
      echo("No repo or executable found!")
      when defined(haveZipLib):
        echo("Falling back.. Downloading source code from repo...")
        # use dom96's httpclient to download zip
        downloadFile("https://github.com/Araq/Nimrod/zipball/master",
                     thisDir / "update.zip")
        try:
          echo("Extracting source code from archive...")
          var zip: TZipArchive
          discard open(zip, thisDir & "/update.zip", fmRead)
          extractAll(zip, thisDir & "/")
        except:
          quit("Error reading archive.")
      else:
        quit("No failback available. Exiting...")
    
    echo("Starting update...")
    boot(args)
    echo("Update complete!")

# -------------- tests --------------------------------------------------------

template `|`(a, b): expr = (if a.len > 0: a else: b)

proc tests(args: string) =
  # we compile the tester with taintMode:on to have a basic
  # taint mode test :-)
  exec "nimrod cc --taintMode:on tests/testament/tester"
  let tester = quoteShell(getCurrentDir() / "tests/testament/tester".exe)
  exec tester & " " & (args|"all")
  exec tester & " html"

proc temp(args: string) =
  var output = "compiler" / "nimrod".exe
  var finalDest = "bin" / "nimrod_temp".exe
  exec("nimrod c compiler" / "nimrod")
  copyExe(output, finalDest)
  if args.len > 0: exec(finalDest & " " & args)

proc showHelp() = 
  quit(HelpText % [NimrodVersion & repeatChar(44-len(NimrodVersion)), 
                   CompileDate, CompileTime])

var op = initOptParser()
op.next()
case op.kind
of cmdLongOption, cmdShortOption: showHelp()
of cmdArgument:
  case normalize(op.key) 
  of "boot": boot(op.cmdLineRest)
  of "clean": clean(op.cmdLineRest)
  of "web": web(op.cmdLineRest)
  of "csource": csource(op.cmdLineRest)
  of "zip": zip(op.cmdLineRest)
  of "inno": inno(op.cmdLineRest)
  of "install": install(op.cmdLineRest)
  of "test", "tests": tests(op.cmdLineRest)
  of "update": 
    when defined(withUpdate):
      update(op.cmdLineRest)
    else:
      quit "this Koch has not been compiled with -d:withUpdate"
  of "temp": temp(op.cmdLineRest)
  else: showHelp()
of cmdEnd: showHelp()