summary refs log tree commit diff stats
path: root/compiler/commands.nim
Commit message (Collapse)AuthorAgeFilesLines
* fix #2844 #3911; add --spellsuggest to suggest symbols in scope with similar ↵Timothee Cour2021-03-161-0/+4
| | | | | | | spellings on undefined symbol error (#16067) * add --spellsuggest to suggest symbols in scope with similar spellings on undefined symbol errors * implement --spellsuggest with 0 arguments
* fix #17267 (#17273)flywind2021-03-071-2/+5
| | | | | | | | | | | | | | | | | * remove unnecessary when statement * remove outdated codes * reuse jsffi * move js json coverage * fix #17267 * address comments * Update compiler/main.nim * Update tests/threads/tjsthreads.nim
* follow #17245 deprecate refchecks (#17261)flywind2021-03-051-2/+6
| | | | | * follow #17245 deprecate refchecks * changelog * address comments
* deprecate newruntime (#17245)flywind2021-03-041-0/+1
| | | | | | * deprecate newruntime * tests * Update compiler/commands.nim
* followup #17225: simplify code after removing gc2, generational (#17242)Timothee Cour2021-03-031-6/+5
|
* fix #16731: using deprecated flags triggers a warning (#17225)Timothee Cour2021-03-021-23/+19
| | | | | | * using deprecated flags triggers a warning * cleanups * fixup * address comments
* `--nilseqs` is now a deprecated noop (#17211)Timothee Cour2021-03-011-2/+4
| | | | | * --nilseqs is now a deprecated noop * fix tests; fix: future => sugar
* document `since` (#17048)Timothee Cour2021-02-161-5/+3
| | | | * document `since` * address comment
* `--hintAsError` (#16763)Timothee Cour2021-01-201-4/+6
| | | | | | | * --hintAsError * add test, changelog * condsyms
* Deprecate TaintedString (#15423)Juan Carlos2021-01-151-2/+2
| | | | Co-authored-by: Timothee Cour <timothee.cour2@gmail.com> Co-authored-by: Dominik Picheta <dominikpicheta@googlemail.com>
* IC: next steps (#16632)Andreas Rumpf2021-01-121-3/+3
| | | | | | | | | | | | | * removed dead code * beginnings of a rodfile reader * IC: record global VM state changes and pragma state changes * IC: replay pragmas and VM state changes * implemented rod load file simuation for easier, extensive testing * critical bugfix * IC: stress test logic; should also help with recursive module dependencies; WIP * IC: loading from .rod files begins to work reliably * removed ugly hacks * yet another silly mistake
* IC: next steps (#16550)Andreas Rumpf2021-01-071-8/+9
| | | | | | | | | | | | | | | | | | * cleanups * ast.nim: cleanups * IC: no more sym.tab field, stored externally in the module graph * nimble compiles again * rodfiles: store bitwidth of integers and the endianness in the cookie because we serialize 'int' directly * rodfiles: added compilerproc and export sections * rodfiles: added all the missing sections * rodfiles: track the missing information * IC: architecture for lazy loading of proc bodies * make tests green again * completed the lazy loading of proc bodies * symbol lookup integration, part 1 * symbol lookup integration, part 2 * symbol lookup integration, part 3 * make tcompilerapi work again * rodfiles: fixed config change handling
* make --gc:arc --exceptions:quirky work again [backport:1.4] (#16583)Andreas Rumpf2021-01-041-0/+4
| | | | | * make --gc:arc --exceptions:quirky work again [backport:1.4] * fixes #16404 [backport:1.4]
* big steps torwards an efficient, simple IC implementation (#16543)Andreas Rumpf2021-01-021-5/+0
| | | | | | | | | | | | | | | | | | | * reworked ID handling * the packed AST now has its own ID mechanism * basic serialization code works * extract rodfiles to its own module * rodfiles: store and compare configs * rodfiles: store dependencies * store config at the end * precise dependency tracking * dependency tracking for rodfiles * completed loading of PSym, PType, etc * removed dead code * bugfix: do not realloc seqs when taking addr into an element * make IC opt-in for now * makes tcompilerapi green again * final cleanups Co-authored-by: Andy Davidoff <github@andy.disruptek.com>
* fix #16346 rst2html now honors SuccessX (#16347)Timothee Cour2020-12-261-0/+7
| | | | | | | | | | | * fix #16346 SuccessX rst2html * cleanups * _ * _ * _
* add test for --eval; fix a minor bug (#16224)Timothee Cour2020-12-011-0/+1
|
* cmdline: improve command processing (#16056)Timothee Cour2020-11-261-10/+47
|
* fix #16033 nim js --gc:arc works and ignores --gc:arc (#16036)Timothee Cour2020-11-181-1/+4
|
* new: `nim -e:cmd` to run a command directly; also fixes #15731 (#15687)Timothee Cour2020-11-091-6/+19
| | | | | | | | | | | | | | | * new: `nim -i cmd` * rename -i to -e (for eval); consistent with majority of other programing languages * `nim e -e:cmd` now works; bugfix: `echo cmd | nim e -` now works * honor --betterRun * address comments * --eval alias for -e (replaces undocumented --eval which was a noop) * --eval now defaults to e (nimscript) instead of r * address comment: remove -e, only keep --eval * address comment * fixup * Update compiler/nimconf.nim Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* EnumUtils, speed up findStr in compiler (#15777)cooldome2020-11-031-2/+2
| | | | | | | | * add parseEnumRange * fix runnable example * update changelog * use parseEnumRange in compiler * reorganise code * add changelog, make single normalizer argument
* Use modern enums in compiler (#15775)cooldome2020-11-021-4/+4
|
* CleanupClyybber2020-10-221-2/+0
|
* add Source+Edit links on top of every docgend file (#15642)Timothee Cour2020-10-221-0/+2
|
* add --declaredlocs (#15666)Timothee Cour2020-10-211-0/+2
|
* Make useVersion:1.0 disable the proc arg sym change (#15570)Clyybber2020-10-141-0/+6
| | | | | * Make useVersion:1.0 disable the proc arg sym change * Also do this for useVersion:1.2
* Update the list of GC options when raising an error (closes #15547) (#15553)Benjamin Lee2020-10-141-1/+1
|
* fix #15405. deepcopy arc (#15410)cooldome2020-10-011-1/+2
| | | | | | | * fix #15405 * fix tests * deepcopy for ARC has to be enabled via --deepcopy:on Co-authored-by: Araq <rumpf_a@web.de>
* fix the indentation in `--help` and `--fullhelp` (#15387)Miran2020-09-231-2/+2
| | | | | * fix the indentation in `--help` and `--fullhelp` * a better way to fix it
* fixes #15325 (#15340)Andreas Rumpf2020-09-161-0/+3
|
* Big compiler Cleanup (#14777)Clyybber2020-08-281-11/+10
|
* Fix forward declaration issues in template/macro context (#15091)Clyybber2020-07-291-2/+0
| | | | | | | | | | | | | | | | | | | | | | | * Fix forward declaration issues in template/macro context * Correct forward declaration resolving for overloads * Remove old dead code * WIP consistent gensym ids * Minimize diff * Remove obsoleted hack * Add templInstCounter to give unique IDs to template instantiations * Remove obsoleted code * Eh, init in myOpen, not myProcess... * Remove optNimV019 * Add testcase for #13484
* fix #14684 (#15059)Bung2020-07-251-0/+2
|
* An optimizer for ARC (#14962)Andreas Rumpf2020-07-151-0/+3
| | | | | | | | | | | | | | | | | | | | * WIP: an optimizer for ARC * do not optimize away destructors in 'finally' if unstructured control flow is involved * optimized the optimizer * minor code cleanup * first steps to .cursor inference * cursor inference: big steps to a working solution * baby steps * better .cursor inference * new feature: expandArc for easy inspection of the AST after ARC transformations * added topt_cursor test * adapt tests * cleanups, make tests green * optimize common traversal patterns * moved test case * fixes .cursor inference so that npeg compiles once again * cursor inference: more bugfixes Co-authored-by: Clyybber <darkmine956@gmail.com>
* fix #14912, make `--useVersion:1.0` work again (#14945)Miran2020-07-101-0/+1
| | | | | * fix #14912, make `--useVersion:1.0` work again * a better fix * add test
* VM profiler (#14833)Ico Doornekamp2020-07-091-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | * Crude VM profiler * Added --profileVM flag, refactoring * fixed FileLine hash * Use TLineInfo instead of own FileLine, updated formatting * Refactoring, moved PStackFrame to vmdefs for cleaner data structure * Moved vmprofiler to separate file * Simplified TLineInfo hash, use toFileLineCol for output * Hash * Moved profile data into Config, dump only once at end of run * Changed profile output header to show '#instr' instead of 'count' * Do not accumulate instrcount for non-top frames Co-authored-by: Ico Doornekamp <git@zevv.nl>
* Clean out oldast (#14837)Juan Carlos2020-06-301-2/+0
| | | | * Clean out old Deprecated CLI switch * Update to remove --oldast CLI option
* Deprecated laxStrings for mutating the internal zero terminator on strings ↵Juan Carlos2020-06-231-1/+0
| | | | | and its Deprecated code cleaned out (#14766) Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* Deprecate oldNewlines, clean out deprecated code from oldNewlines (#14763)Juan Carlos2020-06-231-10/+0
|
* compiler/commands: make gitHash settable at compile-time. (#14654)alaviss2020-06-141-1/+1
| | | | This is useful for building nightlies, since we will be building from a generated source archive and git metadata is lost there.
* bug fixes with sfMainModule, hints, mainPackageNotes, mainPackageId, ↵Timothee Cour2020-06-041-2/+0
| | | | | | | hintSuccessX (#14555) * SuccessX `out` now works with --compileOnly and jsonscript; fix bugs in jsonscript * several bug fixes; eg: `nim doc lib/system/io` now is sane * dummy edit to force docs CI
* fix #6583, fix #14376, index+search now generated for all projects, many bug ↵Timothee Cour2020-05-251-2/+2
| | | | | | | | | fixes with nim doc (#14324) * refs #6583 fix nim doc output * changelog * change default for outDir when unspecified * cleanups * --project implies --index
* fix #14364 (#14372) [backport:1.2]Ștefan Talpalaru2020-05-181-0/+1
| | | | Turn on the TLS emulation when using Boehm, since it doesn't scan the real TLS.
* fix some issues with --backend (#14363)Timothee Cour2020-05-161-4/+0
| | | | | * fix some issues with --backend * fix https://github.com/timotheecour/Nim/issues/175; improve upon #14306
* `nim doc --backend:js`, `nim doc --doccmd:-d:foo`, `nim r --backend:js`, ↵Timothee Cour2020-05-111-2/+9
| | | | | | | | | | `--doccmd:skip` + other improvements (#14278) * `nim doc --backend:js|cpp...` `nim doc --doccmd:'-d:foo --threads:on'` `nim r --backend:cpp...` (implies --run --usenimcache) * --usenimcache works with all targets * --docCmd:skip now skips compiling snippets; 50X speedup for doc/manual.rst
* --hint:processing (+friends) is now supported and means ↵Timothee Cour2020-05-081-3/+5
| | | | `--hint:processing:on`, like all other bool flags (#14271)
* remove the nilChecks switch; refs #11570Araq2020-04-201-2/+2
|
* new feature: ability to turn specific warnings to errorsAndreas Rumpf2020-04-041-5/+12
|
* sourcemaps for the JS codegen (#7508)Alexander Ivanov2020-04-031-0/+4
|
* stacktraces can now show custom runtime msgs per frame (#13351)Timothee Cour2020-03-301-0/+2
| | | | | | | | * stacktraces can now show custom runtime msgs * improve tests/stdlib/tstackframes.nim * fix test for --gc:arc * test --stacktraceMsgs:on and --stacktraceMsgs:off * --stacktracemsgs:off by default
* '.push raises: []' now also affects proc types (#13776)Andreas Rumpf2020-03-291-0/+1
| | | | | | | | | * '.push raises: []' now also affects proc types * fixes the regression * less disruptive bugfix * another attempt
f='#n44'>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

 
                            
                                         




                                                   
                                            
                           
 


                                   

                                           


















                                                                                       
                                                                                                                       
 





                                                                               
                      


                                                            
                  
           



                     


                                    
                                   



                   
       
               

                               
 
                                                
                     
             

                                                          
 
                                    



                                                          
               



                                                   
             
             
            



                         
                         
                                         
                      
            
               

         
                                                                              
 

                            
                                                                          

                                                                        
                   
 
                              


                     
             
                   

                     
       




                               
               
 



                                                              

                                                            


                                              
                                                

                                                     

                                              
                                                     
                                       




                                                                     
                 


            
             






                                                                     
                                     

         
                                                 

                 
                                                               

                 

       










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

## Serialization utilities for the compiler.
import std/[strutils, math]

when defined(nimPreviewSlimSystem):
  import std/assertions

# bcc on windows doesn't have C99 functions
when defined(windows) and defined(bcc):
  {.emit: """#if defined(_MSC_VER) && _MSC_VER < 1900
  #include <stdarg.h>
  static int c99_vsnprintf(char *outBuf, size_t size, const char *format, va_list ap) {
    int count = -1;
    if (size != 0) count = _vsnprintf_s(outBuf, size, _TRUNCATE, format, ap);
    if (count == -1) count = _vscprintf(format, ap);
    return count;
  }
  int snprintf(char *outBuf, size_t size, const char *format, ...) {
    int count;
    va_list ap;
    va_start(ap, format);
    count = c99_vsnprintf(outBuf, size, format, ap);
    va_end(ap);
    return count;
  }
  #endif
  """.}

proc c_snprintf(s: cstring; n: uint; frmt: cstring): cint {.importc: "snprintf", header: "<stdio.h>", nodecl, varargs.}


when not declared(signbit):
  proc c_signbit(x: SomeFloat): cint {.importc: "signbit", header: "<math.h>".}
  proc signbit*(x: SomeFloat): bool {.inline.} =
    result = c_signbit(x) != 0

import std/formatfloat

proc toStrMaxPrecision*(f: BiggestFloat | float32): string =
  const literalPostfix = when f is float32: "f" else: ""
  case classify(f)
  of fcNan:
    if signbit(f):
      result = "-NAN"
    else:
      result = "NAN"
  of fcNegZero:
    result = "-0.0" & literalPostfix
  of fcZero:
    result = "0.0" & literalPostfix
  of fcInf:
    result = "INF"
  of fcNegInf:
    result = "-INF"
  else:
    result = ""
    result.addFloatRoundtrip(f)
    result.add literalPostfix

proc encodeStr*(s: string, result: var string) =
  for i in 0..<s.len:
    case s[i]
    of 'a'..'z', 'A'..'Z', '0'..'9', '_': result.add(s[i])
    else: result.add('\\' & toHex(ord(s[i]), 2))

proc hexChar(c: char, xi: var int) =
  case c
  of '0'..'9': xi = (xi shl 4) or (ord(c) - ord('0'))
  of 'a'..'f': xi = (xi shl 4) or (ord(c) - ord('a') + 10)
  of 'A'..'F': xi = (xi shl 4) or (ord(c) - ord('A') + 10)
  else: discard

proc decodeStr*(s: cstring, pos: var int): string =
  var i = pos
  result = ""
  while true:
    case s[i]
    of '\\':
      inc(i, 3)
      var xi = 0
      hexChar(s[i-2], xi)
      hexChar(s[i-1], xi)
      result.add(chr(xi))
    of 'a'..'z', 'A'..'Z', '0'..'9', '_':
      result.add(s[i])
      inc(i)
    else: break
  pos = i

const chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

{.push overflowChecks: off.}

# since negative numbers require a leading '-' they use up 1 byte. Thus we
# subtract/add `vintDelta` here to save space for small negative numbers
# which are common in ROD files:
const vintDelta = 5

template encodeIntImpl(self) =
  var d: char
  var v = x
  var rem = v mod 190
  if rem < 0:
    result.add('-')
    v = - (v div 190)
    rem = - rem
  else:
    v = v div 190
  var idx = int(rem)
  if idx < 62: d = chars[idx]
  else: d = chr(idx - 62 + 128)
  if v != 0: self(v, result)
  result.add(d)

proc encodeVBiggestIntAux(x: BiggestInt, result: var string) =
  ## encode a biggest int as a variable length base 190 int.
  encodeIntImpl(encodeVBiggestIntAux)

proc encodeVBiggestInt*(x: BiggestInt, result: var string) =
  ## encode a biggest int as a variable length base 190 int.
  encodeVBiggestIntAux(x +% vintDelta, result)
  #  encodeIntImpl(encodeVBiggestInt)

proc encodeVIntAux(x: int, result: var string) =
  ## encode an int as a variable length base 190 int.
  encodeIntImpl(encodeVIntAux)

proc encodeVInt*(x: int, result: var string) =
  ## encode an int as a variable length base 190 int.
  encodeVIntAux(x +% vintDelta, result)

template decodeIntImpl() =
  var i = pos
  var sign = - 1
  assert(s[i] in {'a'..'z', 'A'..'Z', '0'..'9', '-', '\x80'..'\xFF'})
  if s[i] == '-':
    inc(i)
    sign = 1
  result = 0
  while true:
    case s[i]
    of '0'..'9': result = result * 190 - (ord(s[i]) - ord('0'))
    of 'a'..'z': result = result * 190 - (ord(s[i]) - ord('a') + 10)
    of 'A'..'Z': result = result * 190 - (ord(s[i]) - ord('A') + 36)
    of '\x80'..'\xFF': result = result * 190 - (ord(s[i]) - 128 + 62)
    else: break
    inc(i)
  result = result * sign -% vintDelta
  pos = i

proc decodeVInt*(s: cstring, pos: var int): int =
  decodeIntImpl()

proc decodeVBiggestInt*(s: cstring, pos: var int): BiggestInt =
  decodeIntImpl()

{.pop.}

iterator decodeVIntArray*(s: cstring): int =
  var i = 0
  while s[i] != '\0':
    yield decodeVInt(s, i)
    if s[i] == ' ': inc i

iterator decodeStrArray*(s: cstring): string =
  var i = 0
  while s[i] != '\0':
    yield decodeStr(s, i)
    if s[i] == ' ': inc i