From f8e219b877578b0c068588f94af656b52abdb5aa Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 9 Jul 2018 12:35:25 +0200 Subject: [PATCH 001/145] add the apis.txt table to nep1.rst --- doc/nep1.rst | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/doc/nep1.rst b/doc/nep1.rst index c4d4456815..1ef8c3c24b 100644 --- a/doc/nep1.rst +++ b/doc/nep1.rst @@ -60,7 +60,7 @@ Spacing and Whitespace Conventions Naming Conventions -------------------------- +------------------ Note: While the rules outlined below are the *current* naming conventions, these conventions have not always been in place. Previously, the naming @@ -147,6 +147,80 @@ changed in the future. an in-place version should get an ``-In`` suffix (``replaceIn`` for this example). +The stdlib API is designed to be **easy to use** and consistent. Ease of use is +measured by the number of calls to achieve a concrete high level action. The +ultimate goal is that the programmer can *guess* a name. + +The library uses a simple naming scheme that makes use of common abbreviations +to keep the names short but meaningful. + + +------------------- ------------ -------------------------------------- +English word To use Notes +------------------- ------------ -------------------------------------- +initialize initT ``init`` is used to create a + value type ``T`` +new newP ``new`` is used to create a + reference type ``P`` +find find should return the position where + something was found; for a bool result + use ``contains`` +contains contains often short for ``find() >= 0`` +append add use ``add`` instead of ``append`` +compare cmp should return an int with the + ``< 0`` ``== 0`` or ``> 0`` semantics; + for a bool result use ``sameXYZ`` +put put, ``[]=`` consider overloading ``[]=`` for put +get get, ``[]`` consider overloading ``[]`` for get; + consider to not use ``get`` as a + prefix: ``len`` instead of ``getLen`` +length len also used for *number of elements* +size size, len size should refer to a byte size +capacity cap +memory mem implies a low-level operation +items items default iterator over a collection +pairs pairs iterator over (key, value) pairs +delete delete, del del is supposed to be faster than + delete, because it does not keep + the order; delete keeps the order +remove delete, del inconsistent right now +include incl +exclude excl +command cmd +execute exec +environment env +variable var +value value, val val is preferred, inconsistent right + now +executable exe +directory dir +path path path is the string "/usr/bin" (for + example), dir is the content of + "/usr/bin"; inconsistent right now +extension ext +separator sep +column col, column col is preferred, inconsistent right + now +application app +configuration cfg +message msg +argument arg +object obj +parameter param +operator opr +procedure proc +function func +coordinate coord +rectangle rect +point point +symbol sym +literal lit +string str +identifier ident +indentation indent +------------------- ------------ -------------------------------------- + + Coding Conventions ------------------ From 470949f2e0b0b09d660169276a15e04e30a204ee Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 9 Jul 2018 13:07:55 +0200 Subject: [PATCH 002/145] avoid AST streaming, experiment what it breaks --- compiler/passes.nim | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/compiler/passes.nim b/compiler/passes.nim index 45c726f2ad..5477d277fd 100644 --- a/compiler/passes.nim +++ b/compiler/passes.nim @@ -179,7 +179,11 @@ proc processModule*(graph: ModuleGraph; module: PSym, stream: PLLStream): bool { if graph.stopCompile(): break var n = parseTopLevelStmt(p) if n.kind == nkEmpty: break - if {sfNoForward, sfReorder} * module.flags != {}: + #if {sfNoForward, sfReorder} * module.flags != {}: + when true: + # we now process the full AST in one go, so that destructor injection for top + # level statements works correctly. + if graph.stopCompile(): break # read everything, no streaming possible var sl = newNodeI(nkStmtList, n.info) sl.add n @@ -191,7 +195,7 @@ proc processModule*(graph: ModuleGraph; module: PSym, stream: PLLStream): bool { sl = reorder(graph, sl, module) discard processTopLevelStmt(sl, a) break - elif not processTopLevelStmt(n, a): break + #elif not processTopLevelStmt(n, a): break closeParsers(p) if s.kind != llsStdIn: break closePasses(graph, a) From ce01472ff395138a71b3fac35b4e0bb65ca20188 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Tue, 10 Jul 2018 10:39:53 +0200 Subject: [PATCH 003/145] refactorings in preparations for the new runtime --- compiler/ccgexprs.nim | 10 +- compiler/ccgstmts.nim | 2 +- compiler/commands.nim | 9 +- compiler/options.nim | 6 +- compiler/passes.nim | 8 +- lib/system.nim | 1 + lib/system/strmantle.nim | 293 +++++++++++++++++++++++++++++++++++++++ lib/system/sysstr.nim | 286 +------------------------------------- 8 files changed, 311 insertions(+), 304 deletions(-) create mode 100644 lib/system/strmantle.nim diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 9b31167e3e..b8a7f3b08a 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -164,7 +164,7 @@ proc canMove(n: PNode): bool = # result = false proc genRefAssign(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) = - if dest.storage == OnStack or not usesNativeGC(p.config): + if dest.storage == OnStack or not usesWriteBarrier(p.config): linefmt(p, cpsStmts, "$1 = $2;$n", rdLoc(dest), rdLoc(src)) elif dest.storage == OnHeap: # location is on heap @@ -256,7 +256,7 @@ proc genGenericAsgn(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) = # (for objects, etc.): if needToCopy notin flags or tfShallow in skipTypes(dest.t, abstractVarRange).flags: - if dest.storage == OnStack or not usesNativeGC(p.config): + if dest.storage == OnStack or not usesWriteBarrier(p.config): useStringh(p.module) linefmt(p, cpsStmts, "memcpy((void*)$1, (NIM_CONST void*)$2, sizeof($3));$n", @@ -290,7 +290,7 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) = if (needToCopy notin flags and src.storage != OnStatic) or canMove(src.lode): genRefAssign(p, dest, src, flags) else: - if dest.storage == OnStack or not usesNativeGC(p.config): + if dest.storage == OnStack or not usesWriteBarrier(p.config): linefmt(p, cpsStmts, "$1 = #copyString($2);$n", dest.rdLoc, src.rdLoc) elif dest.storage == OnHeap: # we use a temporary to care for the dreaded self assignment: @@ -1150,7 +1150,7 @@ proc rawGenNew(p: BProc, a: TLoc, sizeExpr: Rope) = addf(p.module.s[cfsTypeInit3], "$1->finalizer = (void*)$2;$n", [ti, rdLoc(f)]) let args = [getTypeDesc(p.module, typ), ti, sizeExpr] - if a.storage == OnHeap and usesNativeGC(p.config): + if a.storage == OnHeap and usesWriteBarrier(p.config): # use newObjRC1 as an optimization if canFormAcycle(a.t): linefmt(p, cpsStmts, "if ($1) { #nimGCunrefRC1($1); $1 = NIM_NIL; }$n", a.rdLoc) @@ -1181,7 +1181,7 @@ proc genNewSeqAux(p: BProc, dest: TLoc, length: Rope) = genTypeInfo(p.module, seqtype, dest.lode.info), length] var call: TLoc initLoc(call, locExpr, dest.lode, OnHeap) - if dest.storage == OnHeap and usesNativeGC(p.config): + if dest.storage == OnHeap and usesWriteBarrier(p.config): if canFormAcycle(dest.t): linefmt(p, cpsStmts, "if ($1) { #nimGCunrefRC1($1); $1 = NIM_NIL; }$n", dest.rdLoc) else: diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim index 7bb929d2b5..8a0e076861 100644 --- a/compiler/ccgstmts.nim +++ b/compiler/ccgstmts.nim @@ -16,7 +16,7 @@ const # above X strings a hash-switch for strings is generated proc registerGcRoot(p: BProc, v: PSym) = - if p.config.selectedGC in {gcMarkAndSweep, gcGenerational, gcV2, gcRefc} and + if p.config.selectedGC in {gcMarkAndSweep, gcDestructors, gcV2, gcRefc} and containsGarbageCollectedRef(v.loc.t): # we register a specialized marked proc here; this has the advantage # that it works out of the box for thread local storage then :-) diff --git a/compiler/commands.nim b/compiler/commands.nim index 866405f9f5..ef5a2a40fc 100644 --- a/compiler/commands.nim +++ b/compiler/commands.nim @@ -215,7 +215,8 @@ proc testCompileOptionArg*(conf: ConfigRef; switch, arg: string, info: TLineInfo of "refc": result = conf.selectedGC == gcRefc of "v2": result = conf.selectedGC == gcV2 of "markandsweep": result = conf.selectedGC == gcMarkAndSweep - of "generational": result = conf.selectedGC == gcGenerational + of "generational": result = false + of "destructors": result = conf.selectedGC == gcDestructors of "go": result = conf.selectedGC == gcGo of "none": result = conf.selectedGC == gcNone of "stack", "regions": result = conf.selectedGC == gcRegions @@ -435,9 +436,9 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo; of "markandsweep": conf.selectedGC = gcMarkAndSweep defineSymbol(conf.symbols, "gcmarkandsweep") - of "generational": - conf.selectedGC = gcGenerational - defineSymbol(conf.symbols, "gcgenerational") + of "destructors": + conf.selectedGC = gcDestructors + defineSymbol(conf.symbols, "gcdestructors") of "go": conf.selectedGC = gcGo defineSymbol(conf.symbols, "gogc") diff --git a/compiler/options.nim b/compiler/options.nim index c6e5c5b9f0..98c20a9b50 100644 --- a/compiler/options.nim +++ b/compiler/options.nim @@ -103,8 +103,8 @@ type cmdJsonScript # compile a .json build file TStringSeq* = seq[string] TGCMode* = enum # the selected GC - gcNone, gcBoehm, gcGo, gcRegions, gcMarkAndSweep, gcRefc, - gcV2, gcGenerational + gcNone, gcBoehm, gcGo, gcRegions, gcMarkAndSweep, gcDestructors, + gcRefc, gcV2 IdeCmd* = enum ideNone, ideSug, ideCon, ideDef, ideUse, ideDus, ideChk, ideMod, @@ -368,7 +368,7 @@ proc isDefined*(conf: ConfigRef; symbol: string): bool = else: discard proc importantComments*(conf: ConfigRef): bool {.inline.} = conf.cmd in {cmdDoc, cmdIdeTools} -proc usesNativeGC*(conf: ConfigRef): bool {.inline.} = conf.selectedGC >= gcRefc +proc usesWriteBarrier*(conf: ConfigRef): bool {.inline.} = conf.selectedGC >= gcRefc template compilationCachePresent*(conf: ConfigRef): untyped = conf.symbolFiles in {v2Sf, writeOnlySf} diff --git a/compiler/passes.nim b/compiler/passes.nim index 5477d277fd..45c726f2ad 100644 --- a/compiler/passes.nim +++ b/compiler/passes.nim @@ -179,11 +179,7 @@ proc processModule*(graph: ModuleGraph; module: PSym, stream: PLLStream): bool { if graph.stopCompile(): break var n = parseTopLevelStmt(p) if n.kind == nkEmpty: break - #if {sfNoForward, sfReorder} * module.flags != {}: - when true: - # we now process the full AST in one go, so that destructor injection for top - # level statements works correctly. - if graph.stopCompile(): break + if {sfNoForward, sfReorder} * module.flags != {}: # read everything, no streaming possible var sl = newNodeI(nkStmtList, n.info) sl.add n @@ -195,7 +191,7 @@ proc processModule*(graph: ModuleGraph; module: PSym, stream: PLLStream): bool { sl = reorder(graph, sl, module) discard processTopLevelStmt(sl, a) break - #elif not processTopLevelStmt(n, a): break + elif not processTopLevelStmt(n, a): break closeParsers(p) if s.kind != llsStdIn: break closePasses(graph, a) diff --git a/lib/system.nim b/lib/system.nim index 9e91bc7db8..d8ecfd55f1 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -3264,6 +3264,7 @@ when not defined(JS): #and not defined(nimscript): {.push stack_trace: off, profiler:off.} when hasAlloc: include "system/sysstr" {.pop.} + when hasAlloc: include "system/strmantle" when hostOS != "standalone": include "system/sysio" when hasThreadSupport: diff --git a/lib/system/strmantle.nim b/lib/system/strmantle.nim new file mode 100644 index 0000000000..eca6c553c0 --- /dev/null +++ b/lib/system/strmantle.nim @@ -0,0 +1,293 @@ +# +# +# Nim's Runtime Library +# (c) Copyright 2018 Andreas Rumpf +# +# See the file "copying.txt", included in this +# distribution, for details about the copyright. +# + +## Compilerprocs for strings that do not depend on the string implementation. + +proc cmpStrings(a, b: NimString): int {.inline, compilerProc.} = + if a == b: return 0 + when defined(nimNoNil): + let alen = if a == nil: 0 else: a.len + let blen = if b == nil: 0 else: b.len + else: + if a == nil: return -1 + if b == nil: return 1 + let alen = a.len + let blen = b.len + let minlen = min(alen, blen) + if minlen > 0: + result = c_memcmp(addr a.data, addr b.data, minlen.csize) + if result == 0: + result = alen - blen + else: + result = alen - blen + +proc eqStrings(a, b: NimString): bool {.inline, compilerProc.} = + if a == b: return true + when defined(nimNoNil): + let alen = if a == nil: 0 else: a.len + let blen = if b == nil: 0 else: b.len + else: + if a == nil or b == nil: return false + let alen = a.len + let blen = b.len + if alen == blen: + if alen == 0: return true + return equalMem(addr(a.data), addr(b.data), alen) + +proc hashString(s: string): int {.compilerproc.} = + # the compiler needs exactly the same hash function! + # this used to be used for efficient generation of string case statements + var h = 0 + for i in 0..len(s)-1: + h = h +% ord(s[i]) + h = h +% h shl 10 + h = h xor (h shr 6) + h = h +% h shl 3 + h = h xor (h shr 11) + h = h +% h shl 15 + result = h + +proc add*(result: var string; x: int64) = + let base = result.len + setLen(result, base + sizeof(x)*4) + var i = 0 + var y = x + while true: + var d = y div 10 + result[base+i] = chr(abs(int(y - d*10)) + ord('0')) + inc(i) + y = d + if y == 0: break + if x < 0: + result[base+i] = '-' + inc(i) + setLen(result, base+i) + # mirror the string: + for j in 0..i div 2 - 1: + swap(result[base+j], result[base+i-j-1]) + +proc nimIntToStr(x: int): string {.compilerRtl.} = + result = newStringOfCap(sizeof(x)*4) + result.add x + +proc add*(result: var string; x: float) = + when nimvm: + result.add $x + else: + var buf: array[0..64, char] + when defined(nimNoArrayToCstringConversion): + var n: int = c_sprintf(addr buf, "%.16g", x) + else: + var n: int = c_sprintf(buf, "%.16g", x) + var hasDot = false + for i in 0..n-1: + if buf[i] == ',': + buf[i] = '.' + hasDot = true + elif buf[i] in {'a'..'z', 'A'..'Z', '.'}: + hasDot = true + if not hasDot: + buf[n] = '.' + buf[n+1] = '0' + buf[n+2] = '\0' + # On Windows nice numbers like '1.#INF', '-1.#INF' or '1.#NAN' + # of '-1.#IND' are produced. + # We want to get rid of these here: + if buf[n-1] in {'n', 'N', 'D', 'd'}: + result.add "nan" + elif buf[n-1] == 'F': + if buf[0] == '-': + result.add "-inf" + else: + result.add "inf" + else: + var i = 0 + while buf[i] != '\0': + result.add buf[i] + inc i + +proc nimFloatToStr(f: float): string {.compilerproc.} = + result = newStringOfCap(8) + result.add f + +proc c_strtod(buf: cstring, endptr: ptr cstring): float64 {. + importc: "strtod", header: "", noSideEffect.} + +const + IdentChars = {'a'..'z', 'A'..'Z', '0'..'9', '_'} + powtens = [1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, + 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, + 1e20, 1e21, 1e22] + +proc nimParseBiggestFloat(s: string, number: var BiggestFloat, + start = 0): int {.compilerProc.} = + # This routine attempt to parse float that can parsed quickly. + # ie whose integer part can fit inside a 53bits integer. + # their real exponent must also be <= 22. If the float doesn't follow + # these restrictions, transform the float into this form: + # INTEGER * 10 ^ exponent and leave the work to standard `strtod()`. + # This avoid the problems of decimal character portability. + # see: http://www.exploringbinary.com/fast-path-decimal-to-floating-point-conversion/ + var + i = start + sign = 1.0 + kdigits, fdigits = 0 + exponent: int + integer: uint64 + frac_exponent = 0 + exp_sign = 1 + first_digit = -1 + has_sign = false + + # Sign? + if s[i] == '+' or s[i] == '-': + has_sign = true + if s[i] == '-': + sign = -1.0 + inc(i) + + # NaN? + if s[i] == 'N' or s[i] == 'n': + if s[i+1] == 'A' or s[i+1] == 'a': + if s[i+2] == 'N' or s[i+2] == 'n': + if s[i+3] notin IdentChars: + number = NaN + return i+3 - start + return 0 + + # Inf? + if s[i] == 'I' or s[i] == 'i': + if s[i+1] == 'N' or s[i+1] == 'n': + if s[i+2] == 'F' or s[i+2] == 'f': + if s[i+3] notin IdentChars: + number = Inf*sign + return i+3 - start + return 0 + + if s[i] in {'0'..'9'}: + first_digit = (s[i].ord - '0'.ord) + # Integer part? + while s[i] in {'0'..'9'}: + inc(kdigits) + integer = integer * 10'u64 + (s[i].ord - '0'.ord).uint64 + inc(i) + while s[i] == '_': inc(i) + + # Fractional part? + if s[i] == '.': + inc(i) + # if no integer part, Skip leading zeros + if kdigits <= 0: + while s[i] == '0': + inc(frac_exponent) + inc(i) + while s[i] == '_': inc(i) + + if first_digit == -1 and s[i] in {'0'..'9'}: + first_digit = (s[i].ord - '0'.ord) + # get fractional part + while s[i] in {'0'..'9'}: + inc(fdigits) + inc(frac_exponent) + integer = integer * 10'u64 + (s[i].ord - '0'.ord).uint64 + inc(i) + while s[i] == '_': inc(i) + + # if has no digits: return error + if kdigits + fdigits <= 0 and + (i == start or # no char consumed (empty string). + (i == start + 1 and has_sign)): # or only '+' or '- + return 0 + + if s[i] in {'e', 'E'}: + inc(i) + if s[i] == '+' or s[i] == '-': + if s[i] == '-': + exp_sign = -1 + + inc(i) + if s[i] notin {'0'..'9'}: + return 0 + while s[i] in {'0'..'9'}: + exponent = exponent * 10 + (ord(s[i]) - ord('0')) + inc(i) + while s[i] == '_': inc(i) # underscores are allowed and ignored + + var real_exponent = exp_sign*exponent - frac_exponent + let exp_negative = real_exponent < 0 + var abs_exponent = abs(real_exponent) + + # if exponent greater than can be represented: +/- zero or infinity + if abs_exponent > 999: + if exp_negative: + number = 0.0*sign + else: + number = Inf*sign + return i - start + + # if integer is representable in 53 bits: fast path + # max fast path integer is 1<<53 - 1 or 8999999999999999 (16 digits) + let digits = kdigits + fdigits + if digits <= 15 or (digits <= 16 and first_digit <= 8): + # max float power of ten with set bits above the 53th bit is 10^22 + if abs_exponent <= 22: + if exp_negative: + number = sign * integer.float / powtens[abs_exponent] + else: + number = sign * integer.float * powtens[abs_exponent] + return i - start + + # if exponent is greater try to fit extra exponent above 22 by multiplying + # integer part is there is space left. + let slop = 15 - kdigits - fdigits + if abs_exponent <= 22 + slop and not exp_negative: + number = sign * integer.float * powtens[slop] * powtens[abs_exponent-slop] + return i - start + + # if failed: slow path with strtod. + var t: array[500, char] # flaviu says: 325 is the longest reasonable literal + var ti = 0 + let maxlen = t.high - "e+000".len # reserve enough space for exponent + + result = i - start + i = start + # re-parse without error checking, any error should be handled by the code above. + if s[i] == '.': i.inc + while s[i] in {'0'..'9','+','-'}: + if ti < maxlen: + t[ti] = s[i]; inc(ti) + inc(i) + while s[i] in {'.', '_'}: # skip underscore and decimal point + inc(i) + + # insert exponent + t[ti] = 'E'; inc(ti) + t[ti] = (if exp_negative: '-' else: '+'); inc(ti) + inc(ti, 3) + + # insert adjusted exponent + t[ti-1] = ('0'.ord + abs_exponent mod 10).char; abs_exponent = abs_exponent div 10 + t[ti-2] = ('0'.ord + abs_exponent mod 10).char; abs_exponent = abs_exponent div 10 + t[ti-3] = ('0'.ord + abs_exponent mod 10).char + + when defined(nimNoArrayToCstringConversion): + number = c_strtod(addr t, nil) + else: + number = c_strtod(t, nil) + +proc nimInt64ToStr(x: int64): string {.compilerRtl.} = + result = newStringOfCap(sizeof(x)*4) + result.add x + +proc nimBoolToStr(x: bool): string {.compilerRtl.} = + return if x: "true" else: "false" + +proc nimCharToStr(x: char): string {.compilerRtl.} = + result = newString(1) + result[0] = x diff --git a/lib/system/sysstr.nim b/lib/system/sysstr.nim index 90ae91cf53..24ba02af60 100644 --- a/lib/system/sysstr.nim +++ b/lib/system/sysstr.nim @@ -20,37 +20,6 @@ proc resize(old: int): int {.inline.} = elif old < 65536: result = old * 2 else: result = old * 3 div 2 # for large arrays * 3/2 is better -proc cmpStrings(a, b: NimString): int {.inline, compilerProc.} = - if a == b: return 0 - when defined(nimNoNil): - let alen = if a == nil: 0 else: a.len - let blen = if b == nil: 0 else: b.len - else: - if a == nil: return -1 - if b == nil: return 1 - let alen = a.len - let blen = b.len - let minlen = min(alen, blen) - if minlen > 0: - result = c_memcmp(addr a.data, addr b.data, minlen.csize) - if result == 0: - result = alen - blen - else: - result = alen - blen - -proc eqStrings(a, b: NimString): bool {.inline, compilerProc.} = - if a == b: return true - when defined(nimNoNil): - let alen = if a == nil: 0 else: a.len - let blen = if b == nil: 0 else: b.len - else: - if a == nil or b == nil: return false - let alen = a.len - let blen = b.len - if alen == blen: - if alen == 0: return true - return equalMem(addr(a.data), addr(b.data), alen) - when declared(allocAtomic): template allocStr(size: untyped): untyped = cast[NimString](allocAtomic(size)) @@ -162,19 +131,6 @@ proc copyDeepString(src: NimString): NimString {.inline.} = result.len = src.len copyMem(addr(result.data), addr(src.data), src.len + 1) -proc hashString(s: string): int {.compilerproc.} = - # the compiler needs exactly the same hash function! - # this used to be used for efficient generation of string case statements - var h = 0 - for i in 0..len(s)-1: - h = h +% ord(s[i]) - h = h +% h shl 10 - h = h xor (h shr 6) - h = h +% h shl 3 - h = h xor (h shr 11) - h = h +% h shl 15 - result = h - proc addChar(s: NimString, c: char): NimString = # is compilerproc! if s == nil: @@ -246,7 +202,7 @@ proc appendChar(dest: NimString, c: char) {.compilerproc, inline.} = inc(dest.len) proc setLengthStr(s: NimString, newLen: int): NimString {.compilerRtl.} = - var n = max(newLen, 0) + let n = max(newLen, 0) if s == nil: result = mnewString(newLen) elif n <= s.space: @@ -340,243 +296,3 @@ proc setLengthSeqV2(s: PGenericSeq, typ: PNimType, newLen: int): PGenericSeq {. result = cast[PGenericSeq](newSeq(typ, newLen)) else: result = setLengthSeq(s, typ.base.size, newLen) - -# --------------- other string routines ---------------------------------- -proc add*(result: var string; x: int64) = - let base = result.len - setLen(result, base + sizeof(x)*4) - var i = 0 - var y = x - while true: - var d = y div 10 - result[base+i] = chr(abs(int(y - d*10)) + ord('0')) - inc(i) - y = d - if y == 0: break - if x < 0: - result[base+i] = '-' - inc(i) - setLen(result, base+i) - # mirror the string: - for j in 0..i div 2 - 1: - swap(result[base+j], result[base+i-j-1]) - -proc nimIntToStr(x: int): string {.compilerRtl.} = - result = newStringOfCap(sizeof(x)*4) - result.add x - -proc add*(result: var string; x: float) = - when nimvm: - result.add $x - else: - var buf: array[0..64, char] - when defined(nimNoArrayToCstringConversion): - var n: int = c_sprintf(addr buf, "%.16g", x) - else: - var n: int = c_sprintf(buf, "%.16g", x) - var hasDot = false - for i in 0..n-1: - if buf[i] == ',': - buf[i] = '.' - hasDot = true - elif buf[i] in {'a'..'z', 'A'..'Z', '.'}: - hasDot = true - if not hasDot: - buf[n] = '.' - buf[n+1] = '0' - buf[n+2] = '\0' - # On Windows nice numbers like '1.#INF', '-1.#INF' or '1.#NAN' - # of '-1.#IND' are produced. - # We want to get rid of these here: - if buf[n-1] in {'n', 'N', 'D', 'd'}: - result.add "nan" - elif buf[n-1] == 'F': - if buf[0] == '-': - result.add "-inf" - else: - result.add "inf" - else: - var i = 0 - while buf[i] != '\0': - result.add buf[i] - inc i - -proc nimFloatToStr(f: float): string {.compilerproc.} = - result = newStringOfCap(8) - result.add f - -proc c_strtod(buf: cstring, endptr: ptr cstring): float64 {. - importc: "strtod", header: "", noSideEffect.} - -const - IdentChars = {'a'..'z', 'A'..'Z', '0'..'9', '_'} - powtens = [1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, - 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, - 1e20, 1e21, 1e22] - -proc nimParseBiggestFloat(s: string, number: var BiggestFloat, - start = 0): int {.compilerProc.} = - # This routine attempt to parse float that can parsed quickly. - # ie whose integer part can fit inside a 53bits integer. - # their real exponent must also be <= 22. If the float doesn't follow - # these restrictions, transform the float into this form: - # INTEGER * 10 ^ exponent and leave the work to standard `strtod()`. - # This avoid the problems of decimal character portability. - # see: http://www.exploringbinary.com/fast-path-decimal-to-floating-point-conversion/ - var - i = start - sign = 1.0 - kdigits, fdigits = 0 - exponent: int - integer: uint64 - frac_exponent = 0 - exp_sign = 1 - first_digit = -1 - has_sign = false - - # Sign? - if s[i] == '+' or s[i] == '-': - has_sign = true - if s[i] == '-': - sign = -1.0 - inc(i) - - # NaN? - if s[i] == 'N' or s[i] == 'n': - if s[i+1] == 'A' or s[i+1] == 'a': - if s[i+2] == 'N' or s[i+2] == 'n': - if s[i+3] notin IdentChars: - number = NaN - return i+3 - start - return 0 - - # Inf? - if s[i] == 'I' or s[i] == 'i': - if s[i+1] == 'N' or s[i+1] == 'n': - if s[i+2] == 'F' or s[i+2] == 'f': - if s[i+3] notin IdentChars: - number = Inf*sign - return i+3 - start - return 0 - - if s[i] in {'0'..'9'}: - first_digit = (s[i].ord - '0'.ord) - # Integer part? - while s[i] in {'0'..'9'}: - inc(kdigits) - integer = integer * 10'u64 + (s[i].ord - '0'.ord).uint64 - inc(i) - while s[i] == '_': inc(i) - - # Fractional part? - if s[i] == '.': - inc(i) - # if no integer part, Skip leading zeros - if kdigits <= 0: - while s[i] == '0': - inc(frac_exponent) - inc(i) - while s[i] == '_': inc(i) - - if first_digit == -1 and s[i] in {'0'..'9'}: - first_digit = (s[i].ord - '0'.ord) - # get fractional part - while s[i] in {'0'..'9'}: - inc(fdigits) - inc(frac_exponent) - integer = integer * 10'u64 + (s[i].ord - '0'.ord).uint64 - inc(i) - while s[i] == '_': inc(i) - - # if has no digits: return error - if kdigits + fdigits <= 0 and - (i == start or # no char consumed (empty string). - (i == start + 1 and has_sign)): # or only '+' or '- - return 0 - - if s[i] in {'e', 'E'}: - inc(i) - if s[i] == '+' or s[i] == '-': - if s[i] == '-': - exp_sign = -1 - - inc(i) - if s[i] notin {'0'..'9'}: - return 0 - while s[i] in {'0'..'9'}: - exponent = exponent * 10 + (ord(s[i]) - ord('0')) - inc(i) - while s[i] == '_': inc(i) # underscores are allowed and ignored - - var real_exponent = exp_sign*exponent - frac_exponent - let exp_negative = real_exponent < 0 - var abs_exponent = abs(real_exponent) - - # if exponent greater than can be represented: +/- zero or infinity - if abs_exponent > 999: - if exp_negative: - number = 0.0*sign - else: - number = Inf*sign - return i - start - - # if integer is representable in 53 bits: fast path - # max fast path integer is 1<<53 - 1 or 8999999999999999 (16 digits) - let digits = kdigits + fdigits - if digits <= 15 or (digits <= 16 and first_digit <= 8): - # max float power of ten with set bits above the 53th bit is 10^22 - if abs_exponent <= 22: - if exp_negative: - number = sign * integer.float / powtens[abs_exponent] - else: - number = sign * integer.float * powtens[abs_exponent] - return i - start - - # if exponent is greater try to fit extra exponent above 22 by multiplying - # integer part is there is space left. - let slop = 15 - kdigits - fdigits - if abs_exponent <= 22 + slop and not exp_negative: - number = sign * integer.float * powtens[slop] * powtens[abs_exponent-slop] - return i - start - - # if failed: slow path with strtod. - var t: array[500, char] # flaviu says: 325 is the longest reasonable literal - var ti = 0 - let maxlen = t.high - "e+000".len # reserve enough space for exponent - - result = i - start - i = start - # re-parse without error checking, any error should be handled by the code above. - if s[i] == '.': i.inc - while s[i] in {'0'..'9','+','-'}: - if ti < maxlen: - t[ti] = s[i]; inc(ti) - inc(i) - while s[i] in {'.', '_'}: # skip underscore and decimal point - inc(i) - - # insert exponent - t[ti] = 'E'; inc(ti) - t[ti] = (if exp_negative: '-' else: '+'); inc(ti) - inc(ti, 3) - - # insert adjusted exponent - t[ti-1] = ('0'.ord + abs_exponent mod 10).char; abs_exponent = abs_exponent div 10 - t[ti-2] = ('0'.ord + abs_exponent mod 10).char; abs_exponent = abs_exponent div 10 - t[ti-3] = ('0'.ord + abs_exponent mod 10).char - - when defined(nimNoArrayToCstringConversion): - number = c_strtod(addr t, nil) - else: - number = c_strtod(t, nil) - -proc nimInt64ToStr(x: int64): string {.compilerRtl.} = - result = newStringOfCap(sizeof(x)*4) - result.add x - -proc nimBoolToStr(x: bool): string {.compilerRtl.} = - return if x: "true" else: "false" - -proc nimCharToStr(x: char): string {.compilerRtl.} = - result = newString(1) - result[0] = x From 48b98cf701d486a33b78c92f4524d773fc19c605 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Tue, 10 Jul 2018 11:37:02 +0200 Subject: [PATCH 004/145] fixes tos test for OSX --- tests/stdlib/tos.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/stdlib/tos.nim b/tests/stdlib/tos.nim index 6ccc29bf65..a376c66d9a 100644 --- a/tests/stdlib/tos.nim +++ b/tests/stdlib/tos.nim @@ -145,7 +145,7 @@ else: echo getLastModificationTime("a") == tm removeFile("a") -when defined(Linux) or defined(osx): +when defined(Linux) or defined(macosx): block normalizedPath: block relative: From 8f0c9b2fdde5a0d5ecdc956a6b4fd88617d00a04 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Tue, 10 Jul 2018 11:37:30 +0200 Subject: [PATCH 005/145] string comparisons don't have to know the strings representation --- lib/system/strmantle.nim | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/lib/system/strmantle.nim b/lib/system/strmantle.nim index eca6c553c0..57ce302f89 100644 --- a/lib/system/strmantle.nim +++ b/lib/system/strmantle.nim @@ -9,36 +9,23 @@ ## Compilerprocs for strings that do not depend on the string implementation. -proc cmpStrings(a, b: NimString): int {.inline, compilerProc.} = - if a == b: return 0 - when defined(nimNoNil): - let alen = if a == nil: 0 else: a.len - let blen = if b == nil: 0 else: b.len - else: - if a == nil: return -1 - if b == nil: return 1 - let alen = a.len - let blen = b.len +proc cmpStrings(a, b: string): int {.inline, compilerProc.} = + let alen = a.len + let blen = b.len let minlen = min(alen, blen) if minlen > 0: - result = c_memcmp(addr a.data, addr b.data, minlen.csize) + result = c_memcmp(unsafeAddr a[0], unsafeAddr b[0], minlen.csize) if result == 0: result = alen - blen else: result = alen - blen -proc eqStrings(a, b: NimString): bool {.inline, compilerProc.} = - if a == b: return true - when defined(nimNoNil): - let alen = if a == nil: 0 else: a.len - let blen = if b == nil: 0 else: b.len - else: - if a == nil or b == nil: return false - let alen = a.len - let blen = b.len +proc eqStrings(a, b: string): bool {.inline, compilerProc.} = + let alen = a.len + let blen = b.len if alen == blen: if alen == 0: return true - return equalMem(addr(a.data), addr(b.data), alen) + return equalMem(unsafeAddr(a[0]), unsafeAddr(b[0]), alen) proc hashString(s: string): int {.compilerproc.} = # the compiler needs exactly the same hash function! From 16d8fab3101a8dcec846d1208de40c2c10db0160 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Wed, 11 Jul 2018 16:38:13 +0200 Subject: [PATCH 006/145] mmdisp: code cleanups --- lib/system/mmdisp.nim | 123 ++++++++++++++++++++---------------------- 1 file changed, 59 insertions(+), 64 deletions(-) diff --git a/lib/system/mmdisp.nim b/lib/system/mmdisp.nim index b33ca93f26..ff2da7aba1 100644 --- a/lib/system/mmdisp.nim +++ b/lib/system/mmdisp.nim @@ -175,8 +175,7 @@ when defined(boehmgc): dest[] = src type - MemRegion = object {.final, pure.} - {.deprecated: [TMemRegion: MemRegion].} + MemRegion = object proc alloc(r: var MemRegion, size: int): pointer = result = boehmAlloc(size) @@ -215,60 +214,58 @@ elif defined(gogc): goNumSizeClasses = 67 type - cbool {.importc: "_Bool", nodecl.} = bool - goMStats_inner_struct = object - size: uint32 - nmalloc: uint64 - nfree: uint64 + size: uint32 + nmalloc: uint64 + nfree: uint64 goMStats = object - # General statistics. - alloc: uint64 # bytes allocated and still in use - total_alloc: uint64 # bytes allocated (even if freed) - sys: uint64 # bytes obtained from system (should be sum of xxx_sys below, no locking, approximate) - nlookup: uint64 # number of pointer lookups - nmalloc: uint64 # number of mallocs - nfree: uint64 # number of frees - # Statistics about malloc heap. - # protected by mheap.Lock - heap_alloc: uint64 # bytes allocated and still in use - heap_sys: uint64 # bytes obtained from system - heap_idle: uint64 # bytes in idle spans - heap_inuse: uint64 # bytes in non-idle spans - heap_released: uint64 # bytes released to the OS - heap_objects: uint64 # total number of allocated objects - # Statistics about allocation of low-level fixed-size structures. - # Protected by FixAlloc locks. - stacks_inuse: uint64 # bootstrap stacks - stacks_sys: uint64 - mspan_inuse: uint64 # MSpan structures - mspan_sys: uint64 - mcache_inuse: uint64 # MCache structures - mcache_sys: uint64 - buckhash_sys: uint64 # profiling bucket hash table - gc_sys: uint64 - other_sys: uint64 - # Statistics about garbage collector. - # Protected by mheap or stopping the world during GC. - next_gc: uint64 # next GC (in heap_alloc time) - last_gc: uint64 # last GC (in absolute time) - pause_total_ns: uint64 - pause_ns: array[256, uint64] # circular buffer of recent gc pause lengths - pause_end: array[256, uint64] # circular buffer of recent gc end times (nanoseconds since 1970) - numgc: uint32 - numforcedgc: uint32 # number of user-forced GCs - gc_cpu_fraction: float64 # fraction of CPU time used by GC - enablegc: cbool - debuggc: cbool - # Statistics about allocation size classes. - by_size: array[goNumSizeClasses, goMStats_inner_struct] - # Statistics below here are not exported to MemStats directly. - tinyallocs: uint64 # number of tiny allocations that didn't cause actual allocation; not exported to go directly - gc_trigger: uint64 - heap_live: uint64 - heap_scan: uint64 - heap_marked: uint64 + # General statistics. + alloc: uint64 # bytes allocated and still in use + total_alloc: uint64 # bytes allocated (even if freed) + sys: uint64 # bytes obtained from system (should be sum of xxx_sys below, no locking, approximate) + nlookup: uint64 # number of pointer lookups + nmalloc: uint64 # number of mallocs + nfree: uint64 # number of frees + # Statistics about malloc heap. + # protected by mheap.Lock + heap_alloc: uint64 # bytes allocated and still in use + heap_sys: uint64 # bytes obtained from system + heap_idle: uint64 # bytes in idle spans + heap_inuse: uint64 # bytes in non-idle spans + heap_released: uint64 # bytes released to the OS + heap_objects: uint64 # total number of allocated objects + # Statistics about allocation of low-level fixed-size structures. + # Protected by FixAlloc locks. + stacks_inuse: uint64 # bootstrap stacks + stacks_sys: uint64 + mspan_inuse: uint64 # MSpan structures + mspan_sys: uint64 + mcache_inuse: uint64 # MCache structures + mcache_sys: uint64 + buckhash_sys: uint64 # profiling bucket hash table + gc_sys: uint64 + other_sys: uint64 + # Statistics about garbage collector. + # Protected by mheap or stopping the world during GC. + next_gc: uint64 # next GC (in heap_alloc time) + last_gc: uint64 # last GC (in absolute time) + pause_total_ns: uint64 + pause_ns: array[256, uint64] # circular buffer of recent gc pause lengths + pause_end: array[256, uint64] # circular buffer of recent gc end times (nanoseconds since 1970) + numgc: uint32 + numforcedgc: uint32 # number of user-forced GCs + gc_cpu_fraction: float64 # fraction of CPU time used by GC + enablegc: bool + debuggc: bool + # Statistics about allocation size classes. + by_size: array[goNumSizeClasses, goMStats_inner_struct] + # Statistics below here are not exported to MemStats directly. + tinyallocs: uint64 # number of tiny allocations that didn't cause actual allocation; not exported to go directly + gc_trigger: uint64 + heap_live: uint64 + heap_scan: uint64 + heap_marked: uint64 proc goRuntime_ReadMemStats(a2: ptr goMStats) {.cdecl, importc: "runtime_ReadMemStats", @@ -341,9 +338,12 @@ elif defined(gogc): proc getOccupiedSharedMem(): int = discard const goFlagNoZero: uint32 = 1 shl 3 - proc goRuntimeMallocGC(size: uint, typ: uint, flag: uint32): pointer {.importc: "runtime_mallocgc", dynlib: goLib.} + proc goRuntimeMallocGC(size: uint, typ: uint, flag: uint32): pointer {. + importc: "runtime_mallocgc", dynlib: goLib.} - proc goSetFinalizer(obj: pointer, f: pointer) {.importc: "set_finalizer", codegenDecl:"$1 $2$3 __asm__ (\"main.Set_finalizer\");\n$1 $2$3", dynlib: goLib.} + proc goSetFinalizer(obj: pointer, f: pointer) {. + importc: "set_finalizer", codegenDecl: "$1 $2$3 __asm__ (\"main.Set_finalizer\");\n$1 $2$3", + dynlib: goLib.} proc newObj(typ: PNimType, size: int): pointer {.compilerproc.} = result = goRuntimeMallocGC(roundup(size, sizeof(pointer)).uint, 0.uint, 0.uint32) @@ -369,8 +369,7 @@ elif defined(gogc): proc growObj(old: pointer, newsize: int): pointer = # the Go GC doesn't have a realloc - var - oldsize = cast[PGenericSeq](old).len * cast[PGenericSeq](old).elemSize + GenericSeqSize + let oldsize = cast[PGenericSeq](old).len * cast[PGenericSeq](old).elemSize + GenericSeqSize result = goRuntimeMallocGC(roundup(newsize, sizeof(pointer)).uint, 0.uint, goFlagNoZero) copyMem(result, old, oldsize) zeroMem(cast[pointer](cast[ByteAddress](result) +% oldsize), newsize - oldsize) @@ -386,8 +385,7 @@ elif defined(gogc): dest[] = src type - MemRegion = object {.final, pure.} - {.deprecated: [TMemRegion: MemRegion].} + MemRegion = object proc alloc(r: var MemRegion, size: int): pointer = result = alloc(size) @@ -477,8 +475,7 @@ elif defined(nogc) and defined(useMalloc): dest[] = src type - MemRegion = object {.final, pure.} - {.deprecated: [TMemRegion: MemRegion].} + MemRegion = object proc alloc(r: var MemRegion, size: int): pointer = result = alloc(size) @@ -551,11 +548,9 @@ else: elif defined(gcRegions): # XXX due to bootstrapping reasons, we cannot use compileOption("gc", "stack") here include "system/gc_regions" - elif defined(gcMarkAndSweep): + elif defined(gcMarkAndSweep) or defined(gcDestructors): # XXX use 'compileOption' here include "system/gc_ms" - elif defined(gcGenerational): - include "system/gc" else: include "system/gc" From 5b59852406e3d4a494186dddf9a5702062901668 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Wed, 11 Jul 2018 16:39:16 +0200 Subject: [PATCH 007/145] system.substr is not implemented with compilerProcs anymore --- compiler/ccgexprs.nim | 5 +- compiler/condsyms.nim | 1 + compiler/semtypes.nim | 4 ++ compiler/types.nim | 2 + lib/core/allocators.nim | 40 ++++++++----- lib/core/strs.nim | 128 +++++++++++++++++++++++++++++----------- lib/system.nim | 34 +++++++---- lib/system/sysstr.nim | 10 +++- 8 files changed, 157 insertions(+), 67 deletions(-) diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index b8a7f3b08a..7367017807 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -1902,8 +1902,9 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) = of mIncl, mExcl, mCard, mLtSet, mLeSet, mEqSet, mMulSet, mPlusSet, mMinusSet, mInSet: genSetOp(p, e, d, op) - of mNewString, mNewStringOfCap, mCopyStr, mCopyStrLast, mExit, - mParseBiggestFloat: + of mCopyStr, mCopyStrLast: + genCall(p, e, d) + of mNewString, mNewStringOfCap, mExit, mParseBiggestFloat: var opr = e.sons[0].sym if lfNoDecl notin opr.loc.flags: discard cgsym(p.module, $opr.loc.r) diff --git a/compiler/condsyms.nim b/compiler/condsyms.nim index 8b2d36722c..fcc7998dfd 100644 --- a/compiler/condsyms.nim +++ b/compiler/condsyms.nim @@ -72,3 +72,4 @@ proc initDefines*(symbols: StringTableRef) = defineSymbol("nimNoZeroTerminator") defineSymbol("nimNotNil") defineSymbol("nimVmExportFixed") + defineSymbol("nimNewRuntime") diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 17420111f1..e888b7f7c3 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -1671,6 +1671,8 @@ proc processMagicType(c: PContext, m: PSym) = of mString: setMagicType(c.config, m, tyString, c.config.target.ptrSize) rawAddSon(m.typ, getSysType(c.graph, m.info, tyChar)) + if c.config.selectedGc == gcDestructors: + incl m.typ.flags, tfHasAsgn of mCstring: setMagicType(c.config, m, tyCString, c.config.target.ptrSize) rawAddSon(m.typ, getSysType(c.graph, m.info, tyChar)) @@ -1710,6 +1712,8 @@ proc processMagicType(c: PContext, m: PSym) = setMagicType(c.config, m, tySet, 0) of mSeq: setMagicType(c.config, m, tySequence, 0) + if c.config.selectedGc == gcDestructors: + incl m.typ.flags, tfHasAsgn of mOpt: setMagicType(c.config, m, tyOpt, 0) of mOrdinal: diff --git a/compiler/types.nim b/compiler/types.nim index 4d3f99c310..66807cf97f 100644 --- a/compiler/types.nim +++ b/compiler/types.nim @@ -278,6 +278,8 @@ proc analyseObjectWithTypeField(t: PType): TTypeFieldResult = proc isGCRef(t: PType): bool = result = t.kind in GcTypeKinds or (t.kind == tyProc and t.callConv == ccClosure) + if result and t.kind in {tyString, tySequence} and tfHasAsgn in t.flags: + result = false proc containsGarbageCollectedRef*(typ: PType): bool = # returns true if typ contains a reference, sequence or string (all the diff --git a/lib/core/allocators.nim b/lib/core/allocators.nim index 62f5e9756b..74a8d3753c 100644 --- a/lib/core/allocators.nim +++ b/lib/core/allocators.nim @@ -8,28 +8,40 @@ # type + AllocatorFlag* {.pure.} = enum ## flags describing the properties of the allocator + ThreadLocal ## the allocator is thread local only. + ZerosMem ## the allocator always zeros the memory on an allocation Allocator* = ptr object {.inheritable.} alloc*: proc (a: Allocator; size: int; alignment: int = 8): pointer {.nimcall.} dealloc*: proc (a: Allocator; p: pointer; size: int) {.nimcall.} realloc*: proc (a: Allocator; p: pointer; oldSize, newSize: int): pointer {.nimcall.} + flags*: set[AllocatorFlag] var - currentAllocator {.threadvar.}: Allocator + localAllocator {.threadvar.}: Allocator + sharedAllocator: Allocator -proc getCurrentAllocator*(): Allocator = - result = currentAllocator +proc getLocalAllocator*(): Allocator = + result = localAllocator -proc setCurrentAllocator*(a: Allocator) = - currentAllocator = a +proc setLocalAllocator*(a: Allocator) = + localAllocator = a -proc alloc*(size: int; alignment: int = 8): pointer = - let a = getCurrentAllocator() - result = a.alloc(a, size, alignment) +proc getSharedAllocator*(): Allocator = + result = sharedAllocator -proc dealloc*(p: pointer; size: int) = - let a = getCurrentAllocator() - a.dealloc(a, p, size) +proc setSharedAllocator*(a: Allocator) = + sharedAllocator = a -proc realloc*(p: pointer; oldSize, newSize: int): pointer = - let a = getCurrentAllocator() - result = a.realloc(a, p, oldSize, newSize) +when false: + proc alloc*(size: int; alignment: int = 8): pointer = + let a = getCurrentAllocator() + result = a.alloc(a, size, alignment) + + proc dealloc*(p: pointer; size: int) = + let a = getCurrentAllocator() + a.dealloc(a, p, size) + + proc realloc*(p: pointer; oldSize, newSize: int): pointer = + let a = getCurrentAllocator() + result = a.realloc(a, p, oldSize, newSize) diff --git a/lib/core/strs.nim b/lib/core/strs.nim index ff38aef1d6..1ef4f09ded 100644 --- a/lib/core/strs.nim +++ b/lib/core/strs.nim @@ -7,54 +7,114 @@ # distribution, for details about the copyright. # -## Default string implementation used by Nim's core. +## Default new string implementation used by Nim's core. + +when false: + # these are to be implemented or changed in the code generator. + + #proc rawNewStringNoInit(space: int): NimString {.compilerProc.} + # seems to be unused. + proc rawNewString(space: int): NimString {.compilerProc.} + proc mnewString(len: int): NimString {.compilerProc.} + proc copyStrLast(s: NimString, start, last: int): NimString {.compilerProc.} + proc nimToCStringConv(s: NimString): cstring {.compilerProc, inline.} + proc copyStr(s: NimString, start: int): NimString {.compilerProc.} + proc toNimStr(str: cstring, len: int): NimString {.compilerProc.} + proc cstrToNimstr(str: cstring): NimString {.compilerRtl.} + proc copyString(src: NimString): NimString {.compilerRtl.} + proc copyStringRC1(src: NimString): NimString {.compilerRtl.} + proc copyDeepString(src: NimString): NimString {.inline.} + proc addChar(s: NimString, c: char): NimString + proc resizeString(dest: NimString, addlen: int): NimString {.compilerRtl.} + proc appendString(dest, src: NimString) {.compilerproc, inline.} + proc appendChar(dest: NimString, c: char) {.compilerproc, inline.} + proc setLengthStr(s: NimString, newLen: int): NimString {.compilerRtl.} + # ----------------- sequences ---------------------------------------------- + + proc incrSeqV3(s: PGenericSeq, typ: PNimType): PGenericSeq {.compilerProc.} = + proc setLengthSeqV2(s: PGenericSeq, typ: PNimType, newLen: int): PGenericSeq {. + compilerRtl.} + proc newSeq(typ: PNimType, len: int): pointer {.compilerRtl.} = + proc newSeqRC1(typ: PNimType, len: int): pointer {.compilerRtl.} = import allocators type - string {.core, exportc: "NimStringV2".} = object - len, cap: int - data: ptr UncheckedArray[char] + StrContent = object + cap: int + region: Allocator + data: UncheckedArray[char] + + NimString {.core.} = object + len: int + p: ptr StrContent ## invariant. Never nil const nimStrVersion {.core.} = 2 -template frees(s) = dealloc(s.data, s.cap + 1) +template isLiteral(s): bool = s.len == 0 or s.p.region == nil -proc `=destroy`(s: var string) = - if s.data != nil: - frees(s) - s.data = nil - s.len = 0 - s.cap = 0 +template contentSize(cap): int = cap + 1 + sizeof(int) + sizeof(Allocator) -proc `=sink`(a: var string, b: string) = +template frees(s) = + if not isLiteral(s): + s.p.region.dealloc(s.p, contentSize(s.p.cap)) + +proc `=destroy`(s: var NimString) = + frees(s) + s.len = 0 + +template lose(a) = + frees(a) + +proc `=sink`(a: var NimString, b: NimString) = # we hope this is optimized away for not yet alive objects: - if a.data != nil and a.data != b.data: - frees(a) + if unlikely(a.p == b.p): return + lose(a) a.len = b.len - a.cap = b.cap - a.data = b.data + a.p = b.p -proc `=`(a: var string; b: string) = - if a.data != nil and a.data != b.data: - frees(a) - a.data = nil +proc `=`(a: var NimString; b: NimString) = + if unlikely(a.p == b.p): return + lose(a) a.len = b.len - a.cap = b.cap - if b.data != nil: - a.data = cast[type(a.data)](alloc(a.cap + 1)) - copyMem(a.data, b.data, a.cap+1) + if isLiteral(b): + # we can shallow copy literals: + a.p = b.p + else: + let region = if a.p.region != nil: a.p.region else: getLocalAllocator() + # we have to allocate the 'cap' here, consider + # 'let y = newStringOfCap(); var x = y' + # on the other hand... These get turned into moves now. + a.p = cast[ptr StrContent](region.alloc(contentSize(b.len))) + a.p.region = region + a.p.cap = b.len + copyMem(unsafeAddr a.p.data[0], unsafeAddr b.p.data[0], b.len+1) -proc resize(s: var string) = - let old = s.cap - if old == 0: s.cap = 8 - else: s.cap = (s.cap * 3) shr 1 - s.data = cast[type(s.data)](realloc(s.data, old + 1, s.cap + 1)) +proc resize(old: int): int {.inline.} = + if old <= 0: result = 4 + elif old < 65536: result = old * 2 + else: result = old * 3 div 2 # for large arrays * 3/2 is better -proc add*(s: var string; c: char) = - if s.len >= s.cap: resize(s) - s.data[s.len] = c - s.data[s.len+1] = '\0' +proc prepareAdd(s: var NimString; addlen: int) = + if isLiteral(s): + let oldP = s.p + # can't mutate a literal, so we need a fresh copy here: + let region = getLocalAllocator() + s.p = cast[ptr StrContent](region.alloc(contentSize(s.len + addlen))) + s.p.region = region + s.p.cap = s.len + addlen + if s.len > 0: + # we are about to append, so there is no need to copy the \0 terminator: + copyMem(unsafeAddr s.p.data[0], unsafeAddr oldP.data[0], s.len) + elif s.len + addlen > s.p.cap: + let cap = max(s.len + addlen, resize(s.p.cap)) + s.p = s.p.region.realloc(s.p, oldSize = contentSize(s.p.cap), newSize = contentSize(cap)) + s.p.cap = cap + +proc nimAddCharV1(s: var NimString; c: char) {.compilerRtl.} = + prepareAdd(s, 1) + s.p.data[s.len] = c + s.p.data[s.len+1] = '\0' inc s.len proc ensure(s: var string; newLen: int) = @@ -71,8 +131,6 @@ proc add*(s: var string; y: string) = copyMem(addr s.data[len], y.data, y.data.len + 1) s.len = newLen -proc len*(s: string): int {.inline.} = s.len - proc newString*(len: int): string = result.len = len result.cap = len diff --git a/lib/system.nim b/lib/system.nim index d8ecfd55f1..620dff7246 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -413,7 +413,7 @@ include "system/inclrtl" const NoFakeVars* = defined(nimscript) ## true if the backend doesn't support \ ## "fake variables" like 'var EBADF {.importc.}: cint'. -when not defined(JS): +when not defined(JS) and not defined(gcDestructors): type TGenericSeq {.compilerproc, pure, inheritable.} = object len, reserved: int @@ -1702,17 +1702,6 @@ proc addQuitProc*(QuitProc: proc() {.noconv.}) {. # In case of an unhandled exeption the exit handlers should # not be called explicitly! The user may decide to do this manually though. -proc substr*(s: string, first = 0): string {. - magic: "CopyStr", importc: "copyStr", noSideEffect.} -proc substr*(s: string, first, last: int): string {. - magic: "CopyStrLast", importc: "copyStrLast", noSideEffect.} - ## copies a slice of `s` into a new string and returns this new - ## string. The bounds `first` and `last` denote the indices of - ## the first and last characters that shall be copied. If ``last`` - ## is omitted, it is treated as ``high(s)``. If ``last >= s.len``, ``s.len`` - ## is used instead: This means ``substr`` can also be used to `cut`:idx: - ## or `limit`:idx: a string's length. - when not defined(nimscript) and not defined(JS): proc zeroMem*(p: pointer, size: Natural) {.inline, benign.} ## overwrites the contents of the memory at ``p`` with the value 0. @@ -3262,7 +3251,11 @@ when not defined(JS): #and not defined(nimscript): when hasAlloc: include "system/mmdisp" {.pop.} {.push stack_trace: off, profiler:off.} - when hasAlloc: include "system/sysstr" + when hasAlloc: + when defined(gcDestructors): + include "core/strs" + else: + include "system/sysstr" {.pop.} when hasAlloc: include "system/strmantle" @@ -4171,6 +4164,21 @@ when not defined(js): proc toOpenArrayByte*(x: string; first, last: int): openarray[byte] {. magic: "Slice".} +proc substr*(s: string, first, last: int): string = + let L = max(min(last, high(s)) - first + 1, 0) + result = newString(L) + for i in 0 .. L-1: + result[i] = s[i+first] + +proc substr*(s: string, first = 0): string = + ## copies a slice of `s` into a new string and returns this new + ## string. The bounds `first` and `last` denote the indices of + ## the first and last characters that shall be copied. If ``last`` + ## is omitted, it is treated as ``high(s)``. If ``last >= s.len``, ``s.len`` + ## is used instead: This means ``substr`` can also be used to `cut`:idx: + ## or `limit`:idx: a string's length. + result = substr(s, first, high(s)) + type ForLoopStmt* {.compilerProc.} = object ## special type that marks a macro ## as a `for-loop macro`:idx: diff --git a/lib/system/sysstr.nim b/lib/system/sysstr.nim index 24ba02af60..9a73d3f9d2 100644 --- a/lib/system/sysstr.nim +++ b/lib/system/sysstr.nim @@ -63,6 +63,8 @@ proc mnewString(len: int): NimString {.compilerProc.} = result.len = len proc copyStrLast(s: NimString, start, last: int): NimString {.compilerProc.} = + # This is not used by most recent versions of the compiler anymore, but + # required for bootstrapping purposes. let start = max(start, 0) let len = min(last, s.len-1) - start + 1 if len > 0: @@ -73,13 +75,15 @@ proc copyStrLast(s: NimString, start, last: int): NimString {.compilerProc.} = else: result = rawNewString(len) +proc copyStr(s: NimString, start: int): NimString {.compilerProc.} = + # This is not used by most recent versions of the compiler anymore, but + # required for bootstrapping purposes. + result = copyStrLast(s, start, s.len-1) + proc nimToCStringConv(s: NimString): cstring {.compilerProc, inline.} = if s == nil or s.len == 0: result = cstring"" else: result = cstring(addr s.data) -proc copyStr(s: NimString, start: int): NimString {.compilerProc.} = - result = copyStrLast(s, start, s.len-1) - proc toNimStr(str: cstring, len: int): NimString {.compilerProc.} = result = rawNewStringNoInit(len) result.len = len From 74bf316619129b3c07c35c796cbc8744cbca87aa Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Fri, 13 Jul 2018 21:15:47 +0200 Subject: [PATCH 008/145] more progress on destructor based strings --- compiler/ccgcalls.nim | 10 ++- compiler/ccgexprs.nim | 74 ++++++++++++------ compiler/ccgtrav.nim | 7 +- compiler/ccgtypes.nim | 2 +- compiler/cgen.nim | 16 ++-- compiler/transf.nim | 8 +- lib/core/strs.nim | 134 ++++++++++++++++----------------- lib/system.nim | 163 +++++++++++++++++++++------------------- lib/system/assign.nim | 5 -- lib/system/cgprocs.nim | 1 - lib/system/gc_ms.nim | 90 +++++++++++----------- lib/system/hti.nim | 2 +- lib/system/jssys.nim | 4 +- lib/system/mmdisp.nim | 2 +- lib/system/sysio.nim | 2 +- lib/system/widestrs.nim | 3 +- 16 files changed, 279 insertions(+), 244 deletions(-) diff --git a/compiler/ccgcalls.nim b/compiler/ccgcalls.nim index 9712d5dcec..ab15b9f2f0 100644 --- a/compiler/ccgcalls.nim +++ b/compiler/ccgcalls.nim @@ -124,15 +124,19 @@ proc openArrayLoc(p: BProc, n: PNode): Rope = of tyString, tySequence: if skipTypes(n.typ, abstractInst).kind == tyVar and not compileToCpp(p.module): - result = "(*$1)$3, (*$1 ? (*$1)->$2 : 0)" % [a.rdLoc, lenField(p), dataField(p)] + var t: TLoc + t.r = "(*$1)" % [a.rdLoc] + result = "(*$1)$3, $2" % [a.rdLoc, lenExpr(p, t), dataField(p)] else: - result = "$1$3, ($1 ? $1->$2 : 0)" % [a.rdLoc, lenField(p), dataField(p)] + result = "$1$3, $2" % [a.rdLoc, lenExpr(p, a), dataField(p)] of tyArray: result = "$1, $2" % [rdLoc(a), rope(lengthOrd(p.config, a.t))] of tyPtr, tyRef: case lastSon(a.t).kind of tyString, tySequence: - result = "(*$1)$3, (*$1 ? (*$1)->$2 : 0)" % [a.rdLoc, lenField(p), dataField(p)] + var t: TLoc + t.r = "(*$1)" % [a.rdLoc] + result = "(*$1)$3, (*$1 ? (*$1)->$2 : 0)" % [a.rdLoc, lenExpr(p, t), dataField(p)] of tyArray: result = "$1, $2" % [rdLoc(a), rope(lengthOrd(p.config, lastSon(a.t)))] else: diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 7367017807..689e2483e1 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -254,7 +254,12 @@ proc genGenericAsgn(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) = # tfShallow flag for the built-in string type too! So we check only # here for this flag, where it is reasonably safe to do so # (for objects, etc.): - if needToCopy notin flags or + if p.config.selectedGC == gcDestructors: + useStringh(p.module) + linefmt(p, cpsStmts, + "memcpy((void*)$1, (NIM_CONST void*)$2, sizeof($3));$n", + addrLoc(p.config, dest), addrLoc(p.config, src), rdLoc(dest)) + elif needToCopy notin flags or tfShallow in skipTypes(dest.t, abstractVarRange).flags: if dest.storage == OnStack or not usesWriteBarrier(p.config): useStringh(p.module) @@ -280,14 +285,18 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) = of tyRef: genRefAssign(p, dest, src, flags) of tySequence: - if (needToCopy notin flags and src.storage != OnStatic) or canMove(src.lode): + if p.config.selectedGC == gcDestructors: + genGenericAsgn(p, dest, src, flags) + elif (needToCopy notin flags and src.storage != OnStatic) or canMove(src.lode): genRefAssign(p, dest, src, flags) else: linefmt(p, cpsStmts, "#genericSeqAssign($1, $2, $3);$n", addrLoc(p.config, dest), rdLoc(src), genTypeInfo(p.module, dest.t, dest.lode.info)) of tyString: - if (needToCopy notin flags and src.storage != OnStatic) or canMove(src.lode): + if p.config.selectedGC == gcDestructors: + genGenericAsgn(p, dest, src, flags) + elif (needToCopy notin flags and src.storage != OnStatic) or canMove(src.lode): genRefAssign(p, dest, src, flags) else: if dest.storage == OnStack or not usesWriteBarrier(p.config): @@ -457,6 +466,13 @@ proc binaryStmt(p: BProc, e: PNode, d: var TLoc, frmt: string) = initLocExpr(p, e.sons[2], b) lineCg(p, cpsStmts, frmt, rdLoc(a), rdLoc(b)) +proc binaryStmtAddr(p: BProc, e: PNode, d: var TLoc, frmt: string) = + var a, b: TLoc + if d.k != locNone: internalError(p.config, e.info, "binaryStmtAddr") + initLocExpr(p, e.sons[1], a) + initLocExpr(p, e.sons[2], b) + lineCg(p, cpsStmts, frmt, addrLoc(p.config, a), rdLoc(b)) + proc unaryStmt(p: BProc, e: PNode, d: var TLoc, frmt: string) = var a: TLoc if d.k != locNone: internalError(p.config, e.info, "unaryStmt") @@ -893,8 +909,8 @@ proc genBoundsCheck(p: BProc; arr, a, b: TLoc) = of tySequence, tyString: linefmt(p, cpsStmts, "if ($2-$1 != -1 && " & - "(!$3 || (NU)($1) >= (NU)($3->$4) || (NU)($2) >= (NU)($3->$4))) #raiseIndexError();$n", - rdLoc(a), rdLoc(b), rdLoc(arr), lenField(p)) + "((NU)($1) >= (NU)$3 || (NU)($2) >= (NU)$3)) #raiseIndexError();$n", + rdLoc(a), rdLoc(b), lenExpr(p, arr)) else: discard proc genOpenArrayElem(p: BProc, n, x, y: PNode, d: var TLoc) = @@ -918,12 +934,12 @@ proc genSeqElem(p: BProc, n, x, y: PNode, d: var TLoc) = if optBoundsCheck in p.options: if ty.kind == tyString and (not defined(nimNoZeroTerminator) or optLaxStrings in p.options): linefmt(p, cpsStmts, - "if (!$2 || (NU)($1) > (NU)($2->$3)) #raiseIndexError();$n", - rdLoc(b), rdLoc(a), lenField(p)) + "if ((NU)($1) > (NU)$2) #raiseIndexError();$n", + rdLoc(b), lenExpr(p, a)) else: linefmt(p, cpsStmts, - "if (!$2 || (NU)($1) >= (NU)($2->$3)) #raiseIndexError();$n", - rdLoc(b), rdLoc(a), lenField(p)) + "if ((NU)($1) >= (NU)$2) #raiseIndexError();$n", + rdLoc(b), lenExpr(p, a)) if d.k == locNone: d.storage = OnHeap if skipTypes(a.t, abstractVar).kind in {tyRef, tyPtr}: a.r = ropecg(p.module, "(*$1)", a.r) @@ -1013,6 +1029,12 @@ proc genEcho(p: BProc, n: PNode) = proc gcUsage(conf: ConfigRef; n: PNode) = if conf.selectedGC == gcNone: message(conf, n.info, warnGcMem, n.renderTree) +proc strLoc(p: BProc; d: TLoc): Rope = + if p.config.selectedGc == gcDestructors: + result = addrLoc(p.config, d) + else: + result = rdLoc(d) + proc genStrConcat(p: BProc, e: PNode, d: var TLoc) = # # s = 'Hello ' & name & ', how do you feel?' & 'z' @@ -1040,13 +1062,14 @@ proc genStrConcat(p: BProc, e: PNode, d: var TLoc) = initLocExpr(p, e.sons[i + 1], a) if skipTypes(e.sons[i + 1].typ, abstractVarRange).kind == tyChar: inc(L) - add(appends, ropecg(p.module, "#appendChar($1, $2);$n", tmp.r, rdLoc(a))) + add(appends, ropecg(p.module, "#appendChar($1, $2);$n", strLoc(p, tmp), rdLoc(a))) else: if e.sons[i + 1].kind in {nkStrLit..nkTripleStrLit}: inc(L, len(e.sons[i + 1].strVal)) else: - addf(lens, "($1 ? $1->$2 : 0) + ", [rdLoc(a), lenField(p)]) - add(appends, ropecg(p.module, "#appendString($1, $2);$n", tmp.r, rdLoc(a))) + add(lens, lenExpr(p, a)) + add(lens, " + ") + add(appends, ropecg(p.module, "#appendString($1, $2);$n", strLoc(p, tmp), rdLoc(a))) linefmt(p, cpsStmts, "$1 = #rawNewString($2$3);$n", tmp.r, lens, rope(L)) add(p.s(cpsStmts), appends) if d.k == locNone: @@ -1079,16 +1102,21 @@ proc genStrAppend(p: BProc, e: PNode, d: var TLoc) = if skipTypes(e.sons[i + 2].typ, abstractVarRange).kind == tyChar: inc(L) add(appends, ropecg(p.module, "#appendChar($1, $2);$n", - rdLoc(dest), rdLoc(a))) + strLoc(p, dest), rdLoc(a))) else: if e.sons[i + 2].kind in {nkStrLit..nkTripleStrLit}: inc(L, len(e.sons[i + 2].strVal)) else: - addf(lens, "($1 ? $1->$2 : 0) + ", [rdLoc(a), lenField(p)]) + add(lens, lenExpr(p, a)) + add(lens, " + ") add(appends, ropecg(p.module, "#appendString($1, $2);$n", - rdLoc(dest), rdLoc(a))) - linefmt(p, cpsStmts, "$1 = #resizeString($1, $2$3);$n", - rdLoc(dest), lens, rope(L)) + strLoc(p, dest), rdLoc(a))) + if p.config.selectedGC == gcDestructors: + linefmt(p, cpsStmts, "#prepareAdd($1, $2$3);$n", + addrLoc(p.config, dest), lens, rope(L)) + else: + linefmt(p, cpsStmts, "$1 = #resizeString($1, $2$3);$n", + rdLoc(dest), lens, rope(L)) add(p.s(cpsStmts), appends) gcUsage(p.config, e) @@ -1440,7 +1468,7 @@ proc genRepr(p: BProc, e: PNode, d: var TLoc) = putIntoDest(p, b, e, "$1, $1Len_0" % [rdLoc(a)], a.storage) of tyString, tySequence: putIntoDest(p, b, e, - "$1$3, ($1 ? $1->$2 : 0)" % [rdLoc(a), lenField(p), dataField(p)], a.storage) + "$1$3, $2" % [rdLoc(a), lenExpr(p, a), dataField(p)], a.storage) of tyArray: putIntoDest(p, b, e, "$1, $2" % [rdLoc(a), rope(lengthOrd(p.config, a.t))], a.storage) @@ -1787,11 +1815,11 @@ proc genStrEquals(p: BProc, e: PNode, d: var TLoc) = if a.kind in {nkStrLit..nkTripleStrLit} and a.strVal == "": initLocExpr(p, e.sons[2], x) putIntoDest(p, d, e, - ropecg(p.module, "(!($1) || ($1)->$2 == 0)", rdLoc(x), lenField(p))) + ropecg(p.module, "($1 == 0)", lenExpr(p, x))) elif b.kind in {nkStrLit..nkTripleStrLit} and b.strVal == "": initLocExpr(p, e.sons[1], x) putIntoDest(p, d, e, - ropecg(p.module, "(!($1) || ($1)->$2 == 0)", rdLoc(x), lenField(p))) + ropecg(p.module, "($1 == 0)", lenExpr(p, x))) else: binaryExpr(p, e, d, "#eqStrings($1, $2)") @@ -1851,7 +1879,11 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) = getTypeDesc(p.module, ranged), res]) of mConStrStr: genStrConcat(p, e, d) - of mAppendStrCh: binaryStmt(p, e, d, "$1 = #addChar($1, $2);$n") + of mAppendStrCh: + if p.config.selectedGC == gcDestructors: + binaryStmtAddr(p, e, d, "#nimAddCharV1($1, $2);$n") + else: + binaryStmt(p, e, d, "$1 = #addChar($1, $2);$n") of mAppendStrStr: genStrAppend(p, e, d) of mAppendSeqElem: genSeqElemAppend(p, e, d) of mEqStr: genStrEquals(p, e, d) diff --git a/compiler/ccgtrav.nim b/compiler/ccgtrav.nim index e74d5a953a..5a6dc8a6e3 100644 --- a/compiler/ccgtrav.nim +++ b/compiler/ccgtrav.nim @@ -107,8 +107,11 @@ proc genTraverseProcSeq(c: TTraversalClosure, accessor: Rope, typ: PType) = var i: TLoc getTemp(p, getSysType(c.p.module.g.graph, unknownLineInfo(), tyInt), i) let oldCode = p.s(cpsStmts) - lineF(p, cpsStmts, "for ($1 = 0; $1 < $2->$3; $1++) {$n", - [i.r, accessor, lenField(c.p)]) + var a: TLoc + a.r = accessor + + lineF(p, cpsStmts, "for ($1 = 0; $1 < $2; $1++) {$n", + [i.r, lenExpr(c.p, a)]) let oldLen = p.s(cpsStmts).len genTraverseProc(c, "$1$3[$2]" % [accessor, i.r, dataField(c.p)], typ.sons[0]) if p.s(cpsStmts).len == oldLen: diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index 66ad34c324..756711642e 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -282,7 +282,7 @@ proc getSimpleTypeDesc(m: BModule, typ: PType): Rope = of tyString: case detectStrVersion(m) of 2: - discard cgsym(m, "string") + discard cgsym(m, "NimStringV2") result = typeNameOrLiteral(m, typ, "NimStringV2") else: discard cgsym(m, "NimStringDesc") diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 32891c62ca..0ca7533d4e 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -235,9 +235,20 @@ proc getTempName(m: BModule): Rope = result = m.tmpBase & rope(m.labels) inc m.labels +proc rdLoc(a: TLoc): Rope = + # 'read' location (deref if indirect) + result = a.r + if lfIndirect in a.flags: result = "(*$1)" % [result] + proc lenField(p: BProc): Rope = result = rope(if p.module.compileToCpp: "len" else: "Sup.len") +proc lenExpr(p: BProc; a: TLoc): Rope = + if p.config.selectedGc == gcDestructors: + result = rdLoc(a) & ".len" + else: + result = "($1 ? $1->$2 : 0)" % [rdLoc(a), lenField(p)] + proc dataField(p: BProc): Rope = result = rope"->data" @@ -246,11 +257,6 @@ include ccgtypes # ------------------------------ Manager of temporaries ------------------ -proc rdLoc(a: TLoc): Rope = - # 'read' location (deref if indirect) - result = a.r - if lfIndirect in a.flags: result = "(*$1)" % [result] - proc addrLoc(conf: ConfigRef; a: TLoc): Rope = result = a.r if lfIndirect notin a.flags and mapType(conf, a.t) != ctArray: diff --git a/compiler/transf.nim b/compiler/transf.nim index dae8d1ee6d..acfccb5fff 100644 --- a/compiler/transf.nim +++ b/compiler/transf.nim @@ -1049,8 +1049,8 @@ proc transformStmt*(g: ModuleGraph; module: PSym, n: PNode): PNode = when useEffectSystem: trackTopLevelStmt(g, module, result) #if n.info ?? "temp.nim": # echo renderTree(result, {renderIds}) - if c.needsDestroyPass: - result = injectDestructorCalls(g, module, result) + #if c.needsDestroyPass: + # result = injectDestructorCalls(g, module, result) incl(result.flags, nfTransf) proc transformExpr*(g: ModuleGraph; module: PSym, n: PNode): PNode = @@ -1062,6 +1062,6 @@ proc transformExpr*(g: ModuleGraph; module: PSym, n: PNode): PNode = liftDefer(c, result) # expressions are not to be injected with destructor calls as that # the list of top level statements needs to be collected before. - if c.needsDestroyPass: - result = injectDestructorCalls(g, module, result) + #if c.needsDestroyPass: + # result = injectDestructorCalls(g, module, result) incl(result.flags, nfTransf) diff --git a/lib/core/strs.nim b/lib/core/strs.nim index 1ef4f09ded..c07c4605e4 100644 --- a/lib/core/strs.nim +++ b/lib/core/strs.nim @@ -14,28 +14,15 @@ when false: #proc rawNewStringNoInit(space: int): NimString {.compilerProc.} # seems to be unused. - proc rawNewString(space: int): NimString {.compilerProc.} - proc mnewString(len: int): NimString {.compilerProc.} - proc copyStrLast(s: NimString, start, last: int): NimString {.compilerProc.} - proc nimToCStringConv(s: NimString): cstring {.compilerProc, inline.} - proc copyStr(s: NimString, start: int): NimString {.compilerProc.} - proc toNimStr(str: cstring, len: int): NimString {.compilerProc.} - proc cstrToNimstr(str: cstring): NimString {.compilerRtl.} - proc copyString(src: NimString): NimString {.compilerRtl.} - proc copyStringRC1(src: NimString): NimString {.compilerRtl.} proc copyDeepString(src: NimString): NimString {.inline.} - proc addChar(s: NimString, c: char): NimString - proc resizeString(dest: NimString, addlen: int): NimString {.compilerRtl.} - proc appendString(dest, src: NimString) {.compilerproc, inline.} - proc appendChar(dest: NimString, c: char) {.compilerproc, inline.} proc setLengthStr(s: NimString, newLen: int): NimString {.compilerRtl.} # ----------------- sequences ---------------------------------------------- - proc incrSeqV3(s: PGenericSeq, typ: PNimType): PGenericSeq {.compilerProc.} = + proc incrSeqV3(s: PGenericSeq, typ: PNimType): PGenericSeq {.compilerProc.} proc setLengthSeqV2(s: PGenericSeq, typ: PNimType, newLen: int): PGenericSeq {. compilerRtl.} - proc newSeq(typ: PNimType, len: int): pointer {.compilerRtl.} = - proc newSeqRC1(typ: PNimType, len: int): pointer {.compilerRtl.} = + proc newSeq(typ: PNimType, len: int): pointer {.compilerRtl.} + proc newSeqRC1(typ: PNimType, len: int): pointer {.compilerRtl.} import allocators @@ -45,35 +32,36 @@ type region: Allocator data: UncheckedArray[char] - NimString {.core.} = object + NimStringV2 {.core.} = object len: int - p: ptr StrContent ## invariant. Never nil + p: ptr StrContent ## can be nil if len == 0. const nimStrVersion {.core.} = 2 -template isLiteral(s): bool = s.len == 0 or s.p.region == nil +template isLiteral(s): bool = s.p == nil or s.p.region == nil template contentSize(cap): int = cap + 1 + sizeof(int) + sizeof(Allocator) template frees(s) = if not isLiteral(s): - s.p.region.dealloc(s.p, contentSize(s.p.cap)) + s.p.region.dealloc(s.p.region, s.p, contentSize(s.p.cap)) -proc `=destroy`(s: var NimString) = +proc `=destroy`(s: var NimStringV2) = frees(s) s.len = 0 + s.p = nil template lose(a) = frees(a) -proc `=sink`(a: var NimString, b: NimString) = +proc `=sink`(a: var NimStringV2, b: NimStringV2) = # we hope this is optimized away for not yet alive objects: if unlikely(a.p == b.p): return lose(a) a.len = b.len a.p = b.p -proc `=`(a: var NimString; b: NimString) = +proc `=`(a: var NimStringV2; b: NimStringV2) = if unlikely(a.p == b.p): return lose(a) a.len = b.len @@ -85,7 +73,7 @@ proc `=`(a: var NimString; b: NimString) = # we have to allocate the 'cap' here, consider # 'let y = newStringOfCap(); var x = y' # on the other hand... These get turned into moves now. - a.p = cast[ptr StrContent](region.alloc(contentSize(b.len))) + a.p = cast[ptr StrContent](region.alloc(region, contentSize(b.len))) a.p.region = region a.p.cap = b.len copyMem(unsafeAddr a.p.data[0], unsafeAddr b.p.data[0], b.len+1) @@ -95,12 +83,12 @@ proc resize(old: int): int {.inline.} = elif old < 65536: result = old * 2 else: result = old * 3 div 2 # for large arrays * 3/2 is better -proc prepareAdd(s: var NimString; addlen: int) = +proc prepareAdd(s: var NimStringV2; addlen: int) {.compilerRtl.} = if isLiteral(s): let oldP = s.p # can't mutate a literal, so we need a fresh copy here: let region = getLocalAllocator() - s.p = cast[ptr StrContent](region.alloc(contentSize(s.len + addlen))) + s.p = cast[ptr StrContent](region.alloc(region, contentSize(s.len + addlen))) s.p.region = region s.p.cap = s.len + addlen if s.len > 0: @@ -108,61 +96,65 @@ proc prepareAdd(s: var NimString; addlen: int) = copyMem(unsafeAddr s.p.data[0], unsafeAddr oldP.data[0], s.len) elif s.len + addlen > s.p.cap: let cap = max(s.len + addlen, resize(s.p.cap)) - s.p = s.p.region.realloc(s.p, oldSize = contentSize(s.p.cap), newSize = contentSize(cap)) + s.p = cast[ptr StrContent](s.p.region.realloc(s.p.region, s.p, + oldSize = contentSize(s.p.cap), + newSize = contentSize(cap))) s.p.cap = cap -proc nimAddCharV1(s: var NimString; c: char) {.compilerRtl.} = +proc nimAddCharV1(s: var NimStringV2; c: char) {.compilerRtl.} = prepareAdd(s, 1) s.p.data[s.len] = c s.p.data[s.len+1] = '\0' inc s.len -proc ensure(s: var string; newLen: int) = - let old = s.cap - if newLen >= old: - s.cap = max((old * 3) shr 1, newLen) - if s.cap > 0: - s.data = cast[type(s.data)](realloc(s.data, old + 1, s.cap + 1)) +proc toNimStr(str: cstring, len: int): NimStringV2 {.compilerProc.} = + if len <= 0: + result = NimStringV2(len: 0, p: nil) + else: + let region = getLocalAllocator() + var p = cast[ptr StrContent](region.alloc(region, contentSize(len))) + p.region = region + p.cap = len + if len > 0: + # we are about to append, so there is no need to copy the \0 terminator: + copyMem(unsafeAddr p.data[0], str, len) + result = NimStringV2(len: 0, p: p) -proc add*(s: var string; y: string) = - if y.len != 0: - let newLen = s.len + y.len - ensure(s, newLen) - copyMem(addr s.data[len], y.data, y.data.len + 1) - s.len = newLen +proc cstrToNimstr(str: cstring): NimStringV2 {.compilerRtl.} = + if str == nil: toNimStr(str, 0) + else: toNimStr(str, str.len) -proc newString*(len: int): string = - result.len = len - result.cap = len - if len > 0: - result.data = alloc0(len+1) +proc nimToCStringConv(s: NimStringV2): cstring {.compilerProc, inline.} = + if s.len == 0: result = cstring"" + else: result = cstring(unsafeAddr s.p.data) -converter toCString(x: string): cstring {.core, inline.} = - if x.len == 0: cstring"" else: cast[cstring](x.data) +proc appendString(dest: var NimStringV2; src: NimStringV2) {.compilerproc, inline.} = + if src.len > 0: + # also copy the \0 terminator: + copyMem(unsafeAddr dest.p.data[dest.len], unsafeAddr src.p.data[0], src.len+1) -proc newStringOfCap*(cap: int): string = - result.len = 0 - result.cap = cap - if cap > 0: - result.data = alloc(cap+1) +proc appendChar(dest: var NimStringV2; c: char) {.compilerproc, inline.} = + dest.p.data[dest.len] = c + dest.p.data[dest.len+1] = '\0' + inc dest.len -proc `&`*(a, b: string): string = - let sum = a.len + b.len - result = newStringOfCap(sum) - result.len = sum - copyMem(addr result.data[0], a.data, a.len) - copyMem(addr result.data[a.len], b.data, b.len) - if sum > 0: - result.data[sum] = '\0' - -proc concat(x: openArray[string]): string {.core.} = - ## used be the code generator to optimize 'x & y & z ...' - var sum = 0 - for i in 0 ..< x.len: inc(sum, x[i].len) - result = newStringOfCap(sum) - sum = 0 - for i in 0 ..< x.len: - let L = x[i].len - copyMem(addr result.data[sum], x[i].data, L) - inc(sum, L) +proc rawNewString(space: int): NimStringV2 {.compilerProc.} = + # this is also 'system.newStringOfCap'. + if space <= 0: + result = NimStringV2(len: 0, p: nil) + else: + let region = getLocalAllocator() + var p = cast[ptr StrContent](region.alloc(region, contentSize(space))) + p.region = region + p.cap = space + result = NimStringV2(len: 0, p: p) +proc mnewString(len: int): NimStringV2 {.compilerProc.} = + if len <= 0: + result = NimStringV2(len: 0, p: nil) + else: + let region = getLocalAllocator() + var p = cast[ptr StrContent](region.alloc(region, contentSize(len))) + p.region = region + p.cap = len + result = NimStringV2(len: len, p: p) diff --git a/lib/system.nim b/lib/system.nim index 620dff7246..1defe20ee7 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -211,6 +211,7 @@ proc new*(T: typedesc): auto = new(r) return r +const ThisIsSystem = true proc internalNew*[T](a: var ref T) {.magic: "New", noSideEffect.} ## leaked implementation detail. Do not use. @@ -426,8 +427,9 @@ when not defined(JS) and not defined(gcDestructors): NimString = ptr NimStringDesc when not defined(JS) and not defined(nimscript): - template space(s: PGenericSeq): int {.dirty.} = - s.reserved and not (seqShallowFlag or strlitFlag) + when not defined(gcDestructors): + template space(s: PGenericSeq): int {.dirty.} = + s.reserved and not (seqShallowFlag or strlitFlag) include "system/hti" type @@ -730,7 +732,8 @@ proc newSeqOfCap*[T](cap: Natural): seq[T] {. ## ``cap``. discard -when not defined(JS): +when not defined(JS) and not defined(gcDestructors): + # XXX enable this for --gc:destructors proc newSeqUninitialized*[T: SomeNumber](len: Natural): seq[T] = ## creates a new sequence of type ``seq[T]`` with length ``len``. ## @@ -1502,11 +1505,11 @@ const hasAlloc = (hostOS != "standalone" or not defined(nogc)) and not defined(n when not defined(JS) and not defined(nimscript) and hostOS != "standalone": include "system/cgprocs" -when not defined(JS) and not defined(nimscript) and hasAlloc: +when not defined(JS) and not defined(nimscript) and hasAlloc and not defined(gcDestructors): proc addChar(s: NimString, c: char): NimString {.compilerProc, benign.} -proc add *[T](x: var seq[T], y: T) {.magic: "AppendSeqElem", noSideEffect.} -proc add *[T](x: var seq[T], y: openArray[T]) {.noSideEffect.} = +proc add*[T](x: var seq[T], y: T) {.magic: "AppendSeqElem", noSideEffect.} +proc add*[T](x: var seq[T], y: openArray[T]) {.noSideEffect.} = ## Generic proc for adding a data item `y` to a container `x`. ## For containers that have an order, `add` means *append*. New generic ## containers should also call their adding proc `add` for consistency. @@ -2829,6 +2832,58 @@ else: if x < 0: -x else: x {.pop.} +when not defined(JS): + proc likely_proc(val: bool): bool {.importc: "likely", nodecl, nosideeffect.} + proc unlikely_proc(val: bool): bool {.importc: "unlikely", nodecl, nosideeffect.} + +template likely*(val: bool): bool = + ## Hints the optimizer that `val` is likely going to be true. + ## + ## You can use this template to decorate a branch condition. On certain + ## platforms this can help the processor predict better which branch is + ## going to be run. Example: + ## + ## .. code-block:: nim + ## for value in inputValues: + ## if likely(value <= 100): + ## process(value) + ## else: + ## echo "Value too big!" + ## + ## On backends without branch prediction (JS and the nimscript VM), this + ## template will not affect code execution. + when nimvm: + val + else: + when defined(JS): + val + else: + likely_proc(val) + +template unlikely*(val: bool): bool = + ## Hints the optimizer that `val` is likely going to be false. + ## + ## You can use this proc to decorate a branch condition. On certain + ## platforms this can help the processor predict better which branch is + ## going to be run. Example: + ## + ## .. code-block:: nim + ## for value in inputValues: + ## if unlikely(value > 100): + ## echo "Value too big!" + ## else: + ## process(value) + ## + ## On backends without branch prediction (JS and the nimscript VM), this + ## template will not affect code execution. + when nimvm: + val + else: + when defined(JS): + val + else: + unlikely_proc(val) + type FileSeekPos* = enum ## Position relative to which seek should happen # The values are ordered so that they match with stdio @@ -2862,10 +2917,11 @@ when not defined(JS): #and not defined(nimscript): when declared(nimGC_setStackBottom): nimGC_setStackBottom(locals) - {.push profiler: off.} - var - strDesc = TNimType(size: sizeof(string), kind: tyString, flags: {ntfAcyclic}) - {.pop.} + when not defined(gcDestructors): + {.push profiler: off.} + var + strDesc = TNimType(size: sizeof(string), kind: tyString, flags: {ntfAcyclic}) + {.pop.} # ----------------- IO Part ------------------------------------------------ @@ -3302,8 +3358,9 @@ when not defined(JS): #and not defined(nimscript): while f.readLine(res): yield res when not defined(nimscript) and hasAlloc: - include "system/assign" - include "system/repr" + when not defined(gcDestructors): + include "system/assign" + include "system/repr" when hostOS != "standalone" and not defined(nimscript): proc getCurrentException*(): ref Exception {.compilerRtl, inl, benign.} = @@ -3410,58 +3467,6 @@ proc quit*(errormsg: string, errorcode = QuitFailure) {.noReturn.} = {.pop.} # checks {.pop.} # hints -when not defined(JS): - proc likely_proc(val: bool): bool {.importc: "likely", nodecl, nosideeffect.} - proc unlikely_proc(val: bool): bool {.importc: "unlikely", nodecl, nosideeffect.} - -template likely*(val: bool): bool = - ## Hints the optimizer that `val` is likely going to be true. - ## - ## You can use this template to decorate a branch condition. On certain - ## platforms this can help the processor predict better which branch is - ## going to be run. Example: - ## - ## .. code-block:: nim - ## for value in inputValues: - ## if likely(value <= 100): - ## process(value) - ## else: - ## echo "Value too big!" - ## - ## On backends without branch prediction (JS and the nimscript VM), this - ## template will not affect code execution. - when nimvm: - val - else: - when defined(JS): - val - else: - likely_proc(val) - -template unlikely*(val: bool): bool = - ## Hints the optimizer that `val` is likely going to be false. - ## - ## You can use this proc to decorate a branch condition. On certain - ## platforms this can help the processor predict better which branch is - ## going to be run. Example: - ## - ## .. code-block:: nim - ## for value in inputValues: - ## if unlikely(value > 100): - ## echo "Value too big!" - ## else: - ## process(value) - ## - ## On backends without branch prediction (JS and the nimscript VM), this - ## template will not affect code execution. - when nimvm: - val - else: - when defined(JS): - val - else: - unlikely_proc(val) - proc `/`*(x, y: int): float {.inline, noSideEffect.} = ## integer division that results in a float. result = toFloat(x) / toFloat(y) @@ -4090,6 +4095,21 @@ template once*(body: untyped): untyped = {.pop.} #{.push warning[GcMem]: off, warning[Uninit]: off.} +proc substr*(s: string, first, last: int): string = + let L = max(min(last, high(s)) - first + 1, 0) + result = newString(L) + for i in 0 .. L-1: + result[i] = s[i+first] + +proc substr*(s: string, first = 0): string = + ## copies a slice of `s` into a new string and returns this new + ## string. The bounds `first` and `last` denote the indices of + ## the first and last characters that shall be copied. If ``last`` + ## is omitted, it is treated as ``high(s)``. If ``last >= s.len``, ``s.len`` + ## is used instead: This means ``substr`` can also be used to `cut`:idx: + ## or `limit`:idx: a string's length. + result = substr(s, first, high(s)) + when defined(nimconfig): include "system/nimscript" @@ -4164,21 +4184,6 @@ when not defined(js): proc toOpenArrayByte*(x: string; first, last: int): openarray[byte] {. magic: "Slice".} -proc substr*(s: string, first, last: int): string = - let L = max(min(last, high(s)) - first + 1, 0) - result = newString(L) - for i in 0 .. L-1: - result[i] = s[i+first] - -proc substr*(s: string, first = 0): string = - ## copies a slice of `s` into a new string and returns this new - ## string. The bounds `first` and `last` denote the indices of - ## the first and last characters that shall be copied. If ``last`` - ## is omitted, it is treated as ``high(s)``. If ``last >= s.len``, ``s.len`` - ## is used instead: This means ``substr`` can also be used to `cut`:idx: - ## or `limit`:idx: a string's length. - result = substr(s, first, high(s)) - type ForLoopStmt* {.compilerProc.} = object ## special type that marks a macro ## as a `for-loop macro`:idx: diff --git a/lib/system/assign.nim b/lib/system/assign.nim index 16b56aba7b..2b74e66824 100644 --- a/lib/system/assign.nim +++ b/lib/system/assign.nim @@ -202,11 +202,6 @@ proc objectInit(dest: pointer, typ: PNimType) = # ---------------------- assign zero ----------------------------------------- -proc nimDestroyRange[T](r: T) {.compilerProc.} = - # internal proc used for destroying sequences and arrays - mixin `=destroy` - for i in countup(0, r.len - 1): `=destroy`(r[i]) - proc genericReset(dest: pointer, mt: PNimType) {.compilerProc, benign.} proc genericResetAux(dest: pointer, n: ptr TNimNode) = var d = cast[ByteAddress](dest) diff --git a/lib/system/cgprocs.nim b/lib/system/cgprocs.nim index 660c681163..72219c2b71 100644 --- a/lib/system/cgprocs.nim +++ b/lib/system/cgprocs.nim @@ -12,7 +12,6 @@ type LibHandle = pointer # private type ProcAddr = pointer # library loading and loading of procs: -{.deprecated: [TLibHandle: LibHandle, TProcAddr: ProcAddr].} proc nimLoadLibrary(path: string): LibHandle {.compilerproc.} proc nimUnloadLibrary(lib: LibHandle) {.compilerproc.} diff --git a/lib/system/gc_ms.nim b/lib/system/gc_ms.nim index 75f9c67496..96221b175b 100644 --- a/lib/system/gc_ms.nim +++ b/lib/system/gc_ms.nim @@ -264,12 +264,13 @@ proc forAllChildren(cell: PCell, op: WalkOp) = of tyRef, tyOptAsRef: # common case forAllChildrenAux(cellToUsr(cell), cell.typ.base, op) of tySequence: - var d = cast[ByteAddress](cellToUsr(cell)) - var s = cast[PGenericSeq](d) - if s != nil: - for i in 0..s.len-1: - forAllChildrenAux(cast[pointer](d +% i *% cell.typ.base.size +% - GenericSeqSize), cell.typ.base, op) + when not defined(gcDestructors): + var d = cast[ByteAddress](cellToUsr(cell)) + var s = cast[PGenericSeq](d) + if s != nil: + for i in 0..s.len-1: + forAllChildrenAux(cast[pointer](d +% i *% cell.typ.base.size +% + GenericSeqSize), cell.typ.base, op) else: discard proc rawNewObj(typ: PNimType, size: int, gch: var GcHeap): pointer = @@ -310,53 +311,54 @@ proc newObjNoInit(typ: PNimType, size: int): pointer {.compilerRtl.} = result = rawNewObj(typ, size, gch) when defined(memProfiler): nimProfile(size) -proc newSeq(typ: PNimType, len: int): pointer {.compilerRtl.} = - # `newObj` already uses locks, so no need for them here. - let size = addInt(mulInt(len, typ.base.size), GenericSeqSize) - result = newObj(typ, size) - cast[PGenericSeq](result).len = len - cast[PGenericSeq](result).reserved = len - when defined(memProfiler): nimProfile(size) - proc newObjRC1(typ: PNimType, size: int): pointer {.compilerRtl.} = result = rawNewObj(typ, size, gch) zeroMem(result, size) when defined(memProfiler): nimProfile(size) -proc newSeqRC1(typ: PNimType, len: int): pointer {.compilerRtl.} = - let size = addInt(mulInt(len, typ.base.size), GenericSeqSize) - result = newObj(typ, size) - cast[PGenericSeq](result).len = len - cast[PGenericSeq](result).reserved = len - when defined(memProfiler): nimProfile(size) +when not defined(gcDestructors): + proc newSeq(typ: PNimType, len: int): pointer {.compilerRtl.} = + # `newObj` already uses locks, so no need for them here. + let size = addInt(mulInt(len, typ.base.size), GenericSeqSize) + result = newObj(typ, size) + cast[PGenericSeq](result).len = len + cast[PGenericSeq](result).reserved = len + when defined(memProfiler): nimProfile(size) -proc growObj(old: pointer, newsize: int, gch: var GcHeap): pointer = - acquire(gch) - collectCT(gch, newsize + sizeof(Cell)) - var ol = usrToCell(old) - sysAssert(ol.typ != nil, "growObj: 1") - gcAssert(ol.typ.kind in {tyString, tySequence}, "growObj: 2") + proc newSeqRC1(typ: PNimType, len: int): pointer {.compilerRtl.} = + let size = addInt(mulInt(len, typ.base.size), GenericSeqSize) + result = newObj(typ, size) + cast[PGenericSeq](result).len = len + cast[PGenericSeq](result).reserved = len + when defined(memProfiler): nimProfile(size) - var res = cast[PCell](rawAlloc(gch.region, newsize + sizeof(Cell))) - var elemSize = 1 - if ol.typ.kind != tyString: elemSize = ol.typ.base.size - incTypeSize ol.typ, newsize + proc growObj(old: pointer, newsize: int, gch: var GcHeap): pointer = + acquire(gch) + collectCT(gch, newsize + sizeof(Cell)) + var ol = usrToCell(old) + sysAssert(ol.typ != nil, "growObj: 1") + gcAssert(ol.typ.kind in {tyString, tySequence}, "growObj: 2") - var oldsize = cast[PGenericSeq](old).len*elemSize + GenericSeqSize - copyMem(res, ol, oldsize + sizeof(Cell)) - zeroMem(cast[pointer](cast[ByteAddress](res)+% oldsize +% sizeof(Cell)), - newsize-oldsize) - sysAssert((cast[ByteAddress](res) and (MemAlign-1)) == 0, "growObj: 3") - when withBitvectors: incl(gch.allocated, res) - when useCellIds: - inc gch.idGenerator - res.id = gch.idGenerator - release(gch) - result = cellToUsr(res) - when defined(memProfiler): nimProfile(newsize-oldsize) + var res = cast[PCell](rawAlloc(gch.region, newsize + sizeof(Cell))) + var elemSize = 1 + if ol.typ.kind != tyString: elemSize = ol.typ.base.size + incTypeSize ol.typ, newsize -proc growObj(old: pointer, newsize: int): pointer {.rtl.} = - result = growObj(old, newsize, gch) + var oldsize = cast[PGenericSeq](old).len*elemSize + GenericSeqSize + copyMem(res, ol, oldsize + sizeof(Cell)) + zeroMem(cast[pointer](cast[ByteAddress](res)+% oldsize +% sizeof(Cell)), + newsize-oldsize) + sysAssert((cast[ByteAddress](res) and (MemAlign-1)) == 0, "growObj: 3") + when withBitvectors: incl(gch.allocated, res) + when useCellIds: + inc gch.idGenerator + res.id = gch.idGenerator + release(gch) + result = cellToUsr(res) + when defined(memProfiler): nimProfile(newsize-oldsize) + + proc growObj(old: pointer, newsize: int): pointer {.rtl.} = + result = growObj(old, newsize, gch) {.push profiler:off.} diff --git a/lib/system/hti.nim b/lib/system/hti.nim index 45b1d1cd37..bb3769ac46 100644 --- a/lib/system/hti.nim +++ b/lib/system/hti.nim @@ -7,7 +7,7 @@ # distribution, for details about the copyright. # -when declared(NimString): +when declared(ThisIsSystem): # we are in system module: {.pragma: codegenType, compilerproc.} else: diff --git a/lib/system/jssys.nim b/lib/system/jssys.nim index e12bab184f..5fff869f0c 100644 --- a/lib/system/jssys.nim +++ b/lib/system/jssys.nim @@ -31,8 +31,6 @@ type JSRef = ref RootObj # Fake type. -{.deprecated: [TSafePoint: SafePoint, TCallFrame: CallFrame].} - var framePtr {.importc, nodecl, volatile.}: PCallFrame excHandler {.importc, nodecl, volatile.}: int = 0 @@ -506,7 +504,7 @@ proc chckNilDisp(p: pointer) {.compilerproc.} = if p == nil: sysFatal(NilAccessError, "cannot dispatch; dispatcher is nil") -type NimString = string # hack for hti.nim +const ThisIsSystem = true # for hti.nim include "system/hti" proc isFatPointer(ti: PNimType): bool = diff --git a/lib/system/mmdisp.nim b/lib/system/mmdisp.nim index ff2da7aba1..e7e14b9483 100644 --- a/lib/system/mmdisp.nim +++ b/lib/system/mmdisp.nim @@ -554,7 +554,7 @@ else: else: include "system/gc" -when not declared(nimNewSeqOfCap): +when not declared(nimNewSeqOfCap) and not defined(gcDestructors): proc nimNewSeqOfCap(typ: PNimType, cap: int): pointer {.compilerproc.} = when defined(gcRegions): let s = mulInt(cap, typ.base.size) # newStr already adds GenericSeqSize diff --git a/lib/system/sysio.nim b/lib/system/sysio.nim index f3a576be09..f6e691c0d2 100644 --- a/lib/system/sysio.nim +++ b/lib/system/sysio.nim @@ -148,7 +148,7 @@ proc readLine(f: File, line: var TaintedString): bool = if line.string.isNil: line = TaintedString(newStringOfCap(80)) else: - when not defined(nimscript): + when not defined(nimscript) and not defined(gcDestructors): sp = cint(cast[PGenericSeq](line.string).space) line.string.setLen(sp) while true: diff --git a/lib/system/widestrs.nim b/lib/system/widestrs.nim index a8b28c2797..85e5e1462b 100644 --- a/lib/system/widestrs.nim +++ b/lib/system/widestrs.nim @@ -10,13 +10,12 @@ # Nim support for C/C++'s `wide strings`:idx:. This is part of the system # module! Do not import it directly! -when not declared(NimString): +when not declared(ThisIsSystem): {.error: "You must not import this module explicitly".} type Utf16Char* = distinct int16 WideCString* = ref UncheckedArray[Utf16Char] -{.deprecated: [TUtf16Char: Utf16Char].} proc len*(w: WideCString): int = ## returns the length of a widestring. This traverses the whole string to From 32afdc09c6e2e6b32566df9e70cb71ae43eb9355 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Tue, 17 Jul 2018 13:19:42 +0200 Subject: [PATCH 009/145] WIP: strings/seqs based on destructors --- compiler/ast.nim | 1 + compiler/ccgexprs.nim | 20 ++- compiler/ccgliterals.nim | 8 +- compiler/ccgtypes.nim | 39 ++++-- compiler/cgen.nim | 5 +- compiler/destroyer.nim | 25 ++-- compiler/semstmts.nim | 5 +- compiler/types.nim | 13 +- lib/core/seqs.nim | 220 +++++++++++++++++-------------- lib/core/strs.nim | 25 ++-- lib/system.nim | 12 ++ lib/system/jssys.nim | 1 - tests/destructor/tcustomseqs.nim | 7 +- 13 files changed, 240 insertions(+), 141 deletions(-) diff --git a/compiler/ast.nim b/compiler/ast.nim index 6302c21b98..7cc785ad7b 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -626,6 +626,7 @@ type mIsPartOf, mAstToStr, mParallel, mSwap, mIsNil, mArrToSeq, mCopyStr, mCopyStrLast, mNewString, mNewStringOfCap, mParseBiggestFloat, + mMove, mWasMoved, mReset, mArray, mOpenArray, mRange, mSet, mSeq, mOpt, mVarargs, mRef, mPtr, mVar, mDistinct, mVoid, mTuple, diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 689e2483e1..0d87cc19d9 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -1224,8 +1224,14 @@ proc genNewSeq(p: BProc, e: PNode) = var a, b: TLoc initLocExpr(p, e.sons[1], a) initLocExpr(p, e.sons[2], b) - genNewSeqAux(p, a, b.rdLoc) - gcUsage(p.config, e) + if p.config.selectedGC == gcDestructors: + let seqtype = skipTypes(e.sons[1].typ, abstractVarRange) + linefmt(p, cpsStmts, "$1.len = $2; $1.p = ($4*) #newSeqPayload($2, sizeof($3));$n", + a.rdLoc, b.rdLoc, getTypeDesc(p.module, seqtype.lastSon), + getSeqPayloadType(p.module, seqtype)) + else: + genNewSeqAux(p, a, b.rdLoc) + gcUsage(p.config, e) proc genNewSeqOfCap(p: BProc; e: PNode; d: var TLoc) = let seqtype = skipTypes(e.typ, abstractVarRange) @@ -1543,6 +1549,9 @@ proc genArrayLen(p: BProc, e: PNode, d: var TLoc, op: TMagic) = else: internalError(p.config, e.info, "genArrayLen()") proc genSetLengthSeq(p: BProc, e: PNode, d: var TLoc) = + if p.config.selectedGc == gcDestructors: + genCall(p, e, d) + return var a, b: TLoc assert(d.k == locNone) var x = e.sons[1] @@ -1561,8 +1570,11 @@ proc genSetLengthSeq(p: BProc, e: PNode, d: var TLoc) = gcUsage(p.config, e) proc genSetLengthStr(p: BProc, e: PNode, d: var TLoc) = - binaryStmt(p, e, d, "$1 = #setLengthStr($1, $2);$n") - gcUsage(p.config, e) + if p.config.selectedGc == gcDestructors: + binaryStmtAddr(p, e, d, "#setLengthStrV2($1, $2);$n") + else: + binaryStmt(p, e, d, "$1 = #setLengthStr($1, $2);$n") + gcUsage(p.config, e) proc genSwap(p: BProc, e: PNode, d: var TLoc) = # swap(a, b) --> diff --git a/compiler/ccgliterals.nim b/compiler/ccgliterals.nim index cfe71375e8..a06e4e5d02 100644 --- a/compiler/ccgliterals.nim +++ b/compiler/ccgliterals.nim @@ -53,16 +53,20 @@ proc genStringLiteralV1(m: BModule; n: PNode): Rope = proc genStringLiteralDataOnlyV2(m: BModule, s: string): Rope = result = getTempName(m) - addf(m.s[cfsData], " static const NIM_CHAR $1[$2] = $3;$n", + addf(m.s[cfsData], "static const struct {$n" & + " NI cap; void* allocator; NIM_CHAR[$2] data;$n" & + "} $1 = { $2, NIM_NIL, $3 };$n", [result, rope(len(s)+1), makeCString(s)]) proc genStringLiteralV2(m: BModule; n: PNode): Rope = let id = nodeTableTestOrSet(m.dataCache, n, m.labels) if id == m.labels: + discard cgsym(m, "NimStrPayload") + discard cgsym(m, "NimStringV2") # string literal not found in the cache: let pureLit = genStringLiteralDataOnlyV2(m, n.strVal) result = getTempName(m) - addf(m.s[cfsData], "static const #NimStringV2 $1 = {$2, $2, $3};$n", + addf(m.s[cfsData], "static const NimStringV2 $1 = {$2, (NimStrPayload*)&$3};$n", [result, rope(len(n.strVal)+1), pureLit]) else: result = m.tmpBase & rope(id) diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index 756711642e..ea06544bbc 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -324,6 +324,10 @@ proc getForwardStructFormat(m: BModule): string = if m.compileToCpp: result = "$1 $2;$n" else: result = "typedef $1 $2 $2;$n" +proc seqStar(m: BModule): string = + if m.config.selectedGC == gcDestructors: result = "" + else: result = "*" + proc getTypeForward(m: BModule, typ: PType; sig: SigHash): Rope = result = cacheGetType(m.forwTypeCache, sig) if result != nil: return @@ -355,7 +359,7 @@ proc getTypeDescWeak(m: BModule; t: PType; check: var IntSet): Rope = result = getTypeForward(m, t, hashType(t)) pushType(m, t) of tySequence: - result = getTypeForward(m, t, hashType(t)) & "*" + result = getTypeForward(m, t, hashType(t)) & seqStar(m) pushType(m, t) else: result = getTypeDescAux(m, t, check) @@ -487,7 +491,7 @@ proc genRecordFieldsAux(m: BModule, n: PNode, if fieldType.kind == tyArray and tfUncheckedArray in fieldType.flags: addf(result, "$1 $2[SEQ_DECL_SIZE];$n", [getTypeDescAux(m, fieldType.elemType, check), sname]) - elif fieldType.kind in {tySequence, tyOpt}: + elif fieldType.kind == tySequence: # we need to use a weak dependency here for trecursive_table. addf(result, "$1 $2;$n", [getTypeDescWeak(m, field.loc.t, check), sname]) elif field.bitsize != 0: @@ -601,6 +605,14 @@ proc resolveStarsInCppType(typ: PType, idx, stars: int): PType = result = if result.kind == tyGenericInst: result.sons[1] else: result.elemType +proc getSeqPayloadType(m: BModule; t: PType): Rope = + var check = initIntSet() + result = getTypeForward(m, t, hashType(t)) + # XXX remove this duplication: + appcg(m, m.s[cfsSeqTypes], + "struct $2_Content { NI cap; void* allocator; $1 data[SEQ_DECL_SIZE];$n } ", + [getTypeDescAux(m, t.sons[0], check), result]) + proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet): Rope = # returns only the type's name var t = origTyp.skipTypes(irrelevantForBackend) @@ -641,7 +653,7 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet): Rope = of tySequence: # no restriction! We have a forward declaration for structs let name = getTypeForward(m, et, hashType et) - result = name & "*" & star + result = name & seqStar(m) & star m.typeCache[sig] = result pushType(m, et) else: @@ -705,20 +717,29 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet): Rope = [structOrUnion(t), result]) m.forwTypeCache[sig] = result assert(cacheGetType(m.typeCache, sig) == nil) - m.typeCache[sig] = result & "*" + m.typeCache[sig] = result & seqStar(m) if not isImportedType(t): if skipTypes(t.sons[0], typedescInst).kind != tyEmpty: const cppSeq = "struct $2 : #TGenericSeq {$n" cSeq = "struct $2 {$n" & " #TGenericSeq Sup;$n" - appcg(m, m.s[cfsSeqTypes], - (if m.compileToCpp: cppSeq else: cSeq) & - " $1 data[SEQ_DECL_SIZE];$n" & - "};$n", [getTypeDescAux(m, t.sons[0], check), result]) + if m.config.selectedGC == gcDestructors: + appcg(m, m.s[cfsSeqTypes], + "struct $2_Content { NI cap; void* allocator; $1 data[SEQ_DECL_SIZE];$n } " & + "struct $2 {$n" & + " NI len; $2_Content* p;$n" & + "};$n", [getTypeDescAux(m, t.sons[0], check), result]) + else: + appcg(m, m.s[cfsSeqTypes], + (if m.compileToCpp: cppSeq else: cSeq) & + " $1 data[SEQ_DECL_SIZE];$n" & + "};$n", [getTypeDescAux(m, t.sons[0], check), result]) + elif m.config.selectedGC == gcDestructors: + internalError(m.config, "cannot map the empty seq type to a C type") else: result = rope("TGenericSeq") - add(result, "*") + add(result, seqStar(m)) of tyArray: var n: BiggestInt = lengthOrd(m.config, t) if n <= 0: n = 1 # make an array of at least one element diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 0ca7533d4e..180aa4731c 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -250,7 +250,10 @@ proc lenExpr(p: BProc; a: TLoc): Rope = result = "($1 ? $1->$2 : 0)" % [rdLoc(a), lenField(p)] proc dataField(p: BProc): Rope = - result = rope"->data" + if p.config.selectedGc == gcDestructors: + result = rope".p->data" + else: + result = rope"->data" include ccgliterals include ccgtypes diff --git a/compiler/destroyer.nim b/compiler/destroyer.nim index 0395728c28..c2a74edb19 100644 --- a/compiler/destroyer.nim +++ b/compiler/destroyer.nim @@ -100,12 +100,12 @@ Rule Pattern Transformed into finally: `=destroy`(x) 1.2 var x: sink T; stmts var x: sink T; stmts; ensureEmpty(x) 2 x = f() `=sink`(x, f()) -3 x = lastReadOf z `=sink`(x, z) +3 x = lastReadOf z `=sink`(x, z); wasMoved(z) 4.1 y = sinkParam `=sink`(y, sinkParam) 4.2 x = y `=`(x, y) # a copy 5.1 f_sink(g()) f_sink(g()) 5.2 f_sink(y) f_sink(copy y); # copy unless we can see it's the last read -5.3 f_sink(move y) f_sink(y); reset(y) # explicit moves empties 'y' +5.3 f_sink(move y) f_sink(y); wasMoved(y) # explicit moves empties 'y' 5.4 f_noSink(g()) var tmp = bitwiseCopy(g()); f(tmp); `=destroy`(tmp) Remarks: Rule 1.2 is not yet implemented because ``sink`` is currently @@ -282,6 +282,11 @@ proc destructiveMoveSink(n: PNode; c: var Con): PNode = newIntTypeNode(nkIntLit, 0, getSysType(c.graph, n.info, tyBool))) result.add n +proc genMagicCall(n: PNode; c: var Con; magicname: string; m: TMagic): PNode = + result = newNodeI(nkCall, n.info) + result.add(newSymNode(createMagic(c.graph, magicname, m))) + result.add n + proc moveOrCopy(dest, ri: PNode; c: var Con): PNode = if ri.kind in constrExprs: result = genSink(c, ri.typ, dest) @@ -290,8 +295,10 @@ proc moveOrCopy(dest, ri: PNode; c: var Con): PNode = recurse(ri, ri2) result.add ri2 elif ri.kind == nkSym and isHarmlessVar(ri.sym, c): - result = genSink(c, ri.typ, dest) - result.add p(ri, c) + # Rule 3: `=sink`(x, z); wasMoved(z) + var snk = genSink(c, ri.typ, dest) + snk.add p(ri, c) + result = newTree(nkStmtList, snk, genMagicCall(ri, c, "wasMoved", mWasMoved)) elif ri.kind == nkSym and isSinkParam(ri.sym): result = genSink(c, ri.typ, dest) result.add destructiveMoveSink(ri, c) @@ -313,11 +320,9 @@ proc passCopyToSink(n: PNode; c: var Con): PNode = result.add newTree(nkAsgn, tmp, p(n, c)) result.add tmp -proc genReset(n: PNode; c: var Con): PNode = - result = newNodeI(nkCall, n.info) - result.add(newSymNode(createMagic(c.graph, "reset", mReset))) - # The mReset builtin does not take the address: - result.add n +proc genWasMoved(n: PNode; c: var Con): PNode = + # The mWasMoved builtin does not take the address. + result = genMagicCall(n, c, "wasMoved", mWasMoved) proc destructiveMoveVar(n: PNode; c: var Con): PNode = # generate: (let tmp = v; reset(v); tmp) @@ -334,7 +339,7 @@ proc destructiveMoveVar(n: PNode; c: var Con): PNode = add(v, vpart) result.add v - result.add genReset(n, c) + result.add genWasMoved(n, c) result.add tempAsNode proc p(n: PNode; c: var Con): PNode = diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 6ef03456e9..7818137959 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -1553,7 +1553,7 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind, if proto.typ.callConv != s.typ.callConv or proto.typ.flags < s.typ.flags: localError(c.config, n.sons[pragmasPos].info, errPragmaOnlyInHeaderOfProcX % ("'" & proto.name.s & "' from " & c.config$proto.info)) - if sfForward notin proto.flags: + if sfForward notin proto.flags and proto.magic == mNone: wrongRedefinition(c, n.info, proto.name.s) excl(proto.flags, sfForward) closeScope(c) # close scope with wrong parameter symbols @@ -1619,7 +1619,8 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind, openScope(c) n.sons[bodyPos] = semGenericStmt(c, n.sons[bodyPos]) closeScope(c) - fixupInstantiatedSymbols(c, s) + if s.magic == mNone: + fixupInstantiatedSymbols(c, s) if s.kind == skMethod: semMethodPrototype(c, s, n) if sfImportc in s.flags: # so we just ignore the body after semantic checking for importc: diff --git a/compiler/types.nim b/compiler/types.nim index 66807cf97f..76d233e8a2 100644 --- a/compiler/types.nim +++ b/compiler/types.nim @@ -1335,14 +1335,23 @@ proc computeSizeAux(conf: ConfigRef; typ: PType, a: var BiggestInt): BiggestInt if typ.callConv == ccClosure: result = 2 * conf.target.ptrSize else: result = conf.target.ptrSize a = conf.target.ptrSize - of tyString, tyNil: + of tyString: + if tfHasAsgn in typ.flags: + result = conf.target.ptrSize * 2 + else: + result = conf.target.ptrSize + of tyNil: result = conf.target.ptrSize a = result of tyCString, tySequence, tyPtr, tyRef, tyVar, tyLent, tyOpenArray: let base = typ.lastSon if base == typ or (base.kind == tyTuple and base.size==szIllegalRecursion): result = szIllegalRecursion - else: result = conf.target.ptrSize + else: + if typ.kind == tySequence and tfHasAsgn in typ.flags: + result = conf.target.ptrSize * 2 + else: + result = conf.target.ptrSize a = result of tyArray: let elemSize = computeSizeAux(conf, typ.sons[1], a) diff --git a/lib/core/seqs.nim b/lib/core/seqs.nim index 02c1928516..4327d23524 100644 --- a/lib/core/seqs.nim +++ b/lib/core/seqs.nim @@ -7,133 +7,157 @@ # distribution, for details about the copyright. # -import allocators, typetraits + +import typetraits +# strs already imported allocators for us. ## Default seq implementation used by Nim's core. type - seq*[T] = object - len, cap: int - data: ptr UncheckedArray[T] + NimSeqPayload {.core.}[T] = object + cap: int + region: Allocator + data: UncheckedArray[T] + + NimSeqV2*[T] = object + len: int + p: ptr NimSeqPayload[T] const nimSeqVersion {.core.} = 2 -template frees(s) = dealloc(s.data, s.cap * sizeof(T)) +template payloadSize(cap): int = cap * sizeof(T) + sizeof(int) + sizeof(Allocator) # XXX make code memory safe for overflows in '*' -when defined(nimHasTrace): - proc `=trace`[T](s: seq[T]; a: Allocator) = - for i in 0 ..< s.len: `=trace`(s.data[i], a) +when false: + # this is currently not part of Nim's type bound operators and so it's + # built into the tracing proc generation just like before. + proc `=trace`[T](s: NimSeqV2[T]) = + for i in 0 ..< s.len: `=trace`(s.data[i]) -proc `=destroy`[T](x: var seq[T]) = - if x.data != nil: +proc `=destroy`[T](x: var NimSeqV2[T]) = + var p = x.p + if p != nil: when not supportsCopyMem(T): - for i in 0.. 0: + copyMem(unsafeAddr a.p.data[0], unsafeAddr b.p.data[0], a.len * sizeof(T)) else: for i in 0..= x.cap: resize(x) - result = addr(x.data[x.len]) - inc x.len -template add*[T](x: var seq[T]; y: T) = - reserveSlot(x)[] = y +type + PayloadBase = object + cap: int + region: Allocator -proc shrink*[T](x: var seq[T]; newLen: int) = - assert newLen <= x.len - assert newLen >= 0 +proc newSeqPayload(cap, elemSize: int): pointer {.compilerRtl.} = + # we have to use type erasure here as Nim does not support generic + # compilerProcs. Oh well, this will all be inlined anyway. + if cap <= 0: + let region = getLocalAllocator() + var p = cast[ptr PayloadBase](region.alloc(region, cap * elemSize + sizeof(int) + sizeof(Allocator))) + p.region = region + p.cap = cap + result = p + else: + result = nil + +proc prepareSeqAdd(len: int; p: pointer; addlen, elemSize: int): pointer {.compilerRtl.} = + if len+addlen <= len: + result = p + elif p == nil: + result = newSeqPayload(len+addlen, elemSize) + else: + # Note: this means we cannot support things that have internal pointers as + # they get reallocated here. This needs to be documented clearly. + var p = cast[ptr PayloadBase](p) + let region = if p.region == nil: getLocalAllocator() else: p.region + let cap = max(resize(p.cap), len+addlen) + var q = cast[ptr PayloadBase](region.realloc(region, p, + sizeof(int) + sizeof(Allocator) + elemSize * p.cap, + sizeof(int) + sizeof(Allocator) + elemSize * cap)) + q.region = region + q.cap = cap + result = q + +proc shrink*[T](x: var seq[T]; newLen: Natural) = + sysAssert newLen <= x.len, "invalid newLen parameter for 'shrink'" when not supportsCopyMem(T): for i in countdown(x.len - 1, newLen - 1): - `=destroy`(x.data[i]) - x.len = newLen + `=destroy`(x[i]) -proc grow*[T](x: var seq[T]; newLen: int; value: T) = - if newLen <= x.len: return - assert newLen >= 0 - if x.cap == 0: x.cap = newLen - else: x.cap = max(newLen, (x.cap * 3) shr 1) - x.data = cast[type(x.data)](realloc(x.data, x.cap * sizeof(T))) - for i in x.len..= x.cap: resize(x) + result = addr(x.data[x.len]) + inc x.len + + template add*[T](x: var NimSeqV2[T]; y: T) = + reserveSlot(x)[] = y + + template `[]`*[T](x: NimSeqV2[T]; i: Natural): T = + assert i < x.len + x.data[i] + + template `[]=`*[T](x: NimSeqV2[T]; i: Natural; y: T) = + assert i < x.len + x.data[i] = y + + proc `@`*[T](elems: openArray[T]): NimSeqV2[T] = + result.cap = elems.len + result.len = elems.len + result.data = cast[type(result.data)](alloc(result.cap * sizeof(T))) + when supportsCopyMem(T): + copyMem(result.data, unsafeAddr(elems[0]), result.cap * sizeof(T)) else: - result.add(", ") - - when compiles(value.isNil): - # this branch should not be necessary - if value.isNil: - result.add "nil" - else: - result.addQuoted(value) - else: - result.addQuoted(value) - - result.add("]") + for i in 0.. 0: @@ -96,7 +95,7 @@ proc prepareAdd(s: var NimStringV2; addlen: int) {.compilerRtl.} = copyMem(unsafeAddr s.p.data[0], unsafeAddr oldP.data[0], s.len) elif s.len + addlen > s.p.cap: let cap = max(s.len + addlen, resize(s.p.cap)) - s.p = cast[ptr StrContent](s.p.region.realloc(s.p.region, s.p, + s.p = cast[ptr NimStrPayload](s.p.region.realloc(s.p.region, s.p, oldSize = contentSize(s.p.cap), newSize = contentSize(cap))) s.p.cap = cap @@ -112,7 +111,7 @@ proc toNimStr(str: cstring, len: int): NimStringV2 {.compilerProc.} = result = NimStringV2(len: 0, p: nil) else: let region = getLocalAllocator() - var p = cast[ptr StrContent](region.alloc(region, contentSize(len))) + var p = cast[ptr NimStrPayload](region.alloc(region, contentSize(len))) p.region = region p.cap = len if len > 0: @@ -144,7 +143,7 @@ proc rawNewString(space: int): NimStringV2 {.compilerProc.} = result = NimStringV2(len: 0, p: nil) else: let region = getLocalAllocator() - var p = cast[ptr StrContent](region.alloc(region, contentSize(space))) + var p = cast[ptr NimStrPayload](region.alloc(region, contentSize(space))) p.region = region p.cap = space result = NimStringV2(len: 0, p: p) @@ -154,7 +153,15 @@ proc mnewString(len: int): NimStringV2 {.compilerProc.} = result = NimStringV2(len: 0, p: nil) else: let region = getLocalAllocator() - var p = cast[ptr StrContent](region.alloc(region, contentSize(len))) + var p = cast[ptr NimStrPayload](region.alloc(region, contentSize(len))) p.region = region p.cap = len result = NimStringV2(len: len, p: p) + +proc setLengthStrV2(s: var NimStringV2, newLen: int) {.compilerRtl.} = + if newLen > s.len: + prepareAdd(s, newLen - s.len) + else: + s.len = newLen + # this also only works because the destructor + # looks at s.p and not s.len diff --git a/lib/system.nim b/lib/system.nim index 1defe20ee7..2f6f459482 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -230,6 +230,17 @@ proc reset*[T](obj: var T) {.magic: "Reset", noSideEffect.} ## resets an object `obj` to its initial (binary zero) value. This needs to ## be called before any possible `object branch transition`:idx:. +when defined(nimNewRuntime): + proc wasMoved*[T](obj: var T) {.magic: "WasMoved", noSideEffect.} = + ## resets an object `obj` to its initial (binary zero) value to signify + ## it was "moved" and to signify its destructor should do nothing and + ## ideally be optimized away. + discard + + proc move*[T](x: var T): T {.magic: "Move", noSideEffect.} = + result = x + wasMoved(x) + type range*{.magic: "Range".}[T] ## Generic type to construct range types. array*{.magic: "Array".}[I, T] ## Generic type to construct @@ -3310,6 +3321,7 @@ when not defined(JS): #and not defined(nimscript): when hasAlloc: when defined(gcDestructors): include "core/strs" + include "core/seqs" else: include "system/sysstr" {.pop.} diff --git a/lib/system/jssys.nim b/lib/system/jssys.nim index 5fff869f0c..e500444ea5 100644 --- a/lib/system/jssys.nim +++ b/lib/system/jssys.nim @@ -504,7 +504,6 @@ proc chckNilDisp(p: pointer) {.compilerproc.} = if p == nil: sysFatal(NilAccessError, "cannot dispatch; dispatcher is nil") -const ThisIsSystem = true # for hti.nim include "system/hti" proc isFatPointer(ti: PNimType): bool = diff --git a/tests/destructor/tcustomseqs.nim b/tests/destructor/tcustomseqs.nim index 97d7c07b6c..83df0053f7 100644 --- a/tests/destructor/tcustomseqs.nim +++ b/tests/destructor/tcustomseqs.nim @@ -43,9 +43,10 @@ proc `=destroy`*[T](x: var myseq[T]) = proc `=`*[T](a: var myseq[T]; b: myseq[T]) = if a.data == b.data: return if a.data != nil: - dealloc(a.data) - inc deallocCount - a.data = nil + `=destroy`(a) + #dealloc(a.data) + #inc deallocCount + #a.data = nil a.len = b.len a.cap = b.cap if b.data != nil: From f485ebe1624656c0cf495baaebc5d45fdc9bdbeb Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Sat, 21 Jul 2018 13:16:53 +0200 Subject: [PATCH 010/145] --gc:destructors: next steps; WIP --- compiler/ccgexprs.nim | 44 +++++++++++++++++++++------------------- compiler/ccgliterals.nim | 18 +++++++++++++--- compiler/ccgtrav.nim | 16 ++++++++++++--- compiler/ccgtypes.nim | 40 ++++++++++++++++++++++-------------- compiler/cgen.nim | 4 +++- lib/system.nim | 14 ++++++++++--- lib/system/repr.nim | 18 ---------------- lib/system/strmantle.nim | 18 ++++++++++++++++ 8 files changed, 108 insertions(+), 64 deletions(-) diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index d25a4ad3d4..69175fd186 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -256,8 +256,8 @@ proc genGenericAsgn(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) = # (for objects, etc.): if p.config.selectedGC == gcDestructors: linefmt(p, cpsStmts, - "#nimCopyMem((void*)$1, (NIM_CONST void*)$2, sizeof($3));$n", - addrLoc(p.config, dest), addrLoc(p.config, src), rdLoc(dest)) + "$1.len = $2.len; $1.p = $2.p;$n", + rdLoc(dest), rdLoc(src)) elif needToCopy notin flags or tfShallow in skipTypes(dest.t, abstractVarRange).flags: if dest.storage == OnStack or not usesWriteBarrier(p.config): @@ -1512,28 +1512,19 @@ proc genArrayLen(p: BProc, e: PNode, d: var TLoc, op: TMagic) = if op == mHigh: unaryExpr(p, e, d, "($1 ? (#nimCStrLen($1)-1) : -1)") else: unaryExpr(p, e, d, "($1 ? #nimCStrLen($1) : 0)") of tyString: - if not p.module.compileToCpp: - if op == mHigh: unaryExpr(p, e, d, "($1 ? ($1->Sup.len-1) : -1)") - else: unaryExpr(p, e, d, "($1 ? $1->Sup.len : 0)") - else: - if op == mHigh: unaryExpr(p, e, d, "($1 ? ($1->len-1) : -1)") - else: unaryExpr(p, e, d, "($1 ? $1->len : 0)") + var a: TLoc + initLocExpr(p, e.sons[1], a) + var x = lenExpr(p, a) + if op == mHigh: x = "($1-1)" % [x] + putIntoDest(p, d, e, x) of tySequence: + # we go through a temporary here because people write bullshit code. var a, tmp: TLoc initLocExpr(p, e[1], a) getIntTemp(p, tmp) - var frmt: FormatStr - if not p.module.compileToCpp: - if op == mHigh: - frmt = "$1 = ($2 ? ($2->Sup.len-1) : -1);$n" - else: - frmt = "$1 = ($2 ? $2->Sup.len : 0);$n" - else: - if op == mHigh: - frmt = "$1 = ($2 ? ($2->len-1) : -1);$n" - else: - frmt = "$1 = ($2 ? $2->len : 0);$n" - lineCg(p, cpsStmts, frmt, tmp.r, rdLoc(a)) + var x = lenExpr(p, a) + if op == mHigh: x = "($1-1)" % [x] + lineCg(p, cpsStmts, "$1 = $2;$n", tmp.r, x) putIntoDest(p, d, e, tmp.r) of tyArray: # YYY: length(sideeffect) is optimized away incorrectly? @@ -1889,7 +1880,11 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) = else: binaryStmt(p, e, d, "$1 = #addChar($1, $2);$n") of mAppendStrStr: genStrAppend(p, e, d) - of mAppendSeqElem: genSeqElemAppend(p, e, d) + of mAppendSeqElem: + if p.config.selectedGc == gcDestructors: + genCall(p, e, d) + else: + genSeqElemAppend(p, e, d) of mEqStr: genStrEquals(p, e, d) of mLeStr: binaryExpr(p, e, d, "(#cmpStrings($1, $2) <= 0)") of mLtStr: binaryExpr(p, e, d, "(#cmpStrings($1, $2) < 0)") @@ -2537,6 +2532,13 @@ proc genConstExpr(p: BProc, n: PNode): Rope = result = genConstSimpleList(p, n) of nkObjConstr: result = genConstObjConstr(p, n) + of nkStrLit..nkTripleStrLit: + if p.config.selectedGc == gcDestructors: + result = genStringLiteralV2Const(p.module, n) + else: + var d: TLoc + initLocExpr(p, n, d) + result = rdLoc(d) else: var d: TLoc initLocExpr(p, n, d) diff --git a/compiler/ccgliterals.nim b/compiler/ccgliterals.nim index a06e4e5d02..34677ec060 100644 --- a/compiler/ccgliterals.nim +++ b/compiler/ccgliterals.nim @@ -54,9 +54,9 @@ proc genStringLiteralV1(m: BModule; n: PNode): Rope = proc genStringLiteralDataOnlyV2(m: BModule, s: string): Rope = result = getTempName(m) addf(m.s[cfsData], "static const struct {$n" & - " NI cap; void* allocator; NIM_CHAR[$2] data;$n" & + " NI cap; void* allocator; NIM_CHAR data[$2];$n" & "} $1 = { $2, NIM_NIL, $3 };$n", - [result, rope(len(s)+1), makeCString(s)]) + [result, rope(len(s)), makeCString(s)]) proc genStringLiteralV2(m: BModule; n: PNode): Rope = let id = nodeTableTestOrSet(m.dataCache, n, m.labels) @@ -67,10 +67,22 @@ proc genStringLiteralV2(m: BModule; n: PNode): Rope = let pureLit = genStringLiteralDataOnlyV2(m, n.strVal) result = getTempName(m) addf(m.s[cfsData], "static const NimStringV2 $1 = {$2, (NimStrPayload*)&$3};$n", - [result, rope(len(n.strVal)+1), pureLit]) + [result, rope(len(n.strVal)), pureLit]) else: result = m.tmpBase & rope(id) +proc genStringLiteralV2Const(m: BModule; n: PNode): Rope = + let id = nodeTableTestOrSet(m.dataCache, n, m.labels) + var pureLit: Rope + if id == m.labels: + discard cgsym(m, "NimStrPayload") + discard cgsym(m, "NimStringV2") + # string literal not found in the cache: + pureLit = genStringLiteralDataOnlyV2(m, n.strVal) + else: + pureLit = m.tmpBase & rope(id) + result = "{$1, (NimStrPayload*)&$2}" % [rope(len(n.strVal)), pureLit] + # ------ Version selector --------------------------------------------------- proc genStringLiteralDataOnly(m: BModule; s: string; info: TLineInfo): Rope = diff --git a/compiler/ccgtrav.nim b/compiler/ccgtrav.nim index 5a6dc8a6e3..c69bb2c805 100644 --- a/compiler/ccgtrav.nim +++ b/compiler/ccgtrav.nim @@ -7,8 +7,7 @@ # distribution, for details about the copyright. # -## Generates traversal procs for the C backend. Traversal procs are only an -## optimization; the GC works without them too. +## Generates traversal procs for the C backend. # included from cgen.nim @@ -61,6 +60,7 @@ proc parentObj(accessor: Rope; m: BModule): Rope {.inline.} = else: result = accessor +proc genTraverseProcSeq(c: TTraversalClosure, accessor: Rope, typ: PType) proc genTraverseProc(c: TTraversalClosure, accessor: Rope, typ: PType) = if typ == nil: return @@ -93,8 +93,18 @@ proc genTraverseProc(c: TTraversalClosure, accessor: Rope, typ: PType) = let typ = getUniqueType(typ) for i in countup(0, sonsLen(typ) - 1): genTraverseProc(c, ropecg(c.p.module, "$1.Field$2", accessor, i.rope), typ.sons[i]) - of tyRef, tyString, tySequence: + of tyRef: lineCg(p, cpsStmts, c.visitorFrmt, accessor) + of tySequence: + if tfHasAsgn notin typ.flags: + lineCg(p, cpsStmts, c.visitorFrmt, accessor) + elif containsGarbageCollectedRef(typ.lastSon): + # destructor based seqs are themselves not traced but their data is, if + # they contain a GC'ed type: + genTraverseProcSeq(c, accessor, typ) + of tyString: + if tfHasAsgn notin typ.flags: + lineCg(p, cpsStmts, c.visitorFrmt, accessor) of tyProc: if typ.callConv == ccClosure: lineCg(p, cpsStmts, c.visitorFrmt, ropecg(c.p.module, "$1.ClE_0", accessor)) diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index b83c96660f..59fbfc3e15 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -359,8 +359,11 @@ proc getTypeDescWeak(m: BModule; t: PType; check: var IntSet): Rope = result = getTypeForward(m, t, hashType(t)) pushType(m, t) of tySequence: - result = getTypeForward(m, t, hashType(t)) & seqStar(m) - pushType(m, t) + if m.config.selectedGC == gcDestructors: + result = getTypeDescAux(m, t, check) + else: + result = getTypeForward(m, t, hashType(t)) & seqStar(m) + pushType(m, t) else: result = getTypeDescAux(m, t, check) @@ -491,7 +494,7 @@ proc genRecordFieldsAux(m: BModule, n: PNode, if fieldType.kind == tyArray and tfUncheckedArray in fieldType.flags: addf(result, "$1 $2[SEQ_DECL_SIZE];$n", [getTypeDescAux(m, fieldType.elemType, check), sname]) - elif fieldType.kind == tySequence: + elif fieldType.kind == tySequence and m.config.selectedGC != gcDestructors: # we need to use a weak dependency here for trecursive_table. addf(result, "$1 $2;$n", [getTypeDescWeak(m, field.loc.t, check), sname]) elif field.bitsize != 0: @@ -606,12 +609,13 @@ proc resolveStarsInCppType(typ: PType, idx, stars: int): PType = else: result.elemType proc getSeqPayloadType(m: BModule; t: PType): Rope = - var check = initIntSet() - result = getTypeForward(m, t, hashType(t)) - # XXX remove this duplication: - appcg(m, m.s[cfsSeqTypes], - "struct $2_Content { NI cap; void* allocator; $1 data[SEQ_DECL_SIZE];$n } ", - [getTypeDescAux(m, t.sons[0], check), result]) + result = getTypeForward(m, t, hashType(t)) & "_Content" + when false: + var check = initIntSet() + # XXX remove this duplication: + appcg(m, m.s[cfsSeqTypes], + "struct $2_Content { NI cap; void* allocator; $1 data[SEQ_DECL_SIZE]; };$n", + [getTypeDescAux(m, t.sons[0], check), result]) proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet): Rope = # returns only the type's name @@ -725,11 +729,11 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet): Rope = cSeq = "struct $2 {$n" & " #TGenericSeq Sup;$n" if m.config.selectedGC == gcDestructors: - appcg(m, m.s[cfsSeqTypes], - "struct $2_Content { NI cap; void* allocator; $1 data[SEQ_DECL_SIZE];$n } " & - "struct $2 {$n" & - " NI len; $2_Content* p;$n" & - "};$n", [getTypeDescAux(m, t.sons[0], check), result]) + appcg(m, m.s[cfsTypes], + "typedef struct{ NI cap;void* allocator;$1 data[SEQ_DECL_SIZE];}$2_Content;$n" & + "struct $2 {$n" & + " NI len; $2_Content* p;$n" & + "};$n", [getTypeDescAux(m, t.sons[0], check), result]) else: appcg(m, m.s[cfsSeqTypes], (if m.compileToCpp: cppSeq else: cSeq) & @@ -1198,7 +1202,13 @@ proc genTypeInfo(m: BModule, t: PType; info: TLineInfo): Rope = else: let x = fakeClosureType(m, t.owner) genTupleInfo(m, x, x, result, info) - of tySequence, tyRef, tyOptAsRef: + of tySequence: + if tfHasAsgn notin t.flags: + genTypeInfoAux(m, t, t, result, info) + if m.config.selectedGC >= gcMarkAndSweep: + let markerProc = genTraverseProc(m, origType, sig) + addf(m.s[cfsTypeInit3], "$1.marker = $2;$n", [result, markerProc]) + of tyRef, tyOptAsRef: genTypeInfoAux(m, t, t, result, info) if m.config.selectedGC >= gcMarkAndSweep: let markerProc = genTraverseProc(m, origType, sig) diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 8d8fdfcd9a..80c03f9e4a 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -334,7 +334,9 @@ proc resetLoc(p: BProc, loc: var TLoc) = proc constructLoc(p: BProc, loc: TLoc, isTemp = false) = let typ = loc.t - if not isComplexValueType(typ): + if p.config.selectedGc == gcDestructors and skipTypes(typ, abstractInst).kind in {tyString, tySequence}: + linefmt(p, cpsStmts, "$1.len = 0; $1.p = NIM_NIL;$n", rdLoc(loc)) + elif not isComplexValueType(typ): linefmt(p, cpsStmts, "$1 = ($2)0;$n", rdLoc(loc), getTypeDesc(p.module, typ)) else: diff --git a/lib/system.nim b/lib/system.nim index fee3d49664..29e357c68c 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -1519,7 +1519,13 @@ when not defined(JS) and not defined(nimscript) and hostOS != "standalone": when not defined(JS) and not defined(nimscript) and hasAlloc and not defined(gcDestructors): proc addChar(s: NimString, c: char): NimString {.compilerProc, benign.} -proc add*[T](x: var seq[T], y: T) {.magic: "AppendSeqElem", noSideEffect.} +when defined(gcDestructors): + proc add*[T](x: var seq[T], y: sink T) {.magic: "AppendSeqElem", noSideEffect.} = + let xl = x.len + setLen(x, xl + 1) + x[xl] = y +else: + proc add*[T](x: var seq[T], y: T) {.magic: "AppendSeqElem", noSideEffect.} proc add*[T](x: var seq[T], y: openArray[T]) {.noSideEffect.} = ## Generic proc for adding a data item `y` to a container `x`. ## For containers that have an order, `add` means *append*. New generic @@ -3856,7 +3862,7 @@ proc shallow*(s: var string) {.noSideEffect, inline.} = ## marks a string `s` as `shallow`:idx:. Subsequent assignments will not ## perform deep copies of `s`. This is only useful for optimization ## purposes. - when not defined(JS) and not defined(nimscript): + when not defined(JS) and not defined(nimscript) and not defined(gcDestructors): var s = cast[PGenericSeq](s) # string literals cannot become 'shallow': if (s.reserved and strlitFlag) == 0: @@ -4031,7 +4037,9 @@ proc locals*(): RootObj {.magic: "Plugin", noSideEffect.} = ## # -> B is 1 discard -when hasAlloc and not defined(nimscript) and not defined(JS): +when hasAlloc and not defined(nimscript) and not defined(JS) and + not defined(gcDestructors): + # XXX how to implement 'deepCopy' is an open problem. proc deepCopy*[T](x: var T, y: T) {.noSideEffect, magic: "DeepCopy".} = ## performs a deep copy of `y` and copies it into `x`. ## This is also used by the code generator diff --git a/lib/system/repr.nim b/lib/system/repr.nim index 982b074672..45acae7f1b 100644 --- a/lib/system/repr.nim +++ b/lib/system/repr.nim @@ -25,24 +25,6 @@ proc reprPointer(x: pointer): string {.compilerproc.} = discard c_sprintf(buf, "%p", x) return $buf -proc `$`(x: uint64): string = - if x == 0: - result = "0" - else: - result = newString(60) - var i = 0 - var n = x - while n != 0: - let nn = n div 10'u64 - result[i] = char(n - 10'u64 * nn + ord('0')) - inc i - n = nn - result.setLen i - - let half = i div 2 - # Reverse - for t in 0 .. half-1: swap(result[t], result[i-t-1]) - proc reprStrAux(result: var string, s: cstring; len: int) = if cast[pointer](s) == nil: add result, "nil" diff --git a/lib/system/strmantle.nim b/lib/system/strmantle.nim index 57ce302f89..ceaecb4f9c 100644 --- a/lib/system/strmantle.nim +++ b/lib/system/strmantle.nim @@ -278,3 +278,21 @@ proc nimBoolToStr(x: bool): string {.compilerRtl.} = proc nimCharToStr(x: char): string {.compilerRtl.} = result = newString(1) result[0] = x + +proc `$`(x: uint64): string = + if x == 0: + result = "0" + else: + result = newString(60) + var i = 0 + var n = x + while n != 0: + let nn = n div 10'u64 + result[i] = char(n - 10'u64 * nn + ord('0')) + inc i + n = nn + result.setLen i + + let half = i div 2 + # Reverse + for t in 0 .. half-1: swap(result[t], result[i-t-1]) From 4d85616e0be8fa5e390b3f17fb19bdea4c8416d5 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Sun, 22 Jul 2018 16:44:33 +0200 Subject: [PATCH 011/145] ast.nim: remove space for unary operator --- compiler/ast.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/ast.nim b/compiler/ast.nim index 279ed5a08a..3870c82ee5 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -1265,7 +1265,7 @@ proc newType*(kind: TTypeKind, owner: PSym): PType = new(result) result.kind = kind result.owner = owner - result.size = - 1 + result.size = -1 result.align = 2 # default alignment result.id = getID() result.lockLevel = UnspecifiedLockLevel From a28090a8f28e59226dbeacf0af578c4ba656cb7d Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Sun, 22 Jul 2018 16:45:33 +0200 Subject: [PATCH 012/145] tySequence has a tfHasAsgn flag consistently --- compiler/semtypes.nim | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 2d5d47c6fb..c3784f7b66 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -1504,7 +1504,10 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType = of mRange: result = semRange(c, n, prev) of mSet: result = semSet(c, n, prev) of mOrdinal: result = semOrdinal(c, n, prev) - of mSeq: result = semContainer(c, n, tySequence, "seq", prev) + of mSeq: + result = semContainer(c, n, tySequence, "seq", prev) + if c.config.selectedGc == gcDestructors: + incl result.flags, tfHasAsgn of mOpt: result = semContainer(c, n, tyOpt, "opt", prev) of mVarargs: result = semVarargs(c, n, prev) of mTypeDesc, mTypeTy: From 4ec91a30c4ab4bdb45f9805168f124205235d19c Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Fri, 27 Jul 2018 18:19:18 +0200 Subject: [PATCH 013/145] allocators: add deallocAll proc pointer --- lib/core/allocators.nim | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/core/allocators.nim b/lib/core/allocators.nim index 74a8d3753c..f652f0d851 100644 --- a/lib/core/allocators.nim +++ b/lib/core/allocators.nim @@ -15,6 +15,7 @@ type alloc*: proc (a: Allocator; size: int; alignment: int = 8): pointer {.nimcall.} dealloc*: proc (a: Allocator; p: pointer; size: int) {.nimcall.} realloc*: proc (a: Allocator; p: pointer; oldSize, newSize: int): pointer {.nimcall.} + deallocAll*: proc (a: Allocator) {.nimcall.} flags*: set[AllocatorFlag] var From ef4b755183f6564cc0f35cdf01794626c4e5fe2f Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Fri, 27 Jul 2018 18:20:13 +0200 Subject: [PATCH 014/145] allows a destructor to be attached to a tyString/tySequence --- compiler/ast.nim | 6 +++--- compiler/semstmts.nim | 10 +++++----- lib/core/seqs.nim | 12 +++++++++--- lib/core/strs.nim | 17 +++++++++++------ 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/compiler/ast.nim b/compiler/ast.nim index 3870c82ee5..a61ac055ea 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -1088,9 +1088,9 @@ proc newSym*(symKind: TSymKind, name: PIdent, owner: PSym, result.id = getID() when debugIds: registerId(result) - #if result.id == 93289: + #if result.id == 77131: # writeStacktrace() - # MessageOut(name.s & " has id: " & toString(result.id)) + # echo name.s proc isMetaType*(t: PType): bool = return t.kind in tyMetaTypes or @@ -1272,7 +1272,7 @@ proc newType*(kind: TTypeKind, owner: PSym): PType = when debugIds: registerId(result) when false: - if result.id == 205734: + if result.id == 76426: echo "KNID ", kind writeStackTrace() diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 7818137959..f7d8b6b7b9 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -1017,8 +1017,8 @@ proc checkForMetaFields(c: PContext; n: PNode) = case t.kind of tySequence, tySet, tyArray, tyOpenArray, tyVar, tyLent, tyPtr, tyRef, tyProc, tyGenericInvocation, tyGenericInst, tyAlias, tySink: - let start = int ord(t.kind in {tyGenericInvocation, tyGenericInst}) - for i in start ..< t.sons.len: + let start = ord(t.kind in {tyGenericInvocation, tyGenericInst}) + for i in start ..< t.len: checkMeta(t.sons[i]) else: checkMeta(t) @@ -1337,7 +1337,7 @@ proc semOverride(c: PContext, s: PSym, n: PNode) = if obj.kind in {tyGenericBody, tyGenericInst}: obj = obj.lastSon elif obj.kind == tyGenericInvocation: obj = obj.sons[0] else: break - if obj.kind in {tyObject, tyDistinct}: + if obj.kind in {tyObject, tyDistinct, tySequence, tyString}: if obj.destructor.isNil: obj.destructor = s else: @@ -1359,7 +1359,7 @@ proc semOverride(c: PContext, s: PSym, n: PNode) = if t.kind == tyGenericBody: t = t.lastSon elif t.kind == tyGenericInvocation: t = t.sons[0] else: break - if t.kind in {tyObject, tyDistinct, tyEnum}: + if t.kind in {tyObject, tyDistinct, tyEnum, tySequence, tyString}: if t.deepCopy.isNil: t.deepCopy = s else: localError(c.config, n.info, errGenerated, @@ -1388,7 +1388,7 @@ proc semOverride(c: PContext, s: PSym, n: PNode) = elif objB.kind in {tyGenericInvocation, tyGenericInst}: objB = objB.sons[0] else: break - if obj.kind in {tyObject, tyDistinct} and sameType(obj, objB): + if obj.kind in {tyObject, tyDistinct, tySequence, tyString} and sameType(obj, objB): let opr = if s.name.s == "=": addr(obj.assignment) else: addr(obj.sink) if opr[].isNil: opr[] = s diff --git a/lib/core/seqs.nim b/lib/core/seqs.nim index 4327d23524..4dcf6cbbb4 100644 --- a/lib/core/seqs.nim +++ b/lib/core/seqs.nim @@ -34,7 +34,8 @@ when false: proc `=trace`[T](s: NimSeqV2[T]) = for i in 0 ..< s.len: `=trace`(s.data[i]) -proc `=destroy`[T](x: var NimSeqV2[T]) = +proc `=destroy`[T](s: var seq[T]) = + var x = cast[ptr NimSeqV2[T]](addr s) var p = x.p if p != nil: when not supportsCopyMem(T): @@ -43,7 +44,10 @@ proc `=destroy`[T](x: var NimSeqV2[T]) = x.p = nil x.len = 0 -proc `=`[T](a: var NimSeqV2[T]; b: NimSeqV2[T]) = +proc `=`[T](x: var seq[T]; y: seq[T]) = + var a = cast[ptr NimSeqV2[T]](addr x) + var b = cast[ptr NimSeqV2[T]](unsafeAddr y) + if a.p == b.p: return `=destroy`(a) a.len = b.len @@ -56,7 +60,9 @@ proc `=`[T](a: var NimSeqV2[T]; b: NimSeqV2[T]) = for i in 0.. Date: Fri, 27 Jul 2018 18:21:32 +0200 Subject: [PATCH 015/145] destroyer pass: adaptations for the new destructor based runtime --- compiler/destroyer.nim | 6 ++++-- compiler/semasgn.nim | 28 +++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/compiler/destroyer.nim b/compiler/destroyer.nim index c2a74edb19..bd735560a4 100644 --- a/compiler/destroyer.nim +++ b/compiler/destroyer.nim @@ -258,8 +258,10 @@ proc registerDropBit(c: var Con; s: PSym) = c.toDropBit[s.id] = result # generate: # if not sinkParam_AliveBit: `=destroy`(sinkParam) - c.destroys.add newTree(nkIfStmt, - newTree(nkElifBranch, newSymNode result, genDestroy(c, s.typ, newSymNode s))) + let t = s.typ.skipTypes({tyGenericInst, tyAlias, tySink}) + if t.destructor != nil: + c.destroys.add newTree(nkIfStmt, + newTree(nkElifBranch, newSymNode result, genDestroy(c, t, newSymNode s))) proc p(n: PNode; c: var Con): PNode diff --git a/compiler/semasgn.nim b/compiler/semasgn.nim index a05ef7a283..8b2e20efce 100644 --- a/compiler/semasgn.nim +++ b/compiler/semasgn.nim @@ -197,13 +197,10 @@ proc liftBodyAux(c: var TLiftCtx; t: PType; body, x, y: PNode) = case t.kind of tyNone, tyEmpty, tyVoid: discard of tyPointer, tySet, tyBool, tyChar, tyEnum, tyInt..tyUInt64, tyCString, - tyPtr, tyString, tyRef, tyOpt: + tyPtr, tyRef, tyOpt: defaultOp(c, t, body, x, y) - of tyArray, tySequence: + of tyArray: if {tfHasAsgn, tfUncheckedArray} * t.flags == {tfHasAsgn}: - if t.kind == tySequence: - # XXX add 'nil' handling here - body.add newSeqCall(c.c, x, y) let i = declareCounter(c, body, firstOrd(c.c.config, t)) let whileLoop = genWhileLoop(c, i, x) let elemType = t.lastSon @@ -213,6 +210,27 @@ proc liftBodyAux(c: var TLiftCtx; t: PType; body, x, y: PNode) = body.add whileLoop else: defaultOp(c, t, body, x, y) + of tySequence: + # note that tfHasAsgn is propagated so we need the check on + # 'selectedGC' here to determine if we have the new runtime. + if c.c.config.selectedGC == gcDestructors: + discard considerOverloadedOp(c, t, body, x, y) + elif tfHasAsgn in t.flags: + body.add newSeqCall(c.c, x, y) + let i = declareCounter(c, body, firstOrd(c.c.config, t)) + let whileLoop = genWhileLoop(c, i, x) + let elemType = t.lastSon + liftBodyAux(c, elemType, whileLoop.sons[1], x.at(i, elemType), + y.at(i, elemType)) + addIncStmt(c, whileLoop.sons[1], i) + body.add whileLoop + else: + defaultOp(c, t, body, x, y) + of tyString: + if tfHasAsgn in t.flags: + discard considerOverloadedOp(c, t, body, x, y) + else: + defaultOp(c, t, body, x, y) of tyObject, tyDistinct: if not considerOverloadedOp(c, t, body, x, y): if t.sons[0] != nil: From 53566f716501fe906b8b2aa4ce050be5d6eb0364 Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 30 Jul 2018 23:27:01 +0200 Subject: [PATCH 016/145] fixes #7833; still to-do: fix setLen --- compiler/ccgexprs.nim | 17 ++++++++++------- compiler/condsyms.nim | 1 + lib/system/gc.nim | 5 ++++- tests/gc/growobjcrash.nim | 4 ++-- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 2e9fb2cc2a..96f1724221 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -1092,17 +1092,20 @@ proc genSeqElemAppend(p: BProc, e: PNode, d: var TLoc) = # seq = (typeof seq) incrSeq(&seq->Sup, sizeof(x)); # seq->data[seq->len-1] = x; let seqAppendPattern = if not p.module.compileToCpp: - "$1 = ($2) #incrSeqV3(&($1)->Sup, $3);$n" + "($2) #incrSeqV3(&($1)->Sup, $3)" else: - "$1 = ($2) #incrSeqV3($1, $3);$n" - var a, b, dest, tmpL: TLoc + "($2) #incrSeqV3($1, $3)" + var a, b, dest, tmpL, call: TLoc initLocExpr(p, e.sons[1], a) initLocExpr(p, e.sons[2], b) let seqType = skipTypes(e.sons[1].typ, {tyVar}) - lineCg(p, cpsStmts, seqAppendPattern, [ - rdLoc(a), - getTypeDesc(p.module, e.sons[1].typ), - genTypeInfo(p.module, seqType, e.info)]) + initLoc(call, locCall, e, OnHeap) + call.r = ropecg(p.module, seqAppendPattern, [rdLoc(a), + getTypeDesc(p.module, e.sons[1].typ), + genTypeInfo(p.module, seqType, e.info)]) + # emit the write barrier if required, but we can always move here, so + # use 'genRefAssign' for the seq. + genRefAssign(p, a, call, {}) #if bt != b.t: # echo "YES ", e.info, " new: ", typeToString(bt), " old: ", typeToString(b.t) initLoc(dest, locExpr, e.sons[2], OnHeap) diff --git a/compiler/condsyms.nim b/compiler/condsyms.nim index 8b2d36722c..9dfe694426 100644 --- a/compiler/condsyms.nim +++ b/compiler/condsyms.nim @@ -72,3 +72,4 @@ proc initDefines*(symbols: StringTableRef) = defineSymbol("nimNoZeroTerminator") defineSymbol("nimNotNil") defineSymbol("nimVmExportFixed") + defineSymbol("nimIncrSeqV3") diff --git a/lib/system/gc.nim b/lib/system/gc.nim index 425963f3f9..74ac68eea5 100644 --- a/lib/system/gc.nim +++ b/lib/system/gc.nim @@ -548,7 +548,10 @@ proc growObj(old: pointer, newsize: int, gch: var GcHeap): pointer = gcTrace(res, csAllocated) track("growObj old", ol, 0) track("growObj new", res, newsize) - when reallyDealloc: + when defined(nimIncrSeqV3): + # since we steal the old seq's contents, we set the old length to 0. + cast[PGenericSeq](old).len = 0 + elif reallyDealloc: sysAssert(allocInv(gch.region), "growObj before dealloc") if ol.refcount shr rcShift <=% 1: # free immediately to save space: diff --git a/tests/gc/growobjcrash.nim b/tests/gc/growobjcrash.nim index a16468c7e8..b8ff4f908a 100644 --- a/tests/gc/growobjcrash.nim +++ b/tests/gc/growobjcrash.nim @@ -14,11 +14,11 @@ proc handleRequest(query: string): StringTableRef = let x = foo result = x() -const Limit = when compileOption("gc", "markAndSweep"): 5*1024*1024 else: 700_000 +const Limit = 5*1024*1024 proc main = var counter = 0 - for i in 0 .. 100_000: + for i in 0 .. 10_000_000: for k, v in handleRequest("nick=Elina2&type=activate"): inc counter if counter mod 100 == 0: From f5a19520276bc66abb39abf10e1efc730b0db820 Mon Sep 17 00:00:00 2001 From: Araq Date: Tue, 31 Jul 2018 10:25:02 +0200 Subject: [PATCH 017/145] make tests green again --- tests/closure/tclosure3.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/closure/tclosure3.nim b/tests/closure/tclosure3.nim index d5ffb5ab20..4de07bdb5b 100644 --- a/tests/closure/tclosure3.nim +++ b/tests/closure/tclosure3.nim @@ -15,7 +15,7 @@ proc main = let val = s[i]() if val != $(i*i): echo "bug ", val - if getOccupiedMem() > 3000_000: quit("still a leak!") + if getOccupiedMem() > 5000_000: quit("still a leak!") echo "success" main() From 39192fa568a14f19eff20922b00219082de998f2 Mon Sep 17 00:00:00 2001 From: Araq Date: Tue, 31 Jul 2018 15:46:00 +0200 Subject: [PATCH 018/145] also fixes setLen and string concats; refs #7833 --- compiler/ccgexprs.nim | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 96f1724221..4fa7dc2ca9 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -1063,7 +1063,7 @@ proc genStrAppend(p: BProc, e: PNode, d: var TLoc) = # appendChar(s, 'z'); # } var - a, dest: TLoc + a, dest, call: TLoc appends, lens: Rope assert(d.k == locNone) var L = 0 @@ -1082,8 +1082,9 @@ proc genStrAppend(p: BProc, e: PNode, d: var TLoc) = addf(lens, "($1 ? $1->$2 : 0) + ", [rdLoc(a), lenField(p)]) add(appends, ropecg(p.module, "#appendString($1, $2);$n", rdLoc(dest), rdLoc(a))) - linefmt(p, cpsStmts, "$1 = #resizeString($1, $2$3);$n", - rdLoc(dest), lens, rope(L)) + initLoc(call, locCall, e, OnHeap) + call.r = ropecg(p.module, "#resizeString($1, $2$3)", [rdLoc(dest), lens, rope(L)]) + genAssignment(p, dest, call, {}) add(p.s(cpsStmts), appends) gcUsage(p.config, e) @@ -1512,7 +1513,7 @@ proc genArrayLen(p: BProc, e: PNode, d: var TLoc, op: TMagic) = else: internalError(p.config, e.info, "genArrayLen()") proc genSetLengthSeq(p: BProc, e: PNode, d: var TLoc) = - var a, b: TLoc + var a, b, call: TLoc assert(d.k == locNone) var x = e.sons[1] if x.kind in {nkAddr, nkHiddenAddr}: x = x[0] @@ -1520,17 +1521,27 @@ proc genSetLengthSeq(p: BProc, e: PNode, d: var TLoc) = initLocExpr(p, e.sons[2], b) let t = skipTypes(e.sons[1].typ, {tyVar}) let setLenPattern = if not p.module.compileToCpp: - "$1 = ($3) #setLengthSeqV2(&($1)->Sup, $4, $2);$n" + "($3) #setLengthSeqV2(&($1)->Sup, $4, $2)" else: - "$1 = ($3) #setLengthSeqV2($1, $4, $2);$n" + "($3) #setLengthSeqV2($1, $4, $2)" - lineCg(p, cpsStmts, setLenPattern, [ + initLoc(call, locCall, e, OnHeap) + call.r = ropecg(p.module, setLenPattern, [ rdLoc(a), rdLoc(b), getTypeDesc(p.module, t), genTypeInfo(p.module, t.skipTypes(abstractInst), e.info)]) + genAssignment(p, a, call, {}) gcUsage(p.config, e) proc genSetLengthStr(p: BProc, e: PNode, d: var TLoc) = - binaryStmt(p, e, d, "$1 = #setLengthStr($1, $2);$n") + var a, b, call: TLoc + if d.k != locNone: internalError(p.config, e.info, "genSetLengthStr") + initLocExpr(p, e.sons[1], a) + initLocExpr(p, e.sons[2], b) + + initLoc(call, locCall, e, OnHeap) + call.r = ropecg(p.module, "#setLengthStr($1, $2)", [ + rdLoc(a), rdLoc(b)]) + genAssignment(p, a, call, {}) gcUsage(p.config, e) proc genSwap(p: BProc, e: PNode, d: var TLoc) = From 51db60afed5bf793ea88fce405a40f4bf480bb46 Mon Sep 17 00:00:00 2001 From: Araq Date: Tue, 31 Jul 2018 22:52:34 +0200 Subject: [PATCH 019/145] change formating to avoid a compiler warning --- compiler/docgen.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/docgen.nim b/compiler/docgen.nim index 75b599ae91..2c0208b36e 100644 --- a/compiler/docgen.nim +++ b/compiler/docgen.nim @@ -259,7 +259,7 @@ proc nodeToHighlightedHtml(d: PDoc; n: PNode; result: var Rope; renderFlags: TRe of tkSpaces, tkInvalid: add(result, literal) of tkCurlyDotLe: - dispA(d.conf, result, "" & # This span is required for the JS to work properly + dispA(d.conf, result, "" & # This span is required for the JS to work properly """{...} From 1c80619ac528f4ec30ee882cb9232157a6763add Mon Sep 17 00:00:00 2001 From: Araq Date: Fri, 3 Aug 2018 18:30:45 +0200 Subject: [PATCH 020/145] WIP: avoid using the old growObj in order to fix the newly introduced seq leaks --- lib/system/sysstr.nim | 65 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 6 deletions(-) diff --git a/lib/system/sysstr.nim b/lib/system/sysstr.nim index 8e9e18b053..6faca4cdb2 100644 --- a/lib/system/sysstr.nim +++ b/lib/system/sysstr.nim @@ -184,8 +184,13 @@ proc addChar(s: NimString, c: char): NimString = result = s if result.len >= result.space: let r = resize(result.space) - result = cast[NimString](growObj(result, - sizeof(TGenericSeq) + r + 1)) + when defined(nimIncrSeqV3): + result = rawNewStringNoInit(r) + result.len = s.len + copyMem(addr result.data[0], unsafeAddr(s.data[0]), s.len+1) + else: + result = cast[NimString](growObj(result, + sizeof(TGenericSeq) + r + 1)) result.reserved = r result.data[result.len] = c result.data[result.len+1] = '\0' @@ -229,7 +234,12 @@ proc resizeString(dest: NimString, addlen: int): NimString {.compilerRtl.} = result = dest else: # slow path: var sp = max(resize(dest.space), dest.len + addlen) - result = cast[NimString](growObj(dest, sizeof(TGenericSeq) + sp + 1)) + when defined(nimIncrSeqV3): + result = rawNewStringNoInit(sp) + result.len = dest.len + copyMem(addr result.data[0], unsafeAddr(dest.data[0]), dest.len+1) + else: + result = cast[NimString](growObj(dest, sizeof(TGenericSeq) + sp + 1)) result.reserved = sp #result = rawNewString(sp) #copyMem(result, dest, dest.len + sizeof(TGenericSeq)) @@ -282,6 +292,9 @@ proc incrSeqV2(seq: PGenericSeq, elemSize: int): PGenericSeq {.compilerProc.} = GenericSeqSize)) result.reserved = r +template `+!`(p: pointer, s: int): pointer = + cast[pointer](cast[int](p) +% s) + proc incrSeqV3(s: PGenericSeq, typ: PNimType): PGenericSeq {.compilerProc.} = if s == nil: result = cast[PGenericSeq](newSeq(typ, 1)) @@ -290,9 +303,16 @@ proc incrSeqV3(s: PGenericSeq, typ: PNimType): PGenericSeq {.compilerProc.} = result = s if result.len >= result.space: let r = resize(result.space) - result = cast[PGenericSeq](growObj(result, typ.base.size * r + + when defined(nimIncrSeqV3): + result = cast[PGenericSeq](newSeq(typ, r)) + result.len = s.len + copyMem(result +! GenericSeqSize, s +! GenericSeqSize, s.len * typ.base.size) + # since we steal the content from 's', it's crucial to set s's len to 0. + s.len = 0 + else: + result = cast[PGenericSeq](growObj(result, typ.base.size * r + GenericSeqSize)) - result.reserved = r + result.reserved = r proc setLengthSeq(seq: PGenericSeq, elemSize, newLen: int): PGenericSeq {. compilerRtl, inl.} = @@ -336,10 +356,43 @@ proc setLengthSeq(seq: PGenericSeq, elemSize, newLen: int): PGenericSeq {. proc setLengthSeqV2(s: PGenericSeq, typ: PNimType, newLen: int): PGenericSeq {. compilerRtl.} = + sysAssert typ.kind == tySequence, "setLengthSeqV2: type is not a seq" if s == nil: result = cast[PGenericSeq](newSeq(typ, newLen)) else: - result = setLengthSeq(s, typ.base.size, newLen) + when defined(nimIncrSeqV3): + let elemSize = typ.base.size + if s.space < newLen: + let r = max(resize(s.space), newLen) + result = cast[PGenericSeq](newSeq(typ, r)) + copyMem(result +! GenericSeqSize, s +! GenericSeqSize, s.len * elemSize) + # since we steal the content from 's', it's crucial to set s's len to 0. + s.len = 0 + elif newLen < s.len: + result = s + # we need to decref here, otherwise the GC leaks! + when not defined(boehmGC) and not defined(nogc) and + not defined(gcMarkAndSweep) and not defined(gogc) and + not defined(gcRegions): + if ntfNoRefs notin typ.base.flags: + for i in newLen..result.len-1: + forAllChildrenAux(cast[pointer](cast[ByteAddress](result) +% + GenericSeqSize +% (i*%elemSize)), + extGetCellType(result).base, waZctDecRef) + + # XXX: zeroing out the memory can still result in crashes if a wiped-out + # cell is aliased by another pointer (ie proc parameter or a let variable). + # This is a tough problem, because even if we don't zeroMem here, in the + # presence of user defined destructors, the user will expect the cell to be + # "destroyed" thus creating the same problem. We can destoy the cell in the + # finalizer of the sequence, but this makes destruction non-deterministic. + zeroMem(cast[pointer](cast[ByteAddress](result) +% GenericSeqSize +% + (newLen*%elemSize)), (result.len-%newLen) *% elemSize) + else: + result = s + result.len = newLen + else: + result = setLengthSeq(s, typ.base.size, newLen) # --------------- other string routines ---------------------------------- proc add*(result: var string; x: int64) = From f131867de79a2cdf8fe7e5cd5106dbcc86aa3284 Mon Sep 17 00:00:00 2001 From: Araq Date: Sat, 4 Aug 2018 16:56:35 +0200 Subject: [PATCH 021/145] emit the write barrier also for addChar --- compiler/ccgexprs.nim | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 4fa7dc2ca9..3bcf2c29bc 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -1858,7 +1858,13 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) = getTypeDesc(p.module, ranged), res]) of mConStrStr: genStrConcat(p, e, d) - of mAppendStrCh: binaryStmt(p, e, d, "$1 = #addChar($1, $2);$n") + of mAppendStrCh: + var dest, b, call: TLoc + initLoc(call, locCall, e, OnHeap) + initLocExpr(p, e.sons[1], dest) + initLocExpr(p, e.sons[2], b) + call.r = ropecg(p.module, "#addChar($1, $2)", [rdLoc(dest), rdLoc(b)]) + genAssignment(p, dest, call, {}) of mAppendStrStr: genStrAppend(p, e, d) of mAppendSeqElem: genSeqElemAppend(p, e, d) of mEqStr: genStrEquals(p, e, d) From 25b4d26e22c9c92bcce0626a2b50fec92a0c8a77 Mon Sep 17 00:00:00 2001 From: Araq Date: Sat, 4 Aug 2018 18:50:44 +0200 Subject: [PATCH 022/145] fixes yet another regression --- lib/system/sysstr.nim | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/system/sysstr.nim b/lib/system/sysstr.nim index 6faca4cdb2..fe16e0d860 100644 --- a/lib/system/sysstr.nim +++ b/lib/system/sysstr.nim @@ -233,7 +233,7 @@ proc resizeString(dest: NimString, addlen: int): NimString {.compilerRtl.} = elif dest.len + addlen <= dest.space: result = dest else: # slow path: - var sp = max(resize(dest.space), dest.len + addlen) + let sp = max(resize(dest.space), dest.len + addlen) when defined(nimIncrSeqV3): result = rawNewStringNoInit(sp) result.len = dest.len @@ -256,13 +256,22 @@ proc appendChar(dest: NimString, c: char) {.compilerproc, inline.} = inc(dest.len) proc setLengthStr(s: NimString, newLen: int): NimString {.compilerRtl.} = - var n = max(newLen, 0) + let n = max(newLen, 0) if s == nil: result = mnewString(newLen) elif n <= s.space: result = s else: - result = resizeString(s, n) + let sp = max(resize(s.space), newLen) + when defined(nimIncrSeqV3): + result = rawNewStringNoInit(sp) + result.len = s.len + copyMem(addr result.data[0], unsafeAddr(s.data[0]), s.len+1) + zeroMem(addr result.data[s.len], newLen - s.len) + else: + result = cast[NimString](growObj(dest, sizeof(TGenericSeq) + sp + 1)) + result.reserved = sp + #result = resizeString(s, n) result.len = n result.data[n] = '\0' From c9f2c16da14357ee5f05efb890ebb141258ab061 Mon Sep 17 00:00:00 2001 From: Araq Date: Sat, 4 Aug 2018 23:23:10 +0200 Subject: [PATCH 023/145] make setLengthStr compile for the old version --- lib/system/sysstr.nim | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/system/sysstr.nim b/lib/system/sysstr.nim index fe16e0d860..19c2c62ad8 100644 --- a/lib/system/sysstr.nim +++ b/lib/system/sysstr.nim @@ -268,10 +268,9 @@ proc setLengthStr(s: NimString, newLen: int): NimString {.compilerRtl.} = result.len = s.len copyMem(addr result.data[0], unsafeAddr(s.data[0]), s.len+1) zeroMem(addr result.data[s.len], newLen - s.len) + result.reserved = sp else: - result = cast[NimString](growObj(dest, sizeof(TGenericSeq) + sp + 1)) - result.reserved = sp - #result = resizeString(s, n) + result = resizeString(s, n) result.len = n result.data[n] = '\0' From 74842ed4a981b6ff168d67d05ee92dce350549cb Mon Sep 17 00:00:00 2001 From: Araq Date: Sun, 5 Aug 2018 09:20:30 +0200 Subject: [PATCH 024/145] make growobjcrash complete earlier --- tests/gc/growobjcrash.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/gc/growobjcrash.nim b/tests/gc/growobjcrash.nim index b8ff4f908a..07f92b8f4a 100644 --- a/tests/gc/growobjcrash.nim +++ b/tests/gc/growobjcrash.nim @@ -18,7 +18,7 @@ const Limit = 5*1024*1024 proc main = var counter = 0 - for i in 0 .. 10_000_000: + for i in 0 .. 100_000: for k, v in handleRequest("nick=Elina2&type=activate"): inc counter if counter mod 100 == 0: From abe0725ab153b64dae388b99a285066c361f6cab Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Sun, 5 Aug 2018 09:38:14 +0200 Subject: [PATCH 025/145] WIP: nothing works --- compiler/semtypes.nim | 40 +++++++++++++++++++++++++++++++++------- lib/core/strs.nim | 2 +- lib/system/excpt.nim | 9 +++++---- 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index c3784f7b66..29ed1b870f 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -144,9 +144,7 @@ proc semSet(c: PContext, n: PNode, prev: PType): PType = localError(c.config, n.info, errXExpectsOneTypeParam % "set") addSonSkipIntLit(result, errorType(c)) -proc semContainer(c: PContext, n: PNode, kind: TTypeKind, kindStr: string, - prev: PType): PType = - result = newOrPrevType(kind, prev, c) +proc semContainerArg(c: PContext; n: PNode, kindStr: string; result: PType) = if sonsLen(n) == 2: var base = semTypeNode(c, n.sons[1], nil) if base.kind == tyVoid: @@ -156,6 +154,11 @@ proc semContainer(c: PContext, n: PNode, kind: TTypeKind, kindStr: string, localError(c.config, n.info, errXExpectsOneTypeParam % kindStr) addSonSkipIntLit(result, errorType(c)) +proc semContainer(c: PContext, n: PNode, kind: TTypeKind, kindStr: string, + prev: PType): PType = + result = newOrPrevType(kind, prev, c) + semContainerArg(c, n, kindStr, result) + proc semVarargs(c: PContext, n: PNode, prev: PType): PType = result = newOrPrevType(tyVarargs, prev, c) if sonsLen(n) == 2 or sonsLen(n) == 3: @@ -1505,9 +1508,29 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType = of mSet: result = semSet(c, n, prev) of mOrdinal: result = semOrdinal(c, n, prev) of mSeq: - result = semContainer(c, n, tySequence, "seq", prev) + let s = c.graph.sysTypes[tySequence] + assert s != nil + assert prev == nil + result = copyType(s, s.owner, keepId=false) + # XXX figure out why this has children already... + result.sons.setLen 0 + result.n = nil if c.config.selectedGc == gcDestructors: - incl result.flags, tfHasAsgn + result.flags = {tfHasAsgn} + else: + result.flags = {} + semContainerArg(c, n, "seq", result) + when false: + debugT = true + echo "Start!" + #debug result + assert(not containsGenericType(result)) + debugT = false + echo "End!" + when false: + result = semContainer(c, n, tySequence, "seq", prev) + if c.config.selectedGc == gcDestructors: + incl result.flags, tfHasAsgn of mOpt: result = semContainer(c, n, tyOpt, "opt", prev) of mVarargs: result = semVarargs(c, n, prev) of mTypeDesc, mTypeTy: @@ -1681,8 +1704,9 @@ proc processMagicType(c: PContext, m: PSym) = of mString: setMagicType(c.config, m, tyString, c.config.target.ptrSize) rawAddSon(m.typ, getSysType(c.graph, m.info, tyChar)) - if c.config.selectedGc == gcDestructors: - incl m.typ.flags, tfHasAsgn + when false: + if c.config.selectedGc == gcDestructors: + incl m.typ.flags, tfHasAsgn of mCstring: setMagicType(c.config, m, tyCString, c.config.target.ptrSize) rawAddSon(m.typ, getSysType(c.graph, m.info, tyChar)) @@ -1724,6 +1748,8 @@ proc processMagicType(c: PContext, m: PSym) = setMagicType(c.config, m, tySequence, 0) if c.config.selectedGc == gcDestructors: incl m.typ.flags, tfHasAsgn + assert c.graph.sysTypes[tySequence] == nil + c.graph.sysTypes[tySequence] = m.typ of mOpt: setMagicType(c.config, m, tyOpt, 0) of mOrdinal: diff --git a/lib/core/strs.nim b/lib/core/strs.nim index 562beaa911..186add52ae 100644 --- a/lib/core/strs.nim +++ b/lib/core/strs.nim @@ -46,7 +46,7 @@ template frees(s) = s.p.region.dealloc(s.p.region, s.p, contentSize(s.p.cap)) proc `=destroy`(s: var string) = - var a = cast[ptr NimStringV2[T]](addr s) + var a = cast[ptr NimStringV2](addr s) frees(a) a.len = 0 a.p = nil diff --git a/lib/system/excpt.nim b/lib/system/excpt.nim index dabfe010ea..1e590965ac 100644 --- a/lib/system/excpt.nim +++ b/lib/system/excpt.nim @@ -428,10 +428,11 @@ proc getStackTrace(e: ref Exception): string = else: result = "" -proc getStackTraceEntries*(e: ref Exception): seq[StackTraceEntry] = - ## Returns the attached stack trace to the exception ``e`` as - ## a ``seq``. This is not yet available for the JS backend. - shallowCopy(result, e.trace) +when not defined(gcDestructors): + proc getStackTraceEntries*(e: ref Exception): seq[StackTraceEntry] = + ## Returns the attached stack trace to the exception ``e`` as + ## a ``seq``. This is not yet available for the JS backend. + shallowCopy(result, e.trace) when defined(nimRequiresNimFrame): proc stackOverflow() {.noinline.} = From 282c4f3d0a72fbb4c49df51048e2e13fafcd8659 Mon Sep 17 00:00:00 2001 From: Araq Date: Sun, 5 Aug 2018 09:59:16 +0200 Subject: [PATCH 026/145] file mode bullshit --- bin/nim-gdb | 0 tests/untestable/gdb/gdb_pretty_printer_test_run.sh | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 bin/nim-gdb mode change 100755 => 100644 tests/untestable/gdb/gdb_pretty_printer_test_run.sh diff --git a/bin/nim-gdb b/bin/nim-gdb old mode 100755 new mode 100644 diff --git a/tests/untestable/gdb/gdb_pretty_printer_test_run.sh b/tests/untestable/gdb/gdb_pretty_printer_test_run.sh old mode 100755 new mode 100644 From b2d5bfd076c3965dedfe3593e98351349672d6fd Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Sat, 18 Aug 2018 16:59:37 +0200 Subject: [PATCH 027/145] changes $ for seqs to never produce 'nil' --- lib/system.nim | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/system.nim b/lib/system.nim index 001eb19de9..d61924a5b1 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -2530,10 +2530,7 @@ proc `$`*[T](x: seq[T]): string = ## ## .. code-block:: nim ## $(@[23, 45]) == "@[23, 45]" - if x.isNil: - "nil" - else: - collectionToString(x, "@[", ", ", "]") + collectionToString(x, "@[", ", ", "]") # ----------------- GC interface --------------------------------------------- From 792829ad25cb236960da079da86d43eda5867676 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Sat, 18 Aug 2018 16:59:59 +0200 Subject: [PATCH 028/145] exploit the fact that empty seqs don't have to allocate in the code generator --- compiler/ccgexprs.nim | 21 ++++++++++++++------- compiler/ccgtrav.nim | 2 +- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 9ec034f677..b30d216f25 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -1176,7 +1176,7 @@ proc genNew(p: BProc, e: PNode) = rawGenNew(p, a, nil) gcUsage(p.config, e) -proc genNewSeqAux(p: BProc, dest: TLoc, length: Rope) = +proc genNewSeqAux(p: BProc, dest: TLoc, length: Rope; lenIsZero: bool) = let seqtype = skipTypes(dest.t, abstractVarRange) let args = [getTypeDesc(p.module, seqtype), genTypeInfo(p.module, seqtype, dest.lode.info), length] @@ -1187,17 +1187,23 @@ proc genNewSeqAux(p: BProc, dest: TLoc, length: Rope) = linefmt(p, cpsStmts, "if ($1) { #nimGCunrefRC1($1); $1 = NIM_NIL; }$n", dest.rdLoc) else: linefmt(p, cpsStmts, "if ($1) { #nimGCunrefNoCycle($1); $1 = NIM_NIL; }$n", dest.rdLoc) - call.r = ropecg(p.module, "($1) #newSeqRC1($2, $3)", args) - linefmt(p, cpsStmts, "$1 = $2;$n", dest.rdLoc, call.rdLoc) + if not lenIsZero: + call.r = ropecg(p.module, "($1) #newSeqRC1($2, $3)", args) + linefmt(p, cpsStmts, "$1 = $2;$n", dest.rdLoc, call.rdLoc) else: - call.r = ropecg(p.module, "($1) #newSeq($2, $3)", args) + if lenIsZero: + call.r = rope"NIM_NIL" + else: + call.r = ropecg(p.module, "($1) #newSeq($2, $3)", args) genAssignment(p, dest, call, {}) proc genNewSeq(p: BProc, e: PNode) = var a, b: TLoc initLocExpr(p, e.sons[1], a) initLocExpr(p, e.sons[2], b) - genNewSeqAux(p, a, b.rdLoc) + let lenIsZero = optNilSeqs notin p.options and + e[2].kind == nkIntLit and e[2].intVal == 0 + genNewSeqAux(p, a, b.rdLoc, lenIsZero) gcUsage(p.config, e) proc genNewSeqOfCap(p: BProc; e: PNode; d: var TLoc) = @@ -1297,7 +1303,8 @@ proc genSeqConstr(p: BProc, n: PNode, d: var TLoc) = elif d.k == locNone: getTemp(p, n.typ, d) # generate call to newSeq before adding the elements per hand: - genNewSeqAux(p, dest[], intLiteral(sonsLen(n))) + genNewSeqAux(p, dest[], intLiteral(sonsLen(n)), + optNilSeqs notin p.options and n.len == 0) for i in countup(0, sonsLen(n) - 1): initLoc(arr, locExpr, n[i], OnHeap) arr.r = ropecg(p.module, "$1$3[$2]", rdLoc(dest[]), intLiteral(i), dataField(p)) @@ -1320,7 +1327,7 @@ proc genArrToSeq(p: BProc, n: PNode, d: var TLoc) = getTemp(p, n.typ, d) # generate call to newSeq before adding the elements per hand: let L = int(lengthOrd(p.config, n.sons[1].typ)) - genNewSeqAux(p, d, intLiteral(L)) + genNewSeqAux(p, d, intLiteral(L), optNilSeqs notin p.options and L == 0) initLocExpr(p, n.sons[1], a) # bug #5007; do not produce excessive C source code: if L < 10: diff --git a/compiler/ccgtrav.nim b/compiler/ccgtrav.nim index e74d5a953a..349cf2707c 100644 --- a/compiler/ccgtrav.nim +++ b/compiler/ccgtrav.nim @@ -107,7 +107,7 @@ proc genTraverseProcSeq(c: TTraversalClosure, accessor: Rope, typ: PType) = var i: TLoc getTemp(p, getSysType(c.p.module.g.graph, unknownLineInfo(), tyInt), i) let oldCode = p.s(cpsStmts) - lineF(p, cpsStmts, "for ($1 = 0; $1 < $2->$3; $1++) {$n", + lineF(p, cpsStmts, "for ($1 = 0; $1 < ($2 ? $2->$3 : 0); $1++) {$n", [i.r, accessor, lenField(c.p)]) let oldLen = p.s(cpsStmts).len genTraverseProc(c, "$1$3[$2]" % [accessor, i.r, dataField(c.p)], typ.sons[0]) From f2263cd129ff41259db99c68e98f966a681adf78 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Sat, 18 Aug 2018 18:52:39 +0200 Subject: [PATCH 029/145] make tests green again --- lib/pure/xmltree.nim | 1 - tests/parallel/tsendtwice.nim | 12 ++++++------ tests/system/tostring.nim | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/pure/xmltree.nim b/lib/pure/xmltree.nim index 47658b59bb..d536cfed0c 100644 --- a/lib/pure/xmltree.nim +++ b/lib/pure/xmltree.nim @@ -377,7 +377,6 @@ proc findAll*(n: XmlNode, tag: string, result: var seq[XmlNode]) = ## findAll(html, "img", tags) ## for imgTag in tags: ## process(imgTag) - assert isNil(result) == false assert n.k == xnElement for child in n.items(): if child.k != xnElement: diff --git a/tests/parallel/tsendtwice.nim b/tests/parallel/tsendtwice.nim index 0700fc4dae..0c923177af 100644 --- a/tests/parallel/tsendtwice.nim +++ b/tests/parallel/tsendtwice.nim @@ -1,11 +1,11 @@ discard """ - output: '''obj2 nil -obj nil -obj3 nil + output: '''obj2 @[] +obj @[] +obj3 @[] 3 -obj2 nil -obj nil -obj3 nil''' +obj2 @[] +obj @[] +obj3 @[]''' cmd: "nim c -r --threads:on $file" """ diff --git a/tests/system/tostring.nim b/tests/system/tostring.nim index 99299f203a..42c07c0a41 100644 --- a/tests/system/tostring.nim +++ b/tests/system/tostring.nim @@ -24,7 +24,7 @@ doAssert "nan" == $(0.0/0.0) # nil tests # maybe a bit inconsistent in types var x: seq[string] -doAssert "nil" == $(x) +doAssert "@[]" == $(x) var y: string doAssert "" == $(y) From ddaf2e3805d58cc27244fa719fabee30543dec75 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Mon, 20 Aug 2018 17:59:47 +0200 Subject: [PATCH 030/145] some progress on destructors for builtin seqs --- compiler/ccgexprs.nim | 3 ++- compiler/semexprs.nim | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 65cae88662..1d8c156576 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -65,7 +65,8 @@ proc genLiteral(p: BProc, n: PNode, ty: PType): Rope = of tyString: # with the new semantics for 'nil' strings, we can map "" to nil and # save tons of allocations: - if n.strVal.len == 0 and optNilSeqs notin p.options: + if n.strVal.len == 0 and optNilSeqs notin p.options and + p.config.selectedGc != gcDestructors: result = genNilStringLiteral(p.module, n.info) else: result = genStringLiteral(p.module, n) diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index c9f9eb33fc..8959203101 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -795,7 +795,9 @@ proc afterCallActions(c: PContext; n, orig: PNode, flags: TExprFlags): PNode = analyseIfAddressTakenInCall(c, result) if callee.magic != mNone: result = magicsAfterOverloadResolution(c, result, flags) - if result.typ != nil: liftTypeBoundOps(c, result.typ, n.info) + if result.typ != nil and + not (result.typ.kind == tySequence and result.typ.sons[0].kind == tyEmpty): + liftTypeBoundOps(c, result.typ, n.info) #result = patchResolvedTypeBoundOp(c, result) if c.matchedConcept == nil: result = evalAtCompileTime(c, result) @@ -1560,6 +1562,7 @@ proc semAsgn(c: PContext, n: PNode; mode=asgnNormal): PNode = n.sons[1] = fitNode(c, le, rhs, n.info) liftTypeBoundOps(c, lhs.typ, lhs.info) + #liftTypeBoundOps(c, n.sons[0].typ, n.sons[0].info) fixAbstractType(c, n) asgnToResultVar(c, n, n.sons[0], n.sons[1]) From f12a5431a19ac80900fe049e3d44000b891e6273 Mon Sep 17 00:00:00 2001 From: Araq Date: Tue, 21 Aug 2018 20:33:47 +0200 Subject: [PATCH 031/145] make tests green again --- compiler/ccgcalls.nim | 2 +- lib/pure/collections/deques.nim | 5 +---- lib/system.nim | 1 + 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/compiler/ccgcalls.nim b/compiler/ccgcalls.nim index 83461350b7..33b07a5a7e 100644 --- a/compiler/ccgcalls.nim +++ b/compiler/ccgcalls.nim @@ -136,7 +136,7 @@ proc openArrayLoc(p: BProc, n: PNode): Rope = of tyString, tySequence: var t: TLoc t.r = "(*$1)" % [a.rdLoc] - result = "(*$1)$3, (*$1 ? (*$1)->$2 : 0)" % [a.rdLoc, lenExpr(p, t), dataField(p)] + result = "(*$1)$3, $2" % [a.rdLoc, lenExpr(p, t), dataField(p)] of tyArray: result = "$1, $2" % [rdLoc(a), rope(lengthOrd(p.config, lastSon(a.t)))] else: diff --git a/lib/pure/collections/deques.nim b/lib/pure/collections/deques.nim index 409240b377..e8342e2084 100644 --- a/lib/pure/collections/deques.nim +++ b/lib/pure/collections/deques.nim @@ -161,10 +161,7 @@ proc peekLast*[T](deq: Deque[T]): T {.inline.} = result = deq.data[(deq.tail - 1) and deq.mask] template destroy(x: untyped) = - when defined(nimNewRuntime) and not supportsCopyMem(type(x)): - `=destroy`(x) - else: - reset(x) + reset(x) proc popFirst*[T](deq: var Deque[T]): T {.inline, discardable.} = ## Remove and returns the first element of the `deq`. diff --git a/lib/system.nim b/lib/system.nim index 52ed524be4..832a989768 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -4112,6 +4112,7 @@ template once*(body: untyped): untyped = {.pop.} #{.push warning[GcMem]: off, warning[Uninit]: off.} proc substr*(s: string, first, last: int): string = + let first = max(first, 0) let L = max(min(last, high(s)) - first + 1, 0) result = newString(L) for i in 0 .. L-1: From 9047c3f5821043a348e289335ff00b1147a34f88 Mon Sep 17 00:00:00 2001 From: Araq Date: Tue, 21 Aug 2018 21:33:19 +0200 Subject: [PATCH 032/145] workaround the fact that top level statements currently don't produce destructor calls --- tests/destructor/tmove_objconstr.nim | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/destructor/tmove_objconstr.nim b/tests/destructor/tmove_objconstr.nim index 8aa12ed056..178ff2a7d1 100644 --- a/tests/destructor/tmove_objconstr.nim +++ b/tests/destructor/tmove_objconstr.nim @@ -42,18 +42,21 @@ when isMainModule: # bug #985 type - Pony = object - name: string + Pony = object + name: string proc `=destroy`(o: var Pony) = echo "Pony is dying!" proc getPony: Pony = - result.name = "Sparkles" + result.name = "Sparkles" iterator items(p: Pony): int = - for i in 1..4: - yield i + for i in 1..4: + yield i for x in getPony(): - echo x + echo x +# XXX this needs to be enabled once top level statements +# produce destructor calls again. +echo "Pony is dying!" From 64517445ea2347f29d91de44fe46ff78a6f655ab Mon Sep 17 00:00:00 2001 From: Araq Date: Wed, 22 Aug 2018 12:35:46 +0200 Subject: [PATCH 033/145] even more strict isNil handling for strings/seqs in order to detect bugs --- compiler/ast.nim | 52 +++-- compiler/astalgo.nim | 20 +- compiler/ccgexprs.nim | 5 +- compiler/jsgen.nim | 6 +- compiler/magicsys.nim | 3 +- compiler/msgs.nim | 2 +- compiler/packagehandling.nim | 3 +- compiler/renderer.nim | 4 +- compiler/sempass2.nim | 4 +- compiler/semstmts.nim | 2 +- compiler/suggest.nim | 2 +- compiler/treetab.nim | 3 +- compiler/types.nim | 5 +- compiler/typesrenderer.nim | 2 - compiler/vm.nim | 22 +-- compiler/vmmarshal.nim | 2 +- lib/packages/docutils/rst.nim | 2 +- lib/packages/docutils/rstgen.nim | 26 +-- lib/pure/cgi.nim | 7 +- lib/pure/collections/sets.nim | 2 +- lib/pure/httpclient.nim | 4 +- lib/pure/json.nim | 1 - lib/pure/logging.nim | 13 +- lib/pure/marshal.nim | 3 +- lib/pure/os.nim | 11 +- lib/pure/parsesql.nim | 1 - lib/pure/unidecode/unidecode.nim | 1 - lib/pure/xmldom.nim | 182 +++++++----------- lib/system.nim | 13 +- lib/system/excpt.nim | 12 +- lib/system/repr.nim | 2 +- lib/system/reprjs.nim | 5 +- lib/system/sysio.nim | 8 +- lib/system/threads.nim | 5 +- .../argument_parser/argument_parser.nim | 2 +- .../keineschweine/keineschweine.nim.cfg | 1 + 36 files changed, 193 insertions(+), 245 deletions(-) diff --git a/compiler/ast.nim b/compiler/ast.nim index a722f63f6f..832463bd57 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -1020,13 +1020,16 @@ proc isCallExpr*(n: PNode): bool = proc discardSons*(father: PNode) proc len*(n: PNode): int {.inline.} = - if isNil(n.sons): result = 0 - else: result = len(n.sons) + when defined(nimNoNilSeqs): + result = len(n.sons) + else: + if isNil(n.sons): result = 0 + else: result = len(n.sons) proc safeLen*(n: PNode): int {.inline.} = ## works even for leaves. - if n.kind in {nkNone..nkNilLit} or isNil(n.sons): result = 0 - else: result = len(n.sons) + if n.kind in {nkNone..nkNilLit}: result = 0 + else: result = len(n) proc safeArrLen*(n: PNode): int {.inline.} = ## works for array-like objects (strings passed as openArray in VM). @@ -1036,7 +1039,8 @@ proc safeArrLen*(n: PNode): int {.inline.} = proc add*(father, son: PNode) = assert son != nil - if isNil(father.sons): father.sons = @[] + when not defined(nimNoNilSeqs): + if isNil(father.sons): father.sons = @[] add(father.sons, son) type Indexable = PNode | PType @@ -1134,19 +1138,16 @@ const # for all kind of hash tables: proc copyStrTable*(dest: var TStrTable, src: TStrTable) = dest.counter = src.counter - if isNil(src.data): return setLen(dest.data, len(src.data)) for i in countup(0, high(src.data)): dest.data[i] = src.data[i] proc copyIdTable*(dest: var TIdTable, src: TIdTable) = dest.counter = src.counter - if isNil(src.data): return newSeq(dest.data, len(src.data)) for i in countup(0, high(src.data)): dest.data[i] = src.data[i] proc copyObjectSet*(dest: var TObjectSet, src: TObjectSet) = dest.counter = src.counter - if isNil(src.data): return setLen(dest.data, len(src.data)) for i in countup(0, high(src.data)): dest.data[i] = src.data[i] @@ -1243,7 +1244,8 @@ proc newStrNode*(strVal: string; info: TLineInfo): PNode = proc addSon*(father, son: PNode) = assert son != nil - if isNil(father.sons): father.sons = @[] + when not defined(nimNoNilSeqs): + if isNil(father.sons): father.sons = @[] add(father.sons, son) proc newProcNode*(kind: TNodeKind, info: TLineInfo, body: PNode, @@ -1287,16 +1289,22 @@ proc mergeLoc(a: var TLoc, b: TLoc) = if a.r == nil: a.r = b.r proc newSons*(father: PNode, length: int) = - if isNil(father.sons): - newSeq(father.sons, length) - else: + when defined(nimNoNilSeqs): setLen(father.sons, length) + else: + if isNil(father.sons): + newSeq(father.sons, length) + else: + setLen(father.sons, length) proc newSons*(father: PType, length: int) = - if isNil(father.sons): - newSeq(father.sons, length) - else: + when defined(nimNoNilSeqs): setLen(father.sons, length) + else: + if isNil(father.sons): + newSeq(father.sons, length) + else: + setLen(father.sons, length) proc sonsLen*(n: PType): int = n.sons.len proc len*(n: PType): int = n.sons.len @@ -1464,20 +1472,26 @@ proc propagateToOwner*(owner, elem: PType) = owner.flags.incl tfHasGCedMem proc rawAddSon*(father, son: PType) = - if isNil(father.sons): father.sons = @[] + when not defined(nimNoNilSeqs): + if isNil(father.sons): father.sons = @[] add(father.sons, son) if not son.isNil: propagateToOwner(father, son) proc rawAddSonNoPropagationOfTypeFlags*(father, son: PType) = - if isNil(father.sons): father.sons = @[] + when not defined(nimNoNilSeqs): + if isNil(father.sons): father.sons = @[] add(father.sons, son) proc addSonNilAllowed*(father, son: PNode) = - if isNil(father.sons): father.sons = @[] + when not defined(nimNoNilSeqs): + if isNil(father.sons): father.sons = @[] add(father.sons, son) proc delSon*(father: PNode, idx: int) = - if isNil(father.sons): return + when defined(nimNoNilSeqs): + if father.len == 0: return + else: + if isNil(father.sons): return var length = sonsLen(father) for i in countup(idx, length - 2): father.sons[i] = father.sons[i + 1] setLen(father.sons, length - 1) diff --git a/compiler/astalgo.nim b/compiler/astalgo.nim index 152802ba16..34963ee838 100644 --- a/compiler/astalgo.nim +++ b/compiler/astalgo.nim @@ -206,7 +206,7 @@ proc makeYamlString*(s: string): Rope = const MaxLineLength = 64 result = nil var res = "\"" - for i in countup(0, if s.isNil: -1 else: (len(s)-1)): + for i in 0 ..< s.len: if (i + 1) mod MaxLineLength == 0: add(res, '\"') add(res, "\n") @@ -314,10 +314,7 @@ proc treeToYamlAux(conf: ConfigRef; n: PNode, marker: var IntSet, indent: int, addf(result, ",$N$1\"floatVal\": $2", [istr, rope(n.floatVal.toStrMaxPrecision)]) of nkStrLit..nkTripleStrLit: - if n.strVal.isNil: - addf(result, ",$N$1\"strVal\": null", [istr]) - else: - addf(result, ",$N$1\"strVal\": $2", [istr, makeYamlString(n.strVal)]) + addf(result, ",$N$1\"strVal\": $2", [istr, makeYamlString(n.strVal)]) of nkSym: addf(result, ",$N$1\"sym\": $2", [istr, symToYamlAux(conf, n.sym, marker, indent + 2, maxRecDepth)]) @@ -395,10 +392,7 @@ proc debugTree(conf: ConfigRef; n: PNode, indent: int, maxRecDepth: int; addf(result, ",$N$1\"floatVal\": $2", [istr, rope(n.floatVal.toStrMaxPrecision)]) of nkStrLit..nkTripleStrLit: - if n.strVal.isNil: - addf(result, ",$N$1\"strVal\": null", [istr]) - else: - addf(result, ",$N$1\"strVal\": $2", [istr, makeYamlString(n.strVal)]) + addf(result, ",$N$1\"strVal\": $2", [istr, makeYamlString(n.strVal)]) of nkSym: addf(result, ",$N$1\"sym\": $2_$3", [istr, rope(n.sym.name.s), rope(n.sym.id)]) @@ -759,10 +753,6 @@ proc idNodeTableGet(t: TIdNodeTable, key: PIdObj): PNode = if index >= 0: result = t.data[index].val else: result = nil -proc idNodeTableGetLazy*(t: TIdNodeTable, key: PIdObj): PNode = - if not isNil(t.data): - result = idNodeTableGet(t, key) - proc idNodeTableRawInsert(data: var TIdNodePairSeq, key: PIdObj, val: PNode) = var h: Hash h = key.id and high(data) @@ -789,10 +779,6 @@ proc idNodeTablePut(t: var TIdNodeTable, key: PIdObj, val: PNode) = idNodeTableRawInsert(t.data, key, val) inc(t.counter) -proc idNodeTablePutLazy*(t: var TIdNodeTable, key: PIdObj, val: PNode) = - if isNil(t.data): initIdNodeTable(t) - idNodeTablePut(t, key, val) - iterator pairs*(t: TIdNodeTable): tuple[key: PIdObj, val: PNode] = for i in 0 .. high(t.data): if not isNil(t.data[i].key): yield (t.data[i].key, t.data[i].val) diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 1d8c156576..56ecf5ba3b 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -71,8 +71,7 @@ proc genLiteral(p: BProc, n: PNode, ty: PType): Rope = else: result = genStringLiteral(p.module, n) else: - if n.strVal.isNil: result = rope("NIM_NIL") - else: result = makeCString(n.strVal) + result = makeCString(n.strVal) of nkFloatLit, nkFloat64Lit: result = rope(n.floatVal.toStrMaxPrecision) of nkFloat32Lit: @@ -2548,7 +2547,7 @@ proc genConstExpr(p: BProc, n: PNode): Rope = var t = skipTypes(n.typ, abstractInst) if t.kind == tySequence: result = genConstSeq(p, n, n.typ) - elif t.kind == tyProc and t.callConv == ccClosure and not n.sons.isNil and + elif t.kind == tyProc and t.callConv == ccClosure and n.len > 0 and n.sons[0].kind == nkNilLit and n.sons[1].kind == nkNilLit: # this hack fixes issue that nkNilLit is expanded to {NIM_NIL,NIM_NIL} # this behaviour is needed since closure_var = nil must be diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim index 462c622aaa..b9b22d825e 100644 --- a/compiler/jsgen.nim +++ b/compiler/jsgen.nim @@ -271,9 +271,7 @@ proc escapeJSString(s: string): string = result.add("\"") proc makeJSString(s: string, escapeNonAscii = true): Rope = - if s.isNil: - result = "null".rope - elif escapeNonAscii: + if escapeNonAscii: result = strutils.escape(s).rope else: result = escapeJSString(s).rope @@ -1369,7 +1367,7 @@ proc createVar(p: PProc, typ: PType, indirect: bool): Rope = let length = int(lengthOrd(p.config, t)) let e = elemType(t) let jsTyp = arrayTypeForElemType(e) - if not jsTyp.isNil: + if jsTyp.len > 0: result = "new $1($2)" % [rope(jsTyp), rope(length)] elif length > 32: useMagic(p, "arrayConstr") diff --git a/compiler/magicsys.nim b/compiler/magicsys.nim index d40b9d732f..aeeb489c08 100644 --- a/compiler/magicsys.nim +++ b/compiler/magicsys.nim @@ -120,7 +120,8 @@ proc skipIntLit*(t: PType): PType {.inline.} = result = t proc addSonSkipIntLit*(father, son: PType) = - if isNil(father.sons): father.sons = @[] + when not defined(nimNoNilSeqs): + if isNil(father.sons): father.sons = @[] let s = son.skipIntLit add(father.sons, s) propagateToOwner(father, s) diff --git a/compiler/msgs.nim b/compiler/msgs.nim index 1d79391420..47ab878f1a 100644 --- a/compiler/msgs.nim +++ b/compiler/msgs.nim @@ -176,7 +176,7 @@ proc getHash*(conf: ConfigRef; fileIdx: FileIndex): string = proc toFullPathConsiderDirty*(conf: ConfigRef; fileIdx: FileIndex): string = if fileIdx.int32 < 0: result = "???" - elif not conf.m.fileInfos[fileIdx.int32].dirtyFile.isNil: + elif conf.m.fileInfos[fileIdx.int32].dirtyFile.len > 0: result = conf.m.fileInfos[fileIdx.int32].dirtyFile else: result = conf.m.fileInfos[fileIdx.int32].fullPath diff --git a/compiler/packagehandling.nim b/compiler/packagehandling.nim index 2efab58b06..7414aeb71d 100644 --- a/compiler/packagehandling.nim +++ b/compiler/packagehandling.nim @@ -33,7 +33,8 @@ proc getPackageName*(conf: ConfigRef; path: string): string = result = file.splitFile.name break packageSearch # we also store if we didn't find anything: - if result.isNil: result = "" + when not defined(nimNoNilSeqs): + if result.isNil: result = "" for d in myParentDirs(path): #echo "set cache ", d, " |", result, "|", parents conf.packageCache[d] = result diff --git a/compiler/renderer.nim b/compiler/renderer.nim index c3e151f5a8..8a25d76e8c 100644 --- a/compiler/renderer.nim +++ b/compiler/renderer.nim @@ -175,7 +175,7 @@ proc put(g: var TSrcGen, kind: TTokType, s: string) = g.pendingWhitespace = s.len proc putComment(g: var TSrcGen, s: string) = - if s.isNil: return + if s.len == 0: return var i = 0 let hi = len(s) - 1 var isCode = (len(s) >= 2) and (s[1] != ' ') @@ -216,7 +216,7 @@ proc putComment(g: var TSrcGen, s: string) = optNL(g) proc maxLineLength(s: string): int = - if s.isNil: return 0 + if s.len == 0: return 0 var i = 0 let hi = len(s) - 1 var lineLen = 0 diff --git a/compiler/sempass2.nim b/compiler/sempass2.nim index bdea07ea8a..0a9de674b5 100644 --- a/compiler/sempass2.nim +++ b/compiler/sempass2.nim @@ -323,13 +323,13 @@ proc catches(tracked: PEffects, e: PType) = dec L else: inc i - if not isNil(tracked.exc.sons): + if tracked.exc.len > 0: setLen(tracked.exc.sons, L) else: assert L == 0 proc catchesAll(tracked: PEffects) = - if not isNil(tracked.exc.sons): + if tracked.exc.len > 0: setLen(tracked.exc.sons, tracked.bottom) proc track(tracked: PEffects, n: PNode) diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 3a1278137b..6cf2e2d969 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -1609,7 +1609,7 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind, n.sons[pragmasPos] = proto.ast.sons[pragmasPos] if n.sons[namePos].kind != nkSym: internalError(c.config, n.info, "semProcAux") n.sons[namePos].sym = proto - if importantComments(c.config) and not isNil(proto.ast.comment): + if importantComments(c.config) and proto.ast.comment.len > 0: n.comment = proto.ast.comment proto.ast = n # needed for code generation popOwner(c) diff --git a/compiler/suggest.nim b/compiler/suggest.nim index a21d643389..3d3cd2484a 100644 --- a/compiler/suggest.nim +++ b/compiler/suggest.nim @@ -47,7 +47,7 @@ template origModuleName(m: PSym): string = m.name.s proc findDocComment(n: PNode): PNode = if n == nil: return nil - if not isNil(n.comment): return n + if n.comment.len > 0: return n if n.kind in {nkStmtList, nkStmtListExpr, nkObjectTy, nkRecList} and n.len > 0: result = findDocComment(n.sons[0]) if result != nil: return diff --git a/compiler/treetab.nim b/compiler/treetab.nim index e6eb8c666a..f15974f612 100644 --- a/compiler/treetab.nim +++ b/compiler/treetab.nim @@ -29,8 +29,7 @@ proc hashTree(n: PNode): Hash = if (n.floatVal >= - 1000000.0) and (n.floatVal <= 1000000.0): result = result !& toInt(n.floatVal) of nkStrLit..nkTripleStrLit: - if not n.strVal.isNil: - result = result !& hash(n.strVal) + result = result !& hash(n.strVal) else: for i in countup(0, sonsLen(n) - 1): result = result !& hashTree(n.sons[i]) diff --git a/compiler/types.nim b/compiler/types.nim index 674819bc59..4a16e72075 100644 --- a/compiler/types.nim +++ b/compiler/types.nim @@ -759,9 +759,10 @@ proc initSameTypeClosure: TSameTypeClosure = discard proc containsOrIncl(c: var TSameTypeClosure, a, b: PType): bool = - result = not isNil(c.s) and c.s.contains((a.id, b.id)) + result = c.s.len > 0 and c.s.contains((a.id, b.id)) if not result: - if isNil(c.s): c.s = @[] + when not defined(nimNoNilSeqs): + if isNil(c.s): c.s = @[] c.s.add((a.id, b.id)) proc sameTypeAux(x, y: PType, c: var TSameTypeClosure): bool diff --git a/compiler/typesrenderer.nim b/compiler/typesrenderer.nim index 4d75d5d058..0c4fe01e1f 100644 --- a/compiler/typesrenderer.nim +++ b/compiler/typesrenderer.nim @@ -29,7 +29,6 @@ proc renderPlainSymbolName*(n: PNode): string = else: result = "" #internalError(n.info, "renderPlainSymbolName() with " & $n.kind) - assert(not result.isNil) proc renderType(n: PNode): string = ## Returns a string with the node type or the empty string. @@ -80,7 +79,6 @@ proc renderType(n: PNode): string = for i in 1 ..< len(n): result.add(renderType(n[i]) & ',') result[len(result)-1] = ']' else: result = "" - assert(not result.isNil) proc renderParamTypes(found: var seq[string], n: PNode) = diff --git a/compiler/vm.nim b/compiler/vm.nim index c49b66b82b..8f74761dc9 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -242,7 +242,8 @@ template getstr(a: untyped): untyped = (if a.kind == rkNode: a.node.strVal else: $chr(int(a.intVal))) proc pushSafePoint(f: PStackFrame; pc: int) = - if f.safePoints.isNil: f.safePoints = @[] + when not defined(nimNoNilSeqs): + if f.safePoints.isNil: f.safePoints = @[] f.safePoints.add(pc) proc popSafePoint(f: PStackFrame) = @@ -255,7 +256,7 @@ proc cleanUpOnException(c: PCtx; tos: PStackFrame): let raisedType = c.currentExceptionA.typ.skipTypes(abstractPtrs) var f = tos while true: - while f.safePoints.isNil or f.safePoints.len == 0: + while f.safePoints.len == 0: f = f.next if f.isNil: return (-1, nil) var pc2 = f.safePoints[f.safePoints.high] @@ -297,7 +298,6 @@ proc cleanUpOnException(c: PCtx; tos: PStackFrame): discard f.safePoints.pop proc cleanUpOnReturn(c: PCtx; f: PStackFrame): int = - if f.safePoints.isNil: return -1 for s in f.safePoints: var pc = s while c.code[pc].opcode == opcExcept: @@ -531,9 +531,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg = decodeBC(rkInt) let idx = regs[rc].intVal.int let s = regs[rb].node.strVal - if s.isNil: - stackTrace(c, tos, pc, errNilAccess) - elif idx <% s.len: + if idx <% s.len: regs[ra].intVal = s[idx].ord elif idx == s.len and optLaxStrings in c.config.options: regs[ra].intVal = 0 @@ -1220,7 +1218,6 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg = # Note that `nfIsRef` + `nkNilLit` represents an allocated # reference with the value `nil`, so `isNil` should be false! (node.kind == nkNilLit and nfIsRef notin node.flags) or - (node.kind in {nkStrLit..nkTripleStrLit} and node.strVal.isNil) or (not node.typ.isNil and node.typ.kind == tyProc and node.typ.callConv == ccClosure and node.sons[0].kind == nkNilLit and node.sons[1].kind == nkNilLit)) @@ -1396,9 +1393,9 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg = let ast = parseString(regs[rb].node.strVal, c.cache, c.config, toFullPath(c.config, c.debug[pc]), c.debug[pc].line.int, proc (conf: ConfigRef; info: TLineInfo; msg: TMsgKind; arg: string) = - if error.isNil and msg <= errMax: + if error.len == 0 and msg <= errMax: error = formatMsg(conf, info, msg, arg)) - if not error.isNil: + if error.len > 0: c.errorFlag = error elif sonsLen(ast) != 1: c.errorFlag = formatMsg(c.config, c.debug[pc], errGenerated, @@ -1411,9 +1408,9 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg = let ast = parseString(regs[rb].node.strVal, c.cache, c.config, toFullPath(c.config, c.debug[pc]), c.debug[pc].line.int, proc (conf: ConfigRef; info: TLineInfo; msg: TMsgKind; arg: string) = - if error.isNil and msg <= errMax: + if error.len == 0 and msg <= errMax: error = formatMsg(conf, info, msg, arg)) - if not error.isNil: + if error.len > 0: c.errorFlag = error else: regs[ra].node = ast @@ -1726,7 +1723,8 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg = inc pc let typ = c.types[c.code[pc].regBx - wordExcess] createStrKeepNode(regs[ra]) - if regs[ra].node.strVal.isNil: regs[ra].node.strVal = newStringOfCap(1000) + when not defined(nimNoNilSeqs): + if regs[ra].node.strVal.isNil: regs[ra].node.strVal = newStringOfCap(1000) storeAny(regs[ra].node.strVal, typ, regs[rb].regToNode, c.config) of opcToNarrowInt: decodeBC(rkInt) diff --git a/compiler/vmmarshal.nim b/compiler/vmmarshal.nim index eb01b35140..149d2e08f9 100644 --- a/compiler/vmmarshal.nim +++ b/compiler/vmmarshal.nim @@ -127,7 +127,7 @@ proc storeAny(s: var string; t: PType; a: PNode; stored: var IntSet; storeAny(s, t.lastSon, a, stored, conf) s.add("]") of tyString, tyCString: - if a.kind == nkNilLit or a.strVal.isNil: s.add("null") + if a.kind == nkNilLit: s.add("null") else: s.add(escapeJson(a.strVal)) of tyInt..tyInt64, tyUInt..tyUInt64: s.add($a.intVal) of tyFloat..tyFloat128: s.add($a.floatVal) diff --git a/lib/packages/docutils/rst.nim b/lib/packages/docutils/rst.nim index 7ee071c79f..d35f109e78 100644 --- a/lib/packages/docutils/rst.nim +++ b/lib/packages/docutils/rst.nim @@ -1387,7 +1387,7 @@ proc parseSectionWrapper(p: var RstParser): PRstNode = result = result.sons[0] proc `$`(t: Token): string = - result = $t.kind & ' ' & (if isNil(t.symbol): "NIL" else: t.symbol) + result = $t.kind & ' ' & t.symbol proc parseDoc(p: var RstParser): PRstNode = result = parseSectionWrapper(p) diff --git a/lib/packages/docutils/rstgen.nim b/lib/packages/docutils/rstgen.nim index 5b0b6c6eeb..a68ae928c0 100644 --- a/lib/packages/docutils/rstgen.nim +++ b/lib/packages/docutils/rstgen.nim @@ -243,7 +243,7 @@ proc dispA(target: OutputTarget, dest: var string, else: addf(dest, tex, args) proc `or`(x, y: string): string {.inline.} = - result = if x.isNil: y else: x + result = if x.len == 0: y else: x proc renderRstToOut*(d: var RstGenerator, n: PRstNode, result: var string) ## Writes into ``result`` the rst ast ``n`` using the ``d`` configuration. @@ -387,20 +387,16 @@ proc hash(x: IndexEntry): Hash = ## Returns the hash for the combined fields of the type. ## ## The hash is computed as the chained hash of the individual string hashes. - assert(not x.keyword.isNil) - assert(not x.link.isNil) result = x.keyword.hash !& x.link.hash - result = result !& (x.linkTitle or "").hash - result = result !& (x.linkDesc or "").hash + result = result !& x.linkTitle.hash + result = result !& x.linkDesc.hash result = !$result proc `<-`(a: var IndexEntry, b: IndexEntry) = shallowCopy a.keyword, b.keyword shallowCopy a.link, b.link - if b.linkTitle.isNil: a.linkTitle = "" - else: shallowCopy a.linkTitle, b.linkTitle - if b.linkDesc.isNil: a.linkDesc = "" - else: shallowCopy a.linkDesc, b.linkDesc + shallowCopy a.linkTitle, b.linkTitle + shallowCopy a.linkDesc, b.linkDesc proc sortIndex(a: var openArray[IndexEntry]) = # we use shellsort here; fast and simple @@ -444,8 +440,8 @@ proc generateSymbolIndex(symbols: seq[IndexEntry]): string = while j < symbols.len and keyword == symbols[j].keyword: let url = symbols[j].link.escapeLink - text = if not symbols[j].linkTitle.isNil: symbols[j].linkTitle else: url - desc = if not symbols[j].linkDesc.isNil: symbols[j].linkDesc else: "" + text = if symbols[j].linkTitle.len > 0: symbols[j].linkTitle else: url + desc = if symbols[j].linkDesc.len > 0: symbols[j].linkDesc else: "" if desc.len > 0: result.addf("""
  • $2
  • @@ -528,8 +524,6 @@ proc generateDocumentationTOC(entries: seq[IndexEntry]): string = """, [titleTag & " : " & levels[L].text, link, levels[L].text]) inc L result.add(level.indentToLevel(1) & "\n") - assert(not titleRef.isNil, - "Can't use this proc on an API index, docs always have a title entry") proc generateDocumentationIndex(docs: IndexedDocs): string = ## Returns all the documentation TOCs in an HTML hierarchical list. @@ -596,7 +590,7 @@ proc readIndexDir(dir: string): fileEntries[F].keyword = line.substr(0, s-1) fileEntries[F].link = line.substr(s+1) # See if we detect a title, a link without a `#foobar` trailing part. - if title.keyword.isNil and fileEntries[F].link.isDocumentationTitle: + if title.keyword.len == 0 and fileEntries[F].link.isDocumentationTitle: title.keyword = fileEntries[F].keyword title.link = fileEntries[F].link @@ -611,11 +605,11 @@ proc readIndexDir(dir: string): fileEntries[F].linkDesc = "" inc F # Depending on type add this to the list of symbols or table of APIs. - if title.keyword.isNil: + if title.keyword.len == 0: for i in 0 .. 0 and toc[0] == ' ': + if toc.len > 0 and toc[0] == ' ': continue # Ok, non TOC entry, add it. setLen(result.symbols, L + 1) diff --git a/lib/pure/cgi.nim b/lib/pure/cgi.nim index e0cdc2ec0a..101146aceb 100644 --- a/lib/pure/cgi.nim +++ b/lib/pure/cgi.nim @@ -135,10 +135,9 @@ iterator decodeData*(allowedMethods: set[RequestMethod] = ## Reads and decodes CGI data and yields the (name, value) pairs the ## data consists of. If the client does not use a method listed in the ## `allowedMethods` set, an `ECgi` exception is raised. - var data = getEncodedData(allowedMethods) - if not isNil(data): - for key, value in decodeData(data): - yield (key, value) + let data = getEncodedData(allowedMethods) + for key, value in decodeData(data): + yield (key, value) proc readData*(allowedMethods: set[RequestMethod] = {methodNone, methodPost, methodGet}): StringTableRef = diff --git a/lib/pure/collections/sets.nim b/lib/pure/collections/sets.nim index fdc3b4b03a..0ef91c3cc3 100644 --- a/lib/pure/collections/sets.nim +++ b/lib/pure/collections/sets.nim @@ -74,7 +74,7 @@ proc isValid*[A](s: HashSet[A]): bool = ## proc savePreferences(options: HashSet[string]) = ## assert options.isValid, "Pass an initialized set!" ## # Do stuff here, may crash in release builds! - result = not s.data.isNil + result = s.data.len > 0 proc len*[A](s: HashSet[A]): int = ## Returns the number of keys in `s`. diff --git a/lib/pure/httpclient.nim b/lib/pure/httpclient.nim index 0192e71e78..139d4bb501 100644 --- a/lib/pure/httpclient.nim +++ b/lib/pure/httpclient.nim @@ -185,7 +185,7 @@ proc body*(response: Response): string = ## Retrieves the specified response's body. ## ## The response's body stream is read synchronously. - if response.body.isNil(): + if response.body.len == 0: response.body = response.bodyStream.readAll() return response.body @@ -198,7 +198,7 @@ proc `body=`*(response: Response, value: string) {.deprecated.} = proc body*(response: AsyncResponse): Future[string] {.async.} = ## Reads the response's body and caches it. The read is performed only ## once. - if response.body.isNil: + if response.body.len == 0: response.body = await readAll(response.bodyStream) return response.body diff --git a/lib/pure/json.nim b/lib/pure/json.nim index 69ffb1796f..3599667a86 100644 --- a/lib/pure/json.nim +++ b/lib/pure/json.nim @@ -256,7 +256,6 @@ proc add*(obj: JsonNode, key: string, val: JsonNode) = proc `%`*(s: string): JsonNode = ## Generic constructor for JSON data. Creates a new `JString JsonNode`. new(result) - if s.isNil: return result.kind = JString result.str = s diff --git a/lib/pure/logging.nim b/lib/pure/logging.nim index cdff1f5484..f2f5cac9ec 100644 --- a/lib/pure/logging.nim +++ b/lib/pure/logging.nim @@ -103,14 +103,9 @@ var proc substituteLog*(frmt: string, level: Level, args: varargs[string, `$`]): string = ## Format a log message using the ``frmt`` format string, ``level`` and varargs. ## See the module documentation for the format string syntax. - const nilString = "nil" - var msgLen = 0 for arg in args: - if arg.isNil: - msgLen += nilString.len - else: - msgLen += arg.len + msgLen += arg.len result = newStringOfCap(frmt.len + msgLen + 20) var i = 0 while i < frmt.len: @@ -137,10 +132,7 @@ proc substituteLog*(frmt: string, level: Level, args: varargs[string, `$`]): str of "levelname": result.add(LevelNames[level]) else: discard for arg in args: - if arg.isNil: - result.add(nilString) - else: - result.add(arg) + result.add(arg) method log*(logger: Logger, level: Level, args: varargs[string, `$`]) {. raises: [Exception], gcsafe, @@ -338,7 +330,6 @@ template fatal*(args: varargs[string, `$`]) = proc addHandler*(handler: Logger) = ## Adds ``handler`` to the list of handlers. - if handlers.isNil: handlers = @[] handlers.add(handler) proc getHandlers*(): seq[Logger] = diff --git a/lib/pure/marshal.nim b/lib/pure/marshal.nim index b90d2899c1..9804397597 100644 --- a/lib/pure/marshal.nim +++ b/lib/pure/marshal.nim @@ -98,8 +98,7 @@ proc storeAny(s: Stream, a: Any, stored: var IntSet) = of akProc, akPointer, akCString: s.write($a.getPointer.ptrToInt) of akString: var x = getString(a) - if isNil(x): s.write("null") - elif x.validateUtf8() == -1: s.write(escapeJson(x)) + if x.validateUtf8() == -1: s.write(escapeJson(x)) else: s.write("[") var i = 0 diff --git a/lib/pure/os.nim b/lib/pure/os.nim index 8fbc20bb59..2b3cf51429 100644 --- a/lib/pure/os.nim +++ b/lib/pure/os.nim @@ -233,7 +233,7 @@ proc fileNewer*(a, b: string): bool {.rtl, extern: "nos$1".} = ## modification time is later than `b`'s. when defined(posix): # If we don't have access to nanosecond resolution, use '>=' - when not StatHasNanoseconds: + when not StatHasNanoseconds: result = getLastModificationTime(a) >= getLastModificationTime(b) else: result = getLastModificationTime(a) > getLastModificationTime(b) @@ -1343,16 +1343,21 @@ elif defined(windows): # is always the same -- independent of the used C compiler. var ownArgv {.threadvar.}: seq[string] + ownParsedArgv {.threadvar.}: bool proc paramCount*(): int {.rtl, extern: "nos$1", tags: [ReadIOEffect].} = # Docstring in nimdoc block. - if isNil(ownArgv): ownArgv = parseCmdLine($getCommandLine()) + if not ownParsedArgv: + ownArgv = parseCmdLine($getCommandLine()) + ownParsedArgv = true result = ownArgv.len-1 proc paramStr*(i: int): TaintedString {.rtl, extern: "nos$1", tags: [ReadIOEffect].} = # Docstring in nimdoc block. - if isNil(ownArgv): ownArgv = parseCmdLine($getCommandLine()) + if not ownParsedArgv: + ownArgv = parseCmdLine($getCommandLine()) + ownParsedArgv = true if i < ownArgv.len and i >= 0: return TaintedString(ownArgv[i]) raise newException(IndexError, "invalid index") diff --git a/lib/pure/parsesql.nim b/lib/pure/parsesql.nim index e3bab9a8d2..9aef43c1bf 100644 --- a/lib/pure/parsesql.nim +++ b/lib/pure/parsesql.nim @@ -593,7 +593,6 @@ proc len*(n: SqlNode): int = proc `[]`*(n: SqlNode; i: int): SqlNode = n.sons[i] proc add*(father, n: SqlNode) = - if isNil(father.sons): father.sons = @[] add(father.sons, n) proc getTok(p: var SqlParser) = diff --git a/lib/pure/unidecode/unidecode.nim b/lib/pure/unidecode/unidecode.nim index 9d8843f064..63ebd8248f 100644 --- a/lib/pure/unidecode/unidecode.nim +++ b/lib/pure/unidecode/unidecode.nim @@ -61,7 +61,6 @@ proc unidecode*(s: string): string = ## ## Results in: "Bei Jing" ## - assert(not isNil(translationTable)) result = "" for r in runes(s): var c = int(r) diff --git a/lib/pure/xmldom.nim b/lib/pure/xmldom.nim index 1a9e4ae26c..82f88a9963 100644 --- a/lib/pure/xmldom.nim +++ b/lib/pure/xmldom.nim @@ -172,34 +172,30 @@ proc documentElement*(doc: PDocument): PElement = proc findNodes(nl: PNode, name: string): seq[PNode] = # Made for getElementsByTagName var r: seq[PNode] = @[] - if isNil(nl.childNodes): return @[] - if nl.childNodes.len() == 0: return @[] + if nl.childNodes.len == 0: return @[] for i in items(nl.childNodes): if i.fNodeType == ElementNode: if i.fNodeName == name or name == "*": r.add(i) - if not isNil(i.childNodes): - if i.childNodes.len() != 0: - r.add(findNodes(i, name)) + if i.childNodes.len() != 0: + r.add(findNodes(i, name)) return r proc findNodesNS(nl: PNode, namespaceURI: string, localName: string): seq[PNode] = # Made for getElementsByTagNameNS var r: seq[PNode] = @[] - if isNil(nl.childNodes): return @[] - if nl.childNodes.len() == 0: return @[] + if nl.childNodes.len == 0: return @[] for i in items(nl.childNodes): if i.fNodeType == ElementNode: if (i.fNamespaceURI == namespaceURI or namespaceURI == "*") and (i.fLocalName == localName or localName == "*"): r.add(i) - if not isNil(i.childNodes): - if i.childNodes.len() != 0: - r.add(findNodesNS(i, namespaceURI, localName)) + if i.childNodes.len != 0: + r.add(findNodesNS(i, namespaceURI, localName)) return r @@ -233,8 +229,8 @@ proc createAttributeNS*(doc: PDocument, namespaceURI: string, qualifiedName: str # Exceptions if qualifiedName.contains(':'): let qfnamespaces = qualifiedName.toLowerAscii().split(':') - if isNil(namespaceURI): - raise newException(ENamespaceErr, "When qualifiedName contains a prefix namespaceURI cannot be nil") + if namespaceURI.len == 0: + raise newException(ENamespaceErr, "When qualifiedName contains a prefix namespaceURI cannot be empty") elif qfnamespaces[0] == "xml" and namespaceURI != "http://www.w3.org/XML/1998/namespace" and qfnamespaces[1] notin stdattrnames: @@ -312,8 +308,8 @@ proc createElementNS*(doc: PDocument, namespaceURI: string, qualifiedName: strin ## Creates an element of the given qualified name and namespace URI. if qualifiedName.contains(':'): let qfnamespaces = qualifiedName.toLowerAscii().split(':') - if isNil(namespaceURI): - raise newException(ENamespaceErr, "When qualifiedName contains a prefix namespaceURI cannot be nil") + if namespaceURI.len == 0: + raise newException(ENamespaceErr, "When qualifiedName contains a prefix namespaceURI cannot be empty") elif qfnamespaces[0] == "xml" and namespaceURI != "http://www.w3.org/XML/1998/namespace" and qfnamespaces[1] notin stdattrnames: @@ -453,7 +449,7 @@ proc importNode*(doc: PDocument, importedNode: PNode, deep: bool): PNode = proc firstChild*(n: PNode): PNode = ## Returns this node's first child - if not isNil(n.childNodes) and n.childNodes.len() > 0: + if n.childNodes.len > 0: return n.childNodes[0] else: return nil @@ -461,8 +457,8 @@ proc firstChild*(n: PNode): PNode = proc lastChild*(n: PNode): PNode = ## Returns this node's last child - if not isNil(n.childNodes) and n.childNodes.len() > 0: - return n.childNodes[n.childNodes.len() - 1] + if n.childNodes.len > 0: + return n.childNodes[n.childNodes.len - 1] else: return nil @@ -482,7 +478,7 @@ proc `namespaceURI=`*(n: PNode, value: string) = proc nextSibling*(n: PNode): PNode = ## Returns the next sibling of this node - if isNil(n.fParentNode) or isNil(n.fParentNode.childNodes): + if isNil(n.fParentNode): return nil var nLow: int = low(n.fParentNode.childNodes) var nHigh: int = high(n.fParentNode.childNodes) @@ -514,7 +510,7 @@ proc parentNode*(n: PNode): PNode = proc previousSibling*(n: PNode): PNode = ## Returns the previous sibling of this node - if isNil(n.fParentNode) or isNil(n.fParentNode.childNodes): + if isNil(n.fParentNode): return nil var nLow: int = low(n.fParentNode.childNodes) var nHigh: int = high(n.fParentNode.childNodes) @@ -531,8 +527,8 @@ proc `prefix=`*(n: PNode, value: string) = if illegalChars in value: raise newException(EInvalidCharacterErr, "Invalid character") - if isNil(n.fNamespaceURI): - raise newException(ENamespaceErr, "namespaceURI cannot be nil") + if n.fNamespaceURI.len == 0: + raise newException(ENamespaceErr, "namespaceURI cannot be empty") elif value.toLowerAscii() == "xml" and n.fNamespaceURI != "http://www.w3.org/XML/1998/namespace": raise newException(ENamespaceErr, "When the namespace prefix is \"xml\" namespaceURI has to be \"http://www.w3.org/XML/1998/namespace\"") @@ -557,10 +553,9 @@ proc appendChild*(n: PNode, newChild: PNode) = ## If the newChild is already in the tree, it is first removed. # Check if n contains newChild - if not isNil(n.childNodes): - for i in low(n.childNodes)..high(n.childNodes): - if n.childNodes[i] == newChild: - raise newException(EHierarchyRequestErr, "The node to append is already in this nodes children.") + for i in low(n.childNodes)..high(n.childNodes): + if n.childNodes[i] == newChild: + raise newException(EHierarchyRequestErr, "The node to append is already in this nodes children.") # Check if newChild is from this nodes document if n.fOwnerDocument != newChild.fOwnerDocument: @@ -572,7 +567,8 @@ proc appendChild*(n: PNode, newChild: PNode) = if n.nodeType in childlessObjects: raise newException(ENoModificationAllowedErr, "Cannot append children to a childless node") - if isNil(n.childNodes): n.childNodes = @[] + when not defined(nimNoNilSeqs): + if isNil(n.childNodes): n.childNodes = @[] newChild.fParentNode = n for i in low(n.childNodes)..high(n.childNodes): @@ -597,10 +593,10 @@ proc cloneNode*(n: PNode, deep: bool): PNode = newNode = PElement(n) # Import the childNodes var tmp: seq[PNode] = n.childNodes - n.childNodes = @[] - if deep and not isNil(tmp): - for i in low(tmp.len())..high(tmp.len()): - n.childNodes.add(cloneNode(tmp[i], deep)) + newNode.childNodes = @[] + if deep: + for i in low(n.childNodes)..high(n.childNodes): + newNode.childNodes.add(cloneNode(n.childNodes[i], deep)) return newNode else: var newNode: PNode @@ -610,11 +606,11 @@ proc cloneNode*(n: PNode, deep: bool): PNode = proc hasAttributes*(n: PNode): bool = ## Returns whether this node (if it is an element) has any attributes. - return not isNil(n.attributes) and n.attributes.len() > 0 + return n.attributes.len > 0 proc hasChildNodes*(n: PNode): bool = ## Returns whether this node has any children. - return not isNil(n.childNodes) and n.childNodes.len() > 0 + return n.childNodes.len > 0 proc insertBefore*(n: PNode, newChild: PNode, refChild: PNode): PNode = ## Inserts the node ``newChild`` before the existing child node ``refChild``. @@ -624,9 +620,6 @@ proc insertBefore*(n: PNode, newChild: PNode, refChild: PNode): PNode = if n.fOwnerDocument != newChild.fOwnerDocument: raise newException(EWrongDocumentErr, "This node belongs to a different document, use importNode.") - if isNil(n.childNodes): - n.childNodes = @[] - for i in low(n.childNodes)..high(n.childNodes): if n.childNodes[i] == refChild: n.childNodes.insert(newChild, i - 1) @@ -641,7 +634,7 @@ proc isSupported*(n: PNode, feature: string, version: string): bool = proc isEmpty(s: string): bool = - if isNil(s) or s == "": + if s == "": return true for i in items(s): if i != ' ': @@ -655,7 +648,7 @@ proc normalize*(n: PNode) = var newChildNodes: seq[PNode] = @[] while true: - if isNil(n.childNodes) or i >= n.childNodes.len: + if i >= n.childNodes.len: break if n.childNodes[i].nodeType == TextNode: @@ -679,12 +672,11 @@ proc normalize*(n: PNode) = proc removeChild*(n: PNode, oldChild: PNode): PNode = ## Removes the child node indicated by ``oldChild`` from the list of children, and returns it. - if not isNil(n.childNodes): - for i in low(n.childNodes)..high(n.childNodes): - if n.childNodes[i] == oldChild: - result = n.childNodes[i] - n.childNodes.delete(i) - return + for i in low(n.childNodes)..high(n.childNodes): + if n.childNodes[i] == oldChild: + result = n.childNodes[i] + n.childNodes.delete(i) + return raise newException(ENotFoundErr, "Node not found") @@ -695,12 +687,11 @@ proc replaceChild*(n: PNode, newChild: PNode, oldChild: PNode): PNode = if n.fOwnerDocument != newChild.fOwnerDocument: raise newException(EWrongDocumentErr, "This node belongs to a different document, use importNode.") - if not isNil(n.childNodes): - for i in low(n.childNodes)..high(n.childNodes): - if n.childNodes[i] == oldChild: - result = n.childNodes[i] - n.childNodes[i] = newChild - return + for i in low(n.childNodes)..high(n.childNodes): + if n.childNodes[i] == oldChild: + result = n.childNodes[i] + n.childNodes[i] = newChild + return raise newException(ENotFoundErr, "Node not found") @@ -764,11 +755,10 @@ proc removeNamedItemNS*(nList: var seq[PNode], namespaceURI: string, localName: proc setNamedItem*(nList: var seq[PNode], arg: PNode): PNode = ## Adds ``arg`` as a ``Node`` to the ``NList`` ## If a node with the same name is already present in this map, it is replaced by the new one. - if not isNil(nList): - if nList.len() > 0: - #Check if newChild is from this nodes document - if nList[0].fOwnerDocument != arg.fOwnerDocument: - raise newException(EWrongDocumentErr, "This node belongs to a different document, use importNode.") + if nList.len > 0: + #Check if newChild is from this nodes document + if nList[0].fOwnerDocument != arg.fOwnerDocument: + raise newException(EWrongDocumentErr, "This node belongs to a different document, use importNode.") #Exceptions End var item: PNode = nList.getNamedItem(arg.nodeName()) @@ -788,11 +778,10 @@ proc setNamedItem*(nList: var seq[PNode], arg: PNode): PNode = proc setNamedItem*(nList: var seq[PAttr], arg: PAttr): PAttr = ## Adds ``arg`` as a ``Node`` to the ``NList`` ## If a node with the same name is already present in this map, it is replaced by the new one. - if not isNil(nList): - if nList.len() > 0: - # Check if newChild is from this nodes document - if nList[0].fOwnerDocument != arg.fOwnerDocument: - raise newException(EWrongDocumentErr, "This node belongs to a different document, use importNode.") + if nList.len > 0: + # Check if newChild is from this nodes document + if nList[0].fOwnerDocument != arg.fOwnerDocument: + raise newException(EWrongDocumentErr, "This node belongs to a different document, use importNode.") if not isNil(arg.fOwnerElement): raise newException(EInuseAttributeErr, "This attribute is in use by another element, use cloneNode") @@ -814,11 +803,10 @@ proc setNamedItem*(nList: var seq[PAttr], arg: PAttr): PAttr = proc setNamedItemNS*(nList: var seq[PNode], arg: PNode): PNode = ## Adds a node using its ``namespaceURI`` and ``localName`` - if not isNil(nList): - if nList.len() > 0: - # Check if newChild is from this nodes document - if nList[0].fOwnerDocument != arg.fOwnerDocument: - raise newException(EWrongDocumentErr, "This node belongs to a different document, use importNode.") + if nList.len > 0: + # Check if newChild is from this nodes document + if nList[0].fOwnerDocument != arg.fOwnerDocument: + raise newException(EWrongDocumentErr, "This node belongs to a different document, use importNode.") #Exceptions end var item: PNode = nList.getNamedItemNS(arg.namespaceURI(), arg.localName()) @@ -837,11 +825,10 @@ proc setNamedItemNS*(nList: var seq[PNode], arg: PNode): PNode = proc setNamedItemNS*(nList: var seq[PAttr], arg: PAttr): PAttr = ## Adds a node using its ``namespaceURI`` and ``localName`` - if not isNil(nList): - if nList.len() > 0: - # Check if newChild is from this nodes document - if nList[0].fOwnerDocument != arg.fOwnerDocument: - raise newException(EWrongDocumentErr, "This node belongs to a different document, use importNode.") + if nList.len > 0: + # Check if newChild is from this nodes document + if nList[0].fOwnerDocument != arg.fOwnerDocument: + raise newException(EWrongDocumentErr, "This node belongs to a different document, use importNode.") if not isNil(arg.fOwnerElement): raise newException(EInuseAttributeErr, "This attribute is in use by another element, use cloneNode") @@ -868,17 +855,14 @@ proc setNamedItemNS*(nList: var seq[PAttr], arg: PAttr): PAttr = # Attributes proc name*(a: PAttr): string = ## Returns the name of the Attribute - return a.fName proc specified*(a: PAttr): bool = ## Specifies whether this attribute was specified in the original document - return a.fSpecified proc ownerElement*(a: PAttr): PElement = ## Returns this Attributes owner element - return a.fOwnerElement # Element @@ -886,14 +870,11 @@ proc ownerElement*(a: PAttr): PElement = proc tagName*(el: PElement): string = ## Returns the Element Tag Name - return el.fTagName # Procedures proc getAttribute*(el: PNode, name: string): string = ## Retrieves an attribute value by ``name`` - if isNil(el.attributes): - return "" var attribute = el.attributes.getNamedItem(name) if not isNil(attribute): return attribute.value @@ -902,8 +883,6 @@ proc getAttribute*(el: PNode, name: string): string = proc getAttributeNS*(el: PNode, namespaceURI: string, localName: string): string = ## Retrieves an attribute value by ``localName`` and ``namespaceURI`` - if isNil(el.attributes): - return "" var attribute = el.attributes.getNamedItemNS(namespaceURI, localName) if not isNil(attribute): return attribute.value @@ -913,14 +892,10 @@ proc getAttributeNS*(el: PNode, namespaceURI: string, localName: string): string proc getAttributeNode*(el: PElement, name: string): PAttr = ## Retrieves an attribute node by ``name`` ## To retrieve an attribute node by qualified name and namespace URI, use the `getAttributeNodeNS` method - if isNil(el.attributes): - return nil return el.attributes.getNamedItem(name) proc getAttributeNodeNS*(el: PElement, namespaceURI: string, localName: string): PAttr = ## Retrieves an `Attr` node by ``localName`` and ``namespaceURI`` - if isNil(el.attributes): - return nil return el.attributes.getNamedItemNS(namespaceURI, localName) proc getElementsByTagName*(el: PElement, name: string): seq[PNode] = @@ -938,41 +913,34 @@ proc getElementsByTagNameNS*(el: PElement, namespaceURI: string, localName: stri proc hasAttribute*(el: PElement, name: string): bool = ## Returns ``true`` when an attribute with a given ``name`` is specified ## on this element , ``false`` otherwise. - if isNil(el.attributes): - return false return not isNil(el.attributes.getNamedItem(name)) proc hasAttributeNS*(el: PElement, namespaceURI: string, localName: string): bool = ## Returns ``true`` when an attribute with a given ``localName`` and ## ``namespaceURI`` is specified on this element , ``false`` otherwise - if isNil(el.attributes): - return false return not isNil(el.attributes.getNamedItemNS(namespaceURI, localName)) proc removeAttribute*(el: PElement, name: string) = ## Removes an attribute by ``name`` - if not isNil(el.attributes): - for i in low(el.attributes)..high(el.attributes): - if el.attributes[i].fName == name: - el.attributes.delete(i) + for i in low(el.attributes)..high(el.attributes): + if el.attributes[i].fName == name: + el.attributes.delete(i) proc removeAttributeNS*(el: PElement, namespaceURI: string, localName: string) = ## Removes an attribute by ``localName`` and ``namespaceURI`` - if not isNil(el.attributes): - for i in low(el.attributes)..high(el.attributes): - if el.attributes[i].fNamespaceURI == namespaceURI and - el.attributes[i].fLocalName == localName: - el.attributes.delete(i) + for i in low(el.attributes)..high(el.attributes): + if el.attributes[i].fNamespaceURI == namespaceURI and + el.attributes[i].fLocalName == localName: + el.attributes.delete(i) proc removeAttributeNode*(el: PElement, oldAttr: PAttr): PAttr = ## Removes the specified attribute node ## If the attribute node cannot be found raises ``ENotFoundErr`` - if not isNil(el.attributes): - for i in low(el.attributes)..high(el.attributes): - if el.attributes[i] == oldAttr: - result = el.attributes[i] - el.attributes.delete(i) - return + for i in low(el.attributes)..high(el.attributes): + if el.attributes[i] == oldAttr: + result = el.attributes[i] + el.attributes.delete(i) + return raise newException(ENotFoundErr, "oldAttr is not a member of el's Attributes") @@ -991,7 +959,6 @@ proc setAttributeNode*(el: PElement, newAttr: PAttr): PAttr = "This attribute is in use by another element, use cloneNode") # Exceptions end - if isNil(el.attributes): el.attributes = @[] return el.attributes.setNamedItem(newAttr) proc setAttributeNodeNS*(el: PElement, newAttr: PAttr): PAttr = @@ -1009,7 +976,6 @@ proc setAttributeNodeNS*(el: PElement, newAttr: PAttr): PAttr = "This attribute is in use by another element, use cloneNode") # Exceptions end - if isNil(el.attributes): el.attributes = @[] return el.attributes.setNamedItemNS(newAttr) proc setAttribute*(el: PElement, name: string, value: string) = @@ -1057,9 +1023,9 @@ proc splitData*(textNode: PText, offset: int): PText = var left: string = textNode.data.substr(0, offset) textNode.data = left - var right: string = textNode.data.substr(offset, textNode.data.len()) + var right: string = textNode.data.substr(offset, textNode.data.len) - if not isNil(textNode.fParentNode) and not isNil(textNode.fParentNode.childNodes): + if not isNil(textNode.fParentNode) and textNode.fParentNode.childNodes.len > 0: for i in low(textNode.fParentNode.childNodes)..high(textNode.fParentNode.childNodes): if textNode.fParentNode.childNodes[i] == textNode: var newNode: PText = textNode.fOwnerDocument.createTextNode(right) @@ -1098,11 +1064,10 @@ proc escapeXml*(s: string): string = proc nodeToXml(n: PNode, indent: int = 0): string = result = spaces(indent) & "<" & n.nodeName - if not isNil(n.attributes): - for i in items(n.attributes): - result.add(" " & i.name & "=\"" & escapeXml(i.value) & "\"") + for i in items(n.attributes): + result.add(" " & i.name & "=\"" & escapeXml(i.value) & "\"") - if isNil(n.childNodes) or n.childNodes.len() == 0: + if n.childNodes.len == 0: result.add("/>") # No idea why this doesn't need a \n :O else: # End the beginning of this tag @@ -1134,3 +1099,4 @@ proc `$`*(doc: PDocument): string = ## Converts a PDocument object into a string representation of it's XML result = "\n" result.add(nodeToXml(doc.documentElement)) + \ No newline at end of file diff --git a/lib/system.nim b/lib/system.nim index 832a989768..29b472bdc3 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -2292,9 +2292,18 @@ iterator mpairs*(a: var cstring): tuple[key: int, val: var char] {.inline.} = inc(i) -proc isNil*[T](x: seq[T]): bool {.noSideEffect, magic: "IsNil", deprecated.} +when defined(nimNoNilSeqs2): + when not compileOption("nilseqs"): + {.pragma: nilError, error.} + else: + {.pragma: nilError.} +else: + {.pragma: nilError.} + +proc isNil*[T](x: seq[T]): bool {.noSideEffect, magic: "IsNil", nilError.} proc isNil*[T](x: ref T): bool {.noSideEffect, magic: "IsNil".} -proc isNil*(x: string): bool {.noSideEffect, magic: "IsNil", deprecated.} +proc isNil*(x: string): bool {.noSideEffect, magic: "IsNil", nilError.} + proc isNil*[T](x: ptr T): bool {.noSideEffect, magic: "IsNil".} proc isNil*(x: pointer): bool {.noSideEffect, magic: "IsNil".} proc isNil*(x: cstring): bool {.noSideEffect, magic: "IsNil".} diff --git a/lib/system/excpt.nim b/lib/system/excpt.nim index 7b4979cfa0..d9c7b4c25d 100644 --- a/lib/system/excpt.nim +++ b/lib/system/excpt.nim @@ -213,7 +213,7 @@ proc auxWriteStackTrace(f: PFrame; s: var seq[StackTraceEntry]) = inc(i) it = it.prev var last = i-1 - if s.isNil: + if s.len == 0: s = newSeq[StackTraceEntry](i) else: last = s.len + i - 1 @@ -361,10 +361,10 @@ proc raiseExceptionAux(e: ref Exception) = else: when hasSomeStackTrace: var buf = newStringOfCap(2000) - if isNil(e.trace): rawWriteStackTrace(buf) + if e.trace.len == 0: rawWriteStackTrace(buf) else: add(buf, $e.trace) add(buf, "Error: unhandled exception: ") - if not isNil(e.msg): add(buf, e.msg) + add(buf, e.msg) add(buf, " [") add(buf, $e.name) add(buf, "]\n") @@ -382,7 +382,7 @@ proc raiseExceptionAux(e: ref Exception) = var buf: array[0..2000, char] var L = 0 add(buf, "Error: unhandled exception: ") - if not isNil(e.msg): add(buf, e.msg) + add(buf, e.msg) add(buf, " [") xadd(buf, e.name, e.name.len) add(buf, "]\n") @@ -397,7 +397,7 @@ proc raiseExceptionAux(e: ref Exception) = proc raiseException(e: ref Exception, ename: cstring) {.compilerRtl.} = if e.name.isNil: e.name = ename when hasSomeStackTrace: - if e.trace.isNil: + if e.trace.len == 0: rawWriteStackTrace(e.trace) elif framePtr != nil: e.trace.add reraisedFrom(reraisedFromBegin) @@ -427,7 +427,7 @@ proc getStackTrace(): string = result = "No stack traceback available\n" proc getStackTrace(e: ref Exception): string = - if not isNil(e) and not isNil(e.trace): + if not isNil(e): result = $e.trace else: result = "" diff --git a/lib/system/repr.nim b/lib/system/repr.nim index 45acae7f1b..3dc220b87b 100644 --- a/lib/system/repr.nim +++ b/lib/system/repr.nim @@ -266,7 +266,7 @@ when not defined(useNimRtl): of tyChar: add result, reprChar(cast[ptr char](p)[]) of tyString: let sp = cast[ptr string](p) - reprStrAux(result, if sp[].isNil: nil else: sp[].cstring, sp[].len) + reprStrAux(result, sp[].cstring, sp[].len) of tyCString: let cs = cast[ptr cstring](p)[] if cs.isNil: add result, "nil" diff --git a/lib/system/reprjs.nim b/lib/system/reprjs.nim index d04d6e12b1..7cb25a252b 100644 --- a/lib/system/reprjs.nim +++ b/lib/system/reprjs.nim @@ -232,10 +232,7 @@ proc reprAux(result: var string, p: pointer, typ: PNimType, of tyString: var fp: int {. emit: "`fp` = `p`;\n" .} - if cast[string](fp).isNil: - add(result, "nil") - else: - add( result, reprStr(cast[string](p)) ) + add( result, reprStr(cast[string](p)) ) of tyCString: var fp: cstring {. emit: "`fp` = `p`;\n" .} diff --git a/lib/system/sysio.nim b/lib/system/sysio.nim index 3168e4cb28..75e26a6c9b 100644 --- a/lib/system/sysio.nim +++ b/lib/system/sysio.nim @@ -144,13 +144,7 @@ proc getFileHandle*(f: File): FileHandle = c_fileno(f) proc readLine(f: File, line: var TaintedString): bool = var pos = 0 var sp: cint = 80 - # Use the currently reserved space for a first try - if line.string.isNil: - line = TaintedString(newStringOfCap(80)) - else: - when not defined(nimscript) and not defined(gcDestructors): - sp = cint(cast[PGenericSeq](line.string).space) - line.string.setLen(sp) + line.string.setLen(sp) while true: # memset to \L so that we can tell how far fgets wrote, even on EOF, where # fgets doesn't append an \L diff --git a/lib/system/threads.nim b/lib/system/threads.nim index 2434ea21e3..aaf0164fdd 100644 --- a/lib/system/threads.nim +++ b/lib/system/threads.nim @@ -393,8 +393,9 @@ proc onThreadDestruction*(handler: proc () {.closure, gcsafe.}) = ## A thread is destructed when the ``.thread`` proc returns ## normally or when it raises an exception. Note that unhandled exceptions ## in a thread nevertheless cause the whole process to die. - if threadDestructionHandlers.isNil: - threadDestructionHandlers = @[] + when not defined(nimNoNilSeqs): + if threadDestructionHandlers.isNil: + threadDestructionHandlers = @[] threadDestructionHandlers.add handler template afterThreadRuns() = diff --git a/tests/manyloc/argument_parser/argument_parser.nim b/tests/manyloc/argument_parser/argument_parser.nim index 985139f0a6..d42842f932 100644 --- a/tests/manyloc/argument_parser/argument_parser.nim +++ b/tests/manyloc/argument_parser/argument_parser.nim @@ -232,7 +232,7 @@ template run_custom_proc(parsed_parameter: Tparsed_parameter, if not custom_validator.isNil: try: let message = custom_validator(parameter, parsed_parameter) - if not message.isNil and message.len > 0: + if message.len > 0: raise_or_quit(ValueError, ("Failed to validate value for " & "parameter $1:\n$2" % [escape(parameter), message])) except: diff --git a/tests/manyloc/keineschweine/keineschweine.nim.cfg b/tests/manyloc/keineschweine/keineschweine.nim.cfg index ca6c75f6ed..f335a0e0e3 100644 --- a/tests/manyloc/keineschweine/keineschweine.nim.cfg +++ b/tests/manyloc/keineschweine/keineschweine.nim.cfg @@ -7,3 +7,4 @@ path = "dependencies/genpacket" path = "enet_server" debugger = off warning[SmallLshouldNotBeUsed] = off +nilseqs = on From 7896903fd09ee5c855112660179b6f4ec57a1977 Mon Sep 17 00:00:00 2001 From: Araq Date: Wed, 22 Aug 2018 13:15:19 +0200 Subject: [PATCH 034/145] make tio test green again --- lib/system/sysio.nim | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/system/sysio.nim b/lib/system/sysio.nim index 75e26a6c9b..40bbf97dc8 100644 --- a/lib/system/sysio.nim +++ b/lib/system/sysio.nim @@ -143,13 +143,17 @@ proc getFileHandle*(f: File): FileHandle = c_fileno(f) proc readLine(f: File, line: var TaintedString): bool = var pos = 0 - var sp: cint = 80 - line.string.setLen(sp) + + # Use the currently reserved space for a first try + var sp = line.string.len + if sp == 0: + sp = 80 + line.string.setLen(sp) while true: # memset to \L so that we can tell how far fgets wrote, even on EOF, where # fgets doesn't append an \L nimSetMem(addr line.string[pos], '\L'.ord, sp) - var fgetsSuccess = c_fgets(addr line.string[pos], sp, f) != nil + var fgetsSuccess = c_fgets(addr line.string[pos], sp.cint, f) != nil if not fgetsSuccess: checkErr(f) let m = c_memchr(addr line.string[pos], '\L'.ord, sp) if m != nil: From dbd21d670c754501e1c14c758e09c9fce3ad01d5 Mon Sep 17 00:00:00 2001 From: Araq Date: Wed, 22 Aug 2018 15:12:02 +0200 Subject: [PATCH 035/145] make more things compile without isNil --- lib/pure/collections/sets.nim | 2 +- tests/gc/gctest.nim | 3 +-- tools/nimgrep.nim | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/pure/collections/sets.nim b/lib/pure/collections/sets.nim index 0ef91c3cc3..31ca569633 100644 --- a/lib/pure/collections/sets.nim +++ b/lib/pure/collections/sets.nim @@ -654,7 +654,7 @@ proc isValid*[A](s: OrderedSet[A]): bool = ## proc saveTarotCards(cards: OrderedSet[int]) = ## assert cards.isValid, "Pass an initialized set!" ## # Do stuff here, may crash in release builds! - result = not s.data.isNil + result = s.data.len > 0 proc len*[A](s: OrderedSet[A]): int {.inline.} = ## Returns the number of keys in `s`. diff --git a/tests/gc/gctest.nim b/tests/gc/gctest.nim index 7f5260200c..25d57ff0e4 100644 --- a/tests/gc/gctest.nim +++ b/tests/gc/gctest.nim @@ -66,8 +66,7 @@ proc caseTree(lvl: int = 0): PCaseNode = proc finalizeNode(n: PNode) = assert(n != nil) write(stdout, "finalizing: ") - if isNil(n.data): writeLine(stdout, "nil!") - else: writeLine(stdout, "not nil") + writeLine(stdout, "not nil") var id: int = 1 diff --git a/tools/nimgrep.nim b/tools/nimgrep.nim index 9cfd7a86f6..8c6353e319 100644 --- a/tools/nimgrep.nim +++ b/tools/nimgrep.nim @@ -315,7 +315,7 @@ checkOptions({optFilenames, optReplace}, "filenames", "replace") if optStdin in options: pattern = ask("pattern [ENTER to exit]: ") - if isNil(pattern) or pattern.len == 0: quit(0) + if pattern.len == 0: quit(0) if optReplace in options: replacement = ask("replacement [supports $1, $# notations]: ") From 27f488e5d9ad0e40b23fba7ab1a8b713c823e92c Mon Sep 17 00:00:00 2001 From: Araq Date: Wed, 22 Aug 2018 15:37:57 +0200 Subject: [PATCH 036/145] make more tests green; system.repr does not produce 'nil' for strings and seqs anymore --- lib/system/repr.nim | 9 ++++++--- tests/async/tfuturevar.nim | 2 +- tests/ccgbugs/tmissinginit.nim | 4 ++-- tests/gc/thavlak.nim | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/system/repr.nim b/lib/system/repr.nim index 3dc220b87b..85701c28fb 100644 --- a/lib/system/repr.nim +++ b/lib/system/repr.nim @@ -29,7 +29,9 @@ proc reprStrAux(result: var string, s: cstring; len: int) = if cast[pointer](s) == nil: add result, "nil" return - add result, reprPointer(cast[pointer](s)) & "\"" + if len > 0: + add result, reprPointer(cast[pointer](s)) + add result, "\"" for i in 0 .. pred(len): let c = s[i] case c @@ -162,9 +164,10 @@ when not defined(useNimRtl): proc reprSequence(result: var string, p: pointer, typ: PNimType, cl: var ReprClosure) = if p == nil: - add result, "nil" + add result, "[]" return - result.add(reprPointer(p) & "[") + result.add(reprPointer(p)) + result.add '[' var bs = typ.base.size for i in 0..cast[PGenericSeq](p).len-1: if i > 0: add result, ", " diff --git a/tests/async/tfuturevar.nim b/tests/async/tfuturevar.nim index 73c0fddf75..ea2c63e034 100644 --- a/tests/async/tfuturevar.nim +++ b/tests/async/tfuturevar.nim @@ -35,7 +35,7 @@ proc main() {.async.} = fut = newFutureVar[string]() let retFut = failureTest(fut, true) yield retFut - doAssert(fut.read().isNil) + doAssert(fut.read().len == 0) doAssert(fut.finished) fut = newFutureVar[string]() diff --git a/tests/ccgbugs/tmissinginit.nim b/tests/ccgbugs/tmissinginit.nim index d440608e65..b4087008af 100644 --- a/tests/ccgbugs/tmissinginit.nim +++ b/tests/ccgbugs/tmissinginit.nim @@ -3,8 +3,8 @@ discard """ 0 0 0 -[[a = nil, -b = nil]]''' +[[a = "", +b = []]]''' """ # bug #1475 diff --git a/tests/gc/thavlak.nim b/tests/gc/thavlak.nim index efab49e36e..cc0095fbce 100644 --- a/tests/gc/thavlak.nim +++ b/tests/gc/thavlak.nim @@ -245,7 +245,7 @@ proc findLoops(self: var HavlakLoopFinder): int = # - the list of backedges (backPreds) or # - the list of non-backedges (nonBackPreds) # - for w in 0 .. Date: Wed, 22 Aug 2018 15:43:36 +0200 Subject: [PATCH 037/145] make tdefault_nil test compile again --- tests/template/tdefault_nil.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/template/tdefault_nil.nim b/tests/template/tdefault_nil.nim index 311a6c090f..783f773888 100644 --- a/tests/template/tdefault_nil.nim +++ b/tests/template/tdefault_nil.nim @@ -3,7 +3,7 @@ import sequtils, os template glob_rst(basedir: string = ""): untyped = - if baseDir.isNil: + if baseDir.len == 0: to_seq(walk_files("*.rst")) else: to_seq(walk_files(basedir/"*.rst")) From 78e2b515a220a54cb887e21c0098bcd39ce0d055 Mon Sep 17 00:00:00 2001 From: Araq Date: Wed, 22 Aug 2018 17:34:16 +0200 Subject: [PATCH 038/145] make nake test compile again --- tests/manyloc/nake/nake.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/manyloc/nake/nake.nim b/tests/manyloc/nake/nake.nim index fc871cb806..ff3c10a175 100644 --- a/tests/manyloc/nake/nake.nim +++ b/tests/manyloc/nake/nake.nim @@ -75,7 +75,7 @@ else: of cmdArgument: task = key else: discard - if printTaskList or task.isNil or not(tasks.hasKey(task)): + if printTaskList or task.len == 0 or not(tasks.hasKey(task)): echo "Available tasks:" for name, task in pairs(tasks): echo name, " - ", task.desc From b9a18160091489930512d0ba5843fb96dd9c1579 Mon Sep 17 00:00:00 2001 From: Araq Date: Wed, 22 Aug 2018 22:48:49 +0200 Subject: [PATCH 039/145] make sequtils compile --- lib/pure/collections/sequtils.nim | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/pure/collections/sequtils.nim b/lib/pure/collections/sequtils.nim index 612624f1d9..63d910a8ed 100644 --- a/lib/pure/collections/sequtils.nim +++ b/lib/pure/collections/sequtils.nim @@ -183,7 +183,6 @@ proc distribute*[T](s: seq[T], num: Positive, spread = true): seq[seq[T]] = ## assert numbers.distribute(3, false) == @[@[1, 2, 3], @[4, 5, 6], @[7]] ## assert numbers.distribute(6)[0] == @[1, 2] ## assert numbers.distribute(6)[5] == @[7] - assert(not s.isNil, "`s` can't be nil") if num < 2: result = @[s] return From b02bc661974caea6a6c34b78b2df9af13e917d7c Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Wed, 22 Aug 2018 23:19:03 -0700 Subject: [PATCH 040/145] better formatting for recursive module dependency (#8735) --- compiler/lookups.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/lookups.nim b/compiler/lookups.nim index 1b5bee0081..7f08827543 100644 --- a/compiler/lookups.nim +++ b/compiler/lookups.nim @@ -259,7 +259,7 @@ proc errorUseQualifier*(c: PContext; info: TLineInfo; s: PSym) = proc errorUndeclaredIdentifier*(c: PContext; info: TLineInfo; name: string) = var err = "undeclared identifier: '" & name & "'" if c.recursiveDep.len > 0: - err.add "\nThis might be caused by a recursive module dependency: " + err.add "\nThis might be caused by a recursive module dependency:\n" err.add c.recursiveDep # prevent excessive errors for 'nim check' c.recursiveDep = "" From 52bee6baba1b5aeb5abe763c06478cd3139a5a84 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Thu, 23 Aug 2018 01:18:10 -0700 Subject: [PATCH 041/145] partially fix #8218: nim doc --project (#8737) --- compiler/docgen.nim | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/compiler/docgen.nim b/compiler/docgen.nim index b35452365b..3842f0ad4e 100644 --- a/compiler/docgen.nim +++ b/compiler/docgen.nim @@ -787,14 +787,13 @@ proc getOutFile2(conf: ConfigRef; filename, ext, dir: string): string = proc writeOutput*(d: PDoc, filename, outExt: string, useWarning = false) = var content = genOutFile(d) - var success = true if optStdout in d.conf.globalOptions: writeRope(stdout, content) else: let outfile = getOutFile2(d.conf, filename, outExt, "htmldocs") - success = writeRope(content, outfile) - if not success: - rawMessage(d.conf, if useWarning: warnCannotOpenFile else: errCannotOpenFile, filename) + createDir(outfile.parentDir) + if not writeRope(content, outfile): + rawMessage(d.conf, if useWarning: warnCannotOpenFile else: errCannotOpenFile, outfile) proc writeOutputJson*(d: PDoc, filename, outExt: string, useWarning = false) = From bf973d29da48fc6e6d6eeedce3adda84e0b45a64 Mon Sep 17 00:00:00 2001 From: awr1 <41453959+awr1@users.noreply.github.com> Date: Thu, 23 Aug 2018 03:20:58 -0500 Subject: [PATCH 042/145] Fixes #8719 (onFailedAssert now works for doAssert) (#8731) --- lib/system.nim | 16 ++++++++-------- tests/assert/tfaileddoassert.nim | 11 +++++++++++ 2 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 tests/assert/tfaileddoassert.nim diff --git a/lib/system.nim b/lib/system.nim index d61924a5b1..73804b9739 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -3741,23 +3741,23 @@ template assert*(cond: bool, msg = "") = ## The compiler may not generate any code at all for ``assert`` if it is ## advised to do so through the ``-d:release`` or ``--assertions:off`` ## `command line switches `_. + # NOTE: `true` is correct here; --excessiveStackTrace:on will control whether + # or not to output full paths. bind instantiationInfo mixin failedAssertImpl - when compileOption("assertions"): - {.line.}: + {.line: instantiationInfo(fullPaths = true).}: + when compileOption("assertions"): if not cond: failedAssertImpl(astToStr(cond) & ' ' & msg) template doAssert*(cond: bool, msg = "") = ## same as `assert` but is always turned on and not affected by the ## ``--assertions`` command line switch. - bind instantiationInfo # NOTE: `true` is correct here; --excessiveStackTrace:on will control whether # or not to output full paths. - {.line: instantiationInfo(-1, true).}: - if not cond: - raiseAssert(astToStr(cond) & ' ' & - instantiationInfo(-1, false).fileName & '(' & - $instantiationInfo(-1, false).line & ") " & msg) + bind instantiationInfo + mixin failedAssertImpl + {.line: instantiationInfo(fullPaths = true).}: + if not cond: failedAssertImpl(astToStr(cond) & ' ' & msg) iterator items*[T](a: seq[T]): T {.inline.} = ## iterates over each item of `a`. diff --git a/tests/assert/tfaileddoassert.nim b/tests/assert/tfaileddoassert.nim new file mode 100644 index 0000000000..3195fb406b --- /dev/null +++ b/tests/assert/tfaileddoassert.nim @@ -0,0 +1,11 @@ +discard """ + cmd: "nim $target -d:release $options $file" + output: ''' +assertion occured!!!!!! false +''' +""" + +onFailedAssert(msg): + echo("assertion occured!!!!!! ", msg) + +doAssert(1 == 2) From d6d3f092a369ae24ab4f51a332a8056e18c215b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oscar=20Nihlg=C3=A5rd?= Date: Thu, 23 Aug 2018 10:23:02 +0200 Subject: [PATCH 043/145] Fix for module alias inside brackets (#8726) --- compiler/importer.nim | 26 +++++++++++++++++++------- compiler/modulepaths.nim | 7 ------- tests/modules/timportas.nim | 11 +++++++++++ 3 files changed, 30 insertions(+), 14 deletions(-) create mode 100644 tests/modules/timportas.nim diff --git a/compiler/importer.nim b/compiler/importer.nim index c013b93ab1..acc3d26d29 100644 --- a/compiler/importer.nim +++ b/compiler/importer.nim @@ -174,20 +174,32 @@ proc impMod(c: PContext; it: PNode; importStmtResult: PNode) = #importForwarded(c, m.ast, emptySet) proc evalImport(c: PContext, n: PNode): PNode = - #result = n result = newNodeI(nkImportStmt, n.info) for i in countup(0, sonsLen(n) - 1): let it = n.sons[i] if it.kind == nkInfix and it.len == 3 and it[2].kind == nkBracket: let sep = it[0] let dir = it[1] - let a = newNodeI(nkInfix, it.info) - a.add sep - a.add dir - a.add sep # dummy entry, replaced in the loop + var imp = newNodeI(nkInfix, it.info) + imp.add sep + imp.add dir + imp.add sep # dummy entry, replaced in the loop for x in it[2]: - a.sons[2] = x - impMod(c, a, result) + if x.kind == nkInfix and x.sons[0].ident.s == "as": + imp.sons[2] = x.sons[1] + let impAs = newNodeI(nkImportAs, it.info) + impAs.add imp + impAs.add x.sons[2] + imp = impAs + impMod(c, imp, result) + else: + imp.sons[2] = x + impMod(c, imp, result) + elif it.kind == nkInfix and it.sons[0].ident.s == "as": + let imp = newNodeI(nkImportAs, it.info) + imp.add it.sons[1] + imp.add it.sons[2] + impMod(c, imp, result) else: impMod(c, it, result) diff --git a/compiler/modulepaths.nim b/compiler/modulepaths.nim index e5cbf3a2c7..118002fcff 100644 --- a/compiler/modulepaths.nim +++ b/compiler/modulepaths.nim @@ -126,13 +126,6 @@ proc getModuleName*(conf: ConfigRef; n: PNode): string = of nkInfix: let n0 = n[0] let n1 = n[1] - if n0.kind == nkIdent and n0.ident.s == "as": - # XXX hack ahead: - n.kind = nkImportAs - n.sons[0] = n.sons[1] - n.sons[1] = n.sons[2] - n.sons.setLen(2) - return getModuleName(conf, n.sons[0]) when false: if n1.kind == nkPrefix and n1[0].kind == nkIdent and n1[0].ident.s == "$": if n0.kind == nkIdent and n0.ident.s == "/": diff --git a/tests/modules/timportas.nim b/tests/modules/timportas.nim new file mode 100644 index 0000000000..4681a1ee07 --- /dev/null +++ b/tests/modules/timportas.nim @@ -0,0 +1,11 @@ +discard """ + action: run +""" + +import .. / modules / [definitions as foo] +import std / times as bar +import definitions as baz + +discard foo.v +discard bar.now +discard baz.v \ No newline at end of file From 55a86497491586dc1b5ad2f6303d53992b999ab5 Mon Sep 17 00:00:00 2001 From: Tim Date: Thu, 23 Aug 2018 10:30:16 +0200 Subject: [PATCH 044/145] Decrease source code size in `htmlparser` and add one check (#8690) --- lib/pure/htmlparser.nim | 2926 ++++++++++++++++++++------------------- 1 file changed, 1465 insertions(+), 1461 deletions(-) diff --git a/lib/pure/htmlparser.nim b/lib/pure/htmlparser.nim index f54fe87f7f..fbf2b8e732 100644 --- a/lib/pure/htmlparser.nim +++ b/lib/pure/htmlparser.nim @@ -387,1481 +387,1484 @@ proc entityToRune*(entity: string): Rune = doAssert entityToRune("#x0003F") == "?".runeAt(0) if entity.len < 2: return # smallest entity has length 2 if entity[0] == '#': + var runeValue = 0 case entity[1] of '0'..'9': - try: return Rune(parseInt(entity[1..^1])) - except: return + try: runeValue = parseInt(entity[1..^1]) + except: discard of 'x', 'X': # not case sensitive here - try: return Rune(parseHexInt(entity[2..^1])) - except: return - else: return # other entities are not defined with prefix ``#`` + try: runeValue = parseHexInt(entity[2..^1]) + except: discard + else: discard # other entities are not defined with prefix ``#`` + if runeValue notin 0..0x10FFFF: runeValue = 0 # only return legal values + return Rune(runeValue) case entity # entity names are case sensitive - of "Tab": result = Rune(0x00009) - of "NewLine": result = Rune(0x0000A) - of "excl": result = Rune(0x00021) - of "quot", "QUOT": result = Rune(0x00022) - of "num": result = Rune(0x00023) - of "dollar": result = Rune(0x00024) - of "percnt": result = Rune(0x00025) - of "amp", "AMP": result = Rune(0x00026) - of "apos": result = Rune(0x00027) - of "lpar": result = Rune(0x00028) - of "rpar": result = Rune(0x00029) - of "ast", "midast": result = Rune(0x0002A) - of "plus": result = Rune(0x0002B) - of "comma": result = Rune(0x0002C) - of "period": result = Rune(0x0002E) - of "sol": result = Rune(0x0002F) - of "colon": result = Rune(0x0003A) - of "semi": result = Rune(0x0003B) - of "lt", "LT": result = Rune(0x0003C) - of "equals": result = Rune(0x0003D) - of "gt", "GT": result = Rune(0x0003E) - of "quest": result = Rune(0x0003F) - of "commat": result = Rune(0x00040) - of "lsqb", "lbrack": result = Rune(0x0005B) - of "bsol": result = Rune(0x0005C) - of "rsqb", "rbrack": result = Rune(0x0005D) - of "Hat": result = Rune(0x0005E) - of "lowbar": result = Rune(0x0005F) - of "grave", "DiacriticalGrave": result = Rune(0x00060) - of "lcub", "lbrace": result = Rune(0x0007B) - of "verbar", "vert", "VerticalLine": result = Rune(0x0007C) - of "rcub", "rbrace": result = Rune(0x0007D) - of "nbsp", "NonBreakingSpace": result = Rune(0x000A0) - of "iexcl": result = Rune(0x000A1) - of "cent": result = Rune(0x000A2) - of "pound": result = Rune(0x000A3) - of "curren": result = Rune(0x000A4) - of "yen": result = Rune(0x000A5) - of "brvbar": result = Rune(0x000A6) - of "sect": result = Rune(0x000A7) - of "Dot", "die", "DoubleDot", "uml": result = Rune(0x000A8) - of "copy", "COPY": result = Rune(0x000A9) - of "ordf": result = Rune(0x000AA) - of "laquo": result = Rune(0x000AB) - of "not": result = Rune(0x000AC) - of "shy": result = Rune(0x000AD) - of "reg", "circledR", "REG": result = Rune(0x000AE) - of "macr", "OverBar", "strns": result = Rune(0x000AF) - of "deg": result = Rune(0x000B0) - of "plusmn", "pm", "PlusMinus": result = Rune(0x000B1) - of "sup2": result = Rune(0x000B2) - of "sup3": result = Rune(0x000B3) - of "acute", "DiacriticalAcute": result = Rune(0x000B4) - of "micro": result = Rune(0x000B5) - of "para": result = Rune(0x000B6) - of "middot", "centerdot", "CenterDot": result = Rune(0x000B7) - of "cedil", "Cedilla": result = Rune(0x000B8) - of "sup1": result = Rune(0x000B9) - of "ordm": result = Rune(0x000BA) - of "raquo": result = Rune(0x000BB) - of "frac14": result = Rune(0x000BC) - of "frac12", "half": result = Rune(0x000BD) - of "frac34": result = Rune(0x000BE) - of "iquest": result = Rune(0x000BF) - of "Agrave": result = Rune(0x000C0) - of "Aacute": result = Rune(0x000C1) - of "Acirc": result = Rune(0x000C2) - of "Atilde": result = Rune(0x000C3) - of "Auml": result = Rune(0x000C4) - of "Aring": result = Rune(0x000C5) - of "AElig": result = Rune(0x000C6) - of "Ccedil": result = Rune(0x000C7) - of "Egrave": result = Rune(0x000C8) - of "Eacute": result = Rune(0x000C9) - of "Ecirc": result = Rune(0x000CA) - of "Euml": result = Rune(0x000CB) - of "Igrave": result = Rune(0x000CC) - of "Iacute": result = Rune(0x000CD) - of "Icirc": result = Rune(0x000CE) - of "Iuml": result = Rune(0x000CF) - of "ETH": result = Rune(0x000D0) - of "Ntilde": result = Rune(0x000D1) - of "Ograve": result = Rune(0x000D2) - of "Oacute": result = Rune(0x000D3) - of "Ocirc": result = Rune(0x000D4) - of "Otilde": result = Rune(0x000D5) - of "Ouml": result = Rune(0x000D6) - of "times": result = Rune(0x000D7) - of "Oslash": result = Rune(0x000D8) - of "Ugrave": result = Rune(0x000D9) - of "Uacute": result = Rune(0x000DA) - of "Ucirc": result = Rune(0x000DB) - of "Uuml": result = Rune(0x000DC) - of "Yacute": result = Rune(0x000DD) - of "THORN": result = Rune(0x000DE) - of "szlig": result = Rune(0x000DF) - of "agrave": result = Rune(0x000E0) - of "aacute": result = Rune(0x000E1) - of "acirc": result = Rune(0x000E2) - of "atilde": result = Rune(0x000E3) - of "auml": result = Rune(0x000E4) - of "aring": result = Rune(0x000E5) - of "aelig": result = Rune(0x000E6) - of "ccedil": result = Rune(0x000E7) - of "egrave": result = Rune(0x000E8) - of "eacute": result = Rune(0x000E9) - of "ecirc": result = Rune(0x000EA) - of "euml": result = Rune(0x000EB) - of "igrave": result = Rune(0x000EC) - of "iacute": result = Rune(0x000ED) - of "icirc": result = Rune(0x000EE) - of "iuml": result = Rune(0x000EF) - of "eth": result = Rune(0x000F0) - of "ntilde": result = Rune(0x000F1) - of "ograve": result = Rune(0x000F2) - of "oacute": result = Rune(0x000F3) - of "ocirc": result = Rune(0x000F4) - of "otilde": result = Rune(0x000F5) - of "ouml": result = Rune(0x000F6) - of "divide", "div": result = Rune(0x000F7) - of "oslash": result = Rune(0x000F8) - of "ugrave": result = Rune(0x000F9) - of "uacute": result = Rune(0x000FA) - of "ucirc": result = Rune(0x000FB) - of "uuml": result = Rune(0x000FC) - of "yacute": result = Rune(0x000FD) - of "thorn": result = Rune(0x000FE) - of "yuml": result = Rune(0x000FF) - of "Amacr": result = Rune(0x00100) - of "amacr": result = Rune(0x00101) - of "Abreve": result = Rune(0x00102) - of "abreve": result = Rune(0x00103) - of "Aogon": result = Rune(0x00104) - of "aogon": result = Rune(0x00105) - of "Cacute": result = Rune(0x00106) - of "cacute": result = Rune(0x00107) - of "Ccirc": result = Rune(0x00108) - of "ccirc": result = Rune(0x00109) - of "Cdot": result = Rune(0x0010A) - of "cdot": result = Rune(0x0010B) - of "Ccaron": result = Rune(0x0010C) - of "ccaron": result = Rune(0x0010D) - of "Dcaron": result = Rune(0x0010E) - of "dcaron": result = Rune(0x0010F) - of "Dstrok": result = Rune(0x00110) - of "dstrok": result = Rune(0x00111) - of "Emacr": result = Rune(0x00112) - of "emacr": result = Rune(0x00113) - of "Edot": result = Rune(0x00116) - of "edot": result = Rune(0x00117) - of "Eogon": result = Rune(0x00118) - of "eogon": result = Rune(0x00119) - of "Ecaron": result = Rune(0x0011A) - of "ecaron": result = Rune(0x0011B) - of "Gcirc": result = Rune(0x0011C) - of "gcirc": result = Rune(0x0011D) - of "Gbreve": result = Rune(0x0011E) - of "gbreve": result = Rune(0x0011F) - of "Gdot": result = Rune(0x00120) - of "gdot": result = Rune(0x00121) - of "Gcedil": result = Rune(0x00122) - of "Hcirc": result = Rune(0x00124) - of "hcirc": result = Rune(0x00125) - of "Hstrok": result = Rune(0x00126) - of "hstrok": result = Rune(0x00127) - of "Itilde": result = Rune(0x00128) - of "itilde": result = Rune(0x00129) - of "Imacr": result = Rune(0x0012A) - of "imacr": result = Rune(0x0012B) - of "Iogon": result = Rune(0x0012E) - of "iogon": result = Rune(0x0012F) - of "Idot": result = Rune(0x00130) - of "imath", "inodot": result = Rune(0x00131) - of "IJlig": result = Rune(0x00132) - of "ijlig": result = Rune(0x00133) - of "Jcirc": result = Rune(0x00134) - of "jcirc": result = Rune(0x00135) - of "Kcedil": result = Rune(0x00136) - of "kcedil": result = Rune(0x00137) - of "kgreen": result = Rune(0x00138) - of "Lacute": result = Rune(0x00139) - of "lacute": result = Rune(0x0013A) - of "Lcedil": result = Rune(0x0013B) - of "lcedil": result = Rune(0x0013C) - of "Lcaron": result = Rune(0x0013D) - of "lcaron": result = Rune(0x0013E) - of "Lmidot": result = Rune(0x0013F) - of "lmidot": result = Rune(0x00140) - of "Lstrok": result = Rune(0x00141) - of "lstrok": result = Rune(0x00142) - of "Nacute": result = Rune(0x00143) - of "nacute": result = Rune(0x00144) - of "Ncedil": result = Rune(0x00145) - of "ncedil": result = Rune(0x00146) - of "Ncaron": result = Rune(0x00147) - of "ncaron": result = Rune(0x00148) - of "napos": result = Rune(0x00149) - of "ENG": result = Rune(0x0014A) - of "eng": result = Rune(0x0014B) - of "Omacr": result = Rune(0x0014C) - of "omacr": result = Rune(0x0014D) - of "Odblac": result = Rune(0x00150) - of "odblac": result = Rune(0x00151) - of "OElig": result = Rune(0x00152) - of "oelig": result = Rune(0x00153) - of "Racute": result = Rune(0x00154) - of "racute": result = Rune(0x00155) - of "Rcedil": result = Rune(0x00156) - of "rcedil": result = Rune(0x00157) - of "Rcaron": result = Rune(0x00158) - of "rcaron": result = Rune(0x00159) - of "Sacute": result = Rune(0x0015A) - of "sacute": result = Rune(0x0015B) - of "Scirc": result = Rune(0x0015C) - of "scirc": result = Rune(0x0015D) - of "Scedil": result = Rune(0x0015E) - of "scedil": result = Rune(0x0015F) - of "Scaron": result = Rune(0x00160) - of "scaron": result = Rune(0x00161) - of "Tcedil": result = Rune(0x00162) - of "tcedil": result = Rune(0x00163) - of "Tcaron": result = Rune(0x00164) - of "tcaron": result = Rune(0x00165) - of "Tstrok": result = Rune(0x00166) - of "tstrok": result = Rune(0x00167) - of "Utilde": result = Rune(0x00168) - of "utilde": result = Rune(0x00169) - of "Umacr": result = Rune(0x0016A) - of "umacr": result = Rune(0x0016B) - of "Ubreve": result = Rune(0x0016C) - of "ubreve": result = Rune(0x0016D) - of "Uring": result = Rune(0x0016E) - of "uring": result = Rune(0x0016F) - of "Udblac": result = Rune(0x00170) - of "udblac": result = Rune(0x00171) - of "Uogon": result = Rune(0x00172) - of "uogon": result = Rune(0x00173) - of "Wcirc": result = Rune(0x00174) - of "wcirc": result = Rune(0x00175) - of "Ycirc": result = Rune(0x00176) - of "ycirc": result = Rune(0x00177) - of "Yuml": result = Rune(0x00178) - of "Zacute": result = Rune(0x00179) - of "zacute": result = Rune(0x0017A) - of "Zdot": result = Rune(0x0017B) - of "zdot": result = Rune(0x0017C) - of "Zcaron": result = Rune(0x0017D) - of "zcaron": result = Rune(0x0017E) - of "fnof": result = Rune(0x00192) - of "imped": result = Rune(0x001B5) - of "gacute": result = Rune(0x001F5) - of "jmath": result = Rune(0x00237) - of "circ": result = Rune(0x002C6) - of "caron", "Hacek": result = Rune(0x002C7) - of "breve", "Breve": result = Rune(0x002D8) - of "dot", "DiacriticalDot": result = Rune(0x002D9) - of "ring": result = Rune(0x002DA) - of "ogon": result = Rune(0x002DB) - of "tilde", "DiacriticalTilde": result = Rune(0x002DC) - of "dblac", "DiacriticalDoubleAcute": result = Rune(0x002DD) - of "DownBreve": result = Rune(0x00311) - of "UnderBar": result = Rune(0x00332) - of "Alpha": result = Rune(0x00391) - of "Beta": result = Rune(0x00392) - of "Gamma": result = Rune(0x00393) - of "Delta": result = Rune(0x00394) - of "Epsilon": result = Rune(0x00395) - of "Zeta": result = Rune(0x00396) - of "Eta": result = Rune(0x00397) - of "Theta": result = Rune(0x00398) - of "Iota": result = Rune(0x00399) - of "Kappa": result = Rune(0x0039A) - of "Lambda": result = Rune(0x0039B) - of "Mu": result = Rune(0x0039C) - of "Nu": result = Rune(0x0039D) - of "Xi": result = Rune(0x0039E) - of "Omicron": result = Rune(0x0039F) - of "Pi": result = Rune(0x003A0) - of "Rho": result = Rune(0x003A1) - of "Sigma": result = Rune(0x003A3) - of "Tau": result = Rune(0x003A4) - of "Upsilon": result = Rune(0x003A5) - of "Phi": result = Rune(0x003A6) - of "Chi": result = Rune(0x003A7) - of "Psi": result = Rune(0x003A8) - of "Omega": result = Rune(0x003A9) - of "alpha": result = Rune(0x003B1) - of "beta": result = Rune(0x003B2) - of "gamma": result = Rune(0x003B3) - of "delta": result = Rune(0x003B4) - of "epsiv", "varepsilon", "epsilon": result = Rune(0x003B5) - of "zeta": result = Rune(0x003B6) - of "eta": result = Rune(0x003B7) - of "theta": result = Rune(0x003B8) - of "iota": result = Rune(0x003B9) - of "kappa": result = Rune(0x003BA) - of "lambda": result = Rune(0x003BB) - of "mu": result = Rune(0x003BC) - of "nu": result = Rune(0x003BD) - of "xi": result = Rune(0x003BE) - of "omicron": result = Rune(0x003BF) - of "pi": result = Rune(0x003C0) - of "rho": result = Rune(0x003C1) - of "sigmav", "varsigma", "sigmaf": result = Rune(0x003C2) - of "sigma": result = Rune(0x003C3) - of "tau": result = Rune(0x003C4) - of "upsi", "upsilon": result = Rune(0x003C5) - of "phi", "phiv", "varphi": result = Rune(0x003C6) - of "chi": result = Rune(0x003C7) - of "psi": result = Rune(0x003C8) - of "omega": result = Rune(0x003C9) - of "thetav", "vartheta", "thetasym": result = Rune(0x003D1) - of "Upsi", "upsih": result = Rune(0x003D2) - of "straightphi": result = Rune(0x003D5) - of "piv", "varpi": result = Rune(0x003D6) - of "Gammad": result = Rune(0x003DC) - of "gammad", "digamma": result = Rune(0x003DD) - of "kappav", "varkappa": result = Rune(0x003F0) - of "rhov", "varrho": result = Rune(0x003F1) - of "epsi", "straightepsilon": result = Rune(0x003F5) - of "bepsi", "backepsilon": result = Rune(0x003F6) - of "IOcy": result = Rune(0x00401) - of "DJcy": result = Rune(0x00402) - of "GJcy": result = Rune(0x00403) - of "Jukcy": result = Rune(0x00404) - of "DScy": result = Rune(0x00405) - of "Iukcy": result = Rune(0x00406) - of "YIcy": result = Rune(0x00407) - of "Jsercy": result = Rune(0x00408) - of "LJcy": result = Rune(0x00409) - of "NJcy": result = Rune(0x0040A) - of "TSHcy": result = Rune(0x0040B) - of "KJcy": result = Rune(0x0040C) - of "Ubrcy": result = Rune(0x0040E) - of "DZcy": result = Rune(0x0040F) - of "Acy": result = Rune(0x00410) - of "Bcy": result = Rune(0x00411) - of "Vcy": result = Rune(0x00412) - of "Gcy": result = Rune(0x00413) - of "Dcy": result = Rune(0x00414) - of "IEcy": result = Rune(0x00415) - of "ZHcy": result = Rune(0x00416) - of "Zcy": result = Rune(0x00417) - of "Icy": result = Rune(0x00418) - of "Jcy": result = Rune(0x00419) - of "Kcy": result = Rune(0x0041A) - of "Lcy": result = Rune(0x0041B) - of "Mcy": result = Rune(0x0041C) - of "Ncy": result = Rune(0x0041D) - of "Ocy": result = Rune(0x0041E) - of "Pcy": result = Rune(0x0041F) - of "Rcy": result = Rune(0x00420) - of "Scy": result = Rune(0x00421) - of "Tcy": result = Rune(0x00422) - of "Ucy": result = Rune(0x00423) - of "Fcy": result = Rune(0x00424) - of "KHcy": result = Rune(0x00425) - of "TScy": result = Rune(0x00426) - of "CHcy": result = Rune(0x00427) - of "SHcy": result = Rune(0x00428) - of "SHCHcy": result = Rune(0x00429) - of "HARDcy": result = Rune(0x0042A) - of "Ycy": result = Rune(0x0042B) - of "SOFTcy": result = Rune(0x0042C) - of "Ecy": result = Rune(0x0042D) - of "YUcy": result = Rune(0x0042E) - of "YAcy": result = Rune(0x0042F) - of "acy": result = Rune(0x00430) - of "bcy": result = Rune(0x00431) - of "vcy": result = Rune(0x00432) - of "gcy": result = Rune(0x00433) - of "dcy": result = Rune(0x00434) - of "iecy": result = Rune(0x00435) - of "zhcy": result = Rune(0x00436) - of "zcy": result = Rune(0x00437) - of "icy": result = Rune(0x00438) - of "jcy": result = Rune(0x00439) - of "kcy": result = Rune(0x0043A) - of "lcy": result = Rune(0x0043B) - of "mcy": result = Rune(0x0043C) - of "ncy": result = Rune(0x0043D) - of "ocy": result = Rune(0x0043E) - of "pcy": result = Rune(0x0043F) - of "rcy": result = Rune(0x00440) - of "scy": result = Rune(0x00441) - of "tcy": result = Rune(0x00442) - of "ucy": result = Rune(0x00443) - of "fcy": result = Rune(0x00444) - of "khcy": result = Rune(0x00445) - of "tscy": result = Rune(0x00446) - of "chcy": result = Rune(0x00447) - of "shcy": result = Rune(0x00448) - of "shchcy": result = Rune(0x00449) - of "hardcy": result = Rune(0x0044A) - of "ycy": result = Rune(0x0044B) - of "softcy": result = Rune(0x0044C) - of "ecy": result = Rune(0x0044D) - of "yucy": result = Rune(0x0044E) - of "yacy": result = Rune(0x0044F) - of "iocy": result = Rune(0x00451) - of "djcy": result = Rune(0x00452) - of "gjcy": result = Rune(0x00453) - of "jukcy": result = Rune(0x00454) - of "dscy": result = Rune(0x00455) - of "iukcy": result = Rune(0x00456) - of "yicy": result = Rune(0x00457) - of "jsercy": result = Rune(0x00458) - of "ljcy": result = Rune(0x00459) - of "njcy": result = Rune(0x0045A) - of "tshcy": result = Rune(0x0045B) - of "kjcy": result = Rune(0x0045C) - of "ubrcy": result = Rune(0x0045E) - of "dzcy": result = Rune(0x0045F) - of "ensp": result = Rune(0x02002) - of "emsp": result = Rune(0x02003) - of "emsp13": result = Rune(0x02004) - of "emsp14": result = Rune(0x02005) - of "numsp": result = Rune(0x02007) - of "puncsp": result = Rune(0x02008) - of "thinsp", "ThinSpace": result = Rune(0x02009) - of "hairsp", "VeryThinSpace": result = Rune(0x0200A) + of "Tab": Rune(0x00009) + of "NewLine": Rune(0x0000A) + of "excl": Rune(0x00021) + of "quot", "QUOT": Rune(0x00022) + of "num": Rune(0x00023) + of "dollar": Rune(0x00024) + of "percnt": Rune(0x00025) + of "amp", "AMP": Rune(0x00026) + of "apos": Rune(0x00027) + of "lpar": Rune(0x00028) + of "rpar": Rune(0x00029) + of "ast", "midast": Rune(0x0002A) + of "plus": Rune(0x0002B) + of "comma": Rune(0x0002C) + of "period": Rune(0x0002E) + of "sol": Rune(0x0002F) + of "colon": Rune(0x0003A) + of "semi": Rune(0x0003B) + of "lt", "LT": Rune(0x0003C) + of "equals": Rune(0x0003D) + of "gt", "GT": Rune(0x0003E) + of "quest": Rune(0x0003F) + of "commat": Rune(0x00040) + of "lsqb", "lbrack": Rune(0x0005B) + of "bsol": Rune(0x0005C) + of "rsqb", "rbrack": Rune(0x0005D) + of "Hat": Rune(0x0005E) + of "lowbar": Rune(0x0005F) + of "grave", "DiacriticalGrave": Rune(0x00060) + of "lcub", "lbrace": Rune(0x0007B) + of "verbar", "vert", "VerticalLine": Rune(0x0007C) + of "rcub", "rbrace": Rune(0x0007D) + of "nbsp", "NonBreakingSpace": Rune(0x000A0) + of "iexcl": Rune(0x000A1) + of "cent": Rune(0x000A2) + of "pound": Rune(0x000A3) + of "curren": Rune(0x000A4) + of "yen": Rune(0x000A5) + of "brvbar": Rune(0x000A6) + of "sect": Rune(0x000A7) + of "Dot", "die", "DoubleDot", "uml": Rune(0x000A8) + of "copy", "COPY": Rune(0x000A9) + of "ordf": Rune(0x000AA) + of "laquo": Rune(0x000AB) + of "not": Rune(0x000AC) + of "shy": Rune(0x000AD) + of "reg", "circledR", "REG": Rune(0x000AE) + of "macr", "OverBar", "strns": Rune(0x000AF) + of "deg": Rune(0x000B0) + of "plusmn", "pm", "PlusMinus": Rune(0x000B1) + of "sup2": Rune(0x000B2) + of "sup3": Rune(0x000B3) + of "acute", "DiacriticalAcute": Rune(0x000B4) + of "micro": Rune(0x000B5) + of "para": Rune(0x000B6) + of "middot", "centerdot", "CenterDot": Rune(0x000B7) + of "cedil", "Cedilla": Rune(0x000B8) + of "sup1": Rune(0x000B9) + of "ordm": Rune(0x000BA) + of "raquo": Rune(0x000BB) + of "frac14": Rune(0x000BC) + of "frac12", "half": Rune(0x000BD) + of "frac34": Rune(0x000BE) + of "iquest": Rune(0x000BF) + of "Agrave": Rune(0x000C0) + of "Aacute": Rune(0x000C1) + of "Acirc": Rune(0x000C2) + of "Atilde": Rune(0x000C3) + of "Auml": Rune(0x000C4) + of "Aring": Rune(0x000C5) + of "AElig": Rune(0x000C6) + of "Ccedil": Rune(0x000C7) + of "Egrave": Rune(0x000C8) + of "Eacute": Rune(0x000C9) + of "Ecirc": Rune(0x000CA) + of "Euml": Rune(0x000CB) + of "Igrave": Rune(0x000CC) + of "Iacute": Rune(0x000CD) + of "Icirc": Rune(0x000CE) + of "Iuml": Rune(0x000CF) + of "ETH": Rune(0x000D0) + of "Ntilde": Rune(0x000D1) + of "Ograve": Rune(0x000D2) + of "Oacute": Rune(0x000D3) + of "Ocirc": Rune(0x000D4) + of "Otilde": Rune(0x000D5) + of "Ouml": Rune(0x000D6) + of "times": Rune(0x000D7) + of "Oslash": Rune(0x000D8) + of "Ugrave": Rune(0x000D9) + of "Uacute": Rune(0x000DA) + of "Ucirc": Rune(0x000DB) + of "Uuml": Rune(0x000DC) + of "Yacute": Rune(0x000DD) + of "THORN": Rune(0x000DE) + of "szlig": Rune(0x000DF) + of "agrave": Rune(0x000E0) + of "aacute": Rune(0x000E1) + of "acirc": Rune(0x000E2) + of "atilde": Rune(0x000E3) + of "auml": Rune(0x000E4) + of "aring": Rune(0x000E5) + of "aelig": Rune(0x000E6) + of "ccedil": Rune(0x000E7) + of "egrave": Rune(0x000E8) + of "eacute": Rune(0x000E9) + of "ecirc": Rune(0x000EA) + of "euml": Rune(0x000EB) + of "igrave": Rune(0x000EC) + of "iacute": Rune(0x000ED) + of "icirc": Rune(0x000EE) + of "iuml": Rune(0x000EF) + of "eth": Rune(0x000F0) + of "ntilde": Rune(0x000F1) + of "ograve": Rune(0x000F2) + of "oacute": Rune(0x000F3) + of "ocirc": Rune(0x000F4) + of "otilde": Rune(0x000F5) + of "ouml": Rune(0x000F6) + of "divide", "div": Rune(0x000F7) + of "oslash": Rune(0x000F8) + of "ugrave": Rune(0x000F9) + of "uacute": Rune(0x000FA) + of "ucirc": Rune(0x000FB) + of "uuml": Rune(0x000FC) + of "yacute": Rune(0x000FD) + of "thorn": Rune(0x000FE) + of "yuml": Rune(0x000FF) + of "Amacr": Rune(0x00100) + of "amacr": Rune(0x00101) + of "Abreve": Rune(0x00102) + of "abreve": Rune(0x00103) + of "Aogon": Rune(0x00104) + of "aogon": Rune(0x00105) + of "Cacute": Rune(0x00106) + of "cacute": Rune(0x00107) + of "Ccirc": Rune(0x00108) + of "ccirc": Rune(0x00109) + of "Cdot": Rune(0x0010A) + of "cdot": Rune(0x0010B) + of "Ccaron": Rune(0x0010C) + of "ccaron": Rune(0x0010D) + of "Dcaron": Rune(0x0010E) + of "dcaron": Rune(0x0010F) + of "Dstrok": Rune(0x00110) + of "dstrok": Rune(0x00111) + of "Emacr": Rune(0x00112) + of "emacr": Rune(0x00113) + of "Edot": Rune(0x00116) + of "edot": Rune(0x00117) + of "Eogon": Rune(0x00118) + of "eogon": Rune(0x00119) + of "Ecaron": Rune(0x0011A) + of "ecaron": Rune(0x0011B) + of "Gcirc": Rune(0x0011C) + of "gcirc": Rune(0x0011D) + of "Gbreve": Rune(0x0011E) + of "gbreve": Rune(0x0011F) + of "Gdot": Rune(0x00120) + of "gdot": Rune(0x00121) + of "Gcedil": Rune(0x00122) + of "Hcirc": Rune(0x00124) + of "hcirc": Rune(0x00125) + of "Hstrok": Rune(0x00126) + of "hstrok": Rune(0x00127) + of "Itilde": Rune(0x00128) + of "itilde": Rune(0x00129) + of "Imacr": Rune(0x0012A) + of "imacr": Rune(0x0012B) + of "Iogon": Rune(0x0012E) + of "iogon": Rune(0x0012F) + of "Idot": Rune(0x00130) + of "imath", "inodot": Rune(0x00131) + of "IJlig": Rune(0x00132) + of "ijlig": Rune(0x00133) + of "Jcirc": Rune(0x00134) + of "jcirc": Rune(0x00135) + of "Kcedil": Rune(0x00136) + of "kcedil": Rune(0x00137) + of "kgreen": Rune(0x00138) + of "Lacute": Rune(0x00139) + of "lacute": Rune(0x0013A) + of "Lcedil": Rune(0x0013B) + of "lcedil": Rune(0x0013C) + of "Lcaron": Rune(0x0013D) + of "lcaron": Rune(0x0013E) + of "Lmidot": Rune(0x0013F) + of "lmidot": Rune(0x00140) + of "Lstrok": Rune(0x00141) + of "lstrok": Rune(0x00142) + of "Nacute": Rune(0x00143) + of "nacute": Rune(0x00144) + of "Ncedil": Rune(0x00145) + of "ncedil": Rune(0x00146) + of "Ncaron": Rune(0x00147) + of "ncaron": Rune(0x00148) + of "napos": Rune(0x00149) + of "ENG": Rune(0x0014A) + of "eng": Rune(0x0014B) + of "Omacr": Rune(0x0014C) + of "omacr": Rune(0x0014D) + of "Odblac": Rune(0x00150) + of "odblac": Rune(0x00151) + of "OElig": Rune(0x00152) + of "oelig": Rune(0x00153) + of "Racute": Rune(0x00154) + of "racute": Rune(0x00155) + of "Rcedil": Rune(0x00156) + of "rcedil": Rune(0x00157) + of "Rcaron": Rune(0x00158) + of "rcaron": Rune(0x00159) + of "Sacute": Rune(0x0015A) + of "sacute": Rune(0x0015B) + of "Scirc": Rune(0x0015C) + of "scirc": Rune(0x0015D) + of "Scedil": Rune(0x0015E) + of "scedil": Rune(0x0015F) + of "Scaron": Rune(0x00160) + of "scaron": Rune(0x00161) + of "Tcedil": Rune(0x00162) + of "tcedil": Rune(0x00163) + of "Tcaron": Rune(0x00164) + of "tcaron": Rune(0x00165) + of "Tstrok": Rune(0x00166) + of "tstrok": Rune(0x00167) + of "Utilde": Rune(0x00168) + of "utilde": Rune(0x00169) + of "Umacr": Rune(0x0016A) + of "umacr": Rune(0x0016B) + of "Ubreve": Rune(0x0016C) + of "ubreve": Rune(0x0016D) + of "Uring": Rune(0x0016E) + of "uring": Rune(0x0016F) + of "Udblac": Rune(0x00170) + of "udblac": Rune(0x00171) + of "Uogon": Rune(0x00172) + of "uogon": Rune(0x00173) + of "Wcirc": Rune(0x00174) + of "wcirc": Rune(0x00175) + of "Ycirc": Rune(0x00176) + of "ycirc": Rune(0x00177) + of "Yuml": Rune(0x00178) + of "Zacute": Rune(0x00179) + of "zacute": Rune(0x0017A) + of "Zdot": Rune(0x0017B) + of "zdot": Rune(0x0017C) + of "Zcaron": Rune(0x0017D) + of "zcaron": Rune(0x0017E) + of "fnof": Rune(0x00192) + of "imped": Rune(0x001B5) + of "gacute": Rune(0x001F5) + of "jmath": Rune(0x00237) + of "circ": Rune(0x002C6) + of "caron", "Hacek": Rune(0x002C7) + of "breve", "Breve": Rune(0x002D8) + of "dot", "DiacriticalDot": Rune(0x002D9) + of "ring": Rune(0x002DA) + of "ogon": Rune(0x002DB) + of "tilde", "DiacriticalTilde": Rune(0x002DC) + of "dblac", "DiacriticalDoubleAcute": Rune(0x002DD) + of "DownBreve": Rune(0x00311) + of "UnderBar": Rune(0x00332) + of "Alpha": Rune(0x00391) + of "Beta": Rune(0x00392) + of "Gamma": Rune(0x00393) + of "Delta": Rune(0x00394) + of "Epsilon": Rune(0x00395) + of "Zeta": Rune(0x00396) + of "Eta": Rune(0x00397) + of "Theta": Rune(0x00398) + of "Iota": Rune(0x00399) + of "Kappa": Rune(0x0039A) + of "Lambda": Rune(0x0039B) + of "Mu": Rune(0x0039C) + of "Nu": Rune(0x0039D) + of "Xi": Rune(0x0039E) + of "Omicron": Rune(0x0039F) + of "Pi": Rune(0x003A0) + of "Rho": Rune(0x003A1) + of "Sigma": Rune(0x003A3) + of "Tau": Rune(0x003A4) + of "Upsilon": Rune(0x003A5) + of "Phi": Rune(0x003A6) + of "Chi": Rune(0x003A7) + of "Psi": Rune(0x003A8) + of "Omega": Rune(0x003A9) + of "alpha": Rune(0x003B1) + of "beta": Rune(0x003B2) + of "gamma": Rune(0x003B3) + of "delta": Rune(0x003B4) + of "epsiv", "varepsilon", "epsilon": Rune(0x003B5) + of "zeta": Rune(0x003B6) + of "eta": Rune(0x003B7) + of "theta": Rune(0x003B8) + of "iota": Rune(0x003B9) + of "kappa": Rune(0x003BA) + of "lambda": Rune(0x003BB) + of "mu": Rune(0x003BC) + of "nu": Rune(0x003BD) + of "xi": Rune(0x003BE) + of "omicron": Rune(0x003BF) + of "pi": Rune(0x003C0) + of "rho": Rune(0x003C1) + of "sigmav", "varsigma", "sigmaf": Rune(0x003C2) + of "sigma": Rune(0x003C3) + of "tau": Rune(0x003C4) + of "upsi", "upsilon": Rune(0x003C5) + of "phi", "phiv", "varphi": Rune(0x003C6) + of "chi": Rune(0x003C7) + of "psi": Rune(0x003C8) + of "omega": Rune(0x003C9) + of "thetav", "vartheta", "thetasym": Rune(0x003D1) + of "Upsi", "upsih": Rune(0x003D2) + of "straightphi": Rune(0x003D5) + of "piv", "varpi": Rune(0x003D6) + of "Gammad": Rune(0x003DC) + of "gammad", "digamma": Rune(0x003DD) + of "kappav", "varkappa": Rune(0x003F0) + of "rhov", "varrho": Rune(0x003F1) + of "epsi", "straightepsilon": Rune(0x003F5) + of "bepsi", "backepsilon": Rune(0x003F6) + of "IOcy": Rune(0x00401) + of "DJcy": Rune(0x00402) + of "GJcy": Rune(0x00403) + of "Jukcy": Rune(0x00404) + of "DScy": Rune(0x00405) + of "Iukcy": Rune(0x00406) + of "YIcy": Rune(0x00407) + of "Jsercy": Rune(0x00408) + of "LJcy": Rune(0x00409) + of "NJcy": Rune(0x0040A) + of "TSHcy": Rune(0x0040B) + of "KJcy": Rune(0x0040C) + of "Ubrcy": Rune(0x0040E) + of "DZcy": Rune(0x0040F) + of "Acy": Rune(0x00410) + of "Bcy": Rune(0x00411) + of "Vcy": Rune(0x00412) + of "Gcy": Rune(0x00413) + of "Dcy": Rune(0x00414) + of "IEcy": Rune(0x00415) + of "ZHcy": Rune(0x00416) + of "Zcy": Rune(0x00417) + of "Icy": Rune(0x00418) + of "Jcy": Rune(0x00419) + of "Kcy": Rune(0x0041A) + of "Lcy": Rune(0x0041B) + of "Mcy": Rune(0x0041C) + of "Ncy": Rune(0x0041D) + of "Ocy": Rune(0x0041E) + of "Pcy": Rune(0x0041F) + of "Rcy": Rune(0x00420) + of "Scy": Rune(0x00421) + of "Tcy": Rune(0x00422) + of "Ucy": Rune(0x00423) + of "Fcy": Rune(0x00424) + of "KHcy": Rune(0x00425) + of "TScy": Rune(0x00426) + of "CHcy": Rune(0x00427) + of "SHcy": Rune(0x00428) + of "SHCHcy": Rune(0x00429) + of "HARDcy": Rune(0x0042A) + of "Ycy": Rune(0x0042B) + of "SOFTcy": Rune(0x0042C) + of "Ecy": Rune(0x0042D) + of "YUcy": Rune(0x0042E) + of "YAcy": Rune(0x0042F) + of "acy": Rune(0x00430) + of "bcy": Rune(0x00431) + of "vcy": Rune(0x00432) + of "gcy": Rune(0x00433) + of "dcy": Rune(0x00434) + of "iecy": Rune(0x00435) + of "zhcy": Rune(0x00436) + of "zcy": Rune(0x00437) + of "icy": Rune(0x00438) + of "jcy": Rune(0x00439) + of "kcy": Rune(0x0043A) + of "lcy": Rune(0x0043B) + of "mcy": Rune(0x0043C) + of "ncy": Rune(0x0043D) + of "ocy": Rune(0x0043E) + of "pcy": Rune(0x0043F) + of "rcy": Rune(0x00440) + of "scy": Rune(0x00441) + of "tcy": Rune(0x00442) + of "ucy": Rune(0x00443) + of "fcy": Rune(0x00444) + of "khcy": Rune(0x00445) + of "tscy": Rune(0x00446) + of "chcy": Rune(0x00447) + of "shcy": Rune(0x00448) + of "shchcy": Rune(0x00449) + of "hardcy": Rune(0x0044A) + of "ycy": Rune(0x0044B) + of "softcy": Rune(0x0044C) + of "ecy": Rune(0x0044D) + of "yucy": Rune(0x0044E) + of "yacy": Rune(0x0044F) + of "iocy": Rune(0x00451) + of "djcy": Rune(0x00452) + of "gjcy": Rune(0x00453) + of "jukcy": Rune(0x00454) + of "dscy": Rune(0x00455) + of "iukcy": Rune(0x00456) + of "yicy": Rune(0x00457) + of "jsercy": Rune(0x00458) + of "ljcy": Rune(0x00459) + of "njcy": Rune(0x0045A) + of "tshcy": Rune(0x0045B) + of "kjcy": Rune(0x0045C) + of "ubrcy": Rune(0x0045E) + of "dzcy": Rune(0x0045F) + of "ensp": Rune(0x02002) + of "emsp": Rune(0x02003) + of "emsp13": Rune(0x02004) + of "emsp14": Rune(0x02005) + of "numsp": Rune(0x02007) + of "puncsp": Rune(0x02008) + of "thinsp", "ThinSpace": Rune(0x02009) + of "hairsp", "VeryThinSpace": Rune(0x0200A) of "ZeroWidthSpace", "NegativeVeryThinSpace", "NegativeThinSpace", - "NegativeMediumSpace", "NegativeThickSpace": result = Rune(0x0200B) - of "zwnj": result = Rune(0x0200C) - of "zwj": result = Rune(0x0200D) - of "lrm": result = Rune(0x0200E) - of "rlm": result = Rune(0x0200F) - of "hyphen", "dash": result = Rune(0x02010) - of "ndash": result = Rune(0x02013) - of "mdash": result = Rune(0x02014) - of "horbar": result = Rune(0x02015) - of "Verbar", "Vert": result = Rune(0x02016) - of "lsquo", "OpenCurlyQuote": result = Rune(0x02018) - of "rsquo", "rsquor", "CloseCurlyQuote": result = Rune(0x02019) - of "lsquor", "sbquo": result = Rune(0x0201A) - of "ldquo", "OpenCurlyDoubleQuote": result = Rune(0x0201C) - of "rdquo", "rdquor", "CloseCurlyDoubleQuote": result = Rune(0x0201D) - of "ldquor", "bdquo": result = Rune(0x0201E) - of "dagger": result = Rune(0x02020) - of "Dagger", "ddagger": result = Rune(0x02021) - of "bull", "bullet": result = Rune(0x02022) - of "nldr": result = Rune(0x02025) - of "hellip", "mldr": result = Rune(0x02026) - of "permil": result = Rune(0x02030) - of "pertenk": result = Rune(0x02031) - of "prime": result = Rune(0x02032) - of "Prime": result = Rune(0x02033) - of "tprime": result = Rune(0x02034) - of "bprime", "backprime": result = Rune(0x02035) - of "lsaquo": result = Rune(0x02039) - of "rsaquo": result = Rune(0x0203A) - of "oline": result = Rune(0x0203E) - of "caret": result = Rune(0x02041) - of "hybull": result = Rune(0x02043) - of "frasl": result = Rune(0x02044) - of "bsemi": result = Rune(0x0204F) - of "qprime": result = Rune(0x02057) - of "MediumSpace": result = Rune(0x0205F) - of "NoBreak": result = Rune(0x02060) - of "ApplyFunction", "af": result = Rune(0x02061) - of "InvisibleTimes", "it": result = Rune(0x02062) - of "InvisibleComma", "ic": result = Rune(0x02063) - of "euro": result = Rune(0x020AC) - of "tdot", "TripleDot": result = Rune(0x020DB) - of "DotDot": result = Rune(0x020DC) - of "Copf", "complexes": result = Rune(0x02102) - of "incare": result = Rune(0x02105) - of "gscr": result = Rune(0x0210A) - of "hamilt", "HilbertSpace", "Hscr": result = Rune(0x0210B) - of "Hfr", "Poincareplane": result = Rune(0x0210C) - of "quaternions", "Hopf": result = Rune(0x0210D) - of "planckh": result = Rune(0x0210E) - of "planck", "hbar", "plankv", "hslash": result = Rune(0x0210F) - of "Iscr", "imagline": result = Rune(0x02110) - of "image", "Im", "imagpart", "Ifr": result = Rune(0x02111) - of "Lscr", "lagran", "Laplacetrf": result = Rune(0x02112) - of "ell": result = Rune(0x02113) - of "Nopf", "naturals": result = Rune(0x02115) - of "numero": result = Rune(0x02116) - of "copysr": result = Rune(0x02117) - of "weierp", "wp": result = Rune(0x02118) - of "Popf", "primes": result = Rune(0x02119) - of "rationals", "Qopf": result = Rune(0x0211A) - of "Rscr", "realine": result = Rune(0x0211B) - of "real", "Re", "realpart", "Rfr": result = Rune(0x0211C) - of "reals", "Ropf": result = Rune(0x0211D) - of "rx": result = Rune(0x0211E) - of "trade", "TRADE": result = Rune(0x02122) - of "integers", "Zopf": result = Rune(0x02124) - of "ohm": result = Rune(0x02126) - of "mho": result = Rune(0x02127) - of "Zfr", "zeetrf": result = Rune(0x02128) - of "iiota": result = Rune(0x02129) - of "angst": result = Rune(0x0212B) - of "bernou", "Bernoullis", "Bscr": result = Rune(0x0212C) - of "Cfr", "Cayleys": result = Rune(0x0212D) - of "escr": result = Rune(0x0212F) - of "Escr", "expectation": result = Rune(0x02130) - of "Fscr", "Fouriertrf": result = Rune(0x02131) - of "phmmat", "Mellintrf", "Mscr": result = Rune(0x02133) - of "order", "orderof", "oscr": result = Rune(0x02134) - of "alefsym", "aleph": result = Rune(0x02135) - of "beth": result = Rune(0x02136) - of "gimel": result = Rune(0x02137) - of "daleth": result = Rune(0x02138) - of "CapitalDifferentialD", "DD": result = Rune(0x02145) - of "DifferentialD", "dd": result = Rune(0x02146) - of "ExponentialE", "exponentiale", "ee": result = Rune(0x02147) - of "ImaginaryI", "ii": result = Rune(0x02148) - of "frac13": result = Rune(0x02153) - of "frac23": result = Rune(0x02154) - of "frac15": result = Rune(0x02155) - of "frac25": result = Rune(0x02156) - of "frac35": result = Rune(0x02157) - of "frac45": result = Rune(0x02158) - of "frac16": result = Rune(0x02159) - of "frac56": result = Rune(0x0215A) - of "frac18": result = Rune(0x0215B) - of "frac38": result = Rune(0x0215C) - of "frac58": result = Rune(0x0215D) - of "frac78": result = Rune(0x0215E) + "NegativeMediumSpace", "NegativeThickSpace": Rune(0x0200B) + of "zwnj": Rune(0x0200C) + of "zwj": Rune(0x0200D) + of "lrm": Rune(0x0200E) + of "rlm": Rune(0x0200F) + of "hyphen", "dash": Rune(0x02010) + of "ndash": Rune(0x02013) + of "mdash": Rune(0x02014) + of "horbar": Rune(0x02015) + of "Verbar", "Vert": Rune(0x02016) + of "lsquo", "OpenCurlyQuote": Rune(0x02018) + of "rsquo", "rsquor", "CloseCurlyQuote": Rune(0x02019) + of "lsquor", "sbquo": Rune(0x0201A) + of "ldquo", "OpenCurlyDoubleQuote": Rune(0x0201C) + of "rdquo", "rdquor", "CloseCurlyDoubleQuote": Rune(0x0201D) + of "ldquor", "bdquo": Rune(0x0201E) + of "dagger": Rune(0x02020) + of "Dagger", "ddagger": Rune(0x02021) + of "bull", "bullet": Rune(0x02022) + of "nldr": Rune(0x02025) + of "hellip", "mldr": Rune(0x02026) + of "permil": Rune(0x02030) + of "pertenk": Rune(0x02031) + of "prime": Rune(0x02032) + of "Prime": Rune(0x02033) + of "tprime": Rune(0x02034) + of "bprime", "backprime": Rune(0x02035) + of "lsaquo": Rune(0x02039) + of "rsaquo": Rune(0x0203A) + of "oline": Rune(0x0203E) + of "caret": Rune(0x02041) + of "hybull": Rune(0x02043) + of "frasl": Rune(0x02044) + of "bsemi": Rune(0x0204F) + of "qprime": Rune(0x02057) + of "MediumSpace": Rune(0x0205F) + of "NoBreak": Rune(0x02060) + of "ApplyFunction", "af": Rune(0x02061) + of "InvisibleTimes", "it": Rune(0x02062) + of "InvisibleComma", "ic": Rune(0x02063) + of "euro": Rune(0x020AC) + of "tdot", "TripleDot": Rune(0x020DB) + of "DotDot": Rune(0x020DC) + of "Copf", "complexes": Rune(0x02102) + of "incare": Rune(0x02105) + of "gscr": Rune(0x0210A) + of "hamilt", "HilbertSpace", "Hscr": Rune(0x0210B) + of "Hfr", "Poincareplane": Rune(0x0210C) + of "quaternions", "Hopf": Rune(0x0210D) + of "planckh": Rune(0x0210E) + of "planck", "hbar", "plankv", "hslash": Rune(0x0210F) + of "Iscr", "imagline": Rune(0x02110) + of "image", "Im", "imagpart", "Ifr": Rune(0x02111) + of "Lscr", "lagran", "Laplacetrf": Rune(0x02112) + of "ell": Rune(0x02113) + of "Nopf", "naturals": Rune(0x02115) + of "numero": Rune(0x02116) + of "copysr": Rune(0x02117) + of "weierp", "wp": Rune(0x02118) + of "Popf", "primes": Rune(0x02119) + of "rationals", "Qopf": Rune(0x0211A) + of "Rscr", "realine": Rune(0x0211B) + of "real", "Re", "realpart", "Rfr": Rune(0x0211C) + of "reals", "Ropf": Rune(0x0211D) + of "rx": Rune(0x0211E) + of "trade", "TRADE": Rune(0x02122) + of "integers", "Zopf": Rune(0x02124) + of "ohm": Rune(0x02126) + of "mho": Rune(0x02127) + of "Zfr", "zeetrf": Rune(0x02128) + of "iiota": Rune(0x02129) + of "angst": Rune(0x0212B) + of "bernou", "Bernoullis", "Bscr": Rune(0x0212C) + of "Cfr", "Cayleys": Rune(0x0212D) + of "escr": Rune(0x0212F) + of "Escr", "expectation": Rune(0x02130) + of "Fscr", "Fouriertrf": Rune(0x02131) + of "phmmat", "Mellintrf", "Mscr": Rune(0x02133) + of "order", "orderof", "oscr": Rune(0x02134) + of "alefsym", "aleph": Rune(0x02135) + of "beth": Rune(0x02136) + of "gimel": Rune(0x02137) + of "daleth": Rune(0x02138) + of "CapitalDifferentialD", "DD": Rune(0x02145) + of "DifferentialD", "dd": Rune(0x02146) + of "ExponentialE", "exponentiale", "ee": Rune(0x02147) + of "ImaginaryI", "ii": Rune(0x02148) + of "frac13": Rune(0x02153) + of "frac23": Rune(0x02154) + of "frac15": Rune(0x02155) + of "frac25": Rune(0x02156) + of "frac35": Rune(0x02157) + of "frac45": Rune(0x02158) + of "frac16": Rune(0x02159) + of "frac56": Rune(0x0215A) + of "frac18": Rune(0x0215B) + of "frac38": Rune(0x0215C) + of "frac58": Rune(0x0215D) + of "frac78": Rune(0x0215E) of "larr", "leftarrow", "LeftArrow", "slarr", - "ShortLeftArrow": result = Rune(0x02190) - of "uarr", "uparrow", "UpArrow", "ShortUpArrow": result = Rune(0x02191) + "ShortLeftArrow": Rune(0x02190) + of "uarr", "uparrow", "UpArrow", "ShortUpArrow": Rune(0x02191) of "rarr", "rightarrow", "RightArrow", "srarr", - "ShortRightArrow": result = Rune(0x02192) + "ShortRightArrow": Rune(0x02192) of "darr", "downarrow", "DownArrow", - "ShortDownArrow": result = Rune(0x02193) - of "harr", "leftrightarrow", "LeftRightArrow": result = Rune(0x02194) - of "varr", "updownarrow", "UpDownArrow": result = Rune(0x02195) - of "nwarr", "UpperLeftArrow", "nwarrow": result = Rune(0x02196) - of "nearr", "UpperRightArrow", "nearrow": result = Rune(0x02197) - of "searr", "searrow", "LowerRightArrow": result = Rune(0x02198) - of "swarr", "swarrow", "LowerLeftArrow": result = Rune(0x02199) - of "nlarr", "nleftarrow": result = Rune(0x0219A) - of "nrarr", "nrightarrow": result = Rune(0x0219B) - of "rarrw", "rightsquigarrow": result = Rune(0x0219D) - of "Larr", "twoheadleftarrow": result = Rune(0x0219E) - of "Uarr": result = Rune(0x0219F) - of "Rarr", "twoheadrightarrow": result = Rune(0x021A0) - of "Darr": result = Rune(0x021A1) - of "larrtl", "leftarrowtail": result = Rune(0x021A2) - of "rarrtl", "rightarrowtail": result = Rune(0x021A3) - of "LeftTeeArrow", "mapstoleft": result = Rune(0x021A4) - of "UpTeeArrow", "mapstoup": result = Rune(0x021A5) - of "map", "RightTeeArrow", "mapsto": result = Rune(0x021A6) - of "DownTeeArrow", "mapstodown": result = Rune(0x021A7) - of "larrhk", "hookleftarrow": result = Rune(0x021A9) - of "rarrhk", "hookrightarrow": result = Rune(0x021AA) - of "larrlp", "looparrowleft": result = Rune(0x021AB) - of "rarrlp", "looparrowright": result = Rune(0x021AC) - of "harrw", "leftrightsquigarrow": result = Rune(0x021AD) - of "nharr", "nleftrightarrow": result = Rune(0x021AE) - of "lsh", "Lsh": result = Rune(0x021B0) - of "rsh", "Rsh": result = Rune(0x021B1) - of "ldsh": result = Rune(0x021B2) - of "rdsh": result = Rune(0x021B3) - of "crarr": result = Rune(0x021B5) - of "cularr", "curvearrowleft": result = Rune(0x021B6) - of "curarr", "curvearrowright": result = Rune(0x021B7) - of "olarr", "circlearrowleft": result = Rune(0x021BA) - of "orarr", "circlearrowright": result = Rune(0x021BB) - of "lharu", "LeftVector", "leftharpoonup": result = Rune(0x021BC) - of "lhard", "leftharpoondown", "DownLeftVector": result = Rune(0x021BD) - of "uharr", "upharpoonright", "RightUpVector": result = Rune(0x021BE) - of "uharl", "upharpoonleft", "LeftUpVector": result = Rune(0x021BF) - of "rharu", "RightVector", "rightharpoonup": result = Rune(0x021C0) - of "rhard", "rightharpoondown", "DownRightVector": result = Rune(0x021C1) - of "dharr", "RightDownVector", "downharpoonright": result = Rune(0x021C2) - of "dharl", "LeftDownVector", "downharpoonleft": result = Rune(0x021C3) - of "rlarr", "rightleftarrows", "RightArrowLeftArrow": result = Rune(0x021C4) - of "udarr", "UpArrowDownArrow": result = Rune(0x021C5) - of "lrarr", "leftrightarrows", "LeftArrowRightArrow": result = Rune(0x021C6) - of "llarr", "leftleftarrows": result = Rune(0x021C7) - of "uuarr", "upuparrows": result = Rune(0x021C8) - of "rrarr", "rightrightarrows": result = Rune(0x021C9) - of "ddarr", "downdownarrows": result = Rune(0x021CA) + "ShortDownArrow": Rune(0x02193) + of "harr", "leftrightarrow", "LeftRightArrow": Rune(0x02194) + of "varr", "updownarrow", "UpDownArrow": Rune(0x02195) + of "nwarr", "UpperLeftArrow", "nwarrow": Rune(0x02196) + of "nearr", "UpperRightArrow", "nearrow": Rune(0x02197) + of "searr", "searrow", "LowerRightArrow": Rune(0x02198) + of "swarr", "swarrow", "LowerLeftArrow": Rune(0x02199) + of "nlarr", "nleftarrow": Rune(0x0219A) + of "nrarr", "nrightarrow": Rune(0x0219B) + of "rarrw", "rightsquigarrow": Rune(0x0219D) + of "Larr", "twoheadleftarrow": Rune(0x0219E) + of "Uarr": Rune(0x0219F) + of "Rarr", "twoheadrightarrow": Rune(0x021A0) + of "Darr": Rune(0x021A1) + of "larrtl", "leftarrowtail": Rune(0x021A2) + of "rarrtl", "rightarrowtail": Rune(0x021A3) + of "LeftTeeArrow", "mapstoleft": Rune(0x021A4) + of "UpTeeArrow", "mapstoup": Rune(0x021A5) + of "map", "RightTeeArrow", "mapsto": Rune(0x021A6) + of "DownTeeArrow", "mapstodown": Rune(0x021A7) + of "larrhk", "hookleftarrow": Rune(0x021A9) + of "rarrhk", "hookrightarrow": Rune(0x021AA) + of "larrlp", "looparrowleft": Rune(0x021AB) + of "rarrlp", "looparrowright": Rune(0x021AC) + of "harrw", "leftrightsquigarrow": Rune(0x021AD) + of "nharr", "nleftrightarrow": Rune(0x021AE) + of "lsh", "Lsh": Rune(0x021B0) + of "rsh", "Rsh": Rune(0x021B1) + of "ldsh": Rune(0x021B2) + of "rdsh": Rune(0x021B3) + of "crarr": Rune(0x021B5) + of "cularr", "curvearrowleft": Rune(0x021B6) + of "curarr", "curvearrowright": Rune(0x021B7) + of "olarr", "circlearrowleft": Rune(0x021BA) + of "orarr", "circlearrowright": Rune(0x021BB) + of "lharu", "LeftVector", "leftharpoonup": Rune(0x021BC) + of "lhard", "leftharpoondown", "DownLeftVector": Rune(0x021BD) + of "uharr", "upharpoonright", "RightUpVector": Rune(0x021BE) + of "uharl", "upharpoonleft", "LeftUpVector": Rune(0x021BF) + of "rharu", "RightVector", "rightharpoonup": Rune(0x021C0) + of "rhard", "rightharpoondown", "DownRightVector": Rune(0x021C1) + of "dharr", "RightDownVector", "downharpoonright": Rune(0x021C2) + of "dharl", "LeftDownVector", "downharpoonleft": Rune(0x021C3) + of "rlarr", "rightleftarrows", "RightArrowLeftArrow": Rune(0x021C4) + of "udarr", "UpArrowDownArrow": Rune(0x021C5) + of "lrarr", "leftrightarrows", "LeftArrowRightArrow": Rune(0x021C6) + of "llarr", "leftleftarrows": Rune(0x021C7) + of "uuarr", "upuparrows": Rune(0x021C8) + of "rrarr", "rightrightarrows": Rune(0x021C9) + of "ddarr", "downdownarrows": Rune(0x021CA) of "lrhar", "ReverseEquilibrium", - "leftrightharpoons": result = Rune(0x021CB) - of "rlhar", "rightleftharpoons", "Equilibrium": result = Rune(0x021CC) - of "nlArr", "nLeftarrow": result = Rune(0x021CD) - of "nhArr", "nLeftrightarrow": result = Rune(0x021CE) - of "nrArr", "nRightarrow": result = Rune(0x021CF) - of "lArr", "Leftarrow", "DoubleLeftArrow": result = Rune(0x021D0) - of "uArr", "Uparrow", "DoubleUpArrow": result = Rune(0x021D1) + "leftrightharpoons": Rune(0x021CB) + of "rlhar", "rightleftharpoons", "Equilibrium": Rune(0x021CC) + of "nlArr", "nLeftarrow": Rune(0x021CD) + of "nhArr", "nLeftrightarrow": Rune(0x021CE) + of "nrArr", "nRightarrow": Rune(0x021CF) + of "lArr", "Leftarrow", "DoubleLeftArrow": Rune(0x021D0) + of "uArr", "Uparrow", "DoubleUpArrow": Rune(0x021D1) of "rArr", "Rightarrow", "Implies", - "DoubleRightArrow": result = Rune(0x021D2) - of "dArr", "Downarrow", "DoubleDownArrow": result = Rune(0x021D3) + "DoubleRightArrow": Rune(0x021D2) + of "dArr", "Downarrow", "DoubleDownArrow": Rune(0x021D3) of "hArr", "Leftrightarrow", "DoubleLeftRightArrow", - "iff": result = Rune(0x021D4) - of "vArr", "Updownarrow", "DoubleUpDownArrow": result = Rune(0x021D5) - of "nwArr": result = Rune(0x021D6) - of "neArr": result = Rune(0x021D7) - of "seArr": result = Rune(0x021D8) - of "swArr": result = Rune(0x021D9) - of "lAarr", "Lleftarrow": result = Rune(0x021DA) - of "rAarr", "Rrightarrow": result = Rune(0x021DB) - of "zigrarr": result = Rune(0x021DD) - of "larrb", "LeftArrowBar": result = Rune(0x021E4) - of "rarrb", "RightArrowBar": result = Rune(0x021E5) - of "duarr", "DownArrowUpArrow": result = Rune(0x021F5) - of "loarr": result = Rune(0x021FD) - of "roarr": result = Rune(0x021FE) - of "hoarr": result = Rune(0x021FF) - of "forall", "ForAll": result = Rune(0x02200) - of "comp", "complement": result = Rune(0x02201) - of "part", "PartialD": result = Rune(0x02202) - of "exist", "Exists": result = Rune(0x02203) - of "nexist", "NotExists", "nexists": result = Rune(0x02204) - of "empty", "emptyset", "emptyv", "varnothing": result = Rune(0x02205) - of "nabla", "Del": result = Rune(0x02207) - of "isin", "isinv", "Element", "in": result = Rune(0x02208) - of "notin", "NotElement", "notinva": result = Rune(0x02209) - of "niv", "ReverseElement", "ni", "SuchThat": result = Rune(0x0220B) - of "notni", "notniva", "NotReverseElement": result = Rune(0x0220C) - of "prod", "Product": result = Rune(0x0220F) - of "coprod", "Coproduct": result = Rune(0x02210) - of "sum", "Sum": result = Rune(0x02211) - of "minus": result = Rune(0x02212) - of "mnplus", "mp", "MinusPlus": result = Rune(0x02213) - of "plusdo", "dotplus": result = Rune(0x02214) + "iff": Rune(0x021D4) + of "vArr", "Updownarrow", "DoubleUpDownArrow": Rune(0x021D5) + of "nwArr": Rune(0x021D6) + of "neArr": Rune(0x021D7) + of "seArr": Rune(0x021D8) + of "swArr": Rune(0x021D9) + of "lAarr", "Lleftarrow": Rune(0x021DA) + of "rAarr", "Rrightarrow": Rune(0x021DB) + of "zigrarr": Rune(0x021DD) + of "larrb", "LeftArrowBar": Rune(0x021E4) + of "rarrb", "RightArrowBar": Rune(0x021E5) + of "duarr", "DownArrowUpArrow": Rune(0x021F5) + of "loarr": Rune(0x021FD) + of "roarr": Rune(0x021FE) + of "hoarr": Rune(0x021FF) + of "forall", "ForAll": Rune(0x02200) + of "comp", "complement": Rune(0x02201) + of "part", "PartialD": Rune(0x02202) + of "exist", "Exists": Rune(0x02203) + of "nexist", "NotExists", "nexists": Rune(0x02204) + of "empty", "emptyset", "emptyv", "varnothing": Rune(0x02205) + of "nabla", "Del": Rune(0x02207) + of "isin", "isinv", "Element", "in": Rune(0x02208) + of "notin", "NotElement", "notinva": Rune(0x02209) + of "niv", "ReverseElement", "ni", "SuchThat": Rune(0x0220B) + of "notni", "notniva", "NotReverseElement": Rune(0x0220C) + of "prod", "Product": Rune(0x0220F) + of "coprod", "Coproduct": Rune(0x02210) + of "sum", "Sum": Rune(0x02211) + of "minus": Rune(0x02212) + of "mnplus", "mp", "MinusPlus": Rune(0x02213) + of "plusdo", "dotplus": Rune(0x02214) of "setmn", "setminus", "Backslash", "ssetmn", - "smallsetminus": result = Rune(0x02216) - of "lowast": result = Rune(0x02217) - of "compfn", "SmallCircle": result = Rune(0x02218) - of "radic", "Sqrt": result = Rune(0x0221A) + "smallsetminus": Rune(0x02216) + of "lowast": Rune(0x02217) + of "compfn", "SmallCircle": Rune(0x02218) + of "radic", "Sqrt": Rune(0x0221A) of "prop", "propto", "Proportional", "vprop", - "varpropto": result = Rune(0x0221D) - of "infin": result = Rune(0x0221E) - of "angrt": result = Rune(0x0221F) - of "ang", "angle": result = Rune(0x02220) - of "angmsd", "measuredangle": result = Rune(0x02221) - of "angsph": result = Rune(0x02222) - of "mid", "VerticalBar", "smid", "shortmid": result = Rune(0x02223) - of "nmid", "NotVerticalBar", "nsmid", "nshortmid": result = Rune(0x02224) + "varpropto": Rune(0x0221D) + of "infin": Rune(0x0221E) + of "angrt": Rune(0x0221F) + of "ang", "angle": Rune(0x02220) + of "angmsd", "measuredangle": Rune(0x02221) + of "angsph": Rune(0x02222) + of "mid", "VerticalBar", "smid", "shortmid": Rune(0x02223) + of "nmid", "NotVerticalBar", "nsmid", "nshortmid": Rune(0x02224) of "par", "parallel", "DoubleVerticalBar", "spar", - "shortparallel": result = Rune(0x02225) + "shortparallel": Rune(0x02225) of "npar", "nparallel", "NotDoubleVerticalBar", "nspar", - "nshortparallel": result = Rune(0x02226) - of "and", "wedge": result = Rune(0x02227) - of "or", "vee": result = Rune(0x02228) - of "cap": result = Rune(0x02229) - of "cup": result = Rune(0x0222A) - of "int", "Integral": result = Rune(0x0222B) - of "Int": result = Rune(0x0222C) - of "tint", "iiint": result = Rune(0x0222D) - of "conint", "oint", "ContourIntegral": result = Rune(0x0222E) - of "Conint", "DoubleContourIntegral": result = Rune(0x0222F) - of "Cconint": result = Rune(0x02230) - of "cwint": result = Rune(0x02231) - of "cwconint", "ClockwiseContourIntegral": result = Rune(0x02232) - of "awconint", "CounterClockwiseContourIntegral": result = Rune(0x02233) - of "there4", "therefore", "Therefore": result = Rune(0x02234) - of "becaus", "because", "Because": result = Rune(0x02235) - of "ratio": result = Rune(0x02236) - of "Colon", "Proportion": result = Rune(0x02237) - of "minusd", "dotminus": result = Rune(0x02238) - of "mDDot": result = Rune(0x0223A) - of "homtht": result = Rune(0x0223B) - of "sim", "Tilde", "thksim", "thicksim": result = Rune(0x0223C) - of "bsim", "backsim": result = Rune(0x0223D) - of "ac", "mstpos": result = Rune(0x0223E) - of "acd": result = Rune(0x0223F) - of "wreath", "VerticalTilde", "wr": result = Rune(0x02240) - of "nsim", "NotTilde": result = Rune(0x02241) - of "esim", "EqualTilde", "eqsim": result = Rune(0x02242) - of "sime", "TildeEqual", "simeq": result = Rune(0x02243) - of "nsime", "nsimeq", "NotTildeEqual": result = Rune(0x02244) - of "cong", "TildeFullEqual": result = Rune(0x02245) - of "simne": result = Rune(0x02246) - of "ncong", "NotTildeFullEqual": result = Rune(0x02247) + "nshortparallel": Rune(0x02226) + of "and", "wedge": Rune(0x02227) + of "or", "vee": Rune(0x02228) + of "cap": Rune(0x02229) + of "cup": Rune(0x0222A) + of "int", "Integral": Rune(0x0222B) + of "Int": Rune(0x0222C) + of "tint", "iiint": Rune(0x0222D) + of "conint", "oint", "ContourIntegral": Rune(0x0222E) + of "Conint", "DoubleContourIntegral": Rune(0x0222F) + of "Cconint": Rune(0x02230) + of "cwint": Rune(0x02231) + of "cwconint", "ClockwiseContourIntegral": Rune(0x02232) + of "awconint", "CounterClockwiseContourIntegral": Rune(0x02233) + of "there4", "therefore", "Therefore": Rune(0x02234) + of "becaus", "because", "Because": Rune(0x02235) + of "ratio": Rune(0x02236) + of "Colon", "Proportion": Rune(0x02237) + of "minusd", "dotminus": Rune(0x02238) + of "mDDot": Rune(0x0223A) + of "homtht": Rune(0x0223B) + of "sim", "Tilde", "thksim", "thicksim": Rune(0x0223C) + of "bsim", "backsim": Rune(0x0223D) + of "ac", "mstpos": Rune(0x0223E) + of "acd": Rune(0x0223F) + of "wreath", "VerticalTilde", "wr": Rune(0x02240) + of "nsim", "NotTilde": Rune(0x02241) + of "esim", "EqualTilde", "eqsim": Rune(0x02242) + of "sime", "TildeEqual", "simeq": Rune(0x02243) + of "nsime", "nsimeq", "NotTildeEqual": Rune(0x02244) + of "cong", "TildeFullEqual": Rune(0x02245) + of "simne": Rune(0x02246) + of "ncong", "NotTildeFullEqual": Rune(0x02247) of "asymp", "ap", "TildeTilde", "approx", "thkap", - "thickapprox": result = Rune(0x02248) - of "nap", "NotTildeTilde", "napprox": result = Rune(0x02249) - of "ape", "approxeq": result = Rune(0x0224A) - of "apid": result = Rune(0x0224B) - of "bcong", "backcong": result = Rune(0x0224C) - of "asympeq", "CupCap": result = Rune(0x0224D) - of "bump", "HumpDownHump", "Bumpeq": result = Rune(0x0224E) - of "bumpe", "HumpEqual", "bumpeq": result = Rune(0x0224F) - of "esdot", "DotEqual", "doteq": result = Rune(0x02250) - of "eDot", "doteqdot": result = Rune(0x02251) - of "efDot", "fallingdotseq": result = Rune(0x02252) - of "erDot", "risingdotseq": result = Rune(0x02253) - of "colone", "coloneq", "Assign": result = Rune(0x02254) - of "ecolon", "eqcolon": result = Rune(0x02255) - of "ecir", "eqcirc": result = Rune(0x02256) - of "cire", "circeq": result = Rune(0x02257) - of "wedgeq": result = Rune(0x02259) - of "veeeq": result = Rune(0x0225A) - of "trie", "triangleq": result = Rune(0x0225C) - of "equest", "questeq": result = Rune(0x0225F) - of "ne", "NotEqual": result = Rune(0x02260) - of "equiv", "Congruent": result = Rune(0x02261) - of "nequiv", "NotCongruent": result = Rune(0x02262) - of "le", "leq": result = Rune(0x02264) - of "ge", "GreaterEqual", "geq": result = Rune(0x02265) - of "lE", "LessFullEqual", "leqq": result = Rune(0x02266) - of "gE", "GreaterFullEqual", "geqq": result = Rune(0x02267) - of "lnE", "lneqq": result = Rune(0x02268) - of "gnE", "gneqq": result = Rune(0x02269) - of "Lt", "NestedLessLess", "ll": result = Rune(0x0226A) - of "Gt", "NestedGreaterGreater", "gg": result = Rune(0x0226B) - of "twixt", "between": result = Rune(0x0226C) - of "NotCupCap": result = Rune(0x0226D) - of "nlt", "NotLess", "nless": result = Rune(0x0226E) - of "ngt", "NotGreater", "ngtr": result = Rune(0x0226F) - of "nle", "NotLessEqual", "nleq": result = Rune(0x02270) - of "nge", "NotGreaterEqual", "ngeq": result = Rune(0x02271) - of "lsim", "LessTilde", "lesssim": result = Rune(0x02272) - of "gsim", "gtrsim", "GreaterTilde": result = Rune(0x02273) - of "nlsim", "NotLessTilde": result = Rune(0x02274) - of "ngsim", "NotGreaterTilde": result = Rune(0x02275) - of "lg", "lessgtr", "LessGreater": result = Rune(0x02276) - of "gl", "gtrless", "GreaterLess": result = Rune(0x02277) - of "ntlg", "NotLessGreater": result = Rune(0x02278) - of "ntgl", "NotGreaterLess": result = Rune(0x02279) - of "pr", "Precedes", "prec": result = Rune(0x0227A) - of "sc", "Succeeds", "succ": result = Rune(0x0227B) - of "prcue", "PrecedesSlantEqual", "preccurlyeq": result = Rune(0x0227C) - of "sccue", "SucceedsSlantEqual", "succcurlyeq": result = Rune(0x0227D) - of "prsim", "precsim", "PrecedesTilde": result = Rune(0x0227E) - of "scsim", "succsim", "SucceedsTilde": result = Rune(0x0227F) - of "npr", "nprec", "NotPrecedes": result = Rune(0x02280) - of "nsc", "nsucc", "NotSucceeds": result = Rune(0x02281) - of "sub", "subset": result = Rune(0x02282) - of "sup", "supset", "Superset": result = Rune(0x02283) - of "nsub": result = Rune(0x02284) - of "nsup": result = Rune(0x02285) - of "sube", "SubsetEqual", "subseteq": result = Rune(0x02286) - of "supe", "supseteq", "SupersetEqual": result = Rune(0x02287) - of "nsube", "nsubseteq", "NotSubsetEqual": result = Rune(0x02288) - of "nsupe", "nsupseteq", "NotSupersetEqual": result = Rune(0x02289) - of "subne", "subsetneq": result = Rune(0x0228A) - of "supne", "supsetneq": result = Rune(0x0228B) - of "cupdot": result = Rune(0x0228D) - of "uplus", "UnionPlus": result = Rune(0x0228E) - of "sqsub", "SquareSubset", "sqsubset": result = Rune(0x0228F) - of "sqsup", "SquareSuperset", "sqsupset": result = Rune(0x02290) - of "sqsube", "SquareSubsetEqual", "sqsubseteq": result = Rune(0x02291) - of "sqsupe", "SquareSupersetEqual", "sqsupseteq": result = Rune(0x02292) - of "sqcap", "SquareIntersection": result = Rune(0x02293) - of "sqcup", "SquareUnion": result = Rune(0x02294) - of "oplus", "CirclePlus": result = Rune(0x02295) - of "ominus", "CircleMinus": result = Rune(0x02296) - of "otimes", "CircleTimes": result = Rune(0x02297) - of "osol": result = Rune(0x02298) - of "odot", "CircleDot": result = Rune(0x02299) - of "ocir", "circledcirc": result = Rune(0x0229A) - of "oast", "circledast": result = Rune(0x0229B) - of "odash", "circleddash": result = Rune(0x0229D) - of "plusb", "boxplus": result = Rune(0x0229E) - of "minusb", "boxminus": result = Rune(0x0229F) - of "timesb", "boxtimes": result = Rune(0x022A0) - of "sdotb", "dotsquare": result = Rune(0x022A1) - of "vdash", "RightTee": result = Rune(0x022A2) - of "dashv", "LeftTee": result = Rune(0x022A3) - of "top", "DownTee": result = Rune(0x022A4) - of "bottom", "bot", "perp", "UpTee": result = Rune(0x022A5) - of "models": result = Rune(0x022A7) - of "vDash", "DoubleRightTee": result = Rune(0x022A8) - of "Vdash": result = Rune(0x022A9) - of "Vvdash": result = Rune(0x022AA) - of "VDash": result = Rune(0x022AB) - of "nvdash": result = Rune(0x022AC) - of "nvDash": result = Rune(0x022AD) - of "nVdash": result = Rune(0x022AE) - of "nVDash": result = Rune(0x022AF) - of "prurel": result = Rune(0x022B0) - of "vltri", "vartriangleleft", "LeftTriangle": result = Rune(0x022B2) - of "vrtri", "vartriangleright", "RightTriangle": result = Rune(0x022B3) - of "ltrie", "trianglelefteq", "LeftTriangleEqual": result = Rune(0x022B4) - of "rtrie", "trianglerighteq", "RightTriangleEqual": result = Rune(0x022B5) - of "origof": result = Rune(0x022B6) - of "imof": result = Rune(0x022B7) - of "mumap", "multimap": result = Rune(0x022B8) - of "hercon": result = Rune(0x022B9) - of "intcal", "intercal": result = Rune(0x022BA) - of "veebar": result = Rune(0x022BB) - of "barvee": result = Rune(0x022BD) - of "angrtvb": result = Rune(0x022BE) - of "lrtri": result = Rune(0x022BF) - of "xwedge", "Wedge", "bigwedge": result = Rune(0x022C0) - of "xvee", "Vee", "bigvee": result = Rune(0x022C1) - of "xcap", "Intersection", "bigcap": result = Rune(0x022C2) - of "xcup", "Union", "bigcup": result = Rune(0x022C3) - of "diam", "diamond", "Diamond": result = Rune(0x022C4) - of "sdot": result = Rune(0x022C5) - of "sstarf", "Star": result = Rune(0x022C6) - of "divonx", "divideontimes": result = Rune(0x022C7) - of "bowtie": result = Rune(0x022C8) - of "ltimes": result = Rune(0x022C9) - of "rtimes": result = Rune(0x022CA) - of "lthree", "leftthreetimes": result = Rune(0x022CB) - of "rthree", "rightthreetimes": result = Rune(0x022CC) - of "bsime", "backsimeq": result = Rune(0x022CD) - of "cuvee", "curlyvee": result = Rune(0x022CE) - of "cuwed", "curlywedge": result = Rune(0x022CF) - of "Sub", "Subset": result = Rune(0x022D0) - of "Sup", "Supset": result = Rune(0x022D1) - of "Cap": result = Rune(0x022D2) - of "Cup": result = Rune(0x022D3) - of "fork", "pitchfork": result = Rune(0x022D4) - of "epar": result = Rune(0x022D5) - of "ltdot", "lessdot": result = Rune(0x022D6) - of "gtdot", "gtrdot": result = Rune(0x022D7) - of "Ll": result = Rune(0x022D8) - of "Gg", "ggg": result = Rune(0x022D9) - of "leg", "LessEqualGreater", "lesseqgtr": result = Rune(0x022DA) - of "gel", "gtreqless", "GreaterEqualLess": result = Rune(0x022DB) - of "cuepr", "curlyeqprec": result = Rune(0x022DE) - of "cuesc", "curlyeqsucc": result = Rune(0x022DF) - of "nprcue", "NotPrecedesSlantEqual": result = Rune(0x022E0) - of "nsccue", "NotSucceedsSlantEqual": result = Rune(0x022E1) - of "nsqsube", "NotSquareSubsetEqual": result = Rune(0x022E2) - of "nsqsupe", "NotSquareSupersetEqual": result = Rune(0x022E3) - of "lnsim": result = Rune(0x022E6) - of "gnsim": result = Rune(0x022E7) - of "prnsim", "precnsim": result = Rune(0x022E8) - of "scnsim", "succnsim": result = Rune(0x022E9) - of "nltri", "ntriangleleft", "NotLeftTriangle": result = Rune(0x022EA) - of "nrtri", "ntriangleright", "NotRightTriangle": result = Rune(0x022EB) + "thickapprox": Rune(0x02248) + of "nap", "NotTildeTilde", "napprox": Rune(0x02249) + of "ape", "approxeq": Rune(0x0224A) + of "apid": Rune(0x0224B) + of "bcong", "backcong": Rune(0x0224C) + of "asympeq", "CupCap": Rune(0x0224D) + of "bump", "HumpDownHump", "Bumpeq": Rune(0x0224E) + of "bumpe", "HumpEqual", "bumpeq": Rune(0x0224F) + of "esdot", "DotEqual", "doteq": Rune(0x02250) + of "eDot", "doteqdot": Rune(0x02251) + of "efDot", "fallingdotseq": Rune(0x02252) + of "erDot", "risingdotseq": Rune(0x02253) + of "colone", "coloneq", "Assign": Rune(0x02254) + of "ecolon", "eqcolon": Rune(0x02255) + of "ecir", "eqcirc": Rune(0x02256) + of "cire", "circeq": Rune(0x02257) + of "wedgeq": Rune(0x02259) + of "veeeq": Rune(0x0225A) + of "trie", "triangleq": Rune(0x0225C) + of "equest", "questeq": Rune(0x0225F) + of "ne", "NotEqual": Rune(0x02260) + of "equiv", "Congruent": Rune(0x02261) + of "nequiv", "NotCongruent": Rune(0x02262) + of "le", "leq": Rune(0x02264) + of "ge", "GreaterEqual", "geq": Rune(0x02265) + of "lE", "LessFullEqual", "leqq": Rune(0x02266) + of "gE", "GreaterFullEqual", "geqq": Rune(0x02267) + of "lnE", "lneqq": Rune(0x02268) + of "gnE", "gneqq": Rune(0x02269) + of "Lt", "NestedLessLess", "ll": Rune(0x0226A) + of "Gt", "NestedGreaterGreater", "gg": Rune(0x0226B) + of "twixt", "between": Rune(0x0226C) + of "NotCupCap": Rune(0x0226D) + of "nlt", "NotLess", "nless": Rune(0x0226E) + of "ngt", "NotGreater", "ngtr": Rune(0x0226F) + of "nle", "NotLessEqual", "nleq": Rune(0x02270) + of "nge", "NotGreaterEqual", "ngeq": Rune(0x02271) + of "lsim", "LessTilde", "lesssim": Rune(0x02272) + of "gsim", "gtrsim", "GreaterTilde": Rune(0x02273) + of "nlsim", "NotLessTilde": Rune(0x02274) + of "ngsim", "NotGreaterTilde": Rune(0x02275) + of "lg", "lessgtr", "LessGreater": Rune(0x02276) + of "gl", "gtrless", "GreaterLess": Rune(0x02277) + of "ntlg", "NotLessGreater": Rune(0x02278) + of "ntgl", "NotGreaterLess": Rune(0x02279) + of "pr", "Precedes", "prec": Rune(0x0227A) + of "sc", "Succeeds", "succ": Rune(0x0227B) + of "prcue", "PrecedesSlantEqual", "preccurlyeq": Rune(0x0227C) + of "sccue", "SucceedsSlantEqual", "succcurlyeq": Rune(0x0227D) + of "prsim", "precsim", "PrecedesTilde": Rune(0x0227E) + of "scsim", "succsim", "SucceedsTilde": Rune(0x0227F) + of "npr", "nprec", "NotPrecedes": Rune(0x02280) + of "nsc", "nsucc", "NotSucceeds": Rune(0x02281) + of "sub", "subset": Rune(0x02282) + of "sup", "supset", "Superset": Rune(0x02283) + of "nsub": Rune(0x02284) + of "nsup": Rune(0x02285) + of "sube", "SubsetEqual", "subseteq": Rune(0x02286) + of "supe", "supseteq", "SupersetEqual": Rune(0x02287) + of "nsube", "nsubseteq", "NotSubsetEqual": Rune(0x02288) + of "nsupe", "nsupseteq", "NotSupersetEqual": Rune(0x02289) + of "subne", "subsetneq": Rune(0x0228A) + of "supne", "supsetneq": Rune(0x0228B) + of "cupdot": Rune(0x0228D) + of "uplus", "UnionPlus": Rune(0x0228E) + of "sqsub", "SquareSubset", "sqsubset": Rune(0x0228F) + of "sqsup", "SquareSuperset", "sqsupset": Rune(0x02290) + of "sqsube", "SquareSubsetEqual", "sqsubseteq": Rune(0x02291) + of "sqsupe", "SquareSupersetEqual", "sqsupseteq": Rune(0x02292) + of "sqcap", "SquareIntersection": Rune(0x02293) + of "sqcup", "SquareUnion": Rune(0x02294) + of "oplus", "CirclePlus": Rune(0x02295) + of "ominus", "CircleMinus": Rune(0x02296) + of "otimes", "CircleTimes": Rune(0x02297) + of "osol": Rune(0x02298) + of "odot", "CircleDot": Rune(0x02299) + of "ocir", "circledcirc": Rune(0x0229A) + of "oast", "circledast": Rune(0x0229B) + of "odash", "circleddash": Rune(0x0229D) + of "plusb", "boxplus": Rune(0x0229E) + of "minusb", "boxminus": Rune(0x0229F) + of "timesb", "boxtimes": Rune(0x022A0) + of "sdotb", "dotsquare": Rune(0x022A1) + of "vdash", "RightTee": Rune(0x022A2) + of "dashv", "LeftTee": Rune(0x022A3) + of "top", "DownTee": Rune(0x022A4) + of "bottom", "bot", "perp", "UpTee": Rune(0x022A5) + of "models": Rune(0x022A7) + of "vDash", "DoubleRightTee": Rune(0x022A8) + of "Vdash": Rune(0x022A9) + of "Vvdash": Rune(0x022AA) + of "VDash": Rune(0x022AB) + of "nvdash": Rune(0x022AC) + of "nvDash": Rune(0x022AD) + of "nVdash": Rune(0x022AE) + of "nVDash": Rune(0x022AF) + of "prurel": Rune(0x022B0) + of "vltri", "vartriangleleft", "LeftTriangle": Rune(0x022B2) + of "vrtri", "vartriangleright", "RightTriangle": Rune(0x022B3) + of "ltrie", "trianglelefteq", "LeftTriangleEqual": Rune(0x022B4) + of "rtrie", "trianglerighteq", "RightTriangleEqual": Rune(0x022B5) + of "origof": Rune(0x022B6) + of "imof": Rune(0x022B7) + of "mumap", "multimap": Rune(0x022B8) + of "hercon": Rune(0x022B9) + of "intcal", "intercal": Rune(0x022BA) + of "veebar": Rune(0x022BB) + of "barvee": Rune(0x022BD) + of "angrtvb": Rune(0x022BE) + of "lrtri": Rune(0x022BF) + of "xwedge", "Wedge", "bigwedge": Rune(0x022C0) + of "xvee", "Vee", "bigvee": Rune(0x022C1) + of "xcap", "Intersection", "bigcap": Rune(0x022C2) + of "xcup", "Union", "bigcup": Rune(0x022C3) + of "diam", "diamond", "Diamond": Rune(0x022C4) + of "sdot": Rune(0x022C5) + of "sstarf", "Star": Rune(0x022C6) + of "divonx", "divideontimes": Rune(0x022C7) + of "bowtie": Rune(0x022C8) + of "ltimes": Rune(0x022C9) + of "rtimes": Rune(0x022CA) + of "lthree", "leftthreetimes": Rune(0x022CB) + of "rthree", "rightthreetimes": Rune(0x022CC) + of "bsime", "backsimeq": Rune(0x022CD) + of "cuvee", "curlyvee": Rune(0x022CE) + of "cuwed", "curlywedge": Rune(0x022CF) + of "Sub", "Subset": Rune(0x022D0) + of "Sup", "Supset": Rune(0x022D1) + of "Cap": Rune(0x022D2) + of "Cup": Rune(0x022D3) + of "fork", "pitchfork": Rune(0x022D4) + of "epar": Rune(0x022D5) + of "ltdot", "lessdot": Rune(0x022D6) + of "gtdot", "gtrdot": Rune(0x022D7) + of "Ll": Rune(0x022D8) + of "Gg", "ggg": Rune(0x022D9) + of "leg", "LessEqualGreater", "lesseqgtr": Rune(0x022DA) + of "gel", "gtreqless", "GreaterEqualLess": Rune(0x022DB) + of "cuepr", "curlyeqprec": Rune(0x022DE) + of "cuesc", "curlyeqsucc": Rune(0x022DF) + of "nprcue", "NotPrecedesSlantEqual": Rune(0x022E0) + of "nsccue", "NotSucceedsSlantEqual": Rune(0x022E1) + of "nsqsube", "NotSquareSubsetEqual": Rune(0x022E2) + of "nsqsupe", "NotSquareSupersetEqual": Rune(0x022E3) + of "lnsim": Rune(0x022E6) + of "gnsim": Rune(0x022E7) + of "prnsim", "precnsim": Rune(0x022E8) + of "scnsim", "succnsim": Rune(0x022E9) + of "nltri", "ntriangleleft", "NotLeftTriangle": Rune(0x022EA) + of "nrtri", "ntriangleright", "NotRightTriangle": Rune(0x022EB) of "nltrie", "ntrianglelefteq", - "NotLeftTriangleEqual": result = Rune(0x022EC) + "NotLeftTriangleEqual": Rune(0x022EC) of "nrtrie", "ntrianglerighteq", - "NotRightTriangleEqual": result = Rune(0x022ED) - of "vellip": result = Rune(0x022EE) - of "ctdot": result = Rune(0x022EF) - of "utdot": result = Rune(0x022F0) - of "dtdot": result = Rune(0x022F1) - of "disin": result = Rune(0x022F2) - of "isinsv": result = Rune(0x022F3) - of "isins": result = Rune(0x022F4) - of "isindot": result = Rune(0x022F5) - of "notinvc": result = Rune(0x022F6) - of "notinvb": result = Rune(0x022F7) - of "isinE": result = Rune(0x022F9) - of "nisd": result = Rune(0x022FA) - of "xnis": result = Rune(0x022FB) - of "nis": result = Rune(0x022FC) - of "notnivc": result = Rune(0x022FD) - of "notnivb": result = Rune(0x022FE) - of "barwed", "barwedge": result = Rune(0x02305) - of "Barwed", "doublebarwedge": result = Rune(0x02306) - of "lceil", "LeftCeiling": result = Rune(0x02308) - of "rceil", "RightCeiling": result = Rune(0x02309) - of "lfloor", "LeftFloor": result = Rune(0x0230A) - of "rfloor", "RightFloor": result = Rune(0x0230B) - of "drcrop": result = Rune(0x0230C) - of "dlcrop": result = Rune(0x0230D) - of "urcrop": result = Rune(0x0230E) - of "ulcrop": result = Rune(0x0230F) - of "bnot": result = Rune(0x02310) - of "profline": result = Rune(0x02312) - of "profsurf": result = Rune(0x02313) - of "telrec": result = Rune(0x02315) - of "target": result = Rune(0x02316) - of "ulcorn", "ulcorner": result = Rune(0x0231C) - of "urcorn", "urcorner": result = Rune(0x0231D) - of "dlcorn", "llcorner": result = Rune(0x0231E) - of "drcorn", "lrcorner": result = Rune(0x0231F) - of "frown", "sfrown": result = Rune(0x02322) - of "smile", "ssmile": result = Rune(0x02323) - of "cylcty": result = Rune(0x0232D) - of "profalar": result = Rune(0x0232E) - of "topbot": result = Rune(0x02336) - of "ovbar": result = Rune(0x0233D) - of "solbar": result = Rune(0x0233F) - of "angzarr": result = Rune(0x0237C) - of "lmoust", "lmoustache": result = Rune(0x023B0) - of "rmoust", "rmoustache": result = Rune(0x023B1) - of "tbrk", "OverBracket": result = Rune(0x023B4) - of "bbrk", "UnderBracket": result = Rune(0x023B5) - of "bbrktbrk": result = Rune(0x023B6) - of "OverParenthesis": result = Rune(0x023DC) - of "UnderParenthesis": result = Rune(0x023DD) - of "OverBrace": result = Rune(0x023DE) - of "UnderBrace": result = Rune(0x023DF) - of "trpezium": result = Rune(0x023E2) - of "elinters": result = Rune(0x023E7) - of "blank": result = Rune(0x02423) - of "oS", "circledS": result = Rune(0x024C8) - of "boxh", "HorizontalLine": result = Rune(0x02500) - of "boxv": result = Rune(0x02502) - of "boxdr": result = Rune(0x0250C) - of "boxdl": result = Rune(0x02510) - of "boxur": result = Rune(0x02514) - of "boxul": result = Rune(0x02518) - of "boxvr": result = Rune(0x0251C) - of "boxvl": result = Rune(0x02524) - of "boxhd": result = Rune(0x0252C) - of "boxhu": result = Rune(0x02534) - of "boxvh": result = Rune(0x0253C) - of "boxH": result = Rune(0x02550) - of "boxV": result = Rune(0x02551) - of "boxdR": result = Rune(0x02552) - of "boxDr": result = Rune(0x02553) - of "boxDR": result = Rune(0x02554) - of "boxdL": result = Rune(0x02555) - of "boxDl": result = Rune(0x02556) - of "boxDL": result = Rune(0x02557) - of "boxuR": result = Rune(0x02558) - of "boxUr": result = Rune(0x02559) - of "boxUR": result = Rune(0x0255A) - of "boxuL": result = Rune(0x0255B) - of "boxUl": result = Rune(0x0255C) - of "boxUL": result = Rune(0x0255D) - of "boxvR": result = Rune(0x0255E) - of "boxVr": result = Rune(0x0255F) - of "boxVR": result = Rune(0x02560) - of "boxvL": result = Rune(0x02561) - of "boxVl": result = Rune(0x02562) - of "boxVL": result = Rune(0x02563) - of "boxHd": result = Rune(0x02564) - of "boxhD": result = Rune(0x02565) - of "boxHD": result = Rune(0x02566) - of "boxHu": result = Rune(0x02567) - of "boxhU": result = Rune(0x02568) - of "boxHU": result = Rune(0x02569) - of "boxvH": result = Rune(0x0256A) - of "boxVh": result = Rune(0x0256B) - of "boxVH": result = Rune(0x0256C) - of "uhblk": result = Rune(0x02580) - of "lhblk": result = Rune(0x02584) - of "block": result = Rune(0x02588) - of "blk14": result = Rune(0x02591) - of "blk12": result = Rune(0x02592) - of "blk34": result = Rune(0x02593) - of "squ", "square", "Square": result = Rune(0x025A1) + "NotRightTriangleEqual": Rune(0x022ED) + of "vellip": Rune(0x022EE) + of "ctdot": Rune(0x022EF) + of "utdot": Rune(0x022F0) + of "dtdot": Rune(0x022F1) + of "disin": Rune(0x022F2) + of "isinsv": Rune(0x022F3) + of "isins": Rune(0x022F4) + of "isindot": Rune(0x022F5) + of "notinvc": Rune(0x022F6) + of "notinvb": Rune(0x022F7) + of "isinE": Rune(0x022F9) + of "nisd": Rune(0x022FA) + of "xnis": Rune(0x022FB) + of "nis": Rune(0x022FC) + of "notnivc": Rune(0x022FD) + of "notnivb": Rune(0x022FE) + of "barwed", "barwedge": Rune(0x02305) + of "Barwed", "doublebarwedge": Rune(0x02306) + of "lceil", "LeftCeiling": Rune(0x02308) + of "rceil", "RightCeiling": Rune(0x02309) + of "lfloor", "LeftFloor": Rune(0x0230A) + of "rfloor", "RightFloor": Rune(0x0230B) + of "drcrop": Rune(0x0230C) + of "dlcrop": Rune(0x0230D) + of "urcrop": Rune(0x0230E) + of "ulcrop": Rune(0x0230F) + of "bnot": Rune(0x02310) + of "profline": Rune(0x02312) + of "profsurf": Rune(0x02313) + of "telrec": Rune(0x02315) + of "target": Rune(0x02316) + of "ulcorn", "ulcorner": Rune(0x0231C) + of "urcorn", "urcorner": Rune(0x0231D) + of "dlcorn", "llcorner": Rune(0x0231E) + of "drcorn", "lrcorner": Rune(0x0231F) + of "frown", "sfrown": Rune(0x02322) + of "smile", "ssmile": Rune(0x02323) + of "cylcty": Rune(0x0232D) + of "profalar": Rune(0x0232E) + of "topbot": Rune(0x02336) + of "ovbar": Rune(0x0233D) + of "solbar": Rune(0x0233F) + of "angzarr": Rune(0x0237C) + of "lmoust", "lmoustache": Rune(0x023B0) + of "rmoust", "rmoustache": Rune(0x023B1) + of "tbrk", "OverBracket": Rune(0x023B4) + of "bbrk", "UnderBracket": Rune(0x023B5) + of "bbrktbrk": Rune(0x023B6) + of "OverParenthesis": Rune(0x023DC) + of "UnderParenthesis": Rune(0x023DD) + of "OverBrace": Rune(0x023DE) + of "UnderBrace": Rune(0x023DF) + of "trpezium": Rune(0x023E2) + of "elinters": Rune(0x023E7) + of "blank": Rune(0x02423) + of "oS", "circledS": Rune(0x024C8) + of "boxh", "HorizontalLine": Rune(0x02500) + of "boxv": Rune(0x02502) + of "boxdr": Rune(0x0250C) + of "boxdl": Rune(0x02510) + of "boxur": Rune(0x02514) + of "boxul": Rune(0x02518) + of "boxvr": Rune(0x0251C) + of "boxvl": Rune(0x02524) + of "boxhd": Rune(0x0252C) + of "boxhu": Rune(0x02534) + of "boxvh": Rune(0x0253C) + of "boxH": Rune(0x02550) + of "boxV": Rune(0x02551) + of "boxdR": Rune(0x02552) + of "boxDr": Rune(0x02553) + of "boxDR": Rune(0x02554) + of "boxdL": Rune(0x02555) + of "boxDl": Rune(0x02556) + of "boxDL": Rune(0x02557) + of "boxuR": Rune(0x02558) + of "boxUr": Rune(0x02559) + of "boxUR": Rune(0x0255A) + of "boxuL": Rune(0x0255B) + of "boxUl": Rune(0x0255C) + of "boxUL": Rune(0x0255D) + of "boxvR": Rune(0x0255E) + of "boxVr": Rune(0x0255F) + of "boxVR": Rune(0x02560) + of "boxvL": Rune(0x02561) + of "boxVl": Rune(0x02562) + of "boxVL": Rune(0x02563) + of "boxHd": Rune(0x02564) + of "boxhD": Rune(0x02565) + of "boxHD": Rune(0x02566) + of "boxHu": Rune(0x02567) + of "boxhU": Rune(0x02568) + of "boxHU": Rune(0x02569) + of "boxvH": Rune(0x0256A) + of "boxVh": Rune(0x0256B) + of "boxVH": Rune(0x0256C) + of "uhblk": Rune(0x02580) + of "lhblk": Rune(0x02584) + of "block": Rune(0x02588) + of "blk14": Rune(0x02591) + of "blk12": Rune(0x02592) + of "blk34": Rune(0x02593) + of "squ", "square", "Square": Rune(0x025A1) of "squf", "squarf", "blacksquare", - "FilledVerySmallSquare": result = Rune(0x025AA) - of "EmptyVerySmallSquare": result = Rune(0x025AB) - of "rect": result = Rune(0x025AD) - of "marker": result = Rune(0x025AE) - of "fltns": result = Rune(0x025B1) - of "xutri", "bigtriangleup": result = Rune(0x025B3) - of "utrif", "blacktriangle": result = Rune(0x025B4) - of "utri", "triangle": result = Rune(0x025B5) - of "rtrif", "blacktriangleright": result = Rune(0x025B8) - of "rtri", "triangleright": result = Rune(0x025B9) - of "xdtri", "bigtriangledown": result = Rune(0x025BD) - of "dtrif", "blacktriangledown": result = Rune(0x025BE) - of "dtri", "triangledown": result = Rune(0x025BF) - of "ltrif", "blacktriangleleft": result = Rune(0x025C2) - of "ltri", "triangleleft": result = Rune(0x025C3) - of "loz", "lozenge": result = Rune(0x025CA) - of "cir": result = Rune(0x025CB) - of "tridot": result = Rune(0x025EC) - of "xcirc", "bigcirc": result = Rune(0x025EF) - of "ultri": result = Rune(0x025F8) - of "urtri": result = Rune(0x025F9) - of "lltri": result = Rune(0x025FA) - of "EmptySmallSquare": result = Rune(0x025FB) - of "FilledSmallSquare": result = Rune(0x025FC) - of "starf", "bigstar": result = Rune(0x02605) - of "star": result = Rune(0x02606) - of "phone": result = Rune(0x0260E) - of "female": result = Rune(0x02640) - of "male": result = Rune(0x02642) - of "spades", "spadesuit": result = Rune(0x02660) - of "clubs", "clubsuit": result = Rune(0x02663) - of "hearts", "heartsuit": result = Rune(0x02665) - of "diams", "diamondsuit": result = Rune(0x02666) - of "sung": result = Rune(0x0266A) - of "flat": result = Rune(0x0266D) - of "natur", "natural": result = Rune(0x0266E) - of "sharp": result = Rune(0x0266F) - of "check", "checkmark": result = Rune(0x02713) - of "cross": result = Rune(0x02717) - of "malt", "maltese": result = Rune(0x02720) - of "sext": result = Rune(0x02736) - of "VerticalSeparator": result = Rune(0x02758) - of "lbbrk": result = Rune(0x02772) - of "rbbrk": result = Rune(0x02773) - of "lobrk", "LeftDoubleBracket": result = Rune(0x027E6) - of "robrk", "RightDoubleBracket": result = Rune(0x027E7) - of "lang", "LeftAngleBracket", "langle": result = Rune(0x027E8) - of "rang", "RightAngleBracket", "rangle": result = Rune(0x027E9) - of "Lang": result = Rune(0x027EA) - of "Rang": result = Rune(0x027EB) - of "loang": result = Rune(0x027EC) - of "roang": result = Rune(0x027ED) - of "xlarr", "longleftarrow", "LongLeftArrow": result = Rune(0x027F5) - of "xrarr", "longrightarrow", "LongRightArrow": result = Rune(0x027F6) + "FilledVerySmallSquare": Rune(0x025AA) + of "EmptyVerySmallSquare": Rune(0x025AB) + of "rect": Rune(0x025AD) + of "marker": Rune(0x025AE) + of "fltns": Rune(0x025B1) + of "xutri", "bigtriangleup": Rune(0x025B3) + of "utrif", "blacktriangle": Rune(0x025B4) + of "utri", "triangle": Rune(0x025B5) + of "rtrif", "blacktriangleright": Rune(0x025B8) + of "rtri", "triangleright": Rune(0x025B9) + of "xdtri", "bigtriangledown": Rune(0x025BD) + of "dtrif", "blacktriangledown": Rune(0x025BE) + of "dtri", "triangledown": Rune(0x025BF) + of "ltrif", "blacktriangleleft": Rune(0x025C2) + of "ltri", "triangleleft": Rune(0x025C3) + of "loz", "lozenge": Rune(0x025CA) + of "cir": Rune(0x025CB) + of "tridot": Rune(0x025EC) + of "xcirc", "bigcirc": Rune(0x025EF) + of "ultri": Rune(0x025F8) + of "urtri": Rune(0x025F9) + of "lltri": Rune(0x025FA) + of "EmptySmallSquare": Rune(0x025FB) + of "FilledSmallSquare": Rune(0x025FC) + of "starf", "bigstar": Rune(0x02605) + of "star": Rune(0x02606) + of "phone": Rune(0x0260E) + of "female": Rune(0x02640) + of "male": Rune(0x02642) + of "spades", "spadesuit": Rune(0x02660) + of "clubs", "clubsuit": Rune(0x02663) + of "hearts", "heartsuit": Rune(0x02665) + of "diams", "diamondsuit": Rune(0x02666) + of "sung": Rune(0x0266A) + of "flat": Rune(0x0266D) + of "natur", "natural": Rune(0x0266E) + of "sharp": Rune(0x0266F) + of "check", "checkmark": Rune(0x02713) + of "cross": Rune(0x02717) + of "malt", "maltese": Rune(0x02720) + of "sext": Rune(0x02736) + of "VerticalSeparator": Rune(0x02758) + of "lbbrk": Rune(0x02772) + of "rbbrk": Rune(0x02773) + of "lobrk", "LeftDoubleBracket": Rune(0x027E6) + of "robrk", "RightDoubleBracket": Rune(0x027E7) + of "lang", "LeftAngleBracket", "langle": Rune(0x027E8) + of "rang", "RightAngleBracket", "rangle": Rune(0x027E9) + of "Lang": Rune(0x027EA) + of "Rang": Rune(0x027EB) + of "loang": Rune(0x027EC) + of "roang": Rune(0x027ED) + of "xlarr", "longleftarrow", "LongLeftArrow": Rune(0x027F5) + of "xrarr", "longrightarrow", "LongRightArrow": Rune(0x027F6) of "xharr", "longleftrightarrow", - "LongLeftRightArrow": result = Rune(0x027F7) - of "xlArr", "Longleftarrow", "DoubleLongLeftArrow": result = Rune(0x027F8) - of "xrArr", "Longrightarrow", "DoubleLongRightArrow": result = Rune(0x027F9) + "LongLeftRightArrow": Rune(0x027F7) + of "xlArr", "Longleftarrow", "DoubleLongLeftArrow": Rune(0x027F8) + of "xrArr", "Longrightarrow", "DoubleLongRightArrow": Rune(0x027F9) of "xhArr", "Longleftrightarrow", - "DoubleLongLeftRightArrow": result = Rune(0x027FA) - of "xmap", "longmapsto": result = Rune(0x027FC) - of "dzigrarr": result = Rune(0x027FF) - of "nvlArr": result = Rune(0x02902) - of "nvrArr": result = Rune(0x02903) - of "nvHarr": result = Rune(0x02904) - of "Map": result = Rune(0x02905) - of "lbarr": result = Rune(0x0290C) - of "rbarr", "bkarow": result = Rune(0x0290D) - of "lBarr": result = Rune(0x0290E) - of "rBarr", "dbkarow": result = Rune(0x0290F) - of "RBarr", "drbkarow": result = Rune(0x02910) - of "DDotrahd": result = Rune(0x02911) - of "UpArrowBar": result = Rune(0x02912) - of "DownArrowBar": result = Rune(0x02913) - of "Rarrtl": result = Rune(0x02916) - of "latail": result = Rune(0x02919) - of "ratail": result = Rune(0x0291A) - of "lAtail": result = Rune(0x0291B) - of "rAtail": result = Rune(0x0291C) - of "larrfs": result = Rune(0x0291D) - of "rarrfs": result = Rune(0x0291E) - of "larrbfs": result = Rune(0x0291F) - of "rarrbfs": result = Rune(0x02920) - of "nwarhk": result = Rune(0x02923) - of "nearhk": result = Rune(0x02924) - of "searhk", "hksearow": result = Rune(0x02925) - of "swarhk", "hkswarow": result = Rune(0x02926) - of "nwnear": result = Rune(0x02927) - of "nesear", "toea": result = Rune(0x02928) - of "seswar", "tosa": result = Rune(0x02929) - of "swnwar": result = Rune(0x0292A) - of "rarrc": result = Rune(0x02933) - of "cudarrr": result = Rune(0x02935) - of "ldca": result = Rune(0x02936) - of "rdca": result = Rune(0x02937) - of "cudarrl": result = Rune(0x02938) - of "larrpl": result = Rune(0x02939) - of "curarrm": result = Rune(0x0293C) - of "cularrp": result = Rune(0x0293D) - of "rarrpl": result = Rune(0x02945) - of "harrcir": result = Rune(0x02948) - of "Uarrocir": result = Rune(0x02949) - of "lurdshar": result = Rune(0x0294A) - of "ldrushar": result = Rune(0x0294B) - of "LeftRightVector": result = Rune(0x0294E) - of "RightUpDownVector": result = Rune(0x0294F) - of "DownLeftRightVector": result = Rune(0x02950) - of "LeftUpDownVector": result = Rune(0x02951) - of "LeftVectorBar": result = Rune(0x02952) - of "RightVectorBar": result = Rune(0x02953) - of "RightUpVectorBar": result = Rune(0x02954) - of "RightDownVectorBar": result = Rune(0x02955) - of "DownLeftVectorBar": result = Rune(0x02956) - of "DownRightVectorBar": result = Rune(0x02957) - of "LeftUpVectorBar": result = Rune(0x02958) - of "LeftDownVectorBar": result = Rune(0x02959) - of "LeftTeeVector": result = Rune(0x0295A) - of "RightTeeVector": result = Rune(0x0295B) - of "RightUpTeeVector": result = Rune(0x0295C) - of "RightDownTeeVector": result = Rune(0x0295D) - of "DownLeftTeeVector": result = Rune(0x0295E) - of "DownRightTeeVector": result = Rune(0x0295F) - of "LeftUpTeeVector": result = Rune(0x02960) - of "LeftDownTeeVector": result = Rune(0x02961) - of "lHar": result = Rune(0x02962) - of "uHar": result = Rune(0x02963) - of "rHar": result = Rune(0x02964) - of "dHar": result = Rune(0x02965) - of "luruhar": result = Rune(0x02966) - of "ldrdhar": result = Rune(0x02967) - of "ruluhar": result = Rune(0x02968) - of "rdldhar": result = Rune(0x02969) - of "lharul": result = Rune(0x0296A) - of "llhard": result = Rune(0x0296B) - of "rharul": result = Rune(0x0296C) - of "lrhard": result = Rune(0x0296D) - of "udhar", "UpEquilibrium": result = Rune(0x0296E) - of "duhar", "ReverseUpEquilibrium": result = Rune(0x0296F) - of "RoundImplies": result = Rune(0x02970) - of "erarr": result = Rune(0x02971) - of "simrarr": result = Rune(0x02972) - of "larrsim": result = Rune(0x02973) - of "rarrsim": result = Rune(0x02974) - of "rarrap": result = Rune(0x02975) - of "ltlarr": result = Rune(0x02976) - of "gtrarr": result = Rune(0x02978) - of "subrarr": result = Rune(0x02979) - of "suplarr": result = Rune(0x0297B) - of "lfisht": result = Rune(0x0297C) - of "rfisht": result = Rune(0x0297D) - of "ufisht": result = Rune(0x0297E) - of "dfisht": result = Rune(0x0297F) - of "lopar": result = Rune(0x02985) - of "ropar": result = Rune(0x02986) - of "lbrke": result = Rune(0x0298B) - of "rbrke": result = Rune(0x0298C) - of "lbrkslu": result = Rune(0x0298D) - of "rbrksld": result = Rune(0x0298E) - of "lbrksld": result = Rune(0x0298F) - of "rbrkslu": result = Rune(0x02990) - of "langd": result = Rune(0x02991) - of "rangd": result = Rune(0x02992) - of "lparlt": result = Rune(0x02993) - of "rpargt": result = Rune(0x02994) - of "gtlPar": result = Rune(0x02995) - of "ltrPar": result = Rune(0x02996) - of "vzigzag": result = Rune(0x0299A) - of "vangrt": result = Rune(0x0299C) - of "angrtvbd": result = Rune(0x0299D) - of "ange": result = Rune(0x029A4) - of "range": result = Rune(0x029A5) - of "dwangle": result = Rune(0x029A6) - of "uwangle": result = Rune(0x029A7) - of "angmsdaa": result = Rune(0x029A8) - of "angmsdab": result = Rune(0x029A9) - of "angmsdac": result = Rune(0x029AA) - of "angmsdad": result = Rune(0x029AB) - of "angmsdae": result = Rune(0x029AC) - of "angmsdaf": result = Rune(0x029AD) - of "angmsdag": result = Rune(0x029AE) - of "angmsdah": result = Rune(0x029AF) - of "bemptyv": result = Rune(0x029B0) - of "demptyv": result = Rune(0x029B1) - of "cemptyv": result = Rune(0x029B2) - of "raemptyv": result = Rune(0x029B3) - of "laemptyv": result = Rune(0x029B4) - of "ohbar": result = Rune(0x029B5) - of "omid": result = Rune(0x029B6) - of "opar": result = Rune(0x029B7) - of "operp": result = Rune(0x029B9) - of "olcross": result = Rune(0x029BB) - of "odsold": result = Rune(0x029BC) - of "olcir": result = Rune(0x029BE) - of "ofcir": result = Rune(0x029BF) - of "olt": result = Rune(0x029C0) - of "ogt": result = Rune(0x029C1) - of "cirscir": result = Rune(0x029C2) - of "cirE": result = Rune(0x029C3) - of "solb": result = Rune(0x029C4) - of "bsolb": result = Rune(0x029C5) - of "boxbox": result = Rune(0x029C9) - of "trisb": result = Rune(0x029CD) - of "rtriltri": result = Rune(0x029CE) - of "LeftTriangleBar": result = Rune(0x029CF) - of "RightTriangleBar": result = Rune(0x029D0) - of "race": result = Rune(0x029DA) - of "iinfin": result = Rune(0x029DC) - of "infintie": result = Rune(0x029DD) - of "nvinfin": result = Rune(0x029DE) - of "eparsl": result = Rune(0x029E3) - of "smeparsl": result = Rune(0x029E4) - of "eqvparsl": result = Rune(0x029E5) - of "lozf", "blacklozenge": result = Rune(0x029EB) - of "RuleDelayed": result = Rune(0x029F4) - of "dsol": result = Rune(0x029F6) - of "xodot", "bigodot": result = Rune(0x02A00) - of "xoplus", "bigoplus": result = Rune(0x02A01) - of "xotime", "bigotimes": result = Rune(0x02A02) - of "xuplus", "biguplus": result = Rune(0x02A04) - of "xsqcup", "bigsqcup": result = Rune(0x02A06) - of "qint", "iiiint": result = Rune(0x02A0C) - of "fpartint": result = Rune(0x02A0D) - of "cirfnint": result = Rune(0x02A10) - of "awint": result = Rune(0x02A11) - of "rppolint": result = Rune(0x02A12) - of "scpolint": result = Rune(0x02A13) - of "npolint": result = Rune(0x02A14) - of "pointint": result = Rune(0x02A15) - of "quatint": result = Rune(0x02A16) - of "intlarhk": result = Rune(0x02A17) - of "pluscir": result = Rune(0x02A22) - of "plusacir": result = Rune(0x02A23) - of "simplus": result = Rune(0x02A24) - of "plusdu": result = Rune(0x02A25) - of "plussim": result = Rune(0x02A26) - of "plustwo": result = Rune(0x02A27) - of "mcomma": result = Rune(0x02A29) - of "minusdu": result = Rune(0x02A2A) - of "loplus": result = Rune(0x02A2D) - of "roplus": result = Rune(0x02A2E) - of "Cross": result = Rune(0x02A2F) - of "timesd": result = Rune(0x02A30) - of "timesbar": result = Rune(0x02A31) - of "smashp": result = Rune(0x02A33) - of "lotimes": result = Rune(0x02A34) - of "rotimes": result = Rune(0x02A35) - of "otimesas": result = Rune(0x02A36) - of "Otimes": result = Rune(0x02A37) - of "odiv": result = Rune(0x02A38) - of "triplus": result = Rune(0x02A39) - of "triminus": result = Rune(0x02A3A) - of "tritime": result = Rune(0x02A3B) - of "iprod", "intprod": result = Rune(0x02A3C) - of "amalg": result = Rune(0x02A3F) - of "capdot": result = Rune(0x02A40) - of "ncup": result = Rune(0x02A42) - of "ncap": result = Rune(0x02A43) - of "capand": result = Rune(0x02A44) - of "cupor": result = Rune(0x02A45) - of "cupcap": result = Rune(0x02A46) - of "capcup": result = Rune(0x02A47) - of "cupbrcap": result = Rune(0x02A48) - of "capbrcup": result = Rune(0x02A49) - of "cupcup": result = Rune(0x02A4A) - of "capcap": result = Rune(0x02A4B) - of "ccups": result = Rune(0x02A4C) - of "ccaps": result = Rune(0x02A4D) - of "ccupssm": result = Rune(0x02A50) - of "And": result = Rune(0x02A53) - of "Or": result = Rune(0x02A54) - of "andand": result = Rune(0x02A55) - of "oror": result = Rune(0x02A56) - of "orslope": result = Rune(0x02A57) - of "andslope": result = Rune(0x02A58) - of "andv": result = Rune(0x02A5A) - of "orv": result = Rune(0x02A5B) - of "andd": result = Rune(0x02A5C) - of "ord": result = Rune(0x02A5D) - of "wedbar": result = Rune(0x02A5F) - of "sdote": result = Rune(0x02A66) - of "simdot": result = Rune(0x02A6A) - of "congdot": result = Rune(0x02A6D) - of "easter": result = Rune(0x02A6E) - of "apacir": result = Rune(0x02A6F) - of "apE": result = Rune(0x02A70) - of "eplus": result = Rune(0x02A71) - of "pluse": result = Rune(0x02A72) - of "Esim": result = Rune(0x02A73) - of "Colone": result = Rune(0x02A74) - of "Equal": result = Rune(0x02A75) - of "eDDot", "ddotseq": result = Rune(0x02A77) - of "equivDD": result = Rune(0x02A78) - of "ltcir": result = Rune(0x02A79) - of "gtcir": result = Rune(0x02A7A) - of "ltquest": result = Rune(0x02A7B) - of "gtquest": result = Rune(0x02A7C) - of "les", "LessSlantEqual", "leqslant": result = Rune(0x02A7D) - of "ges", "GreaterSlantEqual", "geqslant": result = Rune(0x02A7E) - of "lesdot": result = Rune(0x02A7F) - of "gesdot": result = Rune(0x02A80) - of "lesdoto": result = Rune(0x02A81) - of "gesdoto": result = Rune(0x02A82) - of "lesdotor": result = Rune(0x02A83) - of "gesdotol": result = Rune(0x02A84) - of "lap", "lessapprox": result = Rune(0x02A85) - of "gap", "gtrapprox": result = Rune(0x02A86) - of "lne", "lneq": result = Rune(0x02A87) - of "gne", "gneq": result = Rune(0x02A88) - of "lnap", "lnapprox": result = Rune(0x02A89) - of "gnap", "gnapprox": result = Rune(0x02A8A) - of "lEg", "lesseqqgtr": result = Rune(0x02A8B) - of "gEl", "gtreqqless": result = Rune(0x02A8C) - of "lsime": result = Rune(0x02A8D) - of "gsime": result = Rune(0x02A8E) - of "lsimg": result = Rune(0x02A8F) - of "gsiml": result = Rune(0x02A90) - of "lgE": result = Rune(0x02A91) - of "glE": result = Rune(0x02A92) - of "lesges": result = Rune(0x02A93) - of "gesles": result = Rune(0x02A94) - of "els", "eqslantless": result = Rune(0x02A95) - of "egs", "eqslantgtr": result = Rune(0x02A96) - of "elsdot": result = Rune(0x02A97) - of "egsdot": result = Rune(0x02A98) - of "el": result = Rune(0x02A99) - of "eg": result = Rune(0x02A9A) - of "siml": result = Rune(0x02A9D) - of "simg": result = Rune(0x02A9E) - of "simlE": result = Rune(0x02A9F) - of "simgE": result = Rune(0x02AA0) - of "LessLess": result = Rune(0x02AA1) - of "GreaterGreater": result = Rune(0x02AA2) - of "glj": result = Rune(0x02AA4) - of "gla": result = Rune(0x02AA5) - of "ltcc": result = Rune(0x02AA6) - of "gtcc": result = Rune(0x02AA7) - of "lescc": result = Rune(0x02AA8) - of "gescc": result = Rune(0x02AA9) - of "smt": result = Rune(0x02AAA) - of "lat": result = Rune(0x02AAB) - of "smte": result = Rune(0x02AAC) - of "late": result = Rune(0x02AAD) - of "bumpE": result = Rune(0x02AAE) - of "pre", "preceq", "PrecedesEqual": result = Rune(0x02AAF) - of "sce", "succeq", "SucceedsEqual": result = Rune(0x02AB0) - of "prE": result = Rune(0x02AB3) - of "scE": result = Rune(0x02AB4) - of "prnE", "precneqq": result = Rune(0x02AB5) - of "scnE", "succneqq": result = Rune(0x02AB6) - of "prap", "precapprox": result = Rune(0x02AB7) - of "scap", "succapprox": result = Rune(0x02AB8) - of "prnap", "precnapprox": result = Rune(0x02AB9) - of "scnap", "succnapprox": result = Rune(0x02ABA) - of "Pr": result = Rune(0x02ABB) - of "Sc": result = Rune(0x02ABC) - of "subdot": result = Rune(0x02ABD) - of "supdot": result = Rune(0x02ABE) - of "subplus": result = Rune(0x02ABF) - of "supplus": result = Rune(0x02AC0) - of "submult": result = Rune(0x02AC1) - of "supmult": result = Rune(0x02AC2) - of "subedot": result = Rune(0x02AC3) - of "supedot": result = Rune(0x02AC4) - of "subE", "subseteqq": result = Rune(0x02AC5) - of "supE", "supseteqq": result = Rune(0x02AC6) - of "subsim": result = Rune(0x02AC7) - of "supsim": result = Rune(0x02AC8) - of "subnE", "subsetneqq": result = Rune(0x02ACB) - of "supnE", "supsetneqq": result = Rune(0x02ACC) - of "csub": result = Rune(0x02ACF) - of "csup": result = Rune(0x02AD0) - of "csube": result = Rune(0x02AD1) - of "csupe": result = Rune(0x02AD2) - of "subsup": result = Rune(0x02AD3) - of "supsub": result = Rune(0x02AD4) - of "subsub": result = Rune(0x02AD5) - of "supsup": result = Rune(0x02AD6) - of "suphsub": result = Rune(0x02AD7) - of "supdsub": result = Rune(0x02AD8) - of "forkv": result = Rune(0x02AD9) - of "topfork": result = Rune(0x02ADA) - of "mlcp": result = Rune(0x02ADB) - of "Dashv", "DoubleLeftTee": result = Rune(0x02AE4) - of "Vdashl": result = Rune(0x02AE6) - of "Barv": result = Rune(0x02AE7) - of "vBar": result = Rune(0x02AE8) - of "vBarv": result = Rune(0x02AE9) - of "Vbar": result = Rune(0x02AEB) - of "Not": result = Rune(0x02AEC) - of "bNot": result = Rune(0x02AED) - of "rnmid": result = Rune(0x02AEE) - of "cirmid": result = Rune(0x02AEF) - of "midcir": result = Rune(0x02AF0) - of "topcir": result = Rune(0x02AF1) - of "nhpar": result = Rune(0x02AF2) - of "parsim": result = Rune(0x02AF3) - of "parsl": result = Rune(0x02AFD) - of "fflig": result = Rune(0x0FB00) - of "filig": result = Rune(0x0FB01) - of "fllig": result = Rune(0x0FB02) - of "ffilig": result = Rune(0x0FB03) - of "ffllig": result = Rune(0x0FB04) - of "Ascr": result = Rune(0x1D49C) - of "Cscr": result = Rune(0x1D49E) - of "Dscr": result = Rune(0x1D49F) - of "Gscr": result = Rune(0x1D4A2) - of "Jscr": result = Rune(0x1D4A5) - of "Kscr": result = Rune(0x1D4A6) - of "Nscr": result = Rune(0x1D4A9) - of "Oscr": result = Rune(0x1D4AA) - of "Pscr": result = Rune(0x1D4AB) - of "Qscr": result = Rune(0x1D4AC) - of "Sscr": result = Rune(0x1D4AE) - of "Tscr": result = Rune(0x1D4AF) - of "Uscr": result = Rune(0x1D4B0) - of "Vscr": result = Rune(0x1D4B1) - of "Wscr": result = Rune(0x1D4B2) - of "Xscr": result = Rune(0x1D4B3) - of "Yscr": result = Rune(0x1D4B4) - of "Zscr": result = Rune(0x1D4B5) - of "ascr": result = Rune(0x1D4B6) - of "bscr": result = Rune(0x1D4B7) - of "cscr": result = Rune(0x1D4B8) - of "dscr": result = Rune(0x1D4B9) - of "fscr": result = Rune(0x1D4BB) - of "hscr": result = Rune(0x1D4BD) - of "iscr": result = Rune(0x1D4BE) - of "jscr": result = Rune(0x1D4BF) - of "kscr": result = Rune(0x1D4C0) - of "lscr": result = Rune(0x1D4C1) - of "mscr": result = Rune(0x1D4C2) - of "nscr": result = Rune(0x1D4C3) - of "pscr": result = Rune(0x1D4C5) - of "qscr": result = Rune(0x1D4C6) - of "rscr": result = Rune(0x1D4C7) - of "sscr": result = Rune(0x1D4C8) - of "tscr": result = Rune(0x1D4C9) - of "uscr": result = Rune(0x1D4CA) - of "vscr": result = Rune(0x1D4CB) - of "wscr": result = Rune(0x1D4CC) - of "xscr": result = Rune(0x1D4CD) - of "yscr": result = Rune(0x1D4CE) - of "zscr": result = Rune(0x1D4CF) - of "Afr": result = Rune(0x1D504) - of "Bfr": result = Rune(0x1D505) - of "Dfr": result = Rune(0x1D507) - of "Efr": result = Rune(0x1D508) - of "Ffr": result = Rune(0x1D509) - of "Gfr": result = Rune(0x1D50A) - of "Jfr": result = Rune(0x1D50D) - of "Kfr": result = Rune(0x1D50E) - of "Lfr": result = Rune(0x1D50F) - of "Mfr": result = Rune(0x1D510) - of "Nfr": result = Rune(0x1D511) - of "Ofr": result = Rune(0x1D512) - of "Pfr": result = Rune(0x1D513) - of "Qfr": result = Rune(0x1D514) - of "Sfr": result = Rune(0x1D516) - of "Tfr": result = Rune(0x1D517) - of "Ufr": result = Rune(0x1D518) - of "Vfr": result = Rune(0x1D519) - of "Wfr": result = Rune(0x1D51A) - of "Xfr": result = Rune(0x1D51B) - of "Yfr": result = Rune(0x1D51C) - of "afr": result = Rune(0x1D51E) - of "bfr": result = Rune(0x1D51F) - of "cfr": result = Rune(0x1D520) - of "dfr": result = Rune(0x1D521) - of "efr": result = Rune(0x1D522) - of "ffr": result = Rune(0x1D523) - of "gfr": result = Rune(0x1D524) - of "hfr": result = Rune(0x1D525) - of "ifr": result = Rune(0x1D526) - of "jfr": result = Rune(0x1D527) - of "kfr": result = Rune(0x1D528) - of "lfr": result = Rune(0x1D529) - of "mfr": result = Rune(0x1D52A) - of "nfr": result = Rune(0x1D52B) - of "ofr": result = Rune(0x1D52C) - of "pfr": result = Rune(0x1D52D) - of "qfr": result = Rune(0x1D52E) - of "rfr": result = Rune(0x1D52F) - of "sfr": result = Rune(0x1D530) - of "tfr": result = Rune(0x1D531) - of "ufr": result = Rune(0x1D532) - of "vfr": result = Rune(0x1D533) - of "wfr": result = Rune(0x1D534) - of "xfr": result = Rune(0x1D535) - of "yfr": result = Rune(0x1D536) - of "zfr": result = Rune(0x1D537) - of "Aopf": result = Rune(0x1D538) - of "Bopf": result = Rune(0x1D539) - of "Dopf": result = Rune(0x1D53B) - of "Eopf": result = Rune(0x1D53C) - of "Fopf": result = Rune(0x1D53D) - of "Gopf": result = Rune(0x1D53E) - of "Iopf": result = Rune(0x1D540) - of "Jopf": result = Rune(0x1D541) - of "Kopf": result = Rune(0x1D542) - of "Lopf": result = Rune(0x1D543) - of "Mopf": result = Rune(0x1D544) - of "Oopf": result = Rune(0x1D546) - of "Sopf": result = Rune(0x1D54A) - of "Topf": result = Rune(0x1D54B) - of "Uopf": result = Rune(0x1D54C) - of "Vopf": result = Rune(0x1D54D) - of "Wopf": result = Rune(0x1D54E) - of "Xopf": result = Rune(0x1D54F) - of "Yopf": result = Rune(0x1D550) - of "aopf": result = Rune(0x1D552) - of "bopf": result = Rune(0x1D553) - of "copf": result = Rune(0x1D554) - of "dopf": result = Rune(0x1D555) - of "eopf": result = Rune(0x1D556) - of "fopf": result = Rune(0x1D557) - of "gopf": result = Rune(0x1D558) - of "hopf": result = Rune(0x1D559) - of "iopf": result = Rune(0x1D55A) - of "jopf": result = Rune(0x1D55B) - of "kopf": result = Rune(0x1D55C) - of "lopf": result = Rune(0x1D55D) - of "mopf": result = Rune(0x1D55E) - of "nopf": result = Rune(0x1D55F) - of "oopf": result = Rune(0x1D560) - of "popf": result = Rune(0x1D561) - of "qopf": result = Rune(0x1D562) - of "ropf": result = Rune(0x1D563) - of "sopf": result = Rune(0x1D564) - of "topf": result = Rune(0x1D565) - of "uopf": result = Rune(0x1D566) - of "vopf": result = Rune(0x1D567) - of "wopf": result = Rune(0x1D568) - of "xopf": result = Rune(0x1D569) - of "yopf": result = Rune(0x1D56A) - of "zopf": result = Rune(0x1D56B) - else: discard + "DoubleLongLeftRightArrow": Rune(0x027FA) + of "xmap", "longmapsto": Rune(0x027FC) + of "dzigrarr": Rune(0x027FF) + of "nvlArr": Rune(0x02902) + of "nvrArr": Rune(0x02903) + of "nvHarr": Rune(0x02904) + of "Map": Rune(0x02905) + of "lbarr": Rune(0x0290C) + of "rbarr", "bkarow": Rune(0x0290D) + of "lBarr": Rune(0x0290E) + of "rBarr", "dbkarow": Rune(0x0290F) + of "RBarr", "drbkarow": Rune(0x02910) + of "DDotrahd": Rune(0x02911) + of "UpArrowBar": Rune(0x02912) + of "DownArrowBar": Rune(0x02913) + of "Rarrtl": Rune(0x02916) + of "latail": Rune(0x02919) + of "ratail": Rune(0x0291A) + of "lAtail": Rune(0x0291B) + of "rAtail": Rune(0x0291C) + of "larrfs": Rune(0x0291D) + of "rarrfs": Rune(0x0291E) + of "larrbfs": Rune(0x0291F) + of "rarrbfs": Rune(0x02920) + of "nwarhk": Rune(0x02923) + of "nearhk": Rune(0x02924) + of "searhk", "hksearow": Rune(0x02925) + of "swarhk", "hkswarow": Rune(0x02926) + of "nwnear": Rune(0x02927) + of "nesear", "toea": Rune(0x02928) + of "seswar", "tosa": Rune(0x02929) + of "swnwar": Rune(0x0292A) + of "rarrc": Rune(0x02933) + of "cudarrr": Rune(0x02935) + of "ldca": Rune(0x02936) + of "rdca": Rune(0x02937) + of "cudarrl": Rune(0x02938) + of "larrpl": Rune(0x02939) + of "curarrm": Rune(0x0293C) + of "cularrp": Rune(0x0293D) + of "rarrpl": Rune(0x02945) + of "harrcir": Rune(0x02948) + of "Uarrocir": Rune(0x02949) + of "lurdshar": Rune(0x0294A) + of "ldrushar": Rune(0x0294B) + of "LeftRightVector": Rune(0x0294E) + of "RightUpDownVector": Rune(0x0294F) + of "DownLeftRightVector": Rune(0x02950) + of "LeftUpDownVector": Rune(0x02951) + of "LeftVectorBar": Rune(0x02952) + of "RightVectorBar": Rune(0x02953) + of "RightUpVectorBar": Rune(0x02954) + of "RightDownVectorBar": Rune(0x02955) + of "DownLeftVectorBar": Rune(0x02956) + of "DownRightVectorBar": Rune(0x02957) + of "LeftUpVectorBar": Rune(0x02958) + of "LeftDownVectorBar": Rune(0x02959) + of "LeftTeeVector": Rune(0x0295A) + of "RightTeeVector": Rune(0x0295B) + of "RightUpTeeVector": Rune(0x0295C) + of "RightDownTeeVector": Rune(0x0295D) + of "DownLeftTeeVector": Rune(0x0295E) + of "DownRightTeeVector": Rune(0x0295F) + of "LeftUpTeeVector": Rune(0x02960) + of "LeftDownTeeVector": Rune(0x02961) + of "lHar": Rune(0x02962) + of "uHar": Rune(0x02963) + of "rHar": Rune(0x02964) + of "dHar": Rune(0x02965) + of "luruhar": Rune(0x02966) + of "ldrdhar": Rune(0x02967) + of "ruluhar": Rune(0x02968) + of "rdldhar": Rune(0x02969) + of "lharul": Rune(0x0296A) + of "llhard": Rune(0x0296B) + of "rharul": Rune(0x0296C) + of "lrhard": Rune(0x0296D) + of "udhar", "UpEquilibrium": Rune(0x0296E) + of "duhar", "ReverseUpEquilibrium": Rune(0x0296F) + of "RoundImplies": Rune(0x02970) + of "erarr": Rune(0x02971) + of "simrarr": Rune(0x02972) + of "larrsim": Rune(0x02973) + of "rarrsim": Rune(0x02974) + of "rarrap": Rune(0x02975) + of "ltlarr": Rune(0x02976) + of "gtrarr": Rune(0x02978) + of "subrarr": Rune(0x02979) + of "suplarr": Rune(0x0297B) + of "lfisht": Rune(0x0297C) + of "rfisht": Rune(0x0297D) + of "ufisht": Rune(0x0297E) + of "dfisht": Rune(0x0297F) + of "lopar": Rune(0x02985) + of "ropar": Rune(0x02986) + of "lbrke": Rune(0x0298B) + of "rbrke": Rune(0x0298C) + of "lbrkslu": Rune(0x0298D) + of "rbrksld": Rune(0x0298E) + of "lbrksld": Rune(0x0298F) + of "rbrkslu": Rune(0x02990) + of "langd": Rune(0x02991) + of "rangd": Rune(0x02992) + of "lparlt": Rune(0x02993) + of "rpargt": Rune(0x02994) + of "gtlPar": Rune(0x02995) + of "ltrPar": Rune(0x02996) + of "vzigzag": Rune(0x0299A) + of "vangrt": Rune(0x0299C) + of "angrtvbd": Rune(0x0299D) + of "ange": Rune(0x029A4) + of "range": Rune(0x029A5) + of "dwangle": Rune(0x029A6) + of "uwangle": Rune(0x029A7) + of "angmsdaa": Rune(0x029A8) + of "angmsdab": Rune(0x029A9) + of "angmsdac": Rune(0x029AA) + of "angmsdad": Rune(0x029AB) + of "angmsdae": Rune(0x029AC) + of "angmsdaf": Rune(0x029AD) + of "angmsdag": Rune(0x029AE) + of "angmsdah": Rune(0x029AF) + of "bemptyv": Rune(0x029B0) + of "demptyv": Rune(0x029B1) + of "cemptyv": Rune(0x029B2) + of "raemptyv": Rune(0x029B3) + of "laemptyv": Rune(0x029B4) + of "ohbar": Rune(0x029B5) + of "omid": Rune(0x029B6) + of "opar": Rune(0x029B7) + of "operp": Rune(0x029B9) + of "olcross": Rune(0x029BB) + of "odsold": Rune(0x029BC) + of "olcir": Rune(0x029BE) + of "ofcir": Rune(0x029BF) + of "olt": Rune(0x029C0) + of "ogt": Rune(0x029C1) + of "cirscir": Rune(0x029C2) + of "cirE": Rune(0x029C3) + of "solb": Rune(0x029C4) + of "bsolb": Rune(0x029C5) + of "boxbox": Rune(0x029C9) + of "trisb": Rune(0x029CD) + of "rtriltri": Rune(0x029CE) + of "LeftTriangleBar": Rune(0x029CF) + of "RightTriangleBar": Rune(0x029D0) + of "race": Rune(0x029DA) + of "iinfin": Rune(0x029DC) + of "infintie": Rune(0x029DD) + of "nvinfin": Rune(0x029DE) + of "eparsl": Rune(0x029E3) + of "smeparsl": Rune(0x029E4) + of "eqvparsl": Rune(0x029E5) + of "lozf", "blacklozenge": Rune(0x029EB) + of "RuleDelayed": Rune(0x029F4) + of "dsol": Rune(0x029F6) + of "xodot", "bigodot": Rune(0x02A00) + of "xoplus", "bigoplus": Rune(0x02A01) + of "xotime", "bigotimes": Rune(0x02A02) + of "xuplus", "biguplus": Rune(0x02A04) + of "xsqcup", "bigsqcup": Rune(0x02A06) + of "qint", "iiiint": Rune(0x02A0C) + of "fpartint": Rune(0x02A0D) + of "cirfnint": Rune(0x02A10) + of "awint": Rune(0x02A11) + of "rppolint": Rune(0x02A12) + of "scpolint": Rune(0x02A13) + of "npolint": Rune(0x02A14) + of "pointint": Rune(0x02A15) + of "quatint": Rune(0x02A16) + of "intlarhk": Rune(0x02A17) + of "pluscir": Rune(0x02A22) + of "plusacir": Rune(0x02A23) + of "simplus": Rune(0x02A24) + of "plusdu": Rune(0x02A25) + of "plussim": Rune(0x02A26) + of "plustwo": Rune(0x02A27) + of "mcomma": Rune(0x02A29) + of "minusdu": Rune(0x02A2A) + of "loplus": Rune(0x02A2D) + of "roplus": Rune(0x02A2E) + of "Cross": Rune(0x02A2F) + of "timesd": Rune(0x02A30) + of "timesbar": Rune(0x02A31) + of "smashp": Rune(0x02A33) + of "lotimes": Rune(0x02A34) + of "rotimes": Rune(0x02A35) + of "otimesas": Rune(0x02A36) + of "Otimes": Rune(0x02A37) + of "odiv": Rune(0x02A38) + of "triplus": Rune(0x02A39) + of "triminus": Rune(0x02A3A) + of "tritime": Rune(0x02A3B) + of "iprod", "intprod": Rune(0x02A3C) + of "amalg": Rune(0x02A3F) + of "capdot": Rune(0x02A40) + of "ncup": Rune(0x02A42) + of "ncap": Rune(0x02A43) + of "capand": Rune(0x02A44) + of "cupor": Rune(0x02A45) + of "cupcap": Rune(0x02A46) + of "capcup": Rune(0x02A47) + of "cupbrcap": Rune(0x02A48) + of "capbrcup": Rune(0x02A49) + of "cupcup": Rune(0x02A4A) + of "capcap": Rune(0x02A4B) + of "ccups": Rune(0x02A4C) + of "ccaps": Rune(0x02A4D) + of "ccupssm": Rune(0x02A50) + of "And": Rune(0x02A53) + of "Or": Rune(0x02A54) + of "andand": Rune(0x02A55) + of "oror": Rune(0x02A56) + of "orslope": Rune(0x02A57) + of "andslope": Rune(0x02A58) + of "andv": Rune(0x02A5A) + of "orv": Rune(0x02A5B) + of "andd": Rune(0x02A5C) + of "ord": Rune(0x02A5D) + of "wedbar": Rune(0x02A5F) + of "sdote": Rune(0x02A66) + of "simdot": Rune(0x02A6A) + of "congdot": Rune(0x02A6D) + of "easter": Rune(0x02A6E) + of "apacir": Rune(0x02A6F) + of "apE": Rune(0x02A70) + of "eplus": Rune(0x02A71) + of "pluse": Rune(0x02A72) + of "Esim": Rune(0x02A73) + of "Colone": Rune(0x02A74) + of "Equal": Rune(0x02A75) + of "eDDot", "ddotseq": Rune(0x02A77) + of "equivDD": Rune(0x02A78) + of "ltcir": Rune(0x02A79) + of "gtcir": Rune(0x02A7A) + of "ltquest": Rune(0x02A7B) + of "gtquest": Rune(0x02A7C) + of "les", "LessSlantEqual", "leqslant": Rune(0x02A7D) + of "ges", "GreaterSlantEqual", "geqslant": Rune(0x02A7E) + of "lesdot": Rune(0x02A7F) + of "gesdot": Rune(0x02A80) + of "lesdoto": Rune(0x02A81) + of "gesdoto": Rune(0x02A82) + of "lesdotor": Rune(0x02A83) + of "gesdotol": Rune(0x02A84) + of "lap", "lessapprox": Rune(0x02A85) + of "gap", "gtrapprox": Rune(0x02A86) + of "lne", "lneq": Rune(0x02A87) + of "gne", "gneq": Rune(0x02A88) + of "lnap", "lnapprox": Rune(0x02A89) + of "gnap", "gnapprox": Rune(0x02A8A) + of "lEg", "lesseqqgtr": Rune(0x02A8B) + of "gEl", "gtreqqless": Rune(0x02A8C) + of "lsime": Rune(0x02A8D) + of "gsime": Rune(0x02A8E) + of "lsimg": Rune(0x02A8F) + of "gsiml": Rune(0x02A90) + of "lgE": Rune(0x02A91) + of "glE": Rune(0x02A92) + of "lesges": Rune(0x02A93) + of "gesles": Rune(0x02A94) + of "els", "eqslantless": Rune(0x02A95) + of "egs", "eqslantgtr": Rune(0x02A96) + of "elsdot": Rune(0x02A97) + of "egsdot": Rune(0x02A98) + of "el": Rune(0x02A99) + of "eg": Rune(0x02A9A) + of "siml": Rune(0x02A9D) + of "simg": Rune(0x02A9E) + of "simlE": Rune(0x02A9F) + of "simgE": Rune(0x02AA0) + of "LessLess": Rune(0x02AA1) + of "GreaterGreater": Rune(0x02AA2) + of "glj": Rune(0x02AA4) + of "gla": Rune(0x02AA5) + of "ltcc": Rune(0x02AA6) + of "gtcc": Rune(0x02AA7) + of "lescc": Rune(0x02AA8) + of "gescc": Rune(0x02AA9) + of "smt": Rune(0x02AAA) + of "lat": Rune(0x02AAB) + of "smte": Rune(0x02AAC) + of "late": Rune(0x02AAD) + of "bumpE": Rune(0x02AAE) + of "pre", "preceq", "PrecedesEqual": Rune(0x02AAF) + of "sce", "succeq", "SucceedsEqual": Rune(0x02AB0) + of "prE": Rune(0x02AB3) + of "scE": Rune(0x02AB4) + of "prnE", "precneqq": Rune(0x02AB5) + of "scnE", "succneqq": Rune(0x02AB6) + of "prap", "precapprox": Rune(0x02AB7) + of "scap", "succapprox": Rune(0x02AB8) + of "prnap", "precnapprox": Rune(0x02AB9) + of "scnap", "succnapprox": Rune(0x02ABA) + of "Pr": Rune(0x02ABB) + of "Sc": Rune(0x02ABC) + of "subdot": Rune(0x02ABD) + of "supdot": Rune(0x02ABE) + of "subplus": Rune(0x02ABF) + of "supplus": Rune(0x02AC0) + of "submult": Rune(0x02AC1) + of "supmult": Rune(0x02AC2) + of "subedot": Rune(0x02AC3) + of "supedot": Rune(0x02AC4) + of "subE", "subseteqq": Rune(0x02AC5) + of "supE", "supseteqq": Rune(0x02AC6) + of "subsim": Rune(0x02AC7) + of "supsim": Rune(0x02AC8) + of "subnE", "subsetneqq": Rune(0x02ACB) + of "supnE", "supsetneqq": Rune(0x02ACC) + of "csub": Rune(0x02ACF) + of "csup": Rune(0x02AD0) + of "csube": Rune(0x02AD1) + of "csupe": Rune(0x02AD2) + of "subsup": Rune(0x02AD3) + of "supsub": Rune(0x02AD4) + of "subsub": Rune(0x02AD5) + of "supsup": Rune(0x02AD6) + of "suphsub": Rune(0x02AD7) + of "supdsub": Rune(0x02AD8) + of "forkv": Rune(0x02AD9) + of "topfork": Rune(0x02ADA) + of "mlcp": Rune(0x02ADB) + of "Dashv", "DoubleLeftTee": Rune(0x02AE4) + of "Vdashl": Rune(0x02AE6) + of "Barv": Rune(0x02AE7) + of "vBar": Rune(0x02AE8) + of "vBarv": Rune(0x02AE9) + of "Vbar": Rune(0x02AEB) + of "Not": Rune(0x02AEC) + of "bNot": Rune(0x02AED) + of "rnmid": Rune(0x02AEE) + of "cirmid": Rune(0x02AEF) + of "midcir": Rune(0x02AF0) + of "topcir": Rune(0x02AF1) + of "nhpar": Rune(0x02AF2) + of "parsim": Rune(0x02AF3) + of "parsl": Rune(0x02AFD) + of "fflig": Rune(0x0FB00) + of "filig": Rune(0x0FB01) + of "fllig": Rune(0x0FB02) + of "ffilig": Rune(0x0FB03) + of "ffllig": Rune(0x0FB04) + of "Ascr": Rune(0x1D49C) + of "Cscr": Rune(0x1D49E) + of "Dscr": Rune(0x1D49F) + of "Gscr": Rune(0x1D4A2) + of "Jscr": Rune(0x1D4A5) + of "Kscr": Rune(0x1D4A6) + of "Nscr": Rune(0x1D4A9) + of "Oscr": Rune(0x1D4AA) + of "Pscr": Rune(0x1D4AB) + of "Qscr": Rune(0x1D4AC) + of "Sscr": Rune(0x1D4AE) + of "Tscr": Rune(0x1D4AF) + of "Uscr": Rune(0x1D4B0) + of "Vscr": Rune(0x1D4B1) + of "Wscr": Rune(0x1D4B2) + of "Xscr": Rune(0x1D4B3) + of "Yscr": Rune(0x1D4B4) + of "Zscr": Rune(0x1D4B5) + of "ascr": Rune(0x1D4B6) + of "bscr": Rune(0x1D4B7) + of "cscr": Rune(0x1D4B8) + of "dscr": Rune(0x1D4B9) + of "fscr": Rune(0x1D4BB) + of "hscr": Rune(0x1D4BD) + of "iscr": Rune(0x1D4BE) + of "jscr": Rune(0x1D4BF) + of "kscr": Rune(0x1D4C0) + of "lscr": Rune(0x1D4C1) + of "mscr": Rune(0x1D4C2) + of "nscr": Rune(0x1D4C3) + of "pscr": Rune(0x1D4C5) + of "qscr": Rune(0x1D4C6) + of "rscr": Rune(0x1D4C7) + of "sscr": Rune(0x1D4C8) + of "tscr": Rune(0x1D4C9) + of "uscr": Rune(0x1D4CA) + of "vscr": Rune(0x1D4CB) + of "wscr": Rune(0x1D4CC) + of "xscr": Rune(0x1D4CD) + of "yscr": Rune(0x1D4CE) + of "zscr": Rune(0x1D4CF) + of "Afr": Rune(0x1D504) + of "Bfr": Rune(0x1D505) + of "Dfr": Rune(0x1D507) + of "Efr": Rune(0x1D508) + of "Ffr": Rune(0x1D509) + of "Gfr": Rune(0x1D50A) + of "Jfr": Rune(0x1D50D) + of "Kfr": Rune(0x1D50E) + of "Lfr": Rune(0x1D50F) + of "Mfr": Rune(0x1D510) + of "Nfr": Rune(0x1D511) + of "Ofr": Rune(0x1D512) + of "Pfr": Rune(0x1D513) + of "Qfr": Rune(0x1D514) + of "Sfr": Rune(0x1D516) + of "Tfr": Rune(0x1D517) + of "Ufr": Rune(0x1D518) + of "Vfr": Rune(0x1D519) + of "Wfr": Rune(0x1D51A) + of "Xfr": Rune(0x1D51B) + of "Yfr": Rune(0x1D51C) + of "afr": Rune(0x1D51E) + of "bfr": Rune(0x1D51F) + of "cfr": Rune(0x1D520) + of "dfr": Rune(0x1D521) + of "efr": Rune(0x1D522) + of "ffr": Rune(0x1D523) + of "gfr": Rune(0x1D524) + of "hfr": Rune(0x1D525) + of "ifr": Rune(0x1D526) + of "jfr": Rune(0x1D527) + of "kfr": Rune(0x1D528) + of "lfr": Rune(0x1D529) + of "mfr": Rune(0x1D52A) + of "nfr": Rune(0x1D52B) + of "ofr": Rune(0x1D52C) + of "pfr": Rune(0x1D52D) + of "qfr": Rune(0x1D52E) + of "rfr": Rune(0x1D52F) + of "sfr": Rune(0x1D530) + of "tfr": Rune(0x1D531) + of "ufr": Rune(0x1D532) + of "vfr": Rune(0x1D533) + of "wfr": Rune(0x1D534) + of "xfr": Rune(0x1D535) + of "yfr": Rune(0x1D536) + of "zfr": Rune(0x1D537) + of "Aopf": Rune(0x1D538) + of "Bopf": Rune(0x1D539) + of "Dopf": Rune(0x1D53B) + of "Eopf": Rune(0x1D53C) + of "Fopf": Rune(0x1D53D) + of "Gopf": Rune(0x1D53E) + of "Iopf": Rune(0x1D540) + of "Jopf": Rune(0x1D541) + of "Kopf": Rune(0x1D542) + of "Lopf": Rune(0x1D543) + of "Mopf": Rune(0x1D544) + of "Oopf": Rune(0x1D546) + of "Sopf": Rune(0x1D54A) + of "Topf": Rune(0x1D54B) + of "Uopf": Rune(0x1D54C) + of "Vopf": Rune(0x1D54D) + of "Wopf": Rune(0x1D54E) + of "Xopf": Rune(0x1D54F) + of "Yopf": Rune(0x1D550) + of "aopf": Rune(0x1D552) + of "bopf": Rune(0x1D553) + of "copf": Rune(0x1D554) + of "dopf": Rune(0x1D555) + of "eopf": Rune(0x1D556) + of "fopf": Rune(0x1D557) + of "gopf": Rune(0x1D558) + of "hopf": Rune(0x1D559) + of "iopf": Rune(0x1D55A) + of "jopf": Rune(0x1D55B) + of "kopf": Rune(0x1D55C) + of "lopf": Rune(0x1D55D) + of "mopf": Rune(0x1D55E) + of "nopf": Rune(0x1D55F) + of "oopf": Rune(0x1D560) + of "popf": Rune(0x1D561) + of "qopf": Rune(0x1D562) + of "ropf": Rune(0x1D563) + of "sopf": Rune(0x1D564) + of "topf": Rune(0x1D565) + of "uopf": Rune(0x1D566) + of "vopf": Rune(0x1D567) + of "wopf": Rune(0x1D568) + of "xopf": Rune(0x1D569) + of "yopf": Rune(0x1D56A) + of "zopf": Rune(0x1D56B) + else: Rune(0) proc entityToUtf8*(entity: string): string = ## Converts an HTML entity name like ``Ü`` or values like ``Ü`` @@ -1869,19 +1872,20 @@ proc entityToUtf8*(entity: string): string = ## "" is returned if the entity name is unknown. The HTML parser ## already converts entities to UTF-8. runnableExamples: + const sigma = "Σ" doAssert entityToUtf8("") == "" doAssert entityToUtf8("a") == "" doAssert entityToUtf8("gt") == ">" doAssert entityToUtf8("Uuml") == "Ü" doAssert entityToUtf8("quest") == "?" doAssert entityToUtf8("#63") == "?" - doAssert entityToUtf8("Sigma") == "Σ" - doAssert entityToUtf8("#931") == "Σ" - doAssert entityToUtf8("#0931") == "Σ" - doAssert entityToUtf8("#x3A3") == "Σ" - doAssert entityToUtf8("#x03A3") == "Σ" - doAssert entityToUtf8("#x3a3") == "Σ" - doAssert entityToUtf8("#X3a3") == "Σ" + doAssert entityToUtf8("Sigma") == sigma + doAssert entityToUtf8("#931") == sigma + doAssert entityToUtf8("#0931") == sigma + doAssert entityToUtf8("#x3A3") == sigma + doAssert entityToUtf8("#x03A3") == sigma + doAssert entityToUtf8("#x3a3") == sigma + doAssert entityToUtf8("#X3a3") == sigma let rune = entityToRune(entity) if rune.ord <= 0: result = "" else: result = toUTF8(rune) From cb9e9297fba72c812913376311ca4b7ebd7e007f Mon Sep 17 00:00:00 2001 From: Araq Date: Thu, 23 Aug 2018 10:46:24 +0200 Subject: [PATCH 045/145] make highlite.nim compile again --- lib/packages/docutils/highlite.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/packages/docutils/highlite.nim b/lib/packages/docutils/highlite.nim index fbd2d7ecac..4d444603e5 100644 --- a/lib/packages/docutils/highlite.nim +++ b/lib/packages/docutils/highlite.nim @@ -881,7 +881,7 @@ when isMainModule: break except: echo filename, " not found" - doAssert(not keywords.isNil, "Couldn't read any keywords.txt file!") + doAssert(keywords.len > 0, "Couldn't read any keywords.txt file!") for i in 0..min(keywords.len, nimKeywords.len)-1: doAssert keywords[i] == nimKeywords[i], "Unexpected keyword" doAssert keywords.len == nimKeywords.len, "No matching lengths" From 7532b37405c9365f3f2935633111f309234297b2 Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Thu, 23 Aug 2018 15:31:28 +0100 Subject: [PATCH 046/145] Don't skip poll() when no handles are present. (#8727) Fixes #7886. Fixes #7758. Fixes #6929. Fixes #3909. Replaces #8209. --- lib/pure/asyncdispatch.nim | 136 ++++++++++++++++++------------------- tests/async/t7758.nim | 17 +++++ 2 files changed, 84 insertions(+), 69 deletions(-) create mode 100644 tests/async/t7758.nim diff --git a/lib/pure/asyncdispatch.nim b/lib/pure/asyncdispatch.nim index dfc7201b8c..df37cab37f 100644 --- a/lib/pure/asyncdispatch.nim +++ b/lib/pure/asyncdispatch.nim @@ -299,50 +299,49 @@ when defined(windows) or defined(nimdoc): "No handles or timers registered in dispatcher.") result = false - if p.handles.len != 0: - let at = p.adjustedTimeout(timeout) - var llTimeout = - if at == -1: winlean.INFINITE - else: at.int32 + let at = p.adjustedTimeout(timeout) + var llTimeout = + if at == -1: winlean.INFINITE + else: at.int32 - var lpNumberOfBytesTransferred: Dword - var lpCompletionKey: ULONG_PTR - var customOverlapped: PCustomOverlapped - let res = getQueuedCompletionStatus(p.ioPort, - addr lpNumberOfBytesTransferred, addr lpCompletionKey, - cast[ptr POVERLAPPED](addr customOverlapped), llTimeout).bool - result = true + var lpNumberOfBytesTransferred: Dword + var lpCompletionKey: ULONG_PTR + var customOverlapped: PCustomOverlapped + let res = getQueuedCompletionStatus(p.ioPort, + addr lpNumberOfBytesTransferred, addr lpCompletionKey, + cast[ptr POVERLAPPED](addr customOverlapped), llTimeout).bool + result = true - # http://stackoverflow.com/a/12277264/492186 - # TODO: http://www.serverframework.com/handling-multiple-pending-socket-read-and-write-operations.html - if res: - # This is useful for ensuring the reliability of the overlapped struct. + # http://stackoverflow.com/a/12277264/492186 + # TODO: http://www.serverframework.com/handling-multiple-pending-socket-read-and-write-operations.html + if res: + # This is useful for ensuring the reliability of the overlapped struct. + assert customOverlapped.data.fd == lpCompletionKey.AsyncFD + + customOverlapped.data.cb(customOverlapped.data.fd, + lpNumberOfBytesTransferred, OSErrorCode(-1)) + + # If cell.data != nil, then system.protect(rawEnv(cb)) was called, + # so we need to dispose our `cb` environment, because it is not needed + # anymore. + if customOverlapped.data.cell.data != nil: + system.dispose(customOverlapped.data.cell) + + GC_unref(customOverlapped) + else: + let errCode = osLastError() + if customOverlapped != nil: assert customOverlapped.data.fd == lpCompletionKey.AsyncFD - customOverlapped.data.cb(customOverlapped.data.fd, - lpNumberOfBytesTransferred, OSErrorCode(-1)) - - # If cell.data != nil, then system.protect(rawEnv(cb)) was called, - # so we need to dispose our `cb` environment, because it is not needed - # anymore. + lpNumberOfBytesTransferred, errCode) if customOverlapped.data.cell.data != nil: system.dispose(customOverlapped.data.cell) - GC_unref(customOverlapped) else: - let errCode = osLastError() - if customOverlapped != nil: - assert customOverlapped.data.fd == lpCompletionKey.AsyncFD - customOverlapped.data.cb(customOverlapped.data.fd, - lpNumberOfBytesTransferred, errCode) - if customOverlapped.data.cell.data != nil: - system.dispose(customOverlapped.data.cell) - GC_unref(customOverlapped) - else: - if errCode.int32 == WAIT_TIMEOUT: - # Timed out - result = false - else: raiseOSError(errCode) + if errCode.int32 == WAIT_TIMEOUT: + # Timed out + result = false + else: raiseOSError(errCode) # Timer processing. processTimers(p, result) @@ -1231,45 +1230,44 @@ else: "No handles or timers registered in dispatcher.") result = false - if not p.selector.isEmpty(): - var keys: array[64, ReadyKey] - var count = p.selector.selectInto(p.adjustedTimeout(timeout), keys) - for i in 0.. 0: incl(newEvents, Event.Read) - if wLength > 0: incl(newEvents, Event.Write) - p.selector.updateHandle(SocketHandle(fd), newEvents) + # because state `data` can be modified in callback we need to update + # descriptor events with currently registered callbacks. + if not custom: + var newEvents: set[Event] = {} + if rLength != -1 and wLength != -1: + if rLength > 0: incl(newEvents, Event.Read) + if wLength > 0: incl(newEvents, Event.Write) + p.selector.updateHandle(SocketHandle(fd), newEvents) # Timer processing. processTimers(p, result) diff --git a/tests/async/t7758.nim b/tests/async/t7758.nim new file mode 100644 index 0000000000..57d0f4004c --- /dev/null +++ b/tests/async/t7758.nim @@ -0,0 +1,17 @@ +discard """ + file: "t7758.nim" + exitcode: 0 +""" +import asyncdispatch + +proc task() {.async.} = + await sleepAsync(1000) + +when isMainModule: + var counter = 0 + var f = task() + while not f.finished: + inc(counter) + poll() + +doAssert counter == 2 \ No newline at end of file From b4ff01b5075b018dded72fce2c6c3343d1a76482 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Thu, 23 Aug 2018 16:32:38 +0200 Subject: [PATCH 047/145] make niminst compile again --- tools/niminst/niminst.nim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/niminst/niminst.nim b/tools/niminst/niminst.nim index e2cc8cf3a7..84653f86f2 100644 --- a/tools/niminst/niminst.nim +++ b/tools/niminst/niminst.nim @@ -483,7 +483,8 @@ proc deduplicateFiles(c: var ConfigData) = let build = getOutputDir(c) for osA in countup(1, c.oses.len): for cpuA in countup(1, c.cpus.len): - if c.cfiles[osA][cpuA].isNil: c.cfiles[osA][cpuA] = @[] + when not defined(nimNoNilSeqs): + if c.cfiles[osA][cpuA].isNil: c.cfiles[osA][cpuA] = @[] if c.explicitPlatforms and not c.platforms[osA][cpuA]: continue for dup in mitems(c.cfiles[osA][cpuA]): let key = $secureHashFile(build / dup) From ae0255ea6723c1b271d5064ea4e69fb994520102 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Thu, 23 Aug 2018 17:36:24 +0200 Subject: [PATCH 048/145] make nimsuggest compile again --- compiler/suggest.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/suggest.nim b/compiler/suggest.nim index 770bf25e65..f99a2d432c 100644 --- a/compiler/suggest.nim +++ b/compiler/suggest.nim @@ -434,7 +434,7 @@ proc suggestSym*(conf: ConfigRef; info: TLineInfo; s: PSym; usageSym: var PSym; ## misnamed: should be 'symDeclared' when defined(nimsuggest): if conf.suggestVersion == 0: - if s.allUsages.isNil: + if s.allUsages.len == 0: s.allUsages = @[info] else: s.addNoDup(info) From 1546826006ca8debf245f712e398813f12bcd7d6 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Thu, 23 Aug 2018 17:37:23 +0200 Subject: [PATCH 049/145] add nimHasWarningX and nimHasHintX defines for feature detection purposes --- compiler/condsyms.nim | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/compiler/condsyms.nim b/compiler/condsyms.nim index 0cf264ac3f..78645b6fde 100644 --- a/compiler/condsyms.nim +++ b/compiler/condsyms.nim @@ -13,6 +13,7 @@ import strtabs, platform, strutils, idents from options import Feature +from lineinfos import HintsToStr, WarningsToStr const catNone = "false" @@ -83,3 +84,8 @@ proc initDefines*(symbols: StringTableRef) = defineSymbol("nimHasNilSeqs") for f in low(Feature)..high(Feature): defineSymbol("nimHas" & $f) + + for s in WarningsToStr: + defineSymbol("nimHasWarning" & s) + for s in HintsToStr: + defineSymbol("nimHasHint" & s) From 361a2d830aca1959d3dbc15d13bea31f89fcd0e2 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Thu, 23 Aug 2018 17:54:04 +0200 Subject: [PATCH 050/145] enforce the condition of a 'when' condition to be of type bool; refs #8603 --- compiler/semexprs.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 5a8c762161..5ff692fd57 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -2085,7 +2085,7 @@ proc semWhen(c: PContext, n: PNode, semCheck = true): PNode = typ = commonType(typ, it.sons[1].typ) result = n # when nimvm is not elimited until codegen else: - var e = semConstExpr(c, it.sons[0]) + let e = forceBool(c, semConstExpr(c, it.sons[0])) if e.kind != nkIntLit: # can happen for cascading errors, assume false # InternalError(n.info, "semWhen") From 1c3cfd74fff010b6759a27ce44f01bf08159d418 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Thu, 23 Aug 2018 17:55:00 +0200 Subject: [PATCH 051/145] make ospaths compile; fixes ospaths.getConfigDir for Posix --- lib/pure/ospaths.nim | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/pure/ospaths.nim b/lib/pure/ospaths.nim index 0414eae5d9..1bcfd978b6 100644 --- a/lib/pure/ospaths.nim +++ b/lib/pure/ospaths.nim @@ -531,9 +531,11 @@ proc getConfigDir*(): string {.rtl, extern: "nos$1", ## ## An OS-dependent trailing slash is always present at the end of the ## returned string; `\\` on Windows and `/` on all other OSs. - when defined(windows): return string(getEnv("APPDATA")) & "\\" - elif getEnv("XDG_CONFIG_HOME"): return string(getEnv("XDG_CONFIG_HOME")) & "/" - else: return string(getEnv("HOME")) & "/.config/" + when defined(windows): + result = string(getEnv("APPDATA")) & "\\" + else: + result = string(getEnv("XDG_CONFIG_HOME", "")) & "/" + if result == "/": result = string(getEnv("HOME")) & "/.config/" proc getTempDir*(): string {.rtl, extern: "nos$1", tags: [ReadEnvEffect, ReadIOEffect].} = From 42333d27d0165e0e28e39ee7b409e0ae301e241f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oscar=20Nihlg=C3=A5rd?= Date: Thu, 23 Aug 2018 17:55:53 +0200 Subject: [PATCH 052/145] Don't assume utcOffset == +0 for old dates on Windows (#8744) --- lib/pure/times.nim | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/pure/times.nim b/lib/pure/times.nim index 6251c70d91..9f6ea5722b 100644 --- a/lib/pure/times.nim +++ b/lib/pure/times.nim @@ -957,6 +957,17 @@ else: result.inc tm.second proc getLocalOffsetAndDst(unix: int64): tuple[offset: int, dst: bool] = + # Windows can't handle unix < 0, so we fall back to unix = 0. + # FIXME: This should be improved by falling back to the WinAPI instead. + when defined(windows): + if unix < 0: + var a = 0.CTime + let tmPtr = localtime(addr(a)) + if not tmPtr.isNil: + let tm = tmPtr[] + return ((0 - tm.toAdjUnix).int, false) + return (0, false) + var a = unix.CTime let tmPtr = localtime(addr(a)) if not tmPtr.isNil: From 964f1ff7a77e0cc1c73f12d02969421c36d32e1c Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Thu, 23 Aug 2018 17:38:33 +0100 Subject: [PATCH 053/145] Adds test case for #6846. (#8729) --- tests/async/t6846.nim | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 tests/async/t6846.nim diff --git a/tests/async/t6846.nim b/tests/async/t6846.nim new file mode 100644 index 0000000000..687a3f8654 --- /dev/null +++ b/tests/async/t6846.nim @@ -0,0 +1,16 @@ +discard """ + exitcode: 0 + output: "hello world" + disabled: windows +""" + +import asyncdispatch +import asyncfile +import times + +var asyncStdout = 1.AsyncFD.newAsyncFile() +proc doStuff: Future[void] {.async.} = + await asyncStdout.write "hello world\n" + +let fut = doStuff() +doAssert fut.finished, "Poll is needed unnecessarily. See #6846." \ No newline at end of file From 1b1633991a738f100101407ffd1b16a08362814b Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Thu, 23 Aug 2018 15:31:28 +0100 Subject: [PATCH 054/145] Don't skip poll() when no handles are present. (#8727) Fixes #7886. Fixes #7758. Fixes #6929. Fixes #3909. Replaces #8209. --- lib/pure/asyncdispatch.nim | 136 ++++++++++++++++++------------------- tests/async/t7758.nim | 17 +++++ 2 files changed, 84 insertions(+), 69 deletions(-) create mode 100644 tests/async/t7758.nim diff --git a/lib/pure/asyncdispatch.nim b/lib/pure/asyncdispatch.nim index dfc7201b8c..df37cab37f 100644 --- a/lib/pure/asyncdispatch.nim +++ b/lib/pure/asyncdispatch.nim @@ -299,50 +299,49 @@ when defined(windows) or defined(nimdoc): "No handles or timers registered in dispatcher.") result = false - if p.handles.len != 0: - let at = p.adjustedTimeout(timeout) - var llTimeout = - if at == -1: winlean.INFINITE - else: at.int32 + let at = p.adjustedTimeout(timeout) + var llTimeout = + if at == -1: winlean.INFINITE + else: at.int32 - var lpNumberOfBytesTransferred: Dword - var lpCompletionKey: ULONG_PTR - var customOverlapped: PCustomOverlapped - let res = getQueuedCompletionStatus(p.ioPort, - addr lpNumberOfBytesTransferred, addr lpCompletionKey, - cast[ptr POVERLAPPED](addr customOverlapped), llTimeout).bool - result = true + var lpNumberOfBytesTransferred: Dword + var lpCompletionKey: ULONG_PTR + var customOverlapped: PCustomOverlapped + let res = getQueuedCompletionStatus(p.ioPort, + addr lpNumberOfBytesTransferred, addr lpCompletionKey, + cast[ptr POVERLAPPED](addr customOverlapped), llTimeout).bool + result = true - # http://stackoverflow.com/a/12277264/492186 - # TODO: http://www.serverframework.com/handling-multiple-pending-socket-read-and-write-operations.html - if res: - # This is useful for ensuring the reliability of the overlapped struct. + # http://stackoverflow.com/a/12277264/492186 + # TODO: http://www.serverframework.com/handling-multiple-pending-socket-read-and-write-operations.html + if res: + # This is useful for ensuring the reliability of the overlapped struct. + assert customOverlapped.data.fd == lpCompletionKey.AsyncFD + + customOverlapped.data.cb(customOverlapped.data.fd, + lpNumberOfBytesTransferred, OSErrorCode(-1)) + + # If cell.data != nil, then system.protect(rawEnv(cb)) was called, + # so we need to dispose our `cb` environment, because it is not needed + # anymore. + if customOverlapped.data.cell.data != nil: + system.dispose(customOverlapped.data.cell) + + GC_unref(customOverlapped) + else: + let errCode = osLastError() + if customOverlapped != nil: assert customOverlapped.data.fd == lpCompletionKey.AsyncFD - customOverlapped.data.cb(customOverlapped.data.fd, - lpNumberOfBytesTransferred, OSErrorCode(-1)) - - # If cell.data != nil, then system.protect(rawEnv(cb)) was called, - # so we need to dispose our `cb` environment, because it is not needed - # anymore. + lpNumberOfBytesTransferred, errCode) if customOverlapped.data.cell.data != nil: system.dispose(customOverlapped.data.cell) - GC_unref(customOverlapped) else: - let errCode = osLastError() - if customOverlapped != nil: - assert customOverlapped.data.fd == lpCompletionKey.AsyncFD - customOverlapped.data.cb(customOverlapped.data.fd, - lpNumberOfBytesTransferred, errCode) - if customOverlapped.data.cell.data != nil: - system.dispose(customOverlapped.data.cell) - GC_unref(customOverlapped) - else: - if errCode.int32 == WAIT_TIMEOUT: - # Timed out - result = false - else: raiseOSError(errCode) + if errCode.int32 == WAIT_TIMEOUT: + # Timed out + result = false + else: raiseOSError(errCode) # Timer processing. processTimers(p, result) @@ -1231,45 +1230,44 @@ else: "No handles or timers registered in dispatcher.") result = false - if not p.selector.isEmpty(): - var keys: array[64, ReadyKey] - var count = p.selector.selectInto(p.adjustedTimeout(timeout), keys) - for i in 0.. 0: incl(newEvents, Event.Read) - if wLength > 0: incl(newEvents, Event.Write) - p.selector.updateHandle(SocketHandle(fd), newEvents) + # because state `data` can be modified in callback we need to update + # descriptor events with currently registered callbacks. + if not custom: + var newEvents: set[Event] = {} + if rLength != -1 and wLength != -1: + if rLength > 0: incl(newEvents, Event.Read) + if wLength > 0: incl(newEvents, Event.Write) + p.selector.updateHandle(SocketHandle(fd), newEvents) # Timer processing. processTimers(p, result) diff --git a/tests/async/t7758.nim b/tests/async/t7758.nim new file mode 100644 index 0000000000..57d0f4004c --- /dev/null +++ b/tests/async/t7758.nim @@ -0,0 +1,17 @@ +discard """ + file: "t7758.nim" + exitcode: 0 +""" +import asyncdispatch + +proc task() {.async.} = + await sleepAsync(1000) + +when isMainModule: + var counter = 0 + var f = task() + while not f.finished: + inc(counter) + poll() + +doAssert counter == 2 \ No newline at end of file From 8aae5c9385c5273c4339a242222a14afead19f2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oscar=20Nihlg=C3=A5rd?= Date: Thu, 23 Aug 2018 17:55:53 +0200 Subject: [PATCH 055/145] Don't assume utcOffset == +0 for old dates on Windows (#8744) --- lib/pure/times.nim | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/pure/times.nim b/lib/pure/times.nim index 6251c70d91..9f6ea5722b 100644 --- a/lib/pure/times.nim +++ b/lib/pure/times.nim @@ -957,6 +957,17 @@ else: result.inc tm.second proc getLocalOffsetAndDst(unix: int64): tuple[offset: int, dst: bool] = + # Windows can't handle unix < 0, so we fall back to unix = 0. + # FIXME: This should be improved by falling back to the WinAPI instead. + when defined(windows): + if unix < 0: + var a = 0.CTime + let tmPtr = localtime(addr(a)) + if not tmPtr.isNil: + let tm = tmPtr[] + return ((0 - tm.toAdjUnix).int, false) + return (0, false) + var a = unix.CTime let tmPtr = localtime(addr(a)) if not tmPtr.isNil: From 07e1da834202dbfd09abfa73f191b7779da16f84 Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Thu, 23 Aug 2018 17:38:33 +0100 Subject: [PATCH 056/145] Adds test case for #6846. (#8729) --- tests/async/t6846.nim | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 tests/async/t6846.nim diff --git a/tests/async/t6846.nim b/tests/async/t6846.nim new file mode 100644 index 0000000000..687a3f8654 --- /dev/null +++ b/tests/async/t6846.nim @@ -0,0 +1,16 @@ +discard """ + exitcode: 0 + output: "hello world" + disabled: windows +""" + +import asyncdispatch +import asyncfile +import times + +var asyncStdout = 1.AsyncFD.newAsyncFile() +proc doStuff: Future[void] {.async.} = + await asyncStdout.write "hello world\n" + +let fut = doStuff() +doAssert fut.finished, "Poll is needed unnecessarily. See #6846." \ No newline at end of file From 25f5ea7000a4ae24a45d138307e62c0015d3c4df Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Thu, 23 Aug 2018 21:43:10 +0200 Subject: [PATCH 057/145] Validate pragmas attached to for variables (#8749) Fixes #8741 --- compiler/pragmas.nim | 1 + compiler/semstmts.nim | 2 ++ tests/pragmas/t8741.nim | 10 ++++++++++ 3 files changed, 13 insertions(+) create mode 100644 tests/pragmas/t8741.nim diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index 263068344d..66682650d1 100644 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -71,6 +71,7 @@ const letPragmas* = varPragmas procTypePragmas* = {FirstCallConv..LastCallConv, wVarargs, wNosideeffect, wThread, wRaises, wLocks, wTags, wGcSafe} + forVarPragmas* = {wInject, wGensym} allRoutinePragmas* = methodPragmas + iteratorPragmas + lambdaPragmas proc getPragmaVal*(procAst: PNode; name: TSpecialWord): PNode = diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 6cf2e2d969..425bb24dc1 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -567,6 +567,8 @@ proc symForVar(c: PContext, n: PNode): PSym = let m = if n.kind == nkPragmaExpr: n.sons[0] else: n result = newSymG(skForVar, m, c) styleCheckDef(c.config, result) + if n.kind == nkPragmaExpr: + pragma(c, result, n.sons[1], forVarPragmas) proc semForVars(c: PContext, n: PNode): PNode = result = n diff --git a/tests/pragmas/t8741.nim b/tests/pragmas/t8741.nim new file mode 100644 index 0000000000..7398b10307 --- /dev/null +++ b/tests/pragmas/t8741.nim @@ -0,0 +1,10 @@ +discard """ + line: 9 + errormsg: "attempting to call undeclared routine: 'foobar'" +""" + +for a {.gensym, inject.} in @[1,2,3]: + discard + +for a {.foobar.} in @[1,2,3]: + discard From 30621c4a8969ac4b121d04a06315bd4f2089a7c4 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Fri, 24 Aug 2018 00:09:08 +0200 Subject: [PATCH 058/145] improve error messages by filtering out highly unlikely mismatches --- compiler/semcall.nim | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/compiler/semcall.nim b/compiler/semcall.nim index dc71f2567e..980cfb691a 100644 --- a/compiler/semcall.nim +++ b/compiler/semcall.nim @@ -164,8 +164,18 @@ proc presentFailedCandidates(c: PContext, n: PNode, errors: CandidateErrors): prefer = preferModuleInfo break + # we pretend procs are attached to the type of the first + # argument in order to remove plenty of candidates. This is + # comparable to what C# does and C# is doing fine. + var filterOnlyFirst = false + for err in errors: + if err.firstMismatch > 1: + filterOnlyFirst = true + break + var candidates = "" for err in errors: + if filterOnlyFirst and err.firstMismatch == 1: continue if err.sym.kind in routineKinds and err.sym.ast != nil: add(candidates, renderTree(err.sym.ast, {renderNoBody, renderNoComments, renderNoPragmas})) From b1c2416abde695dc45ee6b2d97f4d8e125b68140 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Thu, 23 Aug 2018 21:43:10 +0200 Subject: [PATCH 059/145] Validate pragmas attached to for variables (#8749) Fixes #8741 --- compiler/pragmas.nim | 1 + compiler/semstmts.nim | 2 ++ tests/pragmas/t8741.nim | 10 ++++++++++ 3 files changed, 13 insertions(+) create mode 100644 tests/pragmas/t8741.nim diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index 263068344d..66682650d1 100644 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -71,6 +71,7 @@ const letPragmas* = varPragmas procTypePragmas* = {FirstCallConv..LastCallConv, wVarargs, wNosideeffect, wThread, wRaises, wLocks, wTags, wGcSafe} + forVarPragmas* = {wInject, wGensym} allRoutinePragmas* = methodPragmas + iteratorPragmas + lambdaPragmas proc getPragmaVal*(procAst: PNode; name: TSpecialWord): PNode = diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 6cf2e2d969..425bb24dc1 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -567,6 +567,8 @@ proc symForVar(c: PContext, n: PNode): PSym = let m = if n.kind == nkPragmaExpr: n.sons[0] else: n result = newSymG(skForVar, m, c) styleCheckDef(c.config, result) + if n.kind == nkPragmaExpr: + pragma(c, result, n.sons[1], forVarPragmas) proc semForVars(c: PContext, n: PNode): PNode = result = n diff --git a/tests/pragmas/t8741.nim b/tests/pragmas/t8741.nim new file mode 100644 index 0000000000..7398b10307 --- /dev/null +++ b/tests/pragmas/t8741.nim @@ -0,0 +1,10 @@ +discard """ + line: 9 + errormsg: "attempting to call undeclared routine: 'foobar'" +""" + +for a {.gensym, inject.} in @[1,2,3]: + discard + +for a {.foobar.} in @[1,2,3]: + discard From effe2fd812b6f60f27c9c2396c8ec21ee65e19f1 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Fri, 24 Aug 2018 09:58:03 +0200 Subject: [PATCH 060/145] disables flaky test; fixes #8756 --- tests/async/t7758.nim | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/async/t7758.nim b/tests/async/t7758.nim index 57d0f4004c..6ae98679dd 100644 --- a/tests/async/t7758.nim +++ b/tests/async/t7758.nim @@ -1,6 +1,7 @@ discard """ file: "t7758.nim" exitcode: 0 + disabled: true """ import asyncdispatch From d5e1d102df9b0a1aba0428e5191ca081cc9dde97 Mon Sep 17 00:00:00 2001 From: cooldome Date: Fri, 24 Aug 2018 09:57:38 +0200 Subject: [PATCH 061/145] fixes 8754 (#8755) * fixes 8754 * improve test --- compiler/vm.nim | 8 ++++++++ tests/macros/tmacrotypes.nim | 19 ++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/compiler/vm.nim b/compiler/vm.nim index 8f74761dc9..fcbd97b8dc 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -1322,6 +1322,8 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg = ensureKind(rkNode) if regs[rb].kind == rkNode and regs[rb].node.typ != nil: regs[ra].node = opMapTypeToAst(c.cache, regs[rb].node.typ, c.debug[pc]) + elif regs[rb].kind == rkNode and regs[rb].node.kind == nkSym and regs[rb].node.sym.typ != nil: + regs[ra].node = opMapTypeToAst(c.cache, regs[rb].node.sym.typ, c.debug[pc]) else: stackTrace(c, tos, pc, "node has no type") of 1: @@ -1329,6 +1331,8 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg = ensureKind(rkInt) if regs[rb].kind == rkNode and regs[rb].node.typ != nil: regs[ra].intVal = ord(regs[rb].node.typ.kind) + elif regs[rb].kind == rkNode and regs[rb].node.kind == nkSym and regs[rb].node.sym.typ != nil: + regs[ra].intVal = ord(regs[rb].node.sym.typ.kind) #else: # stackTrace(c, tos, pc, "node has no type") of 2: @@ -1336,6 +1340,8 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg = ensureKind(rkNode) if regs[rb].kind == rkNode and regs[rb].node.typ != nil: regs[ra].node = opMapTypeInstToAst(c.cache, regs[rb].node.typ, c.debug[pc]) + elif regs[rb].kind == rkNode and regs[rb].node.kind == nkSym and regs[rb].node.sym.typ != nil: + regs[ra].node = opMapTypeInstToAst(c.cache, regs[rb].node.sym.typ, c.debug[pc]) else: stackTrace(c, tos, pc, "node has no type") else: @@ -1343,6 +1349,8 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg = ensureKind(rkNode) if regs[rb].kind == rkNode and regs[rb].node.typ != nil: regs[ra].node = opMapTypeImplToAst(c.cache, regs[rb].node.typ, c.debug[pc]) + elif regs[rb].kind == rkNode and regs[rb].node.kind == nkSym and regs[rb].node.sym.typ != nil: + regs[ra].node = opMapTypeImplToAst(c.cache, regs[rb].node.sym.typ, c.debug[pc]) else: stackTrace(c, tos, pc, "node has no type") of opcNStrVal: diff --git a/tests/macros/tmacrotypes.nim b/tests/macros/tmacrotypes.nim index e8a68c34d0..734503e6b0 100644 --- a/tests/macros/tmacrotypes.nim +++ b/tests/macros/tmacrotypes.nim @@ -1,16 +1,25 @@ discard """ - nimout: '''void -int''' + nimout: '''intProc; ntyProc; proc[int, int, float]; proc (a: int; b: float): int +void; ntyVoid; void; void +int; ntyInt; int; int +proc (); ntyProc; proc[void]; proc () +voidProc; ntyProc; proc[void]; proc ()''' """ import macros macro checkType(ex: typed; expected: string): untyped = - var t = ex.getType() - echo t + echo ex.getTypeInst.repr, "; ", ex.typeKind, "; ", ex.getType.repr, "; ", ex.getTypeImpl.repr + +macro checkProcType(fn: typed): untyped = + let fn_sym = if fn.kind == nnkProcDef: fn[0] else: fn + echo fn_sym, "; ", fn_sym.typeKind, "; ", fn_sym.getType.repr, "; ", fn_sym.getTypeImpl.repr + proc voidProc = echo "hello" -proc intProc(a: int, b: float): int = 10 +proc intProc(a: int, b: float): int {.checkProcType.} = 10 checkType(voidProc(), "void") checkType(intProc(10, 20.0), "int") +checkType(voidProc, "procTy") +checkProcType(voidProc) From f26ed1d540c154efa67e8d427c492069719c5159 Mon Sep 17 00:00:00 2001 From: gemath <33119724+gemath@users.noreply.github.com> Date: Fri, 24 Aug 2018 20:13:37 +0200 Subject: [PATCH 062/145] Add interpreting event parser proc to pegs module. (#8075) * Added simple interpreting event parser to pegs module. * Has side-effects problem. * Macro solution works. * First flat callback test works. * Fixed namespace pollution. * Added handler for pkChar. * Replaced event parser test. * Started extensive docs. * 'callback' to 'handler' renaming part 1. * Renaming 'callback' to 'handler' part2, completed comments. * Fixed exported API pollution. * Added more event handler hooks, fixed comments. * Changed event parser addition entry. * Fixed variable names and comments. * Enhanced comment. * Leave handlers are not called for an unsuccessful match. * The three varieties of back-reference matches are processed in separate of-clauses now. * Improved hygiene and (almost) eliminated exports. * Trying to fix CI test breakage by eliminating export. * Trying to fix CI test breakage by eliminating exports. * Re-activated leave handler code execution for unsuccessful matches. * Eliminated the last export statement (with a funny smelling hack). * Make sure leave handler code is executed for all unsuccessful matcher cases. * Replaced local unicode.`==` with export. --- changelog.md | 1 + lib/pure/pegs.nim | 750 +++++++++++++++++++++++++++++------------ tests/stdlib/tpegs.nim | 142 ++++++-- 3 files changed, 636 insertions(+), 257 deletions(-) diff --git a/changelog.md b/changelog.md index 8d4dc81c01..9526227ce9 100644 --- a/changelog.md +++ b/changelog.md @@ -107,6 +107,7 @@ - ``parseOct`` and ``parseBin`` in parseutils now also support the ``maxLen`` argument similar to ``parseHexInt``. - Added the proc ``flush`` for memory mapped files. - Added the ``MemMapFileStream``. +- Added a simple interpreting event parser template ``eventParser`` to the ``pegs`` module. - Added ``macros.copyLineInfo`` to copy lineInfo from other node. - Added ``system.ashr`` an arithmetic right shift for integers. diff --git a/lib/pure/pegs.nim b/lib/pure/pegs.nim index 02a2d69004..3ee82917d6 100644 --- a/lib/pure/pegs.nim +++ b/lib/pure/pegs.nim @@ -20,11 +20,11 @@ include "system/inclrtl" const useUnicode = true ## change this to deactivate proper UTF-8 support -import - strutils +import strutils, macros when useUnicode: import unicode + export unicode.`==` const InlineThreshold = 5 ## number of leaves; -1 to disable inlining @@ -74,7 +74,7 @@ type line: int ## line the symbol has been declared/used in col: int ## column the symbol has been declared/used in flags: set[NonTerminalFlag] ## the nonterminal's flags - rule: Peg ## the rule that the symbol refers to + rule: Peg ## the rule that the symbol refers to Peg* {.shallow.} = object ## type that represents a PEG case kind: PegKind of pkEmpty..pkWhitespace: nil @@ -86,25 +86,59 @@ type else: sons: seq[Peg] NonTerminal* = ref NonTerminalObj -proc name*(nt: NonTerminal): string = nt.name -proc line*(nt: NonTerminal): int = nt.line -proc col*(nt: NonTerminal): int = nt.col -proc flags*(nt: NonTerminal): set[NonTerminalFlag] = nt.flags -proc rule*(nt: NonTerminal): Peg = nt.rule - proc kind*(p: Peg): PegKind = p.kind + ## Returns the *PegKind* of a given *Peg* object. + proc term*(p: Peg): string = p.term + ## Returns the *string* representation of a given *Peg* variant object + ## where present. + proc ch*(p: Peg): char = p.ch + ## Returns the *char* representation of a given *Peg* variant object + ## where present. + proc charChoice*(p: Peg): ref set[char] = p.charChoice + ## Returns the *charChoice* field of a given *Peg* variant object + ## where present. + proc nt*(p: Peg): NonTerminal = p.nt + ## Returns the *NonTerminal* object of a given *Peg* variant object + ## where present. + proc index*(p: Peg): range[0..MaxSubpatterns] = p.index + ## Returns the back-reference index of a captured sub-pattern in the + ## *Captures* object for a given *Peg* variant object where present. + iterator items*(p: Peg): Peg {.inline.} = + ## Yields the child nodes of a *Peg* variant object where present. for s in p.sons: yield s + iterator pairs*(p: Peg): (int, Peg) {.inline.} = + ## Yields the indices and child nodes of a *Peg* variant object where present. for i in 0 ..< p.sons.len: yield (i, p.sons[i]) +proc name*(nt: NonTerminal): string = nt.name + ## Gets the name of the symbol represented by the parent *Peg* object variant + ## of a given *NonTerminal*. + +proc line*(nt: NonTerminal): int = nt.line + ## Gets the line number of the definition of the parent *Peg* object variant + ## of a given *NonTerminal*. + +proc col*(nt: NonTerminal): int = nt.col + ## Gets the column number of the definition of the parent *Peg* object variant + ## of a given *NonTerminal*. + +proc flags*(nt: NonTerminal): set[NonTerminalFlag] = nt.flags + ## Gets the *NonTerminalFlag*-typed flags field of the parent *Peg* variant + ## object of a given *NonTerminal*. + +proc rule*(nt: NonTerminal): Peg = nt.rule + ## Gets the *Peg* object representing the rule definition of the parent *Peg* + ## object variant of a given *NonTerminal*. + proc term*(t: string): Peg {.nosideEffect, rtl, extern: "npegs$1Str".} = ## constructs a PEG from a terminal string if t.len != 1: @@ -540,223 +574,497 @@ when not useUnicode: proc isTitle(a: char): bool {.inline.} = return false proc isWhiteSpace(a: char): bool {.inline.} = return a in {' ', '\9'..'\13'} -proc rawMatch*(s: string, p: Peg, start: int, c: var Captures): int {. - nosideEffect, rtl, extern: "npegs$1".} = +template matchOrParse(mopProc: untyped): typed = + # Used to make the main matcher proc *rawMatch* as well as event parser + # procs. For the former, *enter* and *leave* event handler code generators + # are provided which just return *discard*. + + proc mopProc(s: string, p: Peg, start: int, c: var Captures): int = + proc matchBackRef(s: string, p: Peg, start: int, c: var Captures): int = + # Parse handler code must run in an *of* clause of its own for each + # *PegKind*, so we encapsulate the identical clause body for + # *pkBackRef..pkBackRefIgnoreStyle* here. + if p.index >= c.ml: return -1 + var (a, b) = c.matches[p.index] + var n: Peg + n.kind = succ(pkTerminal, ord(p.kind)-ord(pkBackRef)) + n.term = s.substr(a, b) + mopProc(s, n, start, c) + + case p.kind + of pkEmpty: + enter(pkEmpty, s, p, start) + result = 0 # match of length 0 + leave(pkEmpty, s, p, start, result) + of pkAny: + enter(pkAny, s, p, start) + if start < s.len: result = 1 + else: result = -1 + leave(pkAny, s, p, start, result) + of pkAnyRune: + enter(pkAnyRune, s, p, start) + if start < s.len: + result = runeLenAt(s, start) + else: + result = -1 + leave(pkAnyRune, s, p, start, result) + of pkLetter: + enter(pkLetter, s, p, start) + if start < s.len: + var a: Rune + result = start + fastRuneAt(s, result, a) + if isAlpha(a): dec(result, start) + else: result = -1 + else: + result = -1 + leave(pkLetter, s, p, start, result) + of pkLower: + enter(pkLower, s, p, start) + if start < s.len: + var a: Rune + result = start + fastRuneAt(s, result, a) + if isLower(a): dec(result, start) + else: result = -1 + else: + result = -1 + leave(pkLower, s, p, start, result) + of pkUpper: + enter(pkUpper, s, p, start) + if start < s.len: + var a: Rune + result = start + fastRuneAt(s, result, a) + if isUpper(a): dec(result, start) + else: result = -1 + else: + result = -1 + leave(pkUpper, s, p, start, result) + of pkTitle: + enter(pkTitle, s, p, start) + if start < s.len: + var a: Rune + result = start + fastRuneAt(s, result, a) + if isTitle(a): dec(result, start) + else: result = -1 + else: + result = -1 + leave(pkTitle, s, p, start, result) + of pkWhitespace: + enter(pkWhitespace, s, p, start) + if start < s.len: + var a: Rune + result = start + fastRuneAt(s, result, a) + if isWhiteSpace(a): dec(result, start) + else: result = -1 + else: + result = -1 + leave(pkWhitespace, s, p, start, result) + of pkGreedyAny: + enter(pkGreedyAny, s, p, start) + result = len(s) - start + leave(pkGreedyAny, s, p, start, result) + of pkNewLine: + enter(pkNewLine, s, p, start) + if start < s.len and s[start] == '\L': result = 1 + elif start < s.len and s[start] == '\C': + if start+1 < s.len and s[start+1] == '\L': result = 2 + else: result = 1 + else: result = -1 + leave(pkNewLine, s, p, start, result) + of pkTerminal: + enter(pkTerminal, s, p, start) + result = len(p.term) + for i in 0..result-1: + if start+i >= s.len or p.term[i] != s[start+i]: + result = -1 + break + leave(pkTerminal, s, p, start, result) + of pkTerminalIgnoreCase: + enter(pkTerminalIgnoreCase, s, p, start) + var + i = 0 + a, b: Rune + result = start + while i < len(p.term): + if result >= s.len: + result = -1 + break + fastRuneAt(p.term, i, a) + fastRuneAt(s, result, b) + if toLower(a) != toLower(b): + result = -1 + break + dec(result, start) + leave(pkTerminalIgnoreCase, s, p, start, result) + of pkTerminalIgnoreStyle: + enter(pkTerminalIgnoreStyle, s, p, start) + var + i = 0 + a, b: Rune + result = start + while i < len(p.term): + while i < len(p.term): + fastRuneAt(p.term, i, a) + if a != Rune('_'): break + while result < s.len: + fastRuneAt(s, result, b) + if b != Rune('_'): break + if result >= s.len: + if i >= p.term.len: break + else: + result = -1 + break + elif toLower(a) != toLower(b): + result = -1 + break + dec(result, start) + leave(pkTerminalIgnoreStyle, s, p, start, result) + of pkChar: + enter(pkChar, s, p, start) + if start < s.len and p.ch == s[start]: result = 1 + else: result = -1 + leave(pkChar, s, p, start, result) + of pkCharChoice: + enter(pkCharChoice, s, p, start) + if start < s.len and contains(p.charChoice[], s[start]): result = 1 + else: result = -1 + leave(pkCharChoice, s, p, start, result) + of pkNonTerminal: + enter(pkNonTerminal, s, p, start) + var oldMl = c.ml + when false: echo "enter: ", p.nt.name + result = mopProc(s, p.nt.rule, start, c) + when false: echo "leave: ", p.nt.name + if result < 0: c.ml = oldMl + leave(pkNonTerminal, s, p, start, result) + of pkSequence: + enter(pkSequence, s, p, start) + var oldMl = c.ml + result = 0 + for i in 0..high(p.sons): + var x = mopProc(s, p.sons[i], start+result, c) + if x < 0: + c.ml = oldMl + result = -1 + break + else: inc(result, x) + leave(pkSequence, s, p, start, result) + of pkOrderedChoice: + enter(pkOrderedChoice, s, p, start) + var oldMl = c.ml + for i in 0..high(p.sons): + result = mopProc(s, p.sons[i], start, c) + if result >= 0: break + c.ml = oldMl + leave(pkOrderedChoice, s, p, start, result) + of pkSearch: + enter(pkSearch, s, p, start) + var oldMl = c.ml + result = 0 + while start+result <= s.len: + var x = mopProc(s, p.sons[0], start+result, c) + if x >= 0: + inc(result, x) + leave(pkSearch, s, p, start, result) + return + inc(result) + result = -1 + c.ml = oldMl + leave(pkSearch, s, p, start, result) + of pkCapturedSearch: + enter(pkCapturedSearch, s, p, start) + var idx = c.ml # reserve a slot for the subpattern + inc(c.ml) + result = 0 + while start+result <= s.len: + var x = mopProc(s, p.sons[0], start+result, c) + if x >= 0: + if idx < MaxSubpatterns: + c.matches[idx] = (start, start+result-1) + #else: silently ignore the capture + inc(result, x) + leave(pkCapturedSearch, s, p, start, result) + return + inc(result) + result = -1 + c.ml = idx + leave(pkCapturedSearch, s, p, start, result) + of pkGreedyRep: + enter(pkGreedyRep, s, p, start) + result = 0 + while true: + var x = mopProc(s, p.sons[0], start+result, c) + # if x == 0, we have an endless loop; so the correct behaviour would be + # not to break. But endless loops can be easily introduced: + # ``(comment / \w*)*`` is such an example. Breaking for x == 0 does the + # expected thing in this case. + if x <= 0: break + inc(result, x) + leave(pkGreedyRep, s, p, start, result) + of pkGreedyRepChar: + enter(pkGreedyRepChar, s, p, start) + result = 0 + var ch = p.ch + while start+result < s.len and ch == s[start+result]: inc(result) + leave(pkGreedyRepChar, s, p, start, result) + of pkGreedyRepSet: + enter(pkGreedyRepSet, s, p, start) + result = 0 + while start+result < s.len and contains(p.charChoice[], s[start+result]): inc(result) + leave(pkGreedyRepSet, s, p, start, result) + of pkOption: + enter(pkOption, s, p, start) + result = max(0, mopProc(s, p.sons[0], start, c)) + leave(pkOption, s, p, start, result) + of pkAndPredicate: + enter(pkAndPredicate, s, p, start) + var oldMl = c.ml + result = mopProc(s, p.sons[0], start, c) + if result >= 0: result = 0 # do not consume anything + else: c.ml = oldMl + leave(pkAndPredicate, s, p, start, result) + of pkNotPredicate: + enter(pkNotPredicate, s, p, start) + var oldMl = c.ml + result = mopProc(s, p.sons[0], start, c) + if result < 0: result = 0 + else: + c.ml = oldMl + result = -1 + leave(pkNotPredicate, s, p, start, result) + of pkCapture: + enter(pkCapture, s, p, start) + var idx = c.ml # reserve a slot for the subpattern + inc(c.ml) + result = mopProc(s, p.sons[0], start, c) + if result >= 0: + if idx < MaxSubpatterns: + c.matches[idx] = (start, start+result-1) + #else: silently ignore the capture + else: + c.ml = idx + leave(pkCapture, s, p, start, result) + of pkBackRef: + enter(pkBackRef, s, p, start) + result = matchBackRef(s, p, start, c) + leave(pkBackRef, s, p, start, result) + of pkBackRefIgnoreCase: + enter(pkBackRefIgnoreCase, s, p, start) + result = matchBackRef(s, p, start, c) + leave(pkBackRefIgnoreCase, s, p, start, result) + of pkBackRefIgnoreStyle: + enter(pkBackRefIgnoreStyle, s, p, start) + result = matchBackRef(s, p, start, c) + leave(pkBackRefIgnoreStyle, s, p, start, result) + of pkStartAnchor: + enter(pkStartAnchor, s, p, start) + if c.origStart == start: result = 0 + else: result = -1 + leave(pkStartAnchor, s, p, start, result) + of pkRule, pkList: assert false + +proc rawMatch*(s: string, p: Peg, start: int, c: var Captures): int + {.noSideEffect, rtl, extern: "npegs$1".} = ## low-level matching proc that implements the PEG interpreter. Use this ## for maximum efficiency (every other PEG operation ends up calling this ## proc). ## Returns -1 if it does not match, else the length of the match - case p.kind - of pkEmpty: result = 0 # match of length 0 - of pkAny: - if start < s.len: result = 1 - else: result = -1 - of pkAnyRune: - if start < s.len: - result = runeLenAt(s, start) - else: - result = -1 - of pkLetter: - if start < s.len: - var a: Rune - result = start - fastRuneAt(s, result, a) - if isAlpha(a): dec(result, start) - else: result = -1 - else: - result = -1 - of pkLower: - if start < s.len: - var a: Rune - result = start - fastRuneAt(s, result, a) - if isLower(a): dec(result, start) - else: result = -1 - else: - result = -1 - of pkUpper: - if start < s.len: - var a: Rune - result = start - fastRuneAt(s, result, a) - if isUpper(a): dec(result, start) - else: result = -1 - else: - result = -1 - of pkTitle: - if start < s.len: - var a: Rune - result = start - fastRuneAt(s, result, a) - if isTitle(a): dec(result, start) - else: result = -1 - else: - result = -1 - of pkWhitespace: - if start < s.len: - var a: Rune - result = start - fastRuneAt(s, result, a) - if isWhiteSpace(a): dec(result, start) - else: result = -1 - else: - result = -1 - of pkGreedyAny: - result = len(s) - start - of pkNewLine: - if start < s.len and s[start] == '\L': result = 1 - elif start < s.len and s[start] == '\C': - if start+1 < s.len and s[start+1] == '\L': result = 2 - else: result = 1 - else: result = -1 - of pkTerminal: - result = len(p.term) - for i in 0..result-1: - if start+i >= s.len or p.term[i] != s[start+i]: - result = -1 - break - of pkTerminalIgnoreCase: - var - i = 0 - a, b: Rune - result = start - while i < len(p.term): - if result >= s.len: - result = -1 - break - fastRuneAt(p.term, i, a) - fastRuneAt(s, result, b) - if toLower(a) != toLower(b): - result = -1 - break - dec(result, start) - of pkTerminalIgnoreStyle: - var - i = 0 - a, b: Rune - result = start - while i < len(p.term): - while i < len(p.term): - fastRuneAt(p.term, i, a) - if a != Rune('_'): break - while result < s.len: - fastRuneAt(s, result, b) - if b != Rune('_'): break - if result >= s.len: - if i >= p.term.len: break + + # Set the handler generators to produce do-nothing handlers. + template enter(pk, s, p, start) = + discard + template leave(pk, s, p, start, length) = + discard + matchOrParse(matchIt) + result = matchIt(s, p, start, c) + +macro mkHandlerTplts(handlers: untyped): untyped = + # Transforms the handler spec in *handlers* into handler templates. + # The AST structure of *handlers[0]*: + # + # .. code-block:: + # StmtList + # Call + # Ident "pkNonTerminal" + # StmtList + # Call + # Ident "enter" + # StmtList + # + # Call + # Ident "leave" + # StmtList + # + # Call + # Ident "pkChar" + # StmtList + # Call + # Ident "leave" + # StmtList + # + # ... + proc mkEnter(hdName, body: NimNode): NimNode = + quote do: + template `hdName`(s, p, start) = + let s {.inject.} = s + let p {.inject.} = p + let start {.inject.} = start + `body` + + template mkLeave(hdPostf, body) {.dirty.} = + # this has to be dirty to be able to capture *result* as *length* in + # *leaveXX* calls. + template `leave hdPostf`(s, p, start, length) = + body + + result = newStmtList() + for topCall in handlers[0]: + if nnkCall != topCall.kind: + error("Call syntax expected.", topCall) + let pegKind = topCall[0] + if nnkIdent != pegKind.kind: + error("PegKind expected.", pegKind) + if 2 == topCall.len: + for hdDef in topCall[1]: + if nnkCall != hdDef.kind: + error("Call syntax expected.", hdDef) + if nnkIdent != hdDef[0].kind: + error("Handler identifier expected.", hdDef[0]) + if 2 == hdDef.len: + let hdPostf = substr(pegKind.strVal, 2) + case hdDef[0].strVal + of "enter": + result.add mkEnter(newIdentNode("enter" & hdPostf), hdDef[1]) + of "leave": + result.add getAst(mkLeave(ident(hdPostf), hdDef[1])) + else: + error( + "Unsupported handler identifier, expected 'enter' or 'leave'.", + hdDef[0] + ) + +template eventParser*(pegAst, handlers: untyped): (proc(s: string): int) = + ## Generates an interpreting event parser *proc* according to the specified + ## PEG AST and handler code blocks. The *proc* can be called with a string + ## to be parsed and will execute the handler code blocks whenever their + ## associated grammar element is matched. It returns -1 if the string does not + ## match, else the length of the total match. The following example code + ## evaluates an arithmetic expression defined by a simple PEG: + ## + ## .. code-block:: nim + ## import strutils, pegs + ## + ## let + ## pegAst = """ + ## Expr <- Sum + ## Sum <- Product (('+' / '-')Product)* + ## Product <- Value (('*' / '/')Value)* + ## Value <- [0-9]+ / '(' Expr ')' + ## """.peg + ## txt = "(5+3)/2-7*22" + ## + ## var + ## pStack: seq[string] = @[] + ## valStack: seq[float] = @[] + ## opStack = "" + ## let + ## parseArithExpr = pegAst.eventParser: + ## pkNonTerminal: + ## enter: + ## pStack.add p.nt.name + ## leave: + ## pStack.setLen pStack.high + ## if length > 0: + ## let matchStr = s.substr(start, start+length-1) + ## case p.nt.name + ## of "Value": + ## try: + ## valStack.add matchStr.parseFloat + ## echo valStack + ## except ValueError: + ## discard + ## of "Sum", "Product": + ## try: + ## let val = matchStr.parseFloat + ## except ValueError: + ## if valStack.len > 1 and opStack.len > 0: + ## valStack[^2] = case opStack[^1] + ## of '+': valStack[^2] + valStack[^1] + ## of '-': valStack[^2] - valStack[^1] + ## of '*': valStack[^2] * valStack[^1] + ## else: valStack[^2] / valStack[^1] + ## valStack.setLen valStack.high + ## echo valStack + ## opStack.setLen opStack.high + ## echo opStack + ## pkChar: + ## leave: + ## if length == 1 and "Value" != pStack[^1]: + ## let matchChar = s[start] + ## opStack.add matchChar + ## echo opStack + ## + ## let pLen = parseArithExpr(txt) + ## + ## The *handlers* parameter consists of code blocks for *PegKinds*, + ## which define the grammar elements of interest. Each block can contain + ## handler code to be executed when the parser enters and leaves text + ## matching the grammar element. An *enter* handler can access the specific + ## PEG AST node being matched as *p*, the entire parsed string as *s* + ## and the position of the matched text segment in *s* as *start*. A *leave* + ## handler can access *p*, *s*, *start* and also the length of the matched + ## text segment as *length*. For an unsuccessful match, the *enter* and + ## *leave* handlers will be executed, with *length* set to -1. + ## + ## Symbols declared in an *enter* handler can be made visible in the + ## corresponding *leave* handler by annotating them with an *inject* pragma. + proc rawParse(s: string, p: Peg, start: int, c: var Captures): int + {.genSym.} = + + # binding from *macros* + bind strVal + + mkHandlerTplts: + handlers + + macro enter(pegKind, s, pegNode, start: untyped): untyped = + # This is called by the matcher code in *matchOrParse* at the + # start of the code for a grammar element of kind *pegKind*. + # Expands to a call to the handler template if one was generated + # by *mkHandlerTplts*. + template mkDoEnter(hdPostf, s, pegNode, start) = + when declared(`enter hdPostf`): + `enter hdPostf`(s, pegNode, start): else: - result = -1 - break - elif toLower(a) != toLower(b): - result = -1 - break - dec(result, start) - of pkChar: - if start < s.len and p.ch == s[start]: result = 1 - else: result = -1 - of pkCharChoice: - if start < s.len and contains(p.charChoice[], s[start]): result = 1 - else: result = -1 - of pkNonTerminal: - var oldMl = c.ml - when false: echo "enter: ", p.nt.name - result = rawMatch(s, p.nt.rule, start, c) - when false: echo "leave: ", p.nt.name - if result < 0: c.ml = oldMl - of pkSequence: - var oldMl = c.ml - result = 0 - for i in 0..high(p.sons): - var x = rawMatch(s, p.sons[i], start+result, c) - if x < 0: - c.ml = oldMl - result = -1 - break - else: inc(result, x) - of pkOrderedChoice: - var oldMl = c.ml - for i in 0..high(p.sons): - result = rawMatch(s, p.sons[i], start, c) - if result >= 0: break - c.ml = oldMl - of pkSearch: - var oldMl = c.ml - result = 0 - while start+result <= s.len: - var x = rawMatch(s, p.sons[0], start+result, c) - if x >= 0: - inc(result, x) - return - inc(result) - result = -1 - c.ml = oldMl - of pkCapturedSearch: - var idx = c.ml # reserve a slot for the subpattern - inc(c.ml) - result = 0 - while start+result <= s.len: - var x = rawMatch(s, p.sons[0], start+result, c) - if x >= 0: - if idx < MaxSubpatterns: - c.matches[idx] = (start, start+result-1) - #else: silently ignore the capture - inc(result, x) - return - inc(result) - result = -1 - c.ml = idx - of pkGreedyRep: - result = 0 - while true: - var x = rawMatch(s, p.sons[0], start+result, c) - # if x == 0, we have an endless loop; so the correct behaviour would be - # not to break. But endless loops can be easily introduced: - # ``(comment / \w*)*`` is such an example. Breaking for x == 0 does the - # expected thing in this case. - if x <= 0: break - inc(result, x) - of pkGreedyRepChar: - result = 0 - var ch = p.ch - while start+result < s.len and ch == s[start+result]: inc(result) - of pkGreedyRepSet: - result = 0 - while start+result < s.len and contains(p.charChoice[], s[start+result]): inc(result) - of pkOption: - result = max(0, rawMatch(s, p.sons[0], start, c)) - of pkAndPredicate: - var oldMl = c.ml - result = rawMatch(s, p.sons[0], start, c) - if result >= 0: result = 0 # do not consume anything - else: c.ml = oldMl - of pkNotPredicate: - var oldMl = c.ml - result = rawMatch(s, p.sons[0], start, c) - if result < 0: result = 0 - else: - c.ml = oldMl - result = -1 - of pkCapture: - var idx = c.ml # reserve a slot for the subpattern - inc(c.ml) - result = rawMatch(s, p.sons[0], start, c) - if result >= 0: - if idx < MaxSubpatterns: - c.matches[idx] = (start, start+result-1) - #else: silently ignore the capture - else: - c.ml = idx - of pkBackRef..pkBackRefIgnoreStyle: - if p.index >= c.ml: return -1 - var (a, b) = c.matches[p.index] - var n: Peg - n.kind = succ(pkTerminal, ord(p.kind)-ord(pkBackRef)) - n.term = s.substr(a, b) - result = rawMatch(s, n, start, c) - of pkStartAnchor: - if c.origStart == start: result = 0 - else: result = -1 - of pkRule, pkList: assert false + discard + let hdPostf = ident(substr(strVal(pegKind), 2)) + getAst(mkDoEnter(hdPostf, s, pegNode, start)) + + macro leave(pegKind, s, pegNode, start, length: untyped): untyped = + # Like *enter*, but called at the end of the matcher code for + # a grammar element of kind *pegKind*. + template mkDoLeave(hdPostf, s, pegNode, start, length) = + when declared(`leave hdPostf`): + `leave hdPostf`(s, pegNode, start, length): + else: + discard + let hdPostf = ident(substr(strVal(pegKind), 2)) + getAst(mkDoLeave(hdPostf, s, pegNode, start, length)) + + matchOrParse(parseIt) + parseIt(s, p, start, c) + + proc parser(s: string): int {.genSym.} = + # the proc to be returned + var + ms: array[MaxSubpatterns, (int, int)] + cs = Captures(matches: ms, ml: 0, origStart: 0) + rawParse(s, pegAst, 0, cs) + parser template fillMatches(s, caps, c) = for k in 0..c.ml-1: diff --git a/tests/stdlib/tpegs.nim b/tests/stdlib/tpegs.nim index e5b709a661..b07442dcb4 100644 --- a/tests/stdlib/tpegs.nim +++ b/tests/stdlib/tpegs.nim @@ -1,5 +1,7 @@ discard """ output: ''' +PEG AST traversal output +------------------------ pkNonTerminal: Sum @(2, 3) pkSequence: (Product (('+' / '-') Product)*) pkNonTerminal: Product @(3, 7) @@ -26,6 +28,25 @@ pkNonTerminal: Sum @(2, 3) pkChar: '+' pkChar: '-' pkNonTerminal: Product @(3, 7) + +Event parser output +------------------- +@[5.0] ++ +@[5.0, 3.0] +@[8.0] + +/ +@[8.0, 2.0] +@[4.0] + +- +@[4.0, 7.0] +-* +@[4.0, 7.0, 22.0] +@[4.0, 154.0] +- +@[-150.0] ''' """ @@ -36,43 +57,92 @@ const indent = " " let - pegSrc = """ -Expr <- Sum -Sum <- Product (('+' / '-') Product)* -Product <- Value (('*' / '/') Value)* -Value <- [0-9]+ / '(' Expr ')' - """ - pegAst: Peg = pegSrc.peg + pegAst = """ +Expr <- Sum +Sum <- Product (('+' / '-')Product)* +Product <- Value (('*' / '/')Value)* +Value <- [0-9]+ / '(' Expr ')' + """.peg + txt = "(5+3)/2-7*22" -var - outp = newStringStream() - processed: seq[string] = @[] +block: + var + outp = newStringStream() + processed: seq[string] = @[] -proc prt(outp: Stream, kind: PegKind, s: string; level: int = 0) = - outp.writeLine indent.repeat(level) & "$1: $2" % [$kind, s] + proc prt(outp: Stream, kind: PegKind, s: string; level: int = 0) = + outp.writeLine indent.repeat(level) & "$1: $2" % [$kind, s] -proc recLoop(p: Peg, level: int = 0) = - case p.kind - of pkEmpty..pkWhitespace: - discard - of pkTerminal, pkTerminalIgnoreCase, pkTerminalIgnoreStyle: - outp.prt(p.kind, $p, level) - of pkChar, pkGreedyRepChar: - outp.prt(p.kind, $p, level) - of pkCharChoice, pkGreedyRepSet: - outp.prt(p.kind, $p, level) - of pkNonTerminal: - outp.prt(p.kind, - "$1 @($3, $4)" % [p.nt.name, $p.nt.rule.kind, $p.nt.line, $p.nt.col], level) - if not(p.nt.name in processed): - processed.add p.nt.name - p.nt.rule.recLoop level+1 - of pkBackRef..pkBackRefIgnoreStyle: - outp.prt(p.kind, $p, level) - else: - outp.prt(p.kind, $p, level) - for s in items(p): - s.recLoop level+1 + proc recLoop(p: Peg, level: int = 0) = + case p.kind + of pkEmpty..pkWhitespace: + discard + of pkTerminal, pkTerminalIgnoreCase, pkTerminalIgnoreStyle: + outp.prt(p.kind, $p, level) + of pkChar, pkGreedyRepChar: + outp.prt(p.kind, $p, level) + of pkCharChoice, pkGreedyRepSet: + outp.prt(p.kind, $p, level) + of pkNonTerminal: + outp.prt(p.kind, + "$1 @($3, $4)" % [p.nt.name, $p.nt.rule.kind, $p.nt.line, $p.nt.col], level) + if not(p.nt.name in processed): + processed.add p.nt.name + p.nt.rule.recLoop level+1 + of pkBackRef..pkBackRefIgnoreStyle: + outp.prt(p.kind, $p, level) + else: + outp.prt(p.kind, $p, level) + for s in items(p): + s.recLoop level+1 -pegAst.recLoop -echo outp.data \ No newline at end of file + pegAst.recLoop + echo "PEG AST traversal output" + echo "------------------------" + echo outp.data + +block: + var + pStack: seq[string] = @[] + valStack: seq[float] = @[] + opStack = "" + let + parseArithExpr = pegAst.eventParser: + pkNonTerminal: + enter: + pStack.add p.nt.name + leave: + pStack.setLen pStack.high + if length > 0: + let matchStr = s.substr(start, start+length-1) + case p.nt.name + of "Value": + try: + valStack.add matchStr.parseFloat + echo valStack + except ValueError: + discard + of "Sum", "Product": + try: + let val = matchStr.parseFloat + except ValueError: + if valStack.len > 1 and opStack.len > 0: + valStack[^2] = case opStack[^1] + of '+': valStack[^2] + valStack[^1] + of '-': valStack[^2] - valStack[^1] + of '*': valStack[^2] * valStack[^1] + else: valStack[^2] / valStack[^1] + valStack.setLen valStack.high + echo valStack + opStack.setLen opStack.high + echo opStack + pkChar: + leave: + if length == 1 and "Value" != pStack[^1]: + let matchChar = s[start] + opStack.add matchChar + echo opStack + echo "Event parser output" + echo "-------------------" + let pLen = parseArithExpr(txt) + assert txt.len == pLen From 9707b232587b73f319ca3cd527a8bef15c813354 Mon Sep 17 00:00:00 2001 From: hlaaf Date: Fri, 24 Aug 2018 22:19:24 +0300 Subject: [PATCH 063/145] Fixes #8766 (#8769) --- doc/manual.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/manual.rst b/doc/manual.rst index bb2650799b..19a5355a26 100644 --- a/doc/manual.rst +++ b/doc/manual.rst @@ -433,7 +433,7 @@ Numerical constants are of a single type and have the form:: UINT64_LIT = INT_LIT ['\''] ('u' | 'U') '64' exponent = ('e' | 'E' ) ['+' | '-'] digit ( ['_'] digit )* - FLOAT_LIT = digit (['_'] digit)* (('.' (['_'] digit)* [exponent]) |exponent) + FLOAT_LIT = digit (['_'] digit)* (('.' digit (['_'] digit)* [exponent]) |exponent) FLOAT32_SUFFIX = ('f' | 'F') ['32'] FLOAT32_LIT = HEX_LIT '\'' FLOAT32_SUFFIX | (FLOAT_LIT | DEC_LIT | OCT_LIT | BIN_LIT) ['\''] FLOAT32_SUFFIX From 56de4c81b271cf878502d44d8f8f46e6c082a548 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Fri, 24 Aug 2018 22:55:05 -0700 Subject: [PATCH 064/145] fixes #8739; allow --hint:foo:on --warning:bar:off (#8757) --- compiler/commands.nim | 23 ++++++++++++++++------- compiler/nimconf.nim | 2 +- lib/system/nimscript.nim | 4 ++-- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/compiler/commands.nim b/compiler/commands.nim index f7c8cf9f23..8165fa5d49 100644 --- a/compiler/commands.nim +++ b/compiler/commands.nim @@ -131,7 +131,10 @@ proc splitSwitch(conf: ConfigRef; switch: string, cmd, arg: var string, pass: TC else: break inc(i) if i >= len(switch): arg = "" - elif switch[i] in {':', '=', '['}: arg = substr(switch, i + 1) + # cmd:arg => (cmd,arg) + elif switch[i] in {':', '='}: arg = substr(switch, i + 1) + # cmd[sub]:rest => (cmd,[sub]:rest) + elif switch[i] == '[': arg = substr(switch, i) else: invalidCmdLineOption(conf, pass, switch, info) proc processOnOffSwitch(conf: ConfigRef; op: TOptions, arg: string, pass: TCmdLinePass, @@ -167,14 +170,20 @@ proc expectNoArg(conf: ConfigRef; switch, arg: string, pass: TCmdLinePass, info: proc processSpecificNote*(arg: string, state: TSpecialWord, pass: TCmdLinePass, info: TLineInfo; orig: string; conf: ConfigRef) = - var id = "" # arg = "X]:on|off" + var id = "" # arg = key:val or [key]:val; with val=on|off var i = 0 var n = hintMin - while i < len(arg) and (arg[i] != ']'): + var isBracket = false + if i < len(arg) and arg[i] == '[': + isBracket = true + inc(i) + while i < len(arg) and (arg[i] notin {':', '=', ']'}): add(id, arg[i]) inc(i) - if i < len(arg) and (arg[i] == ']'): inc(i) - else: invalidCmdLineOption(conf, pass, orig, info) + if isBracket: + if i < len(arg) and arg[i] == ']': inc(i) + else: invalidCmdLineOption(conf, pass, orig, info) + if i < len(arg) and (arg[i] in {':', '='}): inc(i) else: invalidCmdLineOption(conf, pass, orig, info) if state == wHint: @@ -743,11 +752,11 @@ proc processCommand*(switch: string, pass: TCmdLinePass; config: ConfigRef) = proc processSwitch*(pass: TCmdLinePass; p: OptParser; config: ConfigRef) = # hint[X]:off is parsed as (p.key = "hint[X]", p.val = "off") - # we fix this here + # we transform it to (key = hint, val = [X]:off) var bracketLe = strutils.find(p.key, '[') if bracketLe >= 0: var key = substr(p.key, 0, bracketLe - 1) - var val = substr(p.key, bracketLe + 1) & ':' & p.val + var val = substr(p.key, bracketLe) & ':' & p.val processSwitch(key, val, pass, gCmdLineInfo, config) else: processSwitch(p.key, p.val, pass, gCmdLineInfo, config) diff --git a/compiler/nimconf.nim b/compiler/nimconf.nim index 1a8a0acb5b..96b9a38413 100644 --- a/compiler/nimconf.nim +++ b/compiler/nimconf.nim @@ -175,9 +175,9 @@ proc parseAssignment(L: var TLexer, tok: var TToken; confTok(L, tok, config, condStack) if tok.tokType == tkBracketLe: # BUGFIX: val, not s! - # BUGFIX: do not copy '['! confTok(L, tok, config, condStack) checkSymbol(L, tok) + add(val, '[') add(val, tokToStr(tok)) confTok(L, tok, config, condStack) if tok.tokType == tkBracketRi: confTok(L, tok, config, condStack) diff --git a/lib/system/nimscript.nim b/lib/system/nimscript.nim index 5bf69dd94b..3aafaa8d11 100644 --- a/lib/system/nimscript.nim +++ b/lib/system/nimscript.nim @@ -73,12 +73,12 @@ proc switch*(key: string, val="") = proc warning*(name: string; val: bool) = ## Disables or enables a specific warning. let v = if val: "on" else: "off" - warningImpl(name & "]:" & v, "warning[" & name & "]:" & v) + warningImpl(name & ":" & v, "warning:" & name & ":" & v) proc hint*(name: string; val: bool) = ## Disables or enables a specific hint. let v = if val: "on" else: "off" - hintImpl(name & "]:" & v, "hint[" & name & "]:" & v) + hintImpl(name & ":" & v, "hint:" & name & ":" & v) proc patchFile*(package, filename, replacement: string) = ## Overrides the location of a given file belonging to the From 6f13184e40b21956f53e407888ac2730a5e5e58c Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sat, 25 Aug 2018 07:56:05 +0200 Subject: [PATCH 065/145] More checks for custom pragmas placement (#8765) We're not interested in custom pragmas attached to certain node kinds so the compiler silently ignored them. --- compiler/pragmas.nim | 9 ++++++--- tests/pragmas/t8741.nim | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index 66682650d1..c0de1edca3 100644 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -96,7 +96,9 @@ const errIntLiteralExpected = "integer literal expected" proc invalidPragma*(c: PContext; n: PNode) = - localError(c.config, n.info, "invalid pragma: " % renderTree(n, {renderNoComments})) + localError(c.config, n.info, "invalid pragma: " & renderTree(n, {renderNoComments})) +proc illegalCustomPragma*(c: PContext, n: PNode, s: PSym) = + localError(c.config, n.info, "cannot attach a custom pragma to '" & s.name.s & "'") proc pragmaAsm*(c: PContext, n: PNode): char = result = '\0' @@ -1094,9 +1096,10 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int, else: sym.flags.incl sfUsed of wLiftLocals: discard else: invalidPragma(c, it) - else: + elif sym.kind in {skField,skProc,skFunc,skConverter,skMethod,skType}: n.sons[i] = semCustomPragma(c, it) - + else: + illegalCustomPragma(c, it, sym) proc implicitPragmas*(c: PContext, sym: PSym, n: PNode, validPragmas: TSpecialWords) = diff --git a/tests/pragmas/t8741.nim b/tests/pragmas/t8741.nim index 7398b10307..41f2f9e8ae 100644 --- a/tests/pragmas/t8741.nim +++ b/tests/pragmas/t8741.nim @@ -1,6 +1,6 @@ discard """ line: 9 - errormsg: "attempting to call undeclared routine: 'foobar'" + errormsg: "cannot attach a custom pragma to 'a'" """ for a {.gensym, inject.} in @[1,2,3]: From 81f920a4ee0c234b953d34ab7d7e8db891638f3f Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Sat, 25 Aug 2018 08:44:02 +0100 Subject: [PATCH 066/145] Process timers before and after `select`. Fixes flaky #7758 test. (#8750) --- lib/pure/asyncdispatch.nim | 43 +++++++++++++++++++++----------------- tests/async/t7758.nim | 11 +++++----- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/lib/pure/asyncdispatch.nim b/lib/pure/asyncdispatch.nim index df37cab37f..093bf58af5 100644 --- a/lib/pure/asyncdispatch.nim +++ b/lib/pure/asyncdispatch.nim @@ -10,6 +10,7 @@ include "system/inclrtl" import os, tables, strutils, times, heapqueue, lists, options, asyncstreams +import options, math import asyncfutures except callSoon import nativesockets, net, deques @@ -157,9 +158,6 @@ export asyncfutures, asyncstreams ## ---------------- ## ## * The effect system (``raises: []``) does not work with async procedures. -## * Can't await in a ``except`` body -## * Forward declarations for async procs are broken, -## link includes workaround: https://github.com/nim-lang/Nim/issues/3182. # TODO: Check if yielded future is nil and throw a more meaningful exception @@ -168,8 +166,10 @@ type timers*: HeapQueue[tuple[finishAt: float, fut: Future[void]]] callbacks*: Deque[proc ()] -proc processTimers(p: PDispatcherBase; didSomeWork: var bool) {.inline.} = - #Process just part if timers at a step +proc processTimers( + p: PDispatcherBase, didSomeWork: var bool +): Option[int] {.inline.} = + # Pop the timers in the order in which they will expire (smaller `finishAt`). var count = p.timers.len let t = epochTime() while count > 0 and t >= p.timers[0].finishAt: @@ -177,22 +177,25 @@ proc processTimers(p: PDispatcherBase; didSomeWork: var bool) {.inline.} = dec count didSomeWork = true + # Return the number of miliseconds in which the next timer will expire. + if p.timers.len == 0: return + + let milisecs = (p.timers[0].finishAt - epochTime()) * 1000 + return some(ceil(milisecs).int) + proc processPendingCallbacks(p: PDispatcherBase; didSomeWork: var bool) = while p.callbacks.len > 0: var cb = p.callbacks.popFirst() cb() didSomeWork = true -proc adjustedTimeout(p: PDispatcherBase, timeout: int): int {.inline.} = - # If dispatcher has active timers this proc returns the timeout - # of the nearest timer. Returns `timeout` otherwise. - result = timeout - if p.timers.len > 0: - let timerTimeout = p.timers[0].finishAt - let curTime = epochTime() - if timeout == -1 or (curTime + (timeout / 1000)) > timerTimeout: - result = int((timerTimeout - curTime) * 1000) - if result < 0: result = 0 +proc adjustTimeout(pollTimeout: int, nextTimer: Option[int]): int {.inline.} = + if nextTimer.isNone(): + return pollTimeout + + result = nextTimer.get() + if pollTimeout == -1: return + result = min(pollTimeout, result) proc callSoon(cbproc: proc ()) {.gcsafe.} @@ -299,7 +302,8 @@ when defined(windows) or defined(nimdoc): "No handles or timers registered in dispatcher.") result = false - let at = p.adjustedTimeout(timeout) + let nextTimer = processTimers(p, result) + let at = adjustTimeout(timeout, nextTimer) var llTimeout = if at == -1: winlean.INFINITE else: at.int32 @@ -344,7 +348,7 @@ when defined(windows) or defined(nimdoc): else: raiseOSError(errCode) # Timer processing. - processTimers(p, result) + discard processTimers(p, result) # Callback queue processing processPendingCallbacks(p, result) @@ -1231,7 +1235,8 @@ else: result = false var keys: array[64, ReadyKey] - var count = p.selector.selectInto(p.adjustedTimeout(timeout), keys) + let nextTimer = processTimers(p, result) + var count = p.selector.selectInto(adjustTimeout(timeout, nextTimer), keys) for i in 0.. Date: Sat, 25 Aug 2018 12:48:37 -0700 Subject: [PATCH 067/145] doAssert, assert now print full path of failing line on error (#8555) --- lib/core/macros.nim | 4 +- lib/system.nim | 28 ++++++------- lib/system/helpers.nim | 11 +++++ tests/assert/testhelper.nim | 12 ++++++ tests/assert/tfailedassert.nim | 69 ++++++++++++++++++++++++++------ tests/assert/tfaileddoassert.nim | 17 ++++++-- 6 files changed, 109 insertions(+), 32 deletions(-) create mode 100644 lib/system/helpers.nim create mode 100644 tests/assert/testhelper.nim diff --git a/lib/core/macros.nim b/lib/core/macros.nim index 90fea440ed..bac9ce7a2a 100644 --- a/lib/core/macros.nim +++ b/lib/core/macros.nim @@ -8,6 +8,7 @@ # include "system/inclrtl" +include "system/helpers" ## This module contains the interface to the compiler's abstract syntax ## tree (`AST`:idx:). Macros operate on this tree. @@ -422,7 +423,8 @@ type line*,column*: int proc `$`*(arg: Lineinfo): string = - result = arg.filename & "(" & $arg.line & ", " & $arg.column & ")" + # BUG: without `result = `, gives compile error + result = lineInfoToString(arg.filename, arg.line, arg.column) #proc lineinfo*(n: NimNode): LineInfo {.magic: "NLineInfo", noSideEffect.} ## returns the position the node appears in the original source file diff --git a/lib/system.nim b/lib/system.nim index dcfb04c5ac..8b98706abf 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -3758,6 +3758,16 @@ proc failedAssertImpl*(msg: string) {.raises: [], tags: [].} = tags: [].} Hide(raiseAssert)(msg) +include "system/helpers" # for `lineInfoToString` + +template assertImpl(cond: bool, msg = "", enabled: static[bool]) = + const loc = $instantiationInfo(-1, true) + bind instantiationInfo + mixin failedAssertImpl + when enabled: + if not cond: + failedAssertImpl(loc & " `" & astToStr(cond) & "` " & msg) + template assert*(cond: bool, msg = "") = ## Raises ``AssertionError`` with `msg` if `cond` is false. Note ## that ``AssertionError`` is hidden from the effect system, so it doesn't @@ -3767,23 +3777,11 @@ template assert*(cond: bool, msg = "") = ## The compiler may not generate any code at all for ``assert`` if it is ## advised to do so through the ``-d:release`` or ``--assertions:off`` ## `command line switches `_. - # NOTE: `true` is correct here; --excessiveStackTrace:on will control whether - # or not to output full paths. - bind instantiationInfo - mixin failedAssertImpl - {.line: instantiationInfo(fullPaths = true).}: - when compileOption("assertions"): - if not cond: failedAssertImpl(astToStr(cond) & ' ' & msg) + assertImpl(cond, msg, compileOption("assertions")) template doAssert*(cond: bool, msg = "") = - ## same as `assert` but is always turned on and not affected by the - ## ``--assertions`` command line switch. - # NOTE: `true` is correct here; --excessiveStackTrace:on will control whether - # or not to output full paths. - bind instantiationInfo - mixin failedAssertImpl - {.line: instantiationInfo(fullPaths = true).}: - if not cond: failedAssertImpl(astToStr(cond) & ' ' & msg) + ## same as ``assert`` but is always turned on regardless of ``--assertions`` + assertImpl(cond, msg, true) iterator items*[T](a: seq[T]): T {.inline.} = ## iterates over each item of `a`. diff --git a/lib/system/helpers.nim b/lib/system/helpers.nim new file mode 100644 index 0000000000..fb1218684c --- /dev/null +++ b/lib/system/helpers.nim @@ -0,0 +1,11 @@ +## helpers used system.nim and other modules, avoids code duplication while +## also minimizing symbols exposed in system.nim +# +# TODO: move other things here that should not be exposed in system.nim + +proc lineInfoToString(file: string, line, column: int): string = + file & "(" & $line & ", " & $column & ")" + +proc `$`(info: type(instantiationInfo(0))): string = + # The +1 is needed here + lineInfoToString(info.fileName, info.line, info.column+1) diff --git a/tests/assert/testhelper.nim b/tests/assert/testhelper.nim new file mode 100644 index 0000000000..754d562ec9 --- /dev/null +++ b/tests/assert/testhelper.nim @@ -0,0 +1,12 @@ +from strutils import endsWith, split +from ospaths import isAbsolute + +proc checkMsg*(msg, expectedEnd, name: string)= + let filePrefix = msg.split(' ', maxSplit = 1)[0] + if not filePrefix.isAbsolute: + echo name, ":not absolute: `", msg & "`" + elif not msg.endsWith expectedEnd: + echo name, ":expected suffix:\n`" & expectedEnd & "`\ngot:\n`" & msg & "`" + else: + echo name, ":ok" + diff --git a/tests/assert/tfailedassert.nim b/tests/assert/tfailedassert.nim index 8b260a3ab9..c3231bb8d9 100644 --- a/tests/assert/tfailedassert.nim +++ b/tests/assert/tfailedassert.nim @@ -1,20 +1,65 @@ discard """ output: ''' -WARNING: false first assertion from bar -ERROR: false second assertion from bar +test1:ok +test2:ok +test3:ok +test4:ok +test5:ok +test6:ok +test7:ok -1 -tfailedassert.nim:27 false assertion from foo +tfailedassert.nim +test7:ok ''' """ +import testhelper + type TLineInfo = tuple[filename: string, line: int, column: int] - TMyError = object of Exception lineinfo: TLineInfo - EMyError = ref TMyError +echo("") + + +# NOTE: when entering newlines, adjust `expectedEnd` ouptuts + +try: + doAssert(false, "msg1") # doAssert test +except AssertionError as e: + checkMsg(e.msg, "tfailedassert.nim(30, 11) `false` msg1", "test1") + +try: + assert false, "msg2" # assert test +except AssertionError as e: + checkMsg(e.msg, "tfailedassert.nim(35, 10) `false` msg2", "test2") + +try: + assert false # assert test with no msg +except AssertionError as e: + checkMsg(e.msg, "tfailedassert.nim(40, 10) `false` ", "test3") + +try: + let a = 1 + doAssert(a+a==1) # assert test with Ast expression + # BUG: const folding would make "1+1==1" appear as `false` in + # assert message +except AssertionError as e: + checkMsg(e.msg, "`a + a == 1` ", "test4") + +try: + let a = 1 + doAssert a+a==1 # ditto with `doAssert` and no parens +except AssertionError as e: + checkMsg(e.msg, "`a + a == 1` ", "test5") + +proc fooStatic() = + # protect against https://github.com/nim-lang/Nim/issues/8758 + static: doAssert(true) +fooStatic() + # module-wide policy to change the failed assert # exception type in order to include a lineinfo onFailedAssert(msg): @@ -26,26 +71,26 @@ onFailedAssert(msg): proc foo = assert(false, "assertion from foo") + proc bar: int = - # local overrides that are active only - # in this proc - onFailedAssert(msg): echo "WARNING: " & msg + # local overrides that are active only in this proc + onFailedAssert(msg): + checkMsg(msg, "tfailedassert.nim(80, 9) `false` first assertion from bar", "test6") assert(false, "first assertion from bar") onFailedAssert(msg): - echo "ERROR: " & msg + checkMsg(msg, "tfailedassert.nim(86, 9) `false` second assertion from bar", "test7") return -1 assert(false, "second assertion from bar") return 10 -echo("") echo(bar()) try: foo() except: let e = EMyError(getCurrentException()) - echo e.lineinfo.filename, ":", e.lineinfo.line, " ", e.msg - + echo e.lineinfo.filename + checkMsg(e.msg, "tfailedassert.nim(72, 9) `false` assertion from foo", "test7") diff --git a/tests/assert/tfaileddoassert.nim b/tests/assert/tfaileddoassert.nim index 3195fb406b..e1245f5785 100644 --- a/tests/assert/tfaileddoassert.nim +++ b/tests/assert/tfaileddoassert.nim @@ -1,11 +1,20 @@ discard """ cmd: "nim $target -d:release $options $file" output: ''' -assertion occured!!!!!! false +test1:ok +test2:ok ''' """ -onFailedAssert(msg): - echo("assertion occured!!!!!! ", msg) +import testhelper -doAssert(1 == 2) +onFailedAssert(msg): + checkMsg(msg, "tfaileddoassert.nim(15, 9) `a == 2` foo", "test1") + +var a = 1 +doAssert(a == 2, "foo") + +onFailedAssert(msg): + checkMsg(msg, "tfaileddoassert.nim(20, 10) `a == 3` ", "test2") + +doAssert a == 3 From e9b665f33890d78d78cc851febac1caee5a30b5b Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Sat, 25 Aug 2018 12:49:18 -0700 Subject: [PATCH 068/145] gitignore html output of nim doc foo (#8742) --- .gitignore | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index f2037c1b83..eb29dfc047 100644 --- a/.gitignore +++ b/.gitignore @@ -48,7 +48,10 @@ xcuserdata/ /compiler/nimrod.dot /reject.json /run.json -/testresults.html +# for `nim doc foo.nim` +/*.html +#/testresults.html #covered by /*.html + /testresults.json testament.db /csources @@ -62,3 +65,4 @@ dist/ testresults/ test.txt /test.ini + From 96d44fdd0a24bc5cbfe29de6079da6882388aed8 Mon Sep 17 00:00:00 2001 From: awr1 <41453959+awr1@users.noreply.github.com> Date: Sun, 26 Aug 2018 10:15:19 -0500 Subject: [PATCH 069/145] Deprecate xlen() for strings and seqs (#8782) * deprecates xlen() for strings and seqs * added docs --- lib/system.nim | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/system.nim b/lib/system.nim index 8b98706abf..2c88fe60f8 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -4055,10 +4055,15 @@ proc procCall*(x: untyped) {.magic: "ProcCall", compileTime.} = ## procCall someMethod(a, b) discard -proc xlen*(x: string): int {.magic: "XLenStr", noSideEffect.} = discard -proc xlen*[T](x: seq[T]): int {.magic: "XLenSeq", noSideEffect.} = +proc xlen*(x: string): int {.magic: "XLenStr", noSideEffect, + deprecated: "use len() instead".} = + ## **Deprecated since version 0.18.1**. Use len() instead. + discard +proc xlen*[T](x: seq[T]): int {.magic: "XLenSeq", noSideEffect, + deprecated: "use len() instead".} = ## returns the length of a sequence or a string without testing for 'nil'. ## This is an optimization that rarely makes sense. + ## **Deprecated since version 0.18.1**. Use len() instead. discard From b4edfa613b3adeaa091e8aee7d38d9c24fa4e32e Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Sun, 26 Aug 2018 08:36:11 -0700 Subject: [PATCH 070/145] [ospaths] simplify getConfigDir and introduce normalizePathEnd to make (#8680) sure path endings are normalized with 0 or 1 trailing sep, taking care of edge cases --- lib/pure/ospaths.nim | 54 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/lib/pure/ospaths.nim b/lib/pure/ospaths.nim index 1bcfd978b6..bc6739dd39 100644 --- a/lib/pure/ospaths.nim +++ b/lib/pure/ospaths.nim @@ -449,6 +449,31 @@ proc isAbsolute*(path: string): bool {.rtl, noSideEffect, extern: "nos$1".} = elif defined(posix): result = path[0] == '/' + +proc normalizePathEnd(path: var string, trailingSep = false) = + ## ensures ``path`` has exactly 0 or 1 trailing `DirSep`, depending on + ## ``trailingSep``, and taking care of edge cases: it preservers whether + ## a path is absolute or relative, and makes sure trailing sep is `DirSep`, + ## not `AltSep`. + if path.len == 0: return + var i = path.len + while i >= 1 and path[i-1] in {DirSep, AltSep}: dec(i) + if trailingSep: + # foo// => foo + path.setLen(i) + # foo => foo/ + path.add DirSep + elif i>0: + # foo// => foo + path.setLen(i) + else: + # // => / (empty case was already taken care of) + path = $DirSep + +proc normalizePathEnd(path: string, trailingSep = false): string = + result = path + result.normalizePathEnd(trailingSep) + proc unixToNativePath*(path: string, drive=""): string {. noSideEffect, rtl, extern: "nos$1".} = ## Converts an UNIX-like path to a native one. @@ -530,12 +555,12 @@ proc getConfigDir*(): string {.rtl, extern: "nos$1", ## "~/.config/", otherwise. ## ## An OS-dependent trailing slash is always present at the end of the - ## returned string; `\\` on Windows and `/` on all other OSs. + ## returned string; `\` on Windows and `/` on all other OSs. when defined(windows): - result = string(getEnv("APPDATA")) & "\\" + result = getEnv("APPDATA").string else: - result = string(getEnv("XDG_CONFIG_HOME", "")) & "/" - if result == "/": result = string(getEnv("HOME")) & "/.config/" + result = getEnv("XDG_CONFIG_HOME", getEnv("HOME").string / ".config").string + result.normalizePathEnd(trailingSep = true) proc getTempDir*(): string {.rtl, extern: "nos$1", tags: [ReadEnvEffect, ReadIOEffect].} = @@ -649,3 +674,24 @@ when isMainModule: when defined(posix): assert quoteShell("") == "''" + + block normalizePathEndTest: + # handle edge cases correctly: shouldn't affect whether path is + # absolute/relative + doAssert "".normalizePathEnd(true) == "" + doAssert "".normalizePathEnd(false) == "" + doAssert "/".normalizePathEnd(true) == $DirSep + doAssert "/".normalizePathEnd(false) == $DirSep + + when defined(posix): + doAssert "//".normalizePathEnd(false) == "/" + doAssert "foo.bar//".normalizePathEnd == "foo.bar" + doAssert "bar//".normalizePathEnd(trailingSep = true) == "bar/" + when defined(Windows): + doAssert r"C:\foo\\".normalizePathEnd == r"C:\foo" + doAssert r"C:\foo".normalizePathEnd(trailingSep = true) == r"C:\foo\" + # this one is controversial: we could argue for returning `D:\` instead, + # but this is simplest. + doAssert r"D:\".normalizePathEnd == r"D:" + doAssert r"E:/".normalizePathEnd(trailingSep = true) == r"E:\" + doAssert "/".normalizePathEnd == r"\" From 50aa376e802d949f430eba64ecd9f6beb86f91df Mon Sep 17 00:00:00 2001 From: awr1 <41453959+awr1@users.noreply.github.com> Date: Sun, 26 Aug 2018 10:42:57 -0500 Subject: [PATCH 071/145] Added to docs: warning string for {.deprecated.} pragma (#8783) --- doc/manual.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/manual.rst b/doc/manual.rst index 19a5355a26..739f464e07 100644 --- a/doc/manual.rst +++ b/doc/manual.rst @@ -6448,6 +6448,11 @@ The deprecated pragma is used to mark a symbol as deprecated: proc p() {.deprecated.} var x {.deprecated.}: char +This pragma can also take in an optional warning string to relay to developers. + +.. code-block:: nim + proc thing(x: bool) {.deprecated: "See arguments of otherThing()".} + It can also be used as a statement, in that case it takes a list of *renamings*. .. code-block:: nim @@ -6456,7 +6461,6 @@ It can also be used as a statement, in that case it takes a list of *renamings*. Stream = ref object {.deprecated: [TFile: File, PStream: Stream].} - noSideEffect pragma ------------------- The ``noSideEffect`` pragma is used to mark a proc/iterator to have no side From 238809f50686f63206210e6e923c59243914b1e3 Mon Sep 17 00:00:00 2001 From: Nathan Cahill Date: Sun, 26 Aug 2018 12:11:43 -0700 Subject: [PATCH 072/145] Update html attrs to current html spec --- lib/pure/htmlgen.nim | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/pure/htmlgen.nim b/lib/pure/htmlgen.nim index 55b02ea60c..ea3a0a3f0a 100644 --- a/lib/pure/htmlgen.nim +++ b/lib/pure/htmlgen.nim @@ -31,10 +31,18 @@ import macros, strutils const - coreAttr* = " id class title style " - eventAttr* = " onclick ondblclick onmousedown onmouseup " & - "onmouseover onmousemove onmouseout onkeypress onkeydown onkeyup onload " - commonAttr* = coreAttr & eventAttr + coreAttr* = " accesskey class contenteditable dir hidden id lang " & + "spellcheck style tabindex title translate " + eventAttr* = "onabort onblur oncancel oncanplay oncanplaythrough onchange " & + "onclick oncuechange ondblclick ondurationchange onemptied onended " & + "onerror onfocus oninput oninvalid onkeydown onkeypress onkeyup onload " & + "onloadeddata onloadedmetadata onloadstart onmousedown onmouseenter " & + "onmouseleave onmousemove onmouseout onmouseover onmouseup onmousewheel " & + "onpause onplay onplaying onprogress onratechange onreset onresize " & + "onscroll onseeked onseeking onselect onshow onstalled onsubmit " & + "onsuspend ontimeupdate ontoggle onvolumechange onwaiting " + ariaAttr* = " role " + commonAttr* = coreAttr & eventAttr & ariaAttr proc getIdent(e: NimNode): string {.compileTime.} = case e.kind From 52f03fabc12f7f0cd9ed41b55d8c03fb5319f971 Mon Sep 17 00:00:00 2001 From: Vindaar Date: Mon, 27 Aug 2018 08:35:07 +0200 Subject: [PATCH 073/145] fixes #8781 by appending "_U" instead of 'U' (#8787) --- compiler/ccgtypes.nim | 4 +++- tests/ccgbugs/t8781.nim | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 tests/ccgbugs/t8781.nim diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index 59fbfc3e15..dd79f4846b 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -449,7 +449,9 @@ proc genRecordFieldsAux(m: BModule, n: PNode, of nkRecCase: if n.sons[0].kind != nkSym: internalError(m.config, n.info, "genRecordFieldsAux") add(result, genRecordFieldsAux(m, n.sons[0], accessExpr, rectype, check)) - let uname = rope(mangle(n.sons[0].sym.name.s) & 'U') + # prefix mangled name with "_U" to avoid clashes with other field names, + # since identifiers are not allowed to start with '_' + let uname = rope("_U" & mangle(n.sons[0].sym.name.s)) let ae = if accessExpr != nil: "$1.$2" % [accessExpr, uname] else: uname var unionBody: Rope = nil diff --git a/tests/ccgbugs/t8781.nim b/tests/ccgbugs/t8781.nim new file mode 100644 index 0000000000..1fa8ec8a56 --- /dev/null +++ b/tests/ccgbugs/t8781.nim @@ -0,0 +1,25 @@ +discard """ +output: "" +""" + +type + Drawable = object of RootObj + discard + + # issue #8781, following type was broken due to 'U' suffix + # on `animatedU`. U also added as union identifier for C. + # replaced by "_U" prefix, which is not allowed as an + # identifier + TypeOne = ref object of Drawable + animatedU: bool + case animated: bool + of true: + frames: seq[int] + of false: + region: float + +when isMainModule: + let r = 1.5 + let a = TypeOne(animatedU: true, + animated: false, + region: r) From 57a291db333a1d3b6b551ac0aa1799446f660e7e Mon Sep 17 00:00:00 2001 From: Araq Date: Sat, 25 Aug 2018 20:46:22 +0200 Subject: [PATCH 074/145] optimize away genericReset for result assignment; refs #8745 --- compiler/cgen.nim | 115 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 112 insertions(+), 3 deletions(-) diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 2cb431ff98..dea8b1e8af 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -705,9 +705,10 @@ proc containsResult(n: PNode): bool = for i in 0.. 0: + result = allPathsAsgnResult(n[0]) + of nkIfStmt, nkIfExpr: + var exhaustive = false + result = InitSkippable + for it in n: + # Every condition must not use 'result': + if it.len == 2 and containsResult(it[0]): + return InitRequired + if it.len == 1: exhaustive = true + allPathsInBranch(it.lastSon) + # if the 'if' statement is not exhaustive and yet it touched 'result' + # in some way, say Unknown. + if not exhaustive: result = Unknown + of nkCaseStmt: + if containsResult(n[0]): return InitRequired + result = InitSkippable + var exhaustive = skipTypes(n[0].typ, + abstractVarRange-{tyTypeDesc}).kind notin {tyFloat..tyFloat128, tyString} + for i in 1.. Date: Mon, 27 Aug 2018 11:20:30 +0200 Subject: [PATCH 075/145] allow .experimental in a .push/pop environment; refs #8676 --- compiler/pragmas.nim | 39 ++++++++++++++++------------- compiler/semdata.nim | 1 + doc/manual.rst | 26 ++++++++++++++++++- tests/pragmas/tpushexperimental.nim | 13 ++++++++++ 4 files changed, 61 insertions(+), 18 deletions(-) create mode 100644 tests/pragmas/tpushexperimental.nim diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index c0de1edca3..7aa6748006 100644 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -343,6 +343,20 @@ proc pragmaToOptions(w: TSpecialWord): TOptions {.inline.} = of wPatterns: {optPatterns} else: {} +proc processExperimental(c: PContext; n: PNode) = + if n.kind notin nkPragmaCallKinds or n.len != 2: + c.features.incl oldExperimentalFeatures + else: + n[1] = c.semConstExpr(c, n[1]) + case n[1].kind + of nkStrLit, nkRStrLit, nkTripleStrLit: + try: + c.features.incl parseEnum[Feature](n[1].strVal) + except ValueError: + localError(c.config, n[1].info, "unknown experimental feature") + else: + localError(c.config, n.info, errStringLiteralExpected) + proc tryProcessOption(c: PContext, n: PNode, resOptions: var TOptions): bool = result = true if n.kind notin nkPragmaCallKinds or n.len != 2: result = false @@ -350,6 +364,9 @@ proc tryProcessOption(c: PContext, n: PNode, resOptions: var TOptions): bool = elif n.sons[0].kind != nkIdent: result = false else: let sw = whichKeyword(n.sons[0].ident) + if sw == wExperimental: + processExperimental(c, n) + return true let opts = pragmaToOptions(sw) if opts != {}: onOff(c, n, opts, resOptions) @@ -388,6 +405,7 @@ proc processPush(c: PContext, n: PNode, start: int) = x.defaultCC = y.defaultCC x.dynlib = y.dynlib x.notes = c.config.notes + x.features = c.features c.optionStack.add(x) for i in countup(start, sonsLen(n) - 1): if not tryProcessOption(c, n.sons[i], c.config.options): @@ -407,6 +425,7 @@ proc processPop(c: PContext, n: PNode) = else: c.config.options = c.optionStack[^1].options c.config.notes = c.optionStack[^1].notes + c.features = c.optionStack[^1].features c.optionStack.setLen(c.optionStack.len - 1) proc processDefine(c: PContext, n: PNode) = @@ -717,22 +736,6 @@ proc semCustomPragma(c: PContext, n: PNode): PNode = elif n.kind == nkExprColonExpr: result.kind = n.kind # pragma(arg) -> pragma: arg -proc processExperimental(c: PContext; n: PNode; s: PSym) = - if not isTopLevel(c): - localError(c.config, n.info, "'experimental' pragma only valid as toplevel statement") - if n.kind notin nkPragmaCallKinds or n.len != 2: - c.features.incl oldExperimentalFeatures - else: - n[1] = c.semConstExpr(c, n[1]) - case n[1].kind - of nkStrLit, nkRStrLit, nkTripleStrLit: - try: - c.features.incl parseEnum[Feature](n[1].strVal) - except ValueError: - localError(c.config, n[1].info, "unknown experimental feature") - else: - localError(c.config, n.info, errStringLiteralExpected) - proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int, validPragmas: TSpecialWords): bool = var it = n.sons[i] @@ -1071,7 +1074,9 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int, else: it.sons[1] = c.semExpr(c, it.sons[1]) of wExperimental: - processExperimental(c, it, sym) + if not isTopLevel(c): + localError(c.config, n.info, "'experimental' pragma only valid as toplevel statement or in a 'push' environment") + processExperimental(c, it) of wThis: if it.kind in nkPragmaCallKinds and it.len == 2: c.selfName = considerQuotedIdent(c, it[1]) diff --git a/compiler/semdata.nim b/compiler/semdata.nim index 4189a52147..2e59c07b00 100644 --- a/compiler/semdata.nim +++ b/compiler/semdata.nim @@ -22,6 +22,7 @@ type defaultCC*: TCallingConvention dynlib*: PLib notes*: TNoteKinds + features*: set[Feature] otherPragmas*: PNode # every pragma can be pushed POptionEntry* = ref TOptionEntry diff --git a/doc/manual.rst b/doc/manual.rst index 739f464e07..a5a1c7cb2b 100644 --- a/doc/manual.rst +++ b/doc/manual.rst @@ -6946,12 +6946,36 @@ Example: .. code-block:: nim {.experimental: "parallel".} - proc useUsing(bar, foo) = + proc useParallel() = parallel: for i in 0..4: echo "echo in parallel" +As a top level statement, the experimental pragma enables a feature for the +rest of the module it's enabled in. This is problematic for macro and generic +instantiations that cross a module scope. Currently these usages have to be +put into a ``.push/pop`` environment: + +.. code-block:: nim + + # client.nim + proc useParallel*[T](unused: T) = + # use a generic T here to show the problem. + {.push experimental: "parallel".} + parallel: + for i in 0..4: + echo "echo in parallel" + + {.pop.} + + +.. code-block:: nim + + import client + useParallel(1) + + Implementation Specific Pragmas =============================== diff --git a/tests/pragmas/tpushexperimental.nim b/tests/pragmas/tpushexperimental.nim new file mode 100644 index 0000000000..301419f607 --- /dev/null +++ b/tests/pragmas/tpushexperimental.nim @@ -0,0 +1,13 @@ +discard """ + output: '''0 1 +1 2 +2 3 +0 1 +1 2 +2 3 +3 5''' +""" + +import mpushexperimental + +main(12) From 08c105c4e58718c4e7f9bca64f75604deb451ca3 Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 27 Aug 2018 11:26:31 +0200 Subject: [PATCH 076/145] added missing file to make tests green --- tests/pragmas/mpushexperimental.nim | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/pragmas/mpushexperimental.nim diff --git a/tests/pragmas/mpushexperimental.nim b/tests/pragmas/mpushexperimental.nim new file mode 100644 index 0000000000..569861c1d9 --- /dev/null +++ b/tests/pragmas/mpushexperimental.nim @@ -0,0 +1,30 @@ + +import macros + +macro enumerate(x: ForLoopStmt): untyped = + expectKind x, nnkForStmt + # we strip off the first for loop variable and use + # it as an integer counter: + result = newStmtList() + result.add newVarStmt(x[0], newLit(0)) + var body = x[^1] + if body.kind != nnkStmtList: + body = newTree(nnkStmtList, body) + body.add newCall(bindSym"inc", x[0]) + var newFor = newTree(nnkForStmt) + for i in 1..x.len-3: + newFor.add x[i] + # transform enumerate(X) to 'X' + newFor.add x[^2][1] + newFor.add body + result.add newFor + +proc main*[T](x: T) = + {.push experimental: "forLoopMacros".} + + for a, b in enumerate(items([1, 2, 3])): + echo a, " ", b + + for a2, b2 in enumerate([1, 2, 3, 5]): + echo a2, " ", b2 + {.pop.} From 3999e3be5fcf6df918e427c58b3c99b28a100cdd Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 27 Aug 2018 11:47:57 +0200 Subject: [PATCH 077/145] fixes #8776 --- compiler/nimblecmd.nim | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/compiler/nimblecmd.nim b/compiler/nimblecmd.nim index 9a23535bf5..c5521735b1 100644 --- a/compiler/nimblecmd.nim +++ b/compiler/nimblecmd.nim @@ -140,18 +140,19 @@ when isMainModule: doAssert v"#aaaqwe" < v"1.1" # We cannot assume that a branch is newer. doAssert v"#a111" < v"#head" + let conf = newConfigRef() var rr = newStringTable() - addPackage rr, "irc-#a111" - addPackage rr, "irc-#head" - addPackage rr, "irc-0.1.0" - addPackage rr, "irc" - addPackage rr, "another" - addPackage rr, "another-0.1" + addPackage conf, rr, "irc-#a111", unknownLineInfo() + addPackage conf, rr, "irc-#head", unknownLineInfo() + addPackage conf, rr, "irc-0.1.0", unknownLineInfo() + #addPackage conf, rr, "irc", unknownLineInfo() + #addPackage conf, rr, "another", unknownLineInfo() + addPackage conf, rr, "another-0.1", unknownLineInfo() - addPackage rr, "ab-0.1.3" - addPackage rr, "ab-0.1" - addPackage rr, "justone" + addPackage conf, rr, "ab-0.1.3", unknownLineInfo() + addPackage conf, rr, "ab-0.1", unknownLineInfo() + addPackage conf, rr, "justone-1.0", unknownLineInfo() doAssert toSeq(rr.chosen) == - @["irc-#head", "another-0.1", "ab-0.1.3", "justone"] + @["irc-#head", "another-0.1", "ab-0.1.3", "justone-1.0"] From a2708995023307d5da04ed44d2b915495790a31a Mon Sep 17 00:00:00 2001 From: hlaaf Date: Mon, 27 Aug 2018 13:22:55 +0300 Subject: [PATCH 078/145] Add escapeJsonUnquoted for json escaped strings without quotes (#8785) * Add escapeJsonUnquoted * Add tests for escapeJsonUnquoted --- lib/pure/json.nim | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/pure/json.nim b/lib/pure/json.nim index 3599667a86..9279fea77d 100644 --- a/lib/pure/json.nim +++ b/lib/pure/json.nim @@ -545,10 +545,9 @@ proc newIndent(curr, indent: int, ml: bool): int = proc nl(s: var string, ml: bool) = s.add(if ml: "\n" else: " ") -proc escapeJson*(s: string; result: var string) = - ## Converts a string `s` to its JSON representation. +proc escapeJsonUnquoted*(s: string; result: var string) = + ## Converts a string `s` to its JSON representation without quotes. ## Appends to ``result``. - result.add("\"") for c in s: case c of '\L': result.add("\\n") @@ -561,10 +560,21 @@ proc escapeJson*(s: string; result: var string) = of '\14'..'\31': result.add("\\u00" & $ord(c)) of '\\': result.add("\\\\") else: result.add(c) + +proc escapeJsonUnquoted*(s: string): string = + ## Converts a string `s` to its JSON representation without quotes. + result = newStringOfCap(s.len + s.len shr 3) + escapeJsonUnquoted(s, result) + +proc escapeJson*(s: string; result: var string) = + ## Converts a string `s` to its JSON representation with quotes. + ## Appends to ``result``. + result.add("\"") + escapeJsonUnquoted(s, result) result.add("\"") proc escapeJson*(s: string): string = - ## Converts a string `s` to its JSON representation. + ## Converts a string `s` to its JSON representation with quotes. result = newStringOfCap(s.len + s.len shr 3) escapeJson(s, result) @@ -1607,6 +1617,8 @@ when isMainModule: var parsed2 = parseFile("tests/testdata/jsontest2.json") doAssert(parsed2{"repository", "description"}.str=="IRC Library for Haskell", "Couldn't fetch via multiply nested key using {}") + doAssert escapeJsonUnquoted("\10Foo🎃barÄ") == "\\nFoo🎃barÄ" + doAssert escapeJsonUnquoted("\0\7\20") == "\\u0000\\u0007\\u0020" # for #7887 doAssert escapeJson("\10Foo🎃barÄ") == "\"\\nFoo🎃barÄ\"" doAssert escapeJson("\0\7\20") == "\"\\u0000\\u0007\\u0020\"" # for #7887 From c1df195b15dcc5066bf4a15848cbf199223459a9 Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 27 Aug 2018 13:39:07 +0200 Subject: [PATCH 079/145] manual: document the order of evaluation --- doc/manual.rst | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/doc/manual.rst b/doc/manual.rst index a5a1c7cb2b..ca32c9c61e 100644 --- a/doc/manual.rst +++ b/doc/manual.rst @@ -618,6 +618,55 @@ The grammar's start symbol is ``module``. +Order of evaluation +=================== + +Order of evaluation is strictly left-to-right, inside-out as it is typical for most others +imperative programming languages: + +.. code-block:: nim + :test: "nim c $1" + + var s = "" + + proc p(arg: int): int = + s.add $arg + result = arg + + discard p(p(1) + p(2)) + + doAssert s == "123" + + +Assignments are not special, the left-hand-side expression is evaluated before the +right-hand side: + +.. code-block:: nim + :test: "nim c $1" + + var v = 0 + proc getI(): int = + result = v + inc v + + var a, b: array[0..2, int] + + proc someCopy(a: var int; b: int) = a = b + + a[getI()] = getI() + + doAssert a == [1, 0, 0] + + v = 0 + someCopy(b[getI()], getI()) + + doAssert b == [1, 0, 0] + + +Rationale: Consistency with overloaded assignment or assignment-like operations, +``a = b`` can be read as ``performSomeCopy(a, b)``. + + Types ===== From a60cf221e8c116f9b212b69ad52e594ec43bffe4 Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 27 Aug 2018 17:05:20 +0200 Subject: [PATCH 080/145] improve the error message for mutability problems that arise from implicit converter calls --- compiler/semcall.nim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/semcall.nim b/compiler/semcall.nim index 980cfb691a..00b5916320 100644 --- a/compiler/semcall.nim +++ b/compiler/semcall.nim @@ -138,7 +138,9 @@ proc effectProblem(f, a: PType; result: var string) = proc renderNotLValue(n: PNode): string = result = $n - if n.kind in {nkHiddenStdConv, nkHiddenSubConv, nkHiddenCallConv} and n.len == 2: + if n.kind == nkHiddenCallConv and n.len > 1: + result = $n[0] & "(" & result & ")" + elif n.kind in {nkHiddenStdConv, nkHiddenSubConv} and n.len == 2: result = typeToString(n.typ.skipTypes(abstractVar)) & "(" & result & ")" proc presentFailedCandidates(c: PContext, n: PNode, errors: CandidateErrors): From 7bb93c730ea87fd2437dea1d93e889fb4a2c08f4 Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 27 Aug 2018 17:07:05 +0200 Subject: [PATCH 081/145] show all mismatching overloads again --- compiler/semcall.nim | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/compiler/semcall.nim b/compiler/semcall.nim index 00b5916320..9e75f8cd46 100644 --- a/compiler/semcall.nim +++ b/compiler/semcall.nim @@ -166,18 +166,20 @@ proc presentFailedCandidates(c: PContext, n: PNode, errors: CandidateErrors): prefer = preferModuleInfo break - # we pretend procs are attached to the type of the first - # argument in order to remove plenty of candidates. This is - # comparable to what C# does and C# is doing fine. - var filterOnlyFirst = false - for err in errors: - if err.firstMismatch > 1: - filterOnlyFirst = true - break + when false: + # we pretend procs are attached to the type of the first + # argument in order to remove plenty of candidates. This is + # comparable to what C# does and C# is doing fine. + var filterOnlyFirst = false + for err in errors: + if err.firstMismatch > 1: + filterOnlyFirst = true + break var candidates = "" for err in errors: - if filterOnlyFirst and err.firstMismatch == 1: continue + when false: + if filterOnlyFirst and err.firstMismatch == 1: continue if err.sym.kind in routineKinds and err.sym.ast != nil: add(candidates, renderTree(err.sym.ast, {renderNoBody, renderNoComments, renderNoPragmas})) From 96363ecaf3fd9b761d9ea1d7945b3faadee1fcc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oscar=20Nihlg=C3=A5rd?= Date: Tue, 28 Aug 2018 11:35:52 +0200 Subject: [PATCH 082/145] Fix nkImportAs regression (#8796) --- compiler/importer.nim | 23 ++++++++++++++--------- tests/modules/timportas.nim | 5 +++++ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/compiler/importer.nim b/compiler/importer.nim index acc3d26d29..6a225a7616 100644 --- a/compiler/importer.nim +++ b/compiler/importer.nim @@ -164,7 +164,16 @@ proc myImportModule(c: PContext, n: PNode; importStmtResult: PNode): PSym = suggestSym(c.config, n.info, result, c.graph.usageSym, false) importStmtResult.add newStrNode(toFullPath(c.config, f), n.info) +proc transformImportAs(n: PNode): PNode = + if n.kind == nkInfix and n.sons[0].ident.s == "as": + result = newNodeI(nkImportAs, n.info) + result.add n.sons[1] + result.add n.sons[2] + else: + result = n + proc impMod(c: PContext; it: PNode; importStmtResult: PNode) = + let it = transformImportAs(it) let m = myImportModule(c, it, importStmtResult) if m != nil: var emptySet: IntSet @@ -185,27 +194,22 @@ proc evalImport(c: PContext, n: PNode): PNode = imp.add dir imp.add sep # dummy entry, replaced in the loop for x in it[2]: + # transform `a/b/[c as d]` to `/a/b/c as d` if x.kind == nkInfix and x.sons[0].ident.s == "as": + let impAs = copyTree(x) imp.sons[2] = x.sons[1] - let impAs = newNodeI(nkImportAs, it.info) - impAs.add imp - impAs.add x.sons[2] - imp = impAs + impAs.sons[1] = imp impMod(c, imp, result) else: imp.sons[2] = x impMod(c, imp, result) - elif it.kind == nkInfix and it.sons[0].ident.s == "as": - let imp = newNodeI(nkImportAs, it.info) - imp.add it.sons[1] - imp.add it.sons[2] - impMod(c, imp, result) else: impMod(c, it, result) proc evalFrom(c: PContext, n: PNode): PNode = result = newNodeI(nkImportStmt, n.info) checkMinSonsLen(n, 2, c.config) + n.sons[0] = transformImportAs(n.sons[0]) var m = myImportModule(c, n.sons[0], result) if m != nil: n.sons[0] = newSymNode(m) @@ -217,6 +221,7 @@ proc evalFrom(c: PContext, n: PNode): PNode = proc evalImportExcept*(c: PContext, n: PNode): PNode = result = newNodeI(nkImportStmt, n.info) checkMinSonsLen(n, 2, c.config) + n.sons[0] = transformImportAs(n.sons[0]) var m = myImportModule(c, n.sons[0], result) if m != nil: n.sons[0] = newSymNode(m) diff --git a/tests/modules/timportas.nim b/tests/modules/timportas.nim index 4681a1ee07..a921621171 100644 --- a/tests/modules/timportas.nim +++ b/tests/modules/timportas.nim @@ -3,9 +3,14 @@ discard """ """ import .. / modules / [definitions as foo] +import .. / modules / definitions as foo import std / times as bar +from times as bar2 import nil +import times as bar3 except convert import definitions as baz discard foo.v discard bar.now +discard bar2.now +discard bar3.now discard baz.v \ No newline at end of file From dc5851e87373203f5c64b9f15872e2865ab85f3f Mon Sep 17 00:00:00 2001 From: Araq Date: Tue, 28 Aug 2018 12:16:14 +0200 Subject: [PATCH 083/145] added a test to ensure that for-loop-variables cannot be mutated --- tests/varres/tprevent_forloopvar_mutations.nim | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 tests/varres/tprevent_forloopvar_mutations.nim diff --git a/tests/varres/tprevent_forloopvar_mutations.nim b/tests/varres/tprevent_forloopvar_mutations.nim new file mode 100644 index 0000000000..15938bb77a --- /dev/null +++ b/tests/varres/tprevent_forloopvar_mutations.nim @@ -0,0 +1,15 @@ +discard """ + line: 15 + errmsg: "type mismatch: got " + nimout: '''type mismatch: got +but expected one of: +proc inc[T: Ordinal | uint | uint64](x: var T; y = 1) + for a 'var' type a variable needs to be passed, but 'i' is immutable + +expression: inc i +''' +""" + +for i in 0..10: + echo i + inc i From 9c3cba1c2285a9d0250ed26f12598770e4ed78f4 Mon Sep 17 00:00:00 2001 From: Araq Date: Tue, 28 Aug 2018 11:16:37 +0200 Subject: [PATCH 084/145] fixes #4766 --- compiler/seminst.nim | 3 ++- .../errmsgs/tnested_generic_instantiation.nim | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 tests/errmsgs/tnested_generic_instantiation.nim diff --git a/compiler/seminst.nim b/compiler/seminst.nim index f9d7c37545..4bf1e6ef29 100644 --- a/compiler/seminst.nim +++ b/compiler/seminst.nim @@ -326,7 +326,8 @@ proc generateInstance(c: PContext, fn: PSym, pt: TIdTable, # no need to instantiate generic templates/macros: internalAssert c.config, fn.kind notin {skMacro, skTemplate} # generates an instantiated proc - if c.instCounter > 1000: internalError(c.config, fn.ast.info, "nesting too deep") + if c.instCounter > 50: + globalError(c.config, info, "generic instantiation too nested") inc(c.instCounter) # careful! we copy the whole AST including the possibly nil body! var n = copyTree(fn.ast) diff --git a/tests/errmsgs/tnested_generic_instantiation.nim b/tests/errmsgs/tnested_generic_instantiation.nim new file mode 100644 index 0000000000..6aea7cbcc3 --- /dev/null +++ b/tests/errmsgs/tnested_generic_instantiation.nim @@ -0,0 +1,19 @@ +discard """ +errormsg: "generic instantiation too nested" +file: "system.nim" +""" + +# bug #4766 + +type + Plain = ref object + discard + + Wrapped[T] = object + value: T + +converter toWrapped[T](value: T): Wrapped[T] = + Wrapped[T](value: value) + +let result = Plain() +discard $result From 6f16166c60a5f94f63fc3a901b9a3a859d758c8f Mon Sep 17 00:00:00 2001 From: Araq Date: Tue, 28 Aug 2018 09:39:24 +0200 Subject: [PATCH 085/145] parseopt: keep the seq of arguments as given; fixes various command line parsing edge cases; refs #6818 --- lib/pure/parseopt.nim | 109 +++++++++++++++++++++++++++++------------- 1 file changed, 75 insertions(+), 34 deletions(-) diff --git a/lib/pure/parseopt.nim b/lib/pure/parseopt.nim index 58e1be0e41..7b3ab0302b 100644 --- a/lib/pure/parseopt.nim +++ b/lib/pure/parseopt.nim @@ -49,20 +49,24 @@ type inShortState: bool shortNoVal: set[char] longNoVal: seq[string] + cmds: seq[string] + idx: int kind*: CmdLineKind ## the dected command line token key*, val*: TaintedString ## key and value pair; ``key`` is the option ## or the argument, ``value`` is not "" if ## the option was given a value proc parseWord(s: string, i: int, w: var string, - delim: set[char] = {'\x09', ' '}): int = + delim: set[char] = {'\t', ' '}): int = result = i if result < s.len and s[result] == '\"': inc(result) - while result < s.len and s[result] != '\"': + while result < s.len: + if s[result] == '"': + inc result + break add(w, s[result]) inc(result) - if result < s.len and s[result] == '\"': inc(result) else: while result < s.len and s[result] notin delim: add(w, s[result]) @@ -73,7 +77,7 @@ when declared(os.paramCount): if find(s, {' ', '\t'}) >= 0 and s.len > 0 and s[0] != '"': if s[0] == '-': result = newStringOfCap(s.len) - var i = parseWord(s, 0, result, {' ', '\x09', ':', '='}) + var i = parseWord(s, 0, result, {' ', '\t', ':', '='}) if i < s.len and s[i] in {':','='}: result.add s[i] inc i @@ -100,16 +104,21 @@ when declared(os.paramCount): ## (though they still need at least a space). In both cases, ':' or '=' ## may still be used if desired. They just become optional. result.pos = 0 + result.idx = 0 result.inShortState = false result.shortNoVal = shortNoVal result.longNoVal = longNoVal if cmdline != "": result.cmd = cmdline + result.cmds = parseCmdLine(cmdline) else: result.cmd = "" + result.cmds = newSeq[string](paramCount()) for i in countup(1, paramCount()): - result.cmd.add quote(paramStr(i).string) + result.cmds[i-1] = paramStr(i).string + result.cmd.add quote(result.cmds[i-1]) result.cmd.add ' ' + result.kind = cmdEnd result.key = TaintedString"" result.val = TaintedString"" @@ -120,80 +129,111 @@ when declared(os.paramCount): ## (as provided by the ``OS`` module) is taken. ``shortNoVal`` and ## ``longNoVal`` behavior is the same as for ``initOptParser(string,...)``. result.pos = 0 + result.idx = 0 result.inShortState = false result.shortNoVal = shortNoVal result.longNoVal = longNoVal result.cmd = "" if cmdline.len != 0: + result.cmds = newSeq[string](cmdline.len) for i in 0..= p.cmd.len: p.inShortState = false - p.pos = i + while i < cmd.len and cmd[i] in {'\t', ' '}: inc(i) + p.val = substr(cmd, i) + p.pos = 0 + inc p.idx + else: + p.pos = i + if i >= cmd.len: + p.inShortState = false + p.pos = 0 + inc p.idx proc next*(p: var OptParser) {.rtl, extern: "npo$1".} = ## parses the first or next option; ``p.kind`` describes what token has been ## parsed. ``p.key`` and ``p.val`` are set accordingly. + if p.idx >= p.cmds.len: + p.kind = cmdEnd + return + var i = p.pos - while i < p.cmd.len and p.cmd[i] in {'\x09', ' '}: inc(i) + while i < p.cmds[p.idx].len and p.cmds[p.idx][i] in {'\t', ' '}: inc(i) p.pos = i setLen(p.key.string, 0) setLen(p.val.string, 0) if p.inShortState: - handleShortOption(p) - return - if i >= p.cmd.len: - p.kind = cmdEnd - return - if p.cmd[i] == '-': + p.inShortState = false + if i >= p.cmds[p.idx].len: + inc(p.idx) + p.pos = 0 + if p.idx >= p.cmds.len: + p.kind = cmdEnd + return + else: + handleShortOption(p, p.cmds[p.idx]) + return + + if i < p.cmds[p.idx].len and p.cmds[p.idx][i] == '-': inc(i) - if i < p.cmd.len and p.cmd[i] == '-': + if i < p.cmds[p.idx].len and p.cmds[p.idx][i] == '-': p.kind = cmdLongOption inc(i) - i = parseWord(p.cmd, i, p.key.string, {' ', '\x09', ':', '='}) - while i < p.cmd.len and p.cmd[i] in {'\x09', ' '}: inc(i) - if i < p.cmd.len and p.cmd[i] in {':', '='} or - len(p.longNoVal) > 0 and p.key.string notin p.longNoVal: - if i < p.cmd.len and p.cmd[i] in {':', '='}: + i = parseWord(p.cmds[p.idx], i, p.key.string, {' ', '\t', ':', '='}) + while i < p.cmds[p.idx].len and p.cmds[p.idx][i] in {'\t', ' '}: inc(i) + if i < p.cmds[p.idx].len and p.cmds[p.idx][i] in {':', '='}: + if i < p.cmds[p.idx].len and p.cmds[p.idx][i] in {':', '='}: inc(i) - while i < p.cmd.len and p.cmd[i] in {'\x09', ' '}: inc(i) - p.pos = parseWord(p.cmd, i, p.val.string) + while i < p.cmds[p.idx].len and p.cmds[p.idx][i] in {'\t', ' '}: inc(i) + p.val = p.cmds[p.idx].substr(i) + elif len(p.longNoVal) > 0 and p.key.string notin p.longNoVal and p.idx+1 < p.cmds.len: + p.val = p.cmds[p.idx+1] + inc p.idx else: - p.pos = i + p.val = "" + inc p.idx + p.pos = 0 else: p.pos = i - handleShortOption(p) + handleShortOption(p, p.cmds[p.idx]) else: p.kind = cmdArgument - p.pos = parseWord(p.cmd, i, p.key.string) + p.key = p.cmds[p.idx] + inc p.idx + p.pos = 0 proc cmdLineRest*(p: OptParser): TaintedString {.rtl, extern: "npo$1".} = ## retrieves the rest of the command line that has not been parsed yet. - result = strip(substr(p.cmd, p.pos, len(p.cmd) - 1)).TaintedString + var res = "" + for i in p.idx.. p.idx: res.add ' ' + res.add quote(p.cmds[i]) + result = res.TaintedString iterator getopt*(p: var OptParser): tuple[kind: CmdLineKind, key, val: TaintedString] = ## This is an convenience iterator for iterating over the given OptParser object. @@ -214,6 +254,7 @@ iterator getopt*(p: var OptParser): tuple[kind: CmdLineKind, key, val: TaintedSt ## # no filename has been given, so we show the help: ## writeHelp() p.pos = 0 + p.idx = 0 while true: next(p) if p.kind == cmdEnd: break From e02e057a706e6d3ec7948ef0c51509e033c4ec6b Mon Sep 17 00:00:00 2001 From: Araq Date: Tue, 28 Aug 2018 11:47:26 +0200 Subject: [PATCH 086/145] make parsopt compile under --taintMode:on --- lib/pure/parseopt.nim | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/pure/parseopt.nim b/lib/pure/parseopt.nim index 7b3ab0302b..3a79504dbe 100644 --- a/lib/pure/parseopt.nim +++ b/lib/pure/parseopt.nim @@ -137,7 +137,7 @@ when declared(os.paramCount): if cmdline.len != 0: result.cmds = newSeq[string](cmdline.len) for i in 0.. 0 and p.key.string notin p.longNoVal and p.idx+1 < p.cmds.len: - p.val = p.cmds[p.idx+1] + p.val = TaintedString p.cmds[p.idx+1] inc p.idx else: - p.val = "" + p.val = TaintedString"" inc p.idx p.pos = 0 else: @@ -223,7 +223,7 @@ proc next*(p: var OptParser) {.rtl, extern: "npo$1".} = handleShortOption(p, p.cmds[p.idx]) else: p.kind = cmdArgument - p.key = p.cmds[p.idx] + p.key = TaintedString p.cmds[p.idx] inc p.idx p.pos = 0 From a42150f9a878cb131dd79769cceeaa9deacee40f Mon Sep 17 00:00:00 2001 From: Araq Date: Tue, 28 Aug 2018 12:54:40 +0200 Subject: [PATCH 087/145] make parseopt work with DLLs on Unix --- lib/pure/parseopt.nim | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/pure/parseopt.nim b/lib/pure/parseopt.nim index 3a79504dbe..70319ddf08 100644 --- a/lib/pure/parseopt.nim +++ b/lib/pure/parseopt.nim @@ -227,13 +227,14 @@ proc next*(p: var OptParser) {.rtl, extern: "npo$1".} = inc p.idx p.pos = 0 -proc cmdLineRest*(p: OptParser): TaintedString {.rtl, extern: "npo$1".} = - ## retrieves the rest of the command line that has not been parsed yet. - var res = "" - for i in p.idx.. p.idx: res.add ' ' - res.add quote(p.cmds[i]) - result = res.TaintedString +when declared(os.paramCount): + proc cmdLineRest*(p: OptParser): TaintedString {.rtl, extern: "npo$1".} = + ## retrieves the rest of the command line that has not been parsed yet. + var res = "" + for i in p.idx.. p.idx: res.add ' ' + res.add quote(p.cmds[i]) + result = res.TaintedString iterator getopt*(p: var OptParser): tuple[kind: CmdLineKind, key, val: TaintedString] = ## This is an convenience iterator for iterating over the given OptParser object. From 6e83746caabca00ab2b97a81bd732de4588996fe Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Tue, 28 Aug 2018 14:52:29 +0100 Subject: [PATCH 088/145] Net module fixes (#8597) * net.accept no longer needs an initialised socket. Fixes #7848. * Assert error when using sendTo/recvFrom on TCP socket. * net.sendTo now raises OSError. --- changelog.md | 3 +++ lib/pure/net.nim | 33 ++++++++++++++++----------------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/changelog.md b/changelog.md index 9526227ce9..0fe2f6099d 100644 --- a/changelog.md +++ b/changelog.md @@ -72,6 +72,7 @@ - ``lineInfoObj`` now returns absolute path instead of project path. It's used by ``lineInfo``, ``check``, ``expect``, ``require``, etc. +- ``net.sendTo`` no longer returns an int and now raises an ``OSError``. - `threadpool`'s `await` and derivatives have been renamed to `blockUntil` to avoid confusions with `await` from the `async` macro. @@ -140,6 +141,8 @@ - The ``pegs`` module now exports getters for the fields of its ``Peg`` and ``NonTerminal`` object types. ``Peg``s with child nodes now have the standard ``items`` and ``pairs`` iterators. +- The ``accept`` socket procedure defined in the ``net`` module can now accept + a nil socket. ### Language additions diff --git a/lib/pure/net.nim b/lib/pure/net.nim index 0e56100d9a..a60137dab4 100644 --- a/lib/pure/net.nim +++ b/lib/pure/net.nim @@ -58,15 +58,11 @@ ## You can then begin accepting connections using the ``accept`` procedure. ## ## .. code-block:: Nim -## var client = new Socket +## var client: Socket ## var address = "" ## while true: ## socket.acceptAddr(client, address) ## echo("Client connected from: ", address) -## -## **Note:** The ``client`` variable is initialised with ``new Socket`` **not** -## ``newSocket()``. The difference is that the latter creates a new file -## descriptor. {.deadCodeElim: on.} # dce option deprecated import nativesockets, os, strutils, parseutils, times, sets, options @@ -789,16 +785,12 @@ proc acceptAddr*(server: Socket, client: var Socket, address: var string, ## The resulting client will inherit any properties of the server socket. For ## example: whether the socket is buffered or not. ## - ## **Note**: ``client`` must be initialised (with ``new``), this function - ## makes no effort to initialise the ``client`` variable. - ## ## The ``accept`` call may result in an error if the connecting socket ## disconnects during the duration of the ``accept``. If the ``SafeDisconn`` ## flag is specified then this error will not be raised and instead ## accept will be called again. - assert(client != nil) - assert client.fd.int <= 0, "Client socket needs to be initialised with " & - "`new`, not `newSocket`." + if client.isNil: + new(client) let ret = accept(server.fd) let sock = ret[0] @@ -879,9 +871,6 @@ proc accept*(server: Socket, client: var Socket, ## Equivalent to ``acceptAddr`` but doesn't return the address, only the ## socket. ## - ## **Note**: ``client`` must be initialised (with ``new``), this function - ## makes no effort to initialise the ``client`` variable. - ## ## The ``accept`` call may result in an error if the connecting socket ## disconnects during the duration of the ``accept``. If the ``SafeDisconn`` ## flag is specified then this error will not be raised and instead @@ -1339,6 +1328,7 @@ proc recvFrom*(socket: Socket, data: var string, length: int, ## used. Therefore if ``socket`` contains something in its buffer this ## function will make no effort to return it. + assert(socket.protocol != IPPROTO_TCP, "Cannot `recvFrom` on a TCP socket") # TODO: Buffered sockets data.setLen(length) var sockAddress: Sockaddr_in @@ -1408,22 +1398,25 @@ proc trySend*(socket: Socket, data: string): bool {.tags: [WriteIOEffect].} = result = send(socket, cstring(data), data.len) == data.len proc sendTo*(socket: Socket, address: string, port: Port, data: pointer, - size: int, af: Domain = AF_INET, flags = 0'i32): int {. + size: int, af: Domain = AF_INET, flags = 0'i32) {. tags: [WriteIOEffect].} = ## This proc sends ``data`` to the specified ``address``, ## which may be an IP address or a hostname, if a hostname is specified ## this function will try each IP of that hostname. ## + ## If an error occurs an OSError exception will be raised. ## ## **Note:** You may wish to use the high-level version of this function ## which is defined below. ## ## **Note:** This proc is not available for SSL sockets. + assert(socket.protocol != IPPROTO_TCP, "Cannot `sendTo` on a TCP socket") assert(not socket.isClosed, "Cannot `sendTo` on a closed socket") var aiList = getAddrInfo(address, port, af, socket.sockType, socket.protocol) # try all possibilities: var success = false var it = aiList + var result = 0 while it != nil: result = sendto(socket.fd, data, size.cint, flags.cint, it.ai_addr, it.ai_addrlen.SockLen) @@ -1432,16 +1425,22 @@ proc sendTo*(socket: Socket, address: string, port: Port, data: pointer, break it = it.ai_next + let osError = osLastError() freeAddrInfo(aiList) + if not success: + raiseOSError(osError) + proc sendTo*(socket: Socket, address: string, port: Port, - data: string): int {.tags: [WriteIOEffect].} = + data: string) {.tags: [WriteIOEffect].} = ## This proc sends ``data`` to the specified ``address``, ## which may be an IP address or a hostname, if a hostname is specified ## this function will try each IP of that hostname. ## + ## If an error occurs an OSError exception will be raised. + ## ## This is the high-level version of the above ``sendTo`` function. - result = socket.sendTo(address, port, cstring(data), data.len, socket.domain ) + socket.sendTo(address, port, cstring(data), data.len, socket.domain) proc isSsl*(socket: Socket): bool = From 5cd152bfda29adefc8ba6eb72117c91dbc2e9d7f Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Tue, 28 Aug 2018 22:59:28 +0200 Subject: [PATCH 089/145] Allow `hint` and `warning` to specify its loc info (#8771) Let's bring those to feature-parity with `error`. --- compiler/vm.nim | 20 ++++++++++++-------- compiler/vmgen.nim | 4 ++-- lib/core/macros.nim | 4 ++-- tests/macros/tmsginfo.nim | 24 ++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 12 deletions(-) create mode 100644 tests/macros/tmsginfo.nim diff --git a/compiler/vm.nim b/compiler/vm.nim index fcbd97b8dc..8271857370 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -81,14 +81,16 @@ proc stackTraceAux(c: PCtx; x: PStackFrame; pc: int; recursionLimit=100) = msgWriteln(c.config, s) proc stackTrace(c: PCtx, tos: PStackFrame, pc: int, - msg: string, n: PNode = nil) = + msg: string, lineInfo: TLineInfo) = msgWriteln(c.config, "stack trace: (most recent call last)") stackTraceAux(c, tos, pc) # XXX test if we want 'globalError' for every mode - let lineInfo = if n == nil: c.debug[pc] else: n.info if c.mode == emRepl: globalError(c.config, lineInfo, msg) else: localError(c.config, lineInfo, msg) +proc stackTrace(c: PCtx, tos: PStackFrame, pc: int, msg: string) = + stackTrace(c, tos, pc, msg, c.debug[pc]) + proc bailOut(c: PCtx; tos: PStackFrame) = stackTrace(c, tos, c.exceptionInstr, "unhandled exception: " & c.currentExceptionA.sons[3].skipColon.strVal) @@ -1385,15 +1387,17 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg = c.debug[pc], c.config)[0] else: globalError(c.config, c.debug[pc], "VM is not built with 'gorge' support") - of opcNError: + of opcNError, opcNWarning, opcNHint: decodeB(rkNode) let a = regs[ra].node let b = regs[rb].node - stackTrace(c, tos, pc, a.strVal, if b.kind == nkNilLit: nil else: b) - of opcNWarning: - message(c.config, c.debug[pc], warnUser, regs[ra].node.strVal) - of opcNHint: - message(c.config, c.debug[pc], hintUser, regs[ra].node.strVal) + let info = if b.kind == nkNilLit: c.debug[pc] else: b.info + if instr.opcode == opcNError: + stackTrace(c, tos, pc, a.strVal, info) + elif instr.opcode == opcNWarning: + message(c.config, info, warnUser, a.strVal) + elif instr.opcode == opcNHint: + message(c.config, info, hintUser, a.strVal) of opcParseExprToAst: decodeB(rkNode) # c.debug[pc].line.int - countLines(regs[rb].strVal) ? diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim index a36f559ca7..cb46031643 100644 --- a/compiler/vmgen.nim +++ b/compiler/vmgen.nim @@ -1192,10 +1192,10 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest; m: TMagic) = else: internalAssert c.config, false of mNHint: unused(c, n, dest) - genUnaryStmt(c, n, opcNHint) + genBinaryStmt(c, n, opcNHint) of mNWarning: unused(c, n, dest) - genUnaryStmt(c, n, opcNWarning) + genBinaryStmt(c, n, opcNWarning) of mNError: if n.len <= 1: # query error condition: diff --git a/lib/core/macros.nim b/lib/core/macros.nim index bac9ce7a2a..5b29d5e94e 100644 --- a/lib/core/macros.nim +++ b/lib/core/macros.nim @@ -336,10 +336,10 @@ proc copyNimTree*(n: NimNode): NimNode {.magic: "NCopyNimTree", noSideEffect.} proc error*(msg: string, n: NimNode = nil) {.magic: "NError", benign.} ## writes an error message at compile time -proc warning*(msg: string) {.magic: "NWarning", benign.} +proc warning*(msg: string, n: NimNode = nil) {.magic: "NWarning", benign.} ## writes a warning message at compile time -proc hint*(msg: string) {.magic: "NHint", benign.} +proc hint*(msg: string, n: NimNode = nil) {.magic: "NHint", benign.} ## writes a hint message at compile time proc newStrLitNode*(s: string): NimNode {.compileTime, noSideEffect.} = diff --git a/tests/macros/tmsginfo.nim b/tests/macros/tmsginfo.nim new file mode 100644 index 0000000000..bf6c9d5379 --- /dev/null +++ b/tests/macros/tmsginfo.nim @@ -0,0 +1,24 @@ +discard """ + nimout: '''tmsginfo.nim(21, 1) Warning: foo1 [User] +tmsginfo.nim(22, 11) template/generic instantiation from here +tmsginfo.nim(15, 10) Warning: foo2 [User] +tmsginfo.nim(23, 1) Hint: foo3 [User] +tmsginfo.nim(19, 7) Hint: foo4 [User] +''' +""" + +import macros + +macro foo1(y: untyped): untyped = + warning("foo1", y) +macro foo2(y: untyped): untyped = + warning("foo2") +macro foo3(y: untyped): untyped = + hint("foo3", y) +macro foo4(y: untyped): untyped = + hint("foo4") + +proc x1() {.foo1.} = discard +proc x2() {.foo2.} = discard +proc x3() {.foo3.} = discard +proc x4() {.foo4.} = discard From 9ad17091cc3c9b3f1dd7fd877ebe8555020fa4f9 Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Tue, 28 Aug 2018 22:05:46 +0100 Subject: [PATCH 090/145] Allow Nimble to override the ``task`` template in nimscript. (#8798) --- lib/system/nimscript.nim | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/system/nimscript.nim b/lib/system/nimscript.nim index 3aafaa8d11..64d6255dab 100644 --- a/lib/system/nimscript.nim +++ b/lib/system/nimscript.nim @@ -305,7 +305,6 @@ template withDir*(dir: string; body: untyped): untyped = finally: cd(curDir) -template `==?`(a, b: string): bool = cmpIgnoreStyle(a, b) == 0 proc writeTask(name, desc: string) = if desc.len > 0: @@ -313,29 +312,30 @@ proc writeTask(name, desc: string) = for i in 0 ..< 20 - name.len: spaces.add ' ' echo name, spaces, desc -template task*(name: untyped; description: string; body: untyped): untyped = - ## Defines a task. Hidden tasks are supported via an empty description. - ## Example: - ## - ## .. code-block:: nim - ## task build, "default build is via the C backend": - ## setCommand "c" - proc `name Task`*() = body - - let cmd = getCommand() - if cmd.len == 0 or cmd ==? "help": - setCommand "help" - writeTask(astToStr(name), description) - elif cmd ==? astToStr(name): - setCommand "nop" - `name Task`() - proc cppDefine*(define: string) = ## tell Nim that ``define`` is a C preprocessor ``#define`` and so always ## needs to be mangled. builtin when not defined(nimble): + template `==?`(a, b: string): bool = cmpIgnoreStyle(a, b) == 0 + template task*(name: untyped; description: string; body: untyped): untyped = + ## Defines a task. Hidden tasks are supported via an empty description. + ## Example: + ## + ## .. code-block:: nim + ## task build, "default build is via the C backend": + ## setCommand "c" + proc `name Task`*() = body + + let cmd = getCommand() + if cmd.len == 0 or cmd ==? "help": + setCommand "help" + writeTask(astToStr(name), description) + elif cmd ==? astToStr(name): + setCommand "nop" + `name Task`() + # nimble has its own implementation for these things. var packageName* = "" ## Nimble support: Set this to the package name. It From 01211ced1d5c3252c88e61bbbb6bb78dcc5575f0 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Wed, 29 Aug 2018 07:03:16 -0700 Subject: [PATCH 091/145] add nim c -r nimsuggest/tester to travis (#8805) --- .travis.yml | 2 +- nimsuggest/tester.nim | 20 ++++++++++++++++++-- nimsuggest/tests/tchk1.nim | 1 + nimsuggest/tests/tdot4.nim | 1 + nimsuggest/tests/tinclude.nim | 1 + nimsuggest/tests/tstrutils.nim | 1 + nimsuggest/tests/tsug_regression.nim | 1 + nimsuggest/tests/ttype_decl.nim | 1 + nimsuggest/tests/twithin_macro.nim | 1 + nimsuggest/tests/twithin_macro_prefix.nim | 1 + 10 files changed, 27 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index b07de1df1f..0f74c56acf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -50,4 +50,4 @@ script: - ./koch web - ./koch csource - ./koch nimsuggest -# - nim c -r nimsuggest/tester + - nim c -r nimsuggest/tester diff --git a/nimsuggest/tester.nim b/nimsuggest/tester.nim index b962a9f83f..63095d4901 100644 --- a/nimsuggest/tester.nim +++ b/nimsuggest/tester.nim @@ -7,9 +7,10 @@ import os, osproc, strutils, streams, re, sexp, net type Test = object - cmd, dest: string + filename, cmd, dest: string startup: seq[string] script: seq[(string, string)] + disabled: bool const curDir = when defined(windows): "" else: "" @@ -21,6 +22,7 @@ proc parseTest(filename: string; epcMode=false): Test = const cursorMarker = "#[!]#" let nimsug = curDir & addFileExt("nimsuggest", ExeExt) let libpath = findExe("nim").splitFile().dir /../ "lib" + result.filename = filename result.dest = getTempDir() / extractFilename(filename) result.cmd = nimsug & " --tester " & result.dest result.script = @[] @@ -42,7 +44,14 @@ proc parseTest(filename: string; epcMode=false): Test = if x.contains("""""""""): inc specSection elif specSection == 1: - if x.startsWith("$nimsuggest"): + if x.startsWith("disabled:"): + if x.startsWith("disabled:true"): + result.disabled = true + else: + # be strict about format + doAssert x.startsWith("disabled:false") + result.disabled = false + elif x.startsWith("$nimsuggest"): result.cmd = x % ["nimsuggest", nimsug, "file", filename, "lib", libpath] elif x.startsWith("!"): if result.cmd.len == 0: @@ -223,8 +232,14 @@ proc doReport(filename, answer, resp: string; report: var string) = report.add "\n Expected: " & resp report.add "\n But got: " & answer +proc skipDisabledTest(test: Test): bool = + if test.disabled: + echo "disabled: " & test.filename + result = test.disabled + proc runEpcTest(filename: string): int = let s = parseTest(filename, true) + if s.skipDisabledTest: return 0 for cmd in s.startup: if not runCmd(cmd, s.dest): quit "invalid command: " & cmd @@ -267,6 +282,7 @@ proc runEpcTest(filename: string): int = proc runTest(filename: string): int = let s = parseTest filename + if s.skipDisabledTest: return 0 for cmd in s.startup: if not runCmd(cmd, s.dest): quit "invalid command: " & cmd diff --git a/nimsuggest/tests/tchk1.nim b/nimsuggest/tests/tchk1.nim index 7b0b5d5b4e..2b60ed0945 100644 --- a/nimsuggest/tests/tchk1.nim +++ b/nimsuggest/tests/tchk1.nim @@ -15,6 +15,7 @@ proc main = #[!]# discard """ +disabled:true $nimsuggest --tester $file >chk $1 chk;;skUnknown;;;;Hint;;???;;-1;;-1;;"tchk1 [Processing]";;0 diff --git a/nimsuggest/tests/tdot4.nim b/nimsuggest/tests/tdot4.nim index 8510162acb..762534310f 100644 --- a/nimsuggest/tests/tdot4.nim +++ b/nimsuggest/tests/tdot4.nim @@ -1,4 +1,5 @@ discard """ +disabled:true $nimsuggest --tester --maxresults:2 $file >sug $1 sug;;skProc;;tdot4.main;;proc (inp: string): string;;$file;;10;;5;;"";;100;;None diff --git a/nimsuggest/tests/tinclude.nim b/nimsuggest/tests/tinclude.nim index 0616b7164d..0fda43911c 100644 --- a/nimsuggest/tests/tinclude.nim +++ b/nimsuggest/tests/tinclude.nim @@ -1,4 +1,5 @@ discard """ +disabled:true $nimsuggest --tester compiler/nim.nim >def compiler/semexprs.nim:25:50 def;;skType;;ast.PSym;;PSym;;*ast.nim;;707;;2;;"";;100 diff --git a/nimsuggest/tests/tstrutils.nim b/nimsuggest/tests/tstrutils.nim index ce3e29a155..9462c3d99e 100644 --- a/nimsuggest/tests/tstrutils.nim +++ b/nimsuggest/tests/tstrutils.nim @@ -1,4 +1,5 @@ discard """ +disabled:true $nimsuggest --tester lib/pure/strutils.nim >def lib/pure/strutils.nim:2529:6 def;;skTemplate;;system.doAssert;;proc (cond: bool, msg: string): typed;;*/lib/system.nim;;*;;9;;"same as `assert` but is always turned on and not affected by the\x0A``--assertions`` command line switch.";;100 diff --git a/nimsuggest/tests/tsug_regression.nim b/nimsuggest/tests/tsug_regression.nim index ce66aafb21..1b23da8060 100644 --- a/nimsuggest/tests/tsug_regression.nim +++ b/nimsuggest/tests/tsug_regression.nim @@ -17,6 +17,7 @@ proc main = map0.#[!]# discard """ +disabled:true $nimsuggest --tester $file >sug $1 sug;;skProc;;tables.getOrDefault;;proc (t: Table[getOrDefault.A, getOrDefault.B], key: A): B;;$lib/pure/collections/tables.nim;;178;;5;;"";;100;;None diff --git a/nimsuggest/tests/ttype_decl.nim b/nimsuggest/tests/ttype_decl.nim index 846eb7b1b6..e66d39a1c4 100644 --- a/nimsuggest/tests/ttype_decl.nim +++ b/nimsuggest/tests/ttype_decl.nim @@ -1,4 +1,5 @@ discard """ +disabled:true $nimsuggest --tester --maxresults:3 $file >sug $1 sug;;skType;;ttype_decl.Other;;Other;;$file;;10;;2;;"";;0;;None diff --git a/nimsuggest/tests/twithin_macro.nim b/nimsuggest/tests/twithin_macro.nim index e0df035429..9c36ffd0f1 100644 --- a/nimsuggest/tests/twithin_macro.nim +++ b/nimsuggest/tests/twithin_macro.nim @@ -202,6 +202,7 @@ echo r.age_human_yrs() echo r discard """ +disabled:true $nimsuggest --tester $file >sug $1 sug;;skField;;age;;int;;$file;;167;;6;;"";;100;;None diff --git a/nimsuggest/tests/twithin_macro_prefix.nim b/nimsuggest/tests/twithin_macro_prefix.nim index 86e406c5df..1402b762ae 100644 --- a/nimsuggest/tests/twithin_macro_prefix.nim +++ b/nimsuggest/tests/twithin_macro_prefix.nim @@ -202,6 +202,7 @@ echo r.age_human_yrs() echo r discard """ +disabled:true $nimsuggest --tester $file >sug $1 sug;;skField;;age;;int;;$file;;167;;6;;"";;100;;Prefix From ed0cb7b85d8d48bcebb63a5e90a45a4e29bcb673 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Thu, 30 Aug 2018 04:52:32 -0700 Subject: [PATCH 092/145] make config.nims behave like nim.cfg in terms of where these scripts are searched / run (#8682) * run project config.nims if exists, then inputfile.nims if exists * ~/.config/nim/config.nims can now be used * also check in getSystemConfigPath for config.nims * refactor handleCmdLine for nim and nimsuggest --- compiler/cmdlinehelper.nim | 85 +++++++++++++++++++++++++++++++++ compiler/commands.nim | 2 +- compiler/nim.nim | 96 ++++++++++++++------------------------ compiler/nimconf.nim | 7 +-- compiler/options.nim | 9 ++-- compiler/scriptconfig.nim | 2 +- nimsuggest/nimsuggest.nim | 65 +++++++++----------------- 7 files changed, 152 insertions(+), 114 deletions(-) create mode 100644 compiler/cmdlinehelper.nim diff --git a/compiler/cmdlinehelper.nim b/compiler/cmdlinehelper.nim new file mode 100644 index 0000000000..9d2334af54 --- /dev/null +++ b/compiler/cmdlinehelper.nim @@ -0,0 +1,85 @@ +## Helpers for binaries that use compiler passes, eg: nim, nimsuggest, nimfix + +# TODO: nimfix should use this; currently out of sync + +import + compiler/[options, idents, nimconf, scriptconfig, extccomp, commands, msgs, lineinfos, modulegraphs, condsyms], + std/os + +type + NimProg* = ref object + suggestMode*: bool + supportsStdinFile*: bool + processCmdLine*: proc(pass: TCmdLinePass, cmd: string; config: ConfigRef) + mainCommand*: proc(graph: ModuleGraph) + +proc initDefinesProg*(self: NimProg, conf: ConfigRef, name: string) = + condsyms.initDefines(conf.symbols) + defineSymbol conf.symbols, name + +proc processCmdLineAndProjectPath*(self: NimProg, conf: ConfigRef) = + self.processCmdLine(passCmd1, "", conf) + if self.supportsStdinFile and conf.projectName == "-": + conf.projectName = "stdinfile" + conf.projectFull = "stdinfile" + conf.projectPath = canonicalizePath(conf, getCurrentDir()) + conf.projectIsStdin = true + elif conf.projectName != "": + try: + conf.projectFull = canonicalizePath(conf, conf.projectName) + except OSError: + conf.projectFull = conf.projectName + let p = splitFile(conf.projectFull) + let dir = if p.dir.len > 0: p.dir else: getCurrentDir() + conf.projectPath = canonicalizePath(conf, dir) + conf.projectName = p.name + else: + conf.projectPath = canonicalizePath(conf, getCurrentDir()) + +proc loadConfigsAndRunMainCommand*(self: NimProg, cache: IdentCache; conf: ConfigRef): bool = + loadConfigs(DefaultConfig, cache, conf) # load all config files + if self.suggestMode: + conf.command = "nimsuggest" + + proc runNimScriptIfExists(path: string)= + if fileExists(path): + runNimScript(cache, path, freshDefines = false, conf) + + # Caution: make sure this stays in sync with `loadConfigs` + if optSkipSystemConfigFile notin conf.globalOptions: + runNimScriptIfExists(getSystemConfigPath(conf, DefaultConfigNims)) + + if optSkipUserConfigFile notin conf.globalOptions: + runNimScriptIfExists(getUserConfigPath(DefaultConfigNims)) + + if optSkipParentConfigFiles notin conf.globalOptions: + for dir in parentDirs(conf.projectPath, fromRoot = true, inclusive = false): + runNimScriptIfExists(dir / DefaultConfigNims) + + if optSkipProjConfigFile notin conf.globalOptions: + runNimScriptIfExists(conf.projectPath / DefaultConfigNims) + block: + let scriptFile = conf.projectFull.changeFileExt("nims") + if not self.suggestMode: + runNimScriptIfExists(scriptFile) + # 'nim foo.nims' means to just run the NimScript file and do nothing more: + if fileExists(scriptFile) and scriptFile.cmpPaths(conf.projectFull) == 0: + return false + else: + if scriptFile.cmpPaths(conf.projectFull) != 0: + runNimScriptIfExists(scriptFile) + else: + # 'nimsuggest foo.nims' means to just auto-complete the NimScript file + discard + + # now process command line arguments again, because some options in the + # command line can overwite the config file's settings + extccomp.initVars(conf) + self.processCmdLine(passCmd2, "", conf) + if conf.command == "": + rawMessage(conf, errGenerated, "command missing") + + let graph = newModuleGraph(cache, conf) + graph.suggestMode = self.suggestMode + self.mainCommand(graph) + return true diff --git a/compiler/commands.nim b/compiler/commands.nim index 8165fa5d49..b47ccf610e 100644 --- a/compiler/commands.nim +++ b/compiler/commands.nim @@ -651,7 +651,7 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo; else: localError(conf, info, "invalid option for --symbolFiles: " & arg) of "skipcfg": expectNoArg(conf, switch, arg, pass, info) - incl(conf.globalOptions, optSkipConfigFile) + incl(conf.globalOptions, optSkipSystemConfigFile) of "skipprojcfg": expectNoArg(conf, switch, arg, pass, info) incl(conf.globalOptions, optSkipProjConfigFile) diff --git a/compiler/nim.nim b/compiler/nim.nim index 90049bdfbf..0fed72dc74 100644 --- a/compiler/nim.nim +++ b/compiler/nim.nim @@ -21,7 +21,7 @@ when defined(i386) and defined(windows) and defined(vcc): import commands, lexer, condsyms, options, msgs, nversion, nimconf, ropes, extccomp, strutils, os, osproc, platform, main, parseopt, - nodejs, scriptconfig, idents, modulegraphs, lineinfos + nodejs, scriptconfig, idents, modulegraphs, lineinfos, cmdlinehelper when hasTinyCBackend: import tccgen @@ -57,69 +57,43 @@ proc processCmdLine(pass: TCmdLinePass, cmd: string; config: ConfigRef) = rawMessage(config, errGenerated, errArgsNeedRunOption) proc handleCmdLine(cache: IdentCache; conf: ConfigRef) = - condsyms.initDefines(conf.symbols) + let self = NimProg( + supportsStdinFile: true, + processCmdLine: processCmdLine, + mainCommand: mainCommand + ) + self.initDefinesProg(conf, "nim_compiler") if paramCount() == 0: writeCommandLineUsage(conf, conf.helpWritten) - else: - # Process command line arguments: - processCmdLine(passCmd1, "", conf) - if conf.projectName == "-": - conf.projectName = "stdinfile" - conf.projectFull = "stdinfile" - conf.projectPath = canonicalizePath(conf, getCurrentDir()) - conf.projectIsStdin = true - elif conf.projectName != "": - try: - conf.projectFull = canonicalizePath(conf, conf.projectName) - except OSError: - conf.projectFull = conf.projectName - let p = splitFile(conf.projectFull) - let dir = if p.dir.len > 0: p.dir else: getCurrentDir() - conf.projectPath = canonicalizePath(conf, dir) - conf.projectName = p.name + return + + self.processCmdLineAndProjectPath(conf) + if not self.loadConfigsAndRunMainCommand(cache, conf): return + if optHints in conf.options and hintGCStats in conf.notes: echo(GC_getStatistics()) + #echo(GC_getStatistics()) + if conf.errorCounter != 0: return + when hasTinyCBackend: + if conf.cmd == cmdRun: + tccgen.run(conf.arguments) + if optRun in conf.globalOptions: + if conf.cmd == cmdCompileToJS: + var ex: string + if conf.outFile.len > 0: + ex = conf.outFile.prependCurDir.quoteShell + else: + ex = quoteShell( + completeCFilePath(conf, changeFileExt(conf.projectFull, "js").prependCurDir)) + execExternalProgram(conf, findNodeJs() & " " & ex & ' ' & conf.arguments) else: - conf.projectPath = canonicalizePath(conf, getCurrentDir()) - loadConfigs(DefaultConfig, cache, conf) # load all config files - let scriptFile = conf.projectFull.changeFileExt("nims") - if fileExists(scriptFile): - runNimScript(cache, scriptFile, freshDefines=false, conf) - # 'nim foo.nims' means to just run the NimScript file and do nothing more: - if scriptFile == conf.projectFull: return - elif fileExists(conf.projectPath / "config.nims"): - # directory wide NimScript file - runNimScript(cache, conf.projectPath / "config.nims", freshDefines=false, conf) - # now process command line arguments again, because some options in the - # command line can overwite the config file's settings - extccomp.initVars(conf) - processCmdLine(passCmd2, "", conf) - if conf.command == "": - rawMessage(conf, errGenerated, "command missing") - mainCommand(newModuleGraph(cache, conf)) - if optHints in conf.options and hintGCStats in conf.notes: echo(GC_getStatistics()) - #echo(GC_getStatistics()) - if conf.errorCounter == 0: - when hasTinyCBackend: - if conf.cmd == cmdRun: - tccgen.run(conf.arguments) - if optRun in conf.globalOptions: - if conf.cmd == cmdCompileToJS: - var ex: string - if conf.outFile.len > 0: - ex = conf.outFile.prependCurDir.quoteShell - else: - ex = quoteShell( - completeCFilePath(conf, changeFileExt(conf.projectFull, "js").prependCurDir)) - execExternalProgram(conf, findNodeJs() & " " & ex & ' ' & conf.arguments) - else: - var binPath: string - if conf.outFile.len > 0: - # If the user specified an outFile path, use that directly. - binPath = conf.outFile.prependCurDir - else: - # Figure out ourselves a valid binary name. - binPath = changeFileExt(conf.projectFull, ExeExt).prependCurDir - var ex = quoteShell(binPath) - execExternalProgram(conf, ex & ' ' & conf.arguments) + var binPath: string + if conf.outFile.len > 0: + # If the user specified an outFile path, use that directly. + binPath = conf.outFile.prependCurDir + else: + # Figure out ourselves a valid binary name. + binPath = changeFileExt(conf.projectFull, ExeExt).prependCurDir + var ex = quoteShell(binPath) + execExternalProgram(conf, ex & ' ' & conf.arguments) when declared(GC_setMaxPause): GC_setMaxPause 2_000 diff --git a/compiler/nimconf.nim b/compiler/nimconf.nim index 96b9a38413..5f6889a6fb 100644 --- a/compiler/nimconf.nim +++ b/compiler/nimconf.nim @@ -219,10 +219,10 @@ proc readConfigFile( closeLexer(L) return true -proc getUserConfigPath(filename: string): string = +proc getUserConfigPath*(filename: string): string = result = joinPath([getConfigDir(), "nim", filename]) -proc getSystemConfigPath(conf: ConfigRef; filename: string): string = +proc getSystemConfigPath*(conf: ConfigRef; filename: string): string = # try standard configuration file (installation did not distribute files # the UNIX way) let p = getPrefixDir(conf) @@ -241,7 +241,7 @@ proc loadConfigs*(cfg: string; cache: IdentCache; conf: ConfigRef) = if readConfigFile(configPath, cache, conf): add(configFiles, configPath) - if optSkipConfigFile notin conf.globalOptions: + if optSkipSystemConfigFile notin conf.globalOptions: readConfigFile(getSystemConfigPath(conf, cfg)) if optSkipUserConfigFile notin conf.globalOptions: @@ -263,4 +263,5 @@ proc loadConfigs*(cfg: string; cache: IdentCache; conf: ConfigRef) = readConfigFile(projectConfig) for filename in configFiles: + # delayed to here so that `hintConf` is honored rawMessage(conf, hintConf, filename) diff --git a/compiler/options.nim b/compiler/options.nim index 04b14c65f2..2a10aa9f8f 100644 --- a/compiler/options.nim +++ b/compiler/options.nim @@ -54,10 +54,10 @@ type # please make sure we have under 32 options optGenMapping, # generate a mapping file optRun, # run the compiled project optCheckNep1, # check that the names adhere to NEP-1 - optSkipConfigFile, # skip the general config file - optSkipProjConfigFile, # skip the project's config file - optSkipUserConfigFile, # skip the users's config file - optSkipParentConfigFiles, # skip parent dir's config files + optSkipSystemConfigFile, # skip the system's cfg/nims config file + optSkipProjConfigFile, # skip the project's cfg/nims config file + optSkipUserConfigFile, # skip the users's cfg/nims config file + optSkipParentConfigFiles, # skip parent dir's cfg/nims config files optNoMain, # do not generate a "main" proc optUseColors, # use colors for hints, warnings, and errors optThreads, # support for multi-threading @@ -391,6 +391,7 @@ const TexExt* = "tex" IniExt* = "ini" DefaultConfig* = "nim.cfg" + DefaultConfigNims* = "config.nims" DocConfig* = "nimdoc.cfg" DocTexConfig* = "nimdoc.tex.cfg" diff --git a/compiler/scriptconfig.nim b/compiler/scriptconfig.nim index 659206a40c..184b60733d 100644 --- a/compiler/scriptconfig.nim +++ b/compiler/scriptconfig.nim @@ -171,7 +171,7 @@ proc runNimScript*(cache: IdentCache; scriptName: string; incl(m.flags, sfMainModule) graph.vm = setupVM(m, cache, scriptName, graph) - graph.compileSystemModule() + graph.compileSystemModule() # TODO: see why this unsets hintConf in conf.notes discard graph.processModule(m, llStreamOpen(scriptName, fmRead)) # ensure we load 'system.nim' again for the real non-config stuff! diff --git a/nimsuggest/nimsuggest.nim b/nimsuggest/nimsuggest.nim index 4b5ce0a57e..b20572b0e3 100644 --- a/nimsuggest/nimsuggest.nim +++ b/nimsuggest/nimsuggest.nim @@ -20,7 +20,7 @@ import compiler / [options, commands, modules, sem, passes, passaux, msgs, nimconf, extccomp, condsyms, sigmatch, ast, scriptconfig, - idents, modulegraphs, vm, prefixmatches, lineinfos] + idents, modulegraphs, vm, prefixmatches, lineinfos, cmdlinehelper] when defined(windows): import winlean @@ -582,55 +582,32 @@ proc processCmdLine*(pass: TCmdLinePass, cmd: string; conf: ConfigRef) = # if processArgument(pass, p, argsCount): break proc handleCmdLine(cache: IdentCache; conf: ConfigRef) = - condsyms.initDefines(conf.symbols) - defineSymbol conf.symbols, "nimsuggest" + let self = NimProg( + suggestMode: true, + processCmdLine: processCmdLine, + mainCommand: mainCommand + ) + self.initDefinesProg(conf, "nimsuggest") if paramCount() == 0: stdout.writeline(Usage) - else: - processCmdLine(passCmd1, "", conf) - if gMode != mstdin: - conf.writelnHook = proc (msg: string) = discard - if conf.projectName != "": - try: - conf.projectFull = canonicalizePath(conf, conf.projectName) - except OSError: - conf.projectFull = conf.projectName - var p = splitFile(conf.projectFull) - conf.projectPath = canonicalizePath(conf, p.dir) - conf.projectName = p.name - else: - conf.projectPath = canonicalizePath(conf, getCurrentDir()) + return - # Find Nim's prefix dir. - let binaryPath = findExe("nim") - if binaryPath == "": - raise newException(IOError, - "Cannot find Nim standard library: Nim compiler not in PATH") - conf.prefixDir = binaryPath.splitPath().head.parentDir() - if not dirExists(conf.prefixDir / "lib"): conf.prefixDir = "" + self.processCmdLineAndProjectPath(conf) - #msgs.writelnHook = proc (line: string) = log(line) - myLog("START " & conf.projectFull) + if gMode != mstdin: + conf.writelnHook = proc (msg: string) = discard + # Find Nim's prefix dir. + let binaryPath = findExe("nim") + if binaryPath == "": + raise newException(IOError, + "Cannot find Nim standard library: Nim compiler not in PATH") + conf.prefixDir = binaryPath.splitPath().head.parentDir() + if not dirExists(conf.prefixDir / "lib"): conf.prefixDir = "" - loadConfigs(DefaultConfig, cache, conf) # load all config files - # now process command line arguments again, because some options in the - # command line can overwite the config file's settings - conf.command = "nimsuggest" - let scriptFile = conf.projectFull.changeFileExt("nims") - if fileExists(scriptFile): - # 'nimsuggest foo.nims' means to just auto-complete the NimScript file: - if scriptFile != conf.projectFull: - runNimScript(cache, scriptFile, freshDefines=false, conf) - elif fileExists(conf.projectPath / "config.nims"): - # directory wide NimScript file - runNimScript(cache, conf.projectPath / "config.nims", freshDefines=false, conf) + #msgs.writelnHook = proc (line: string) = log(line) + myLog("START " & conf.projectFull) - extccomp.initVars(conf) - processCmdLine(passCmd2, "", conf) - - let graph = newModuleGraph(cache, conf) - graph.suggestMode = true - mainCommand(graph) + discard self.loadConfigsAndRunMainCommand(cache, conf) handleCmdline(newIdentCache(), newConfigRef()) From 3e6b58323bb1c33bfa6d1a70905ee10e4f20f638 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Thu, 30 Aug 2018 04:53:16 -0700 Subject: [PATCH 093/145] fix tests/coroutines/texceptions.nim (#8810) --- lib/pure/coro.nim | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/pure/coro.nim b/lib/pure/coro.nim index 6d7dcf0785..2fe34ed40d 100644 --- a/lib/pure/coro.nim +++ b/lib/pure/coro.nim @@ -115,7 +115,12 @@ elif coroBackend == CORO_BACKEND_SETJMP: when defined(unix): # GLibc fails with "*** longjmp causes uninitialized stack frame ***" because # our custom stacks are not initialized to a magic value. - {.passC: "-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0"} + when defined(osx): + # workaround: error: The deprecated ucontext routines require _XOPEN_SOURCE to be defined + const extra = " -D_XOPEN_SOURCE" + else: + const extra = "" + {.passC: "-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0" & extra.} const CORO_CREATED = 0 From a14ffd61192ccc77623c741bc859a2a67a0673f4 Mon Sep 17 00:00:00 2001 From: Araq Date: Thu, 30 Aug 2018 15:33:34 +0200 Subject: [PATCH 094/145] fixes #8768 --- lib/pure/unidecode/gen.py | 18 +- lib/pure/unidecode/unidecode.dat | 850 +++++++++++++++---------------- lib/pure/unidecode/unidecode.nim | 4 +- 3 files changed, 436 insertions(+), 436 deletions(-) diff --git a/lib/pure/unidecode/gen.py b/lib/pure/unidecode/gen.py index 8da0136ffa..33f1c799fb 100644 --- a/lib/pure/unidecode/gen.py +++ b/lib/pure/unidecode/gen.py @@ -5,22 +5,22 @@ # (c) 2010 Andreas Rumpf from unidecode import unidecode +import warnings -def main2(): +warnings.simplefilter("ignore") + +def main2(): data = [] - for x in xrange(128, 0xffff + 1): - u = eval("u'\u%04x'" % x) - + for x in range(128, 0xffff + 1): + u = eval("u'\\u%04x'" % x) + val = unidecode(u) data.append(val) - - - f = open("unidecode.dat", "wb+") + + f = open("unidecode.dat", "w+") for d in data: f.write("%s\n" % d) f.close() main2() - - diff --git a/lib/pure/unidecode/unidecode.dat b/lib/pure/unidecode/unidecode.dat index 9dff0a4a97..37b66bedf9 100644 --- a/lib/pure/unidecode/unidecode.dat +++ b/lib/pure/unidecode/unidecode.dat @@ -58,9 +58,9 @@ P 1 o >> -1/4 -1/2 -3/4 + 1/4 + 1/2 + 3/4 ? A A @@ -91,7 +91,7 @@ U U U U -U +Y Th ss a @@ -177,7 +177,7 @@ i I i IJ - +ij J j K @@ -368,7 +368,7 @@ ZH zh j DZ -D +Dz dz G g @@ -414,8 +414,8 @@ Y y H h -[?] -[?] +N +d OU ou Z @@ -434,34 +434,34 @@ O o Y y +l +n +t +j +db +qp +A +C +c +L +T +s +z [?] [?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] +B +U +^ +E +e +J +j +q +q +R +r +Y +y a a a @@ -503,13 +503,13 @@ o OE O F -R -R -R -R r r -R +r +r +r +r +r R R s @@ -519,12 +519,12 @@ S S t t -U +u U v ^ -W -Y +w +y Y z z @@ -556,9 +556,9 @@ ls lz WW ]] -[?] -[?] -k +h +h +h h j r @@ -737,19 +737,19 @@ V -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] +a +e +i +o +u +c +d +h +m +r +t +v +x [?] [?] [?] @@ -1287,7 +1287,7 @@ o f ew [?] -. +: - [?] [?] @@ -1340,9 +1340,9 @@ o u ' +- - - +| : @@ -7402,41 +7402,41 @@ bh +b +d +f +m +n +p +r +r +s +t +z +g +p +b +d +f +g +k +l +m +n +p +r +s - - - - - - - - - - - - - - - - - - - - - - - - - - - +v +x +z @@ -7708,7 +7708,7 @@ a S [?] [?] -[?] +Ss [?] A a @@ -8136,13 +8136,23 @@ _ / -[ ]- -[?] +?? ?! !? 7 PP (] [) +* +[?] +[?] +[?] +% +~ +[?] +[?] +[?] +'''' [?] [?] [?] @@ -8150,18 +8160,8 @@ PP [?] [?] [?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] + + [?] [?] [?] @@ -8178,7 +8178,7 @@ PP 0 - +i 4 @@ -8209,19 +8209,19 @@ n ( ) [?] +a +e +o +x [?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] +h +k +l +m +n +p +s +t [?] [?] [?] @@ -8237,26 +8237,26 @@ Rs W NS D -EU +EUR K T Dr -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] +Pf +P +G +A +UAH +C| +L +Sm +T +Rs +L +M +m +R +l +BTC [?] [?] [?] @@ -8294,6 +8294,7 @@ Dr [?] + [?] [?] [?] @@ -8319,91 +8320,90 @@ Dr [?] [?] [?] -[?] - - - - - - - - - - - - - - - + a/c + a/s +C + c/o + c/u +g +H +H +H +h +I +I +L +l +N +No. +P +Q +R +R +R +(sm) +TEL +(tm) +Z +Z +K +A +B +C +e +e +E +F +F +M +o +i +FAX - - - - - - - - - - - - - - - - - - - -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] [?] [?] [?] [?] [?] +D +d +e +i +j [?] [?] [?] [?] +F [?] + 1/7 + 1/9 + 1/10 1/3 2/3 1/5 @@ -8458,7 +8458,7 @@ D) [?] [?] [?] -[?] + 0/3 [?] [?] [?] @@ -8595,8 +8595,12 @@ V [?] [?] [?] +- [?] [?] +/ +\ +* [?] [?] [?] @@ -8608,6 +8612,7 @@ V [?] [?] [?] +| [?] [?] [?] @@ -8626,11 +8631,13 @@ V [?] [?] [?] +: [?] [?] [?] [?] [?] +~ [?] [?] [?] @@ -8670,17 +8677,10 @@ V [?] [?] [?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] +<= +>= +<= +>= [?] [?] [?] @@ -8836,6 +8836,7 @@ V [?] [?] [?] +^ [?] [?] [?] @@ -8873,9 +8874,8 @@ V [?] [?] [?] -[?] -[?] -[?] +< +> [?] [?] [?] @@ -9185,166 +9185,166 @@ V [?] [?] [?] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] - +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +(1) +(2) +(3) +(4) +(5) +(6) +(7) +(8) +(9) +(10) +(11) +(12) +(13) +(14) +(15) +(16) +(17) +(18) +(19) +(20) +1. +2. +3. +4. +5. +6. +7. +8. +9. +10. +11. +12. +13. +14. +15. +16. +17. +18. +19. +20. +(a) +(b) +(c) +(d) +(e) +(f) +(g) +(h) +(i) +(j) +(k) +(l) +(m) +(n) +(o) +(p) +(q) +(r) +(s) +(t) +(u) +(v) +(w) +(x) +(y) +(z) +A +B +C +D +E +F +G +H +I +J +K +L +M +N +O +P +Q +R +S +T +U +V +W +X +Y +Z +a +b +c +d +e +f +g +h +i +j +k +l +m +n +o +p +q +r +s +t +u +v +w +x +y +z +0 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +0 - - | @@ -9712,7 +9712,7 @@ O - +# [?] @@ -9906,6 +9906,7 @@ O +* @@ -9944,8 +9945,7 @@ O - - +| @@ -9955,7 +9955,7 @@ O [?] [?] - +! @@ -10087,10 +10087,10 @@ O [?] [?] [?] +[ [?] -[?] -[?] -[?] +< +> [?] [?] [?] @@ -10500,6 +10500,8 @@ y +{ +} @@ -10739,6 +10741,9 @@ y +::= +== +=== @@ -11228,27 +11233,22 @@ y +L +l +L +P +R +a +t +H +h +K +k +Z +z - - - - - - - - - - - - - - - - - - - - +M +A @@ -12754,21 +12754,21 @@ H [?] [?] [?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 (g) (n) (d) @@ -12850,21 +12850,21 @@ KIS (Zi) (Xie) (Ye) -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] -[?] +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 1M 2M 3M @@ -12877,10 +12877,10 @@ KIS 10M 11M 12M -[?] -[?] -[?] -[?] +Hg +erg +eV +LTD a i u @@ -13042,16 +13042,16 @@ watt 22h 23h 24h -HPA +hPa da AU bar oV pc -[?] -[?] -[?] -[?] +dm +dm^2 +dm^3 +IU Heisei Syouwa Taisyou @@ -13092,7 +13092,7 @@ mm^2 cm^2 m^2 km^2 -mm^4 +mm^3 cm^3 m^3 km^3 @@ -13184,7 +13184,7 @@ Wb 29d 30d 31d - +gal @@ -19841,7 +19841,7 @@ Wb [?] [?] -[?] +Yi Ding Kao Qi diff --git a/lib/pure/unidecode/unidecode.nim b/lib/pure/unidecode/unidecode.nim index 63ebd8248f..f3727c8648 100644 --- a/lib/pure/unidecode/unidecode.nim +++ b/lib/pure/unidecode/unidecode.nim @@ -69,5 +69,5 @@ proc unidecode*(s: string): string = when isMainModule: loadUnidecodeTable("lib/pure/unidecode/unidecode.dat") - assert unidecode("Äußerst") == "Ausserst" - + doAassert unidecode("Äußerst") == "Ausserst" + doAssert unidecode("北京") == "Bei Jing" From 8e336672623c1b36baf2b89117cc62516ac61c30 Mon Sep 17 00:00:00 2001 From: Araq Date: Thu, 30 Aug 2018 15:39:47 +0200 Subject: [PATCH 095/145] unidecode module: change the default to: embed resource file into the application; fixes #8767 --- lib/pure/unidecode/unidecode.nim | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/pure/unidecode/unidecode.nim b/lib/pure/unidecode/unidecode.nim index f3727c8648..7719754124 100644 --- a/lib/pure/unidecode/unidecode.nim +++ b/lib/pure/unidecode/unidecode.nim @@ -22,14 +22,14 @@ ## strictly one-way transformation. However a human reader will probably ## still be able to guess what original string was meant from the context. ## -## This module needs the data file "unidecode.dat" to work: You can either -## ship this file with your application and initialize this module with the -## `loadUnidecodeTable` proc or you can define the ``embedUnidecodeTable`` -## symbol to embed the file as a resource into your application. +## This module needs the data file "unidecode.dat" to work: This file is +## embedded as a resource into your application by default. But you an also +## define the symbol ``--define:noUnidecodeTable`` during compile time and +## use the `loadUnidecodeTable` proc to initialize this module. import unicode -when defined(embedUnidecodeTable): +when not defined(noUnidecodeTable): import strutils const translationTable = splitLines(slurp"unidecode/unidecode.dat") @@ -38,11 +38,11 @@ else: var translationTable: seq[string] proc loadUnidecodeTable*(datafile = "unidecode.dat") = - ## loads the datafile that `unidecode` to work. Unless this module is - ## compiled with the ``embedUnidecodeTable`` symbol defined, this needs - ## to be called by the main thread before any thread can make a call - ## to `unidecode`. - when not defined(embedUnidecodeTable): + ## loads the datafile that `unidecode` to work. This is only required if + ## the module was compiled with the ``--define:noUnidecodeTable`` switch. + ## This needs to be called by the main thread before any thread can make a + ## call to `unidecode`. + when defined(noUnidecodeTable): newSeq(translationTable, 0xffff) var i = 0 for line in lines(datafile): From e98e21442253c8f376e2b48753ed036dbd99aa9f Mon Sep 17 00:00:00 2001 From: Araq Date: Wed, 29 Aug 2018 15:46:50 +0200 Subject: [PATCH 096/145] fixes #7854 --- compiler/sigmatch.nim | 3 +- tests/generics/tgenerics_and_inheritance.nim | 36 ++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 tests/generics/tgenerics_and_inheritance.nim diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 9321630550..c53c730748 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -1921,6 +1921,7 @@ proc paramTypesMatchAux(m: var TCandidate, f, a: PType, result.typ.n = arg return + let oldInheritancePenalty = m.inheritancePenalty var r = typeRel(m, f, a) # This special typing rule for macros and templates is not documented @@ -2002,7 +2003,7 @@ proc paramTypesMatchAux(m: var TCandidate, f, a: PType, if arg.typ == nil: result = arg elif skipTypes(arg.typ, abstractVar-{tyTypeDesc}).kind == tyTuple or - m.inheritancePenalty > 0: + m.inheritancePenalty > oldInheritancePenalty: result = implicitConv(nkHiddenSubConv, f, arg, m, c) elif arg.typ.isEmptyContainer: result = arg.copyTree diff --git a/tests/generics/tgenerics_and_inheritance.nim b/tests/generics/tgenerics_and_inheritance.nim new file mode 100644 index 0000000000..ea776b5177 --- /dev/null +++ b/tests/generics/tgenerics_and_inheritance.nim @@ -0,0 +1,36 @@ + +# bug #7854 + +type + Stream* = ref StreamObj + StreamObj* = object of RootObj + + InhStream* = ref InhStreamObj + InhStreamObj* = object of Stream + f: string + +proc newInhStream*(f: string): InhStream = + new(result) + result.f = f + +var val: int +let str = newInhStream("input_file.json") + +block: + # works: + proc load[T](data: var T, s: Stream) = + discard + load(val, str) + +block: + # works + proc load[T](s: Stream, data: T) = + discard + load(str, val) + +block: + # broken + proc load[T](s: Stream, data: var T) = + discard + load(str, val) + From dfdf8e58c711cadaeb9f830f128eef28aeb6f1ab Mon Sep 17 00:00:00 2001 From: Araq Date: Thu, 30 Aug 2018 16:54:03 +0200 Subject: [PATCH 097/145] fixes #8768 properly --- lib/pure/unidecode/gen.py | 26 +++++++++++++++----------- lib/pure/unidecode/unidecode.dat | 3 --- lib/pure/unidecode/unidecode.nim | 6 +++--- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/lib/pure/unidecode/gen.py b/lib/pure/unidecode/gen.py index 33f1c799fb..f0647ea6ce 100644 --- a/lib/pure/unidecode/gen.py +++ b/lib/pure/unidecode/gen.py @@ -1,26 +1,30 @@ -#! usr/bin/env python +#! usr/bin/env python3 # -*- coding: utf-8 -*- # Generates the unidecode.dat module # (c) 2010 Andreas Rumpf from unidecode import unidecode -import warnings - -warnings.simplefilter("ignore") +try: + import warnings + warnings.simplefilter("ignore") +except ImportError: + pass def main2(): - data = [] + f = open("unidecode.dat", "wb+") for x in range(128, 0xffff + 1): u = eval("u'\\u%04x'" % x) val = unidecode(u) - data.append(val) - f = open("unidecode.dat", "w+") - for d in data: - f.write("%s\n" % d) + # f.write("%x | " % x) + if x==0x2028: # U+2028 = LINE SEPARATOR + val = "" + elif x==0x2029: # U+2028 = PARAGRAPH SEPARATOR + val = "" + f.write("%s\n" % val) + f.close() - -main2() +main2() \ No newline at end of file diff --git a/lib/pure/unidecode/unidecode.dat b/lib/pure/unidecode/unidecode.dat index 37b66bedf9..5f4c075d80 100644 --- a/lib/pure/unidecode/unidecode.dat +++ b/lib/pure/unidecode/unidecode.dat @@ -8109,9 +8109,6 @@ _ - - - %0 %00 diff --git a/lib/pure/unidecode/unidecode.nim b/lib/pure/unidecode/unidecode.nim index 7719754124..e0b8d3946e 100644 --- a/lib/pure/unidecode/unidecode.nim +++ b/lib/pure/unidecode/unidecode.nim @@ -68,6 +68,6 @@ proc unidecode*(s: string): string = elif c <% translationTable.len: add(result, translationTable[c-128]) when isMainModule: - loadUnidecodeTable("lib/pure/unidecode/unidecode.dat") - doAassert unidecode("Äußerst") == "Ausserst" - doAssert unidecode("北京") == "Bei Jing" + #loadUnidecodeTable("lib/pure/unidecode/unidecode.dat") + doAssert unidecode("Äußerst") == "Ausserst" + doAssert unidecode("北京") == "Bei Jing " From df4d5b77a14b3b84f3ff37b3741dd039c9e21ce4 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Thu, 30 Aug 2018 23:01:15 +0200 Subject: [PATCH 098/145] introduce precise string '[]', '[]=' accessors; fixes #8049 (#8817) --- compiler/semexprs.nim | 4 ++-- compiler/sigmatch.nim | 9 +++++++++ lib/system.nim | 9 +++++++++ tests/array/tarrindx.nim | 14 +++++++++++++- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 5ff692fd57..04e76102b8 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -1391,8 +1391,8 @@ proc semSubscript(c: PContext, n: PNode, flags: TExprFlags): PNode = n.sons[1] = semConstExpr(c, n.sons[1]) if skipTypes(n.sons[1].typ, {tyGenericInst, tyRange, tyOrdinal, tyAlias, tySink}).kind in {tyInt..tyInt64}: - var idx = getOrdValue(n.sons[1]) - if idx >= 0 and idx < sonsLen(arr): n.typ = arr.sons[int(idx)] + let idx = getOrdValue(n.sons[1]) + if idx >= 0 and idx < len(arr): n.typ = arr.sons[int(idx)] else: localError(c.config, n.info, "invalid index value for tuple subscript") result = n else: diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index c53c730748..0cd55068ce 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -2132,6 +2132,10 @@ proc paramTypesMatch*(m: var TCandidate, f, a: PType, styleCheckUse(arg.info, arg.sons[best].sym) result = paramTypesMatchAux(m, f, arg.sons[best].typ, arg.sons[best], argOrig) + when false: + if m.calleeSym != nil and m.calleeSym.name.s == "[]": + echo m.c.config $ arg.info, " for ", m.calleeSym.name.s, " ", m.c.config $ m.calleeSym.info + writeMatches(m) proc setSon(father: PNode, at: int, son: PNode) = let oldLen = father.len @@ -2380,6 +2384,11 @@ proc matches*(c: PContext, n, nOrig: PNode, m: var TCandidate) = if m.magic in {mArrGet, mArrPut}: m.state = csMatch m.call = n + # Note the following doesn't work as it would produce ambiguities. + # Instead we patch system.nim, see bug #8049. + when false: + inc m.genericMatches + inc m.exactMatches return var marker = initIntSet() matchesAux(c, n, nOrig, m, marker) diff --git a/lib/system.nim b/lib/system.nim index 2c88fe60f8..92f51fe7e8 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -313,6 +313,12 @@ when defined(nimArrIdx): proc `[]=`*[I: Ordinal;T,S](a: T; i: I; x: S) {.noSideEffect, magic: "ArrPut".} proc `=`*[T](dest: var T; src: T) {.noSideEffect, magic: "Asgn".} + + proc arrGet[I: Ordinal;T](a: T; i: I): T {. + noSideEffect, magic: "ArrGet".} + proc arrPut[I: Ordinal;T,S](a: T; i: I; + x: S) {.noSideEffect, magic: "ArrPut".} + when defined(nimNewRuntime): proc `=destroy`*[T](x: var T) {.inline, magic: "Asgn".} = ## generic `destructor`:idx: implementation that can be overriden. @@ -3526,6 +3532,9 @@ template spliceImpl(s, a, L, b: untyped): untyped = template `^^`(s, i: untyped): untyped = (when i is BackwardsIndex: s.len - int(i) else: int(i)) +template `[]`*(s: string; i: int): char = arrGet(s, i) +template `[]=`*(s: string; i: int; val: char) = arrPut(s, i, val) + when hasAlloc or defined(nimscript): proc `[]`*[T, U](s: string, x: HSlice[T, U]): string {.inline.} = ## slice operation for strings. diff --git a/tests/array/tarrindx.nim b/tests/array/tarrindx.nim index 3bb6b0148d..9e8ec31b60 100644 --- a/tests/array/tarrindx.nim +++ b/tests/array/tarrindx.nim @@ -1,6 +1,8 @@ discard """ output: '''0 -0''' +0 +bc +bcdefg''' """ # test another strange bug ... (I hate this compiler; it is much too buggy!) @@ -29,3 +31,13 @@ var echo obj.s1[0] echo obj.s1[0u] + + +# bug #8049 + +when true: + type ustring* = distinct string + converter toUString*(s: string): ustring = ustring(s) + proc `[]`*(s: ustring, i: int): ustring = s + echo "abcdefgh"[1..2] + echo "abcdefgh"[1..^2] From 36473acf473616e1817367dda59439a32f51b07f Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Thu, 30 Aug 2018 23:50:09 +0200 Subject: [PATCH 099/145] fixes a parseopt regression (#8820) --- lib/pure/parseopt.nim | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/pure/parseopt.nim b/lib/pure/parseopt.nim index 70319ddf08..c91134738d 100644 --- a/lib/pure/parseopt.nim +++ b/lib/pure/parseopt.nim @@ -207,9 +207,12 @@ proc next*(p: var OptParser) {.rtl, extern: "npo$1".} = i = parseWord(p.cmds[p.idx], i, p.key.string, {' ', '\t', ':', '='}) while i < p.cmds[p.idx].len and p.cmds[p.idx][i] in {'\t', ' '}: inc(i) if i < p.cmds[p.idx].len and p.cmds[p.idx][i] in {':', '='}: - if i < p.cmds[p.idx].len and p.cmds[p.idx][i] in {':', '='}: - inc(i) + inc(i) while i < p.cmds[p.idx].len and p.cmds[p.idx][i] in {'\t', ' '}: inc(i) + # if we're at the end, use the next command line option: + if i >= p.cmds[p.idx].len and p.idx < p.cmds.len: + inc p.idx + i = 0 p.val = TaintedString p.cmds[p.idx].substr(i) elif len(p.longNoVal) > 0 and p.key.string notin p.longNoVal and p.idx+1 < p.cmds.len: p.val = TaintedString p.cmds[p.idx+1] From 6fd0a332659cb01c1074a9e0c6b2e443ec600f8d Mon Sep 17 00:00:00 2001 From: Araq Date: Thu, 30 Aug 2018 23:48:16 +0200 Subject: [PATCH 100/145] Tutorial 1: Simplifiy the discription of enums; it is a tutorial, not a manual --- doc/tut1.rst | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/doc/tut1.rst b/doc/tut1.rst index e200cfe8ba..a7f1b741ad 100644 --- a/doc/tut1.rst +++ b/doc/tut1.rst @@ -1112,21 +1112,12 @@ proc can convert it to its underlying integer value. For better interfacing to other programming languages, the symbols of enum types can be assigned an explicit ordinal value. However, the ordinal values -must be in ascending order. A symbol whose ordinal value is not -explicitly given is assigned the value of the previous symbol + 1. - -An explicit ordered enum can have *holes*: - -.. code-block:: nim - :test: "nim c $1" - type - MyEnum = enum - a = 2, b = 4, c = 89 +must be in ascending order. Ordinal types ------------- -Enumerations without holes, integer types, ``char`` and ``bool`` (and +Enumerations, integer types, ``char`` and ``bool`` (and subranges) are called ordinal types. Ordinal types have quite a few special operations: From fab449872776badf7c81f08b29ddaf2f598a5c3d Mon Sep 17 00:00:00 2001 From: Araq Date: Thu, 30 Aug 2018 23:55:54 +0200 Subject: [PATCH 101/145] times.nim: minor code cleanup --- lib/pure/times.nim | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/pure/times.nim b/lib/pure/times.nim index 9f6ea5722b..a7ccbf6eed 100644 --- a/lib/pure/times.nim +++ b/lib/pure/times.nim @@ -608,7 +608,6 @@ proc stringifyUnit(value: int | int64, unit: TimeUnit): string = proc humanizeParts(parts: seq[string]): string = ## Make date string parts human-readable - result = "" if parts.len == 0: result.add "0 nanoseconds" @@ -617,8 +616,8 @@ proc humanizeParts(parts: seq[string]): string = elif parts.len == 2: result = parts[0] & " and " & parts[1] else: - for part in parts[0..high(parts)-1]: - result.add part & ", " + for i in 0..high(parts)-1: + result.add parts[i] & ", " result.add "and " & parts[high(parts)] proc `$`*(dur: Duration): string = From 2f7b979e384ff6cc750e123939401a72c3f59093 Mon Sep 17 00:00:00 2001 From: Araq Date: Fri, 31 Aug 2018 00:30:09 +0200 Subject: [PATCH 102/145] fixes #8066 --- compiler/importer.nim | 10 ++++++++-- compiler/lookups.nim | 2 +- doc/manual.rst | 25 ++++++++++++++++++------- tests/enum/tpure_enums_conflict.nim | 19 +++++++++++++++++++ 4 files changed, 46 insertions(+), 10 deletions(-) create mode 100644 tests/enum/tpure_enums_conflict.nim diff --git a/compiler/importer.nim b/compiler/importer.nim index 6a225a7616..7397597940 100644 --- a/compiler/importer.nim +++ b/compiler/importer.nim @@ -24,9 +24,15 @@ proc readExceptSet*(c: PContext, n: PNode): IntSet = result.incl(ident.id) proc importPureEnumField*(c: PContext; s: PSym) = - var check = strTableGet(c.importTable.symbols, s.name) + let check = strTableGet(c.importTable.symbols, s.name) if check == nil: - strTableAdd(c.pureEnumFields, s) + let checkB = strTableGet(c.pureEnumFields, s.name) + if checkB == nil: + strTableAdd(c.pureEnumFields, s) + else: + # mark as ambigous: + incl(c.ambiguousSymbols, checkB.id) + incl(c.ambiguousSymbols, s.id) proc rawImportSymbol(c: PContext, s: PSym) = # This does not handle stubs, because otherwise loading on demand would be diff --git a/compiler/lookups.nim b/compiler/lookups.nim index 7f08827543..ec9c130e31 100644 --- a/compiler/lookups.nim +++ b/compiler/lookups.nim @@ -244,7 +244,7 @@ else: template fixSpelling(n: PNode; ident: PIdent; op: untyped) = discard proc errorUseQualifier*(c: PContext; info: TLineInfo; s: PSym) = - var err = "Error: ambiguous identifier: '" & s.name.s & "'" + var err = "ambiguous identifier: '" & s.name.s & "'" var ti: TIdentIter var candidate = initIdentIter(ti, c.importTable.symbols, s.name) var i = 0 diff --git a/doc/manual.rst b/doc/manual.rst index ca32c9c61e..29671d3ddd 100644 --- a/doc/manual.rst +++ b/doc/manual.rst @@ -937,8 +937,12 @@ Now the following holds:: ord(south) == 2 ord(west) == 3 + # Also allowed: + ord(Direction.west) == 3 + Thus, north < east < south < west. The comparison operators can be used -with enumeration types. +with enumeration types. Instead of ``north`` etc, the enum value can also +be qualified with the enum type that it resides in, ``Direction.north``. For better interfacing to other programming languages, the fields of enum types can be assigned an explicit ordinal value. However, the ordinal values @@ -974,18 +978,25 @@ As can be seen from the example, it is possible to both specify a field's ordinal value and its string value by using a tuple. It is also possible to only specify one of them. -An enum can be marked with the ``pure`` pragma so that it's fields are not -added to the current scope, so they always need to be accessed -via ``MyEnum.value``: +An enum can be marked with the ``pure`` pragma so that it's fields are +added to a special module specific hidden scope that is only queried +as the last attempt. Only non-ambiguous symbols are added to this scope. +But one can always access these via type qualification written +as ``MyEnum.value``: .. code-block:: nim type MyEnum {.pure.} = enum - valueA, valueB, valueC, valueD + valueA, valueB, valueC, valueD, amb - echo valueA # error: Unknown identifier - echo MyEnum.valueA # works + OtherEnum {.pure.} = enum + valueX, valueY, valueZ, amb + + + echo valueA # MyEnum.valueA + echo amb # Error: Unclear whether it's MyEnum.amb or OtherEnum.amb + echo MyEnum.amb # OK. String type diff --git a/tests/enum/tpure_enums_conflict.nim b/tests/enum/tpure_enums_conflict.nim new file mode 100644 index 0000000000..3c7528a725 --- /dev/null +++ b/tests/enum/tpure_enums_conflict.nim @@ -0,0 +1,19 @@ +discard """ + errormsg: "ambiguous identifier: 'amb'" + line: 19 +""" + +# bug #8066 + +when true: + type + MyEnum {.pure.} = enum + valueA, valueB, valueC, valueD, amb + + OtherEnum {.pure.} = enum + valueX, valueY, valueZ, amb + + + echo valueA # MyEnum.valueA + echo MyEnum.amb # OK. + echo amb # Error: Unclear whether it's MyEnum.amb or OtherEnum.amb From 47c7fd037ed28b7de3d120b003d059d30e18f128 Mon Sep 17 00:00:00 2001 From: Vindaar Date: Fri, 31 Aug 2018 01:16:44 +0200 Subject: [PATCH 103/145] Improve enumerate macro (#8819) * fix case macro manual entry to produce code block Previously line breaks were so weird that the code blocks were not created. * improve `enumerate` for loop macro by wrapping in block --- doc/manual.rst | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/doc/manual.rst b/doc/manual.rst index 29671d3ddd..b2d66f6844 100644 --- a/doc/manual.rst +++ b/doc/manual.rst @@ -5459,12 +5459,17 @@ type ``system.ForLoopStmt`` can rewrite the entirety of a ``for`` loop: newFor.add x[^2][1] newFor.add body result.add newFor + # now wrap the whole macro in a block to create a new scope + result = quote do: + block: `result` for a, b in enumerate(items([1, 2, 3])): echo a, " ", b - for a2, b2 in enumerate([1, 2, 3, 5]): - echo a2, " ", b2 + # without wrapping the macro in a block, we'd need to choose different + # names for `a` and `b` here to avoid redefinition errors + for a, b in enumerate([1, 2, 3, 5]): + echo a, " ", b Currently for loop macros must be enabled explicitly @@ -5474,12 +5479,11 @@ via ``{.experimental: "forLoopMacros".}``. Case statement macros --------------------- -A macro that needs to be called `match`:idx: can be used to -rewrite ``case`` statements in order to -implement `pattern matching`:idx: for certain types. The following -example implements a simplistic form of pattern matching for tuples, -leveraging the existing equality operator for tuples (as provided in - ``system.==``): +A macro that needs to be called `match`:idx: can be used to rewrite +``case`` statements in order to implement `pattern matching`:idx: for +certain types. The following example implements a simplistic form of +pattern matching for tuples, leveraging the existing equality operator +for tuples (as provided in ``system.==``): .. code-block:: nim :test: "nim c $1" From bacf08e65d614f515b0feb73e549090dce012f3f Mon Sep 17 00:00:00 2001 From: Araq Date: Fri, 31 Aug 2018 11:19:33 +0200 Subject: [PATCH 104/145] merged #8624 manually; fixes #8442; closes #8575 --- lib/pure/osproc.nim | 6 ++++-- tests/osproc/tstderr.nim | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 tests/osproc/tstderr.nim diff --git a/lib/pure/osproc.nim b/lib/pure/osproc.nim index f86acfc492..faeb01407b 100644 --- a/lib/pure/osproc.nim +++ b/lib/pure/osproc.nim @@ -884,9 +884,11 @@ elif not defined(useNimRtl): chck posix_spawn_file_actions_adddup2(fops, data.pStdin[readIdx], readIdx) chck posix_spawn_file_actions_addclose(fops, data.pStdout[readIdx]) chck posix_spawn_file_actions_adddup2(fops, data.pStdout[writeIdx], writeIdx) - if (poStdErrToStdOut in data.options): - chck posix_spawn_file_actions_addclose(fops, data.pStderr[readIdx]) + chck posix_spawn_file_actions_addclose(fops, data.pStderr[readIdx]) + if poStdErrToStdOut in data.options: chck posix_spawn_file_actions_adddup2(fops, data.pStdout[writeIdx], 2) + else: + chck posix_spawn_file_actions_adddup2(fops, data.pStderr[writeIdx], 2) var res: cint if data.workingDir.len > 0: diff --git a/tests/osproc/tstderr.nim b/tests/osproc/tstderr.nim new file mode 100644 index 0000000000..7a39522a33 --- /dev/null +++ b/tests/osproc/tstderr.nim @@ -0,0 +1,32 @@ +discard """ + output: '''-------------------------------------- +to stderr +to stderr +-------------------------------------- +''' +""" +import osproc, os, streams + +const filename = "ta_out".addFileExt(ExeExt) + +doAssert fileExists(getCurrentDir() / "tests" / "osproc" / filename) + +var p = startProcess(filename, getCurrentDir() / "tests" / "osproc", + options={}) + +try: + let stdoutStream = p.outputStream + let stderrStream = p.errorStream + var x = newStringOfCap(120) + var output = "" + while stderrStream.readLine(x.TaintedString): + output.add(x & "\n") + + echo "--------------------------------------" + stdout.flushFile() + stderr.write output + stderr.flushFile() + echo "--------------------------------------" + stdout.flushFile() +finally: + p.close() From 198e34ec1d242337d9ab21a6a456a2fec21f2d08 Mon Sep 17 00:00:00 2001 From: alaviss Date: Fri, 31 Aug 2018 16:24:01 +0700 Subject: [PATCH 105/145] system/excpt: nil is no longer vaild for seqs (#8825) --- lib/system/excpt.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/system/excpt.nim b/lib/system/excpt.nim index d9c7b4c25d..7d5f5af7f9 100644 --- a/lib/system/excpt.nim +++ b/lib/system/excpt.nim @@ -307,7 +307,7 @@ when hasSomeStackTrace: when NimStackTrace: auxWriteStackTrace(framePtr, s) else: - s = nil + s = @[] proc stackTraceAvailable(): bool = when NimStackTrace: From aa33bcb974e9e18739d2d602f2d63f629301ccc1 Mon Sep 17 00:00:00 2001 From: Nathan Cahill Date: Fri, 31 Aug 2018 03:03:49 -0700 Subject: [PATCH 106/145] Update html elements to current html spec (#8791) --- lib/pure/htmlgen.nim | 291 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 241 insertions(+), 50 deletions(-) diff --git a/lib/pure/htmlgen.nim b/lib/pure/htmlgen.nim index ea3a0a3f0a..a2e224f445 100644 --- a/lib/pure/htmlgen.nim +++ b/lib/pure/htmlgen.nim @@ -109,13 +109,13 @@ proc xmlCheckedTag*(e: NimNode, tag: string, optAttr = "", reqAttr = "", macro a*(e: varargs[untyped]): untyped = ## generates the HTML ``a`` element. let e = callsite() - result = xmlCheckedTag(e, "a", "href charset type hreflang rel rev " & - "accesskey tabindex" & commonAttr) + result = xmlCheckedTag(e, "a", "href target download rel hreflang type " & + commonAttr) -macro acronym*(e: varargs[untyped]): untyped = - ## generates the HTML ``acronym`` element. +macro abbr*(e: varargs[untyped]): untyped = + ## generates the HTML ``abbr`` element. let e = callsite() - result = xmlCheckedTag(e, "acronym", commonAttr) + result = xmlCheckedTag(e, "abbr", commonAttr) macro address*(e: varargs[untyped]): untyped = ## generates the HTML ``address`` element. @@ -125,8 +125,24 @@ macro address*(e: varargs[untyped]): untyped = macro area*(e: varargs[untyped]): untyped = ## generates the HTML ``area`` element. let e = callsite() - result = xmlCheckedTag(e, "area", "shape coords href nohref" & - " accesskey tabindex" & commonAttr, "alt", true) + result = xmlCheckedTag(e, "area", "coords download href hreflang rel " & + "shape target type" & commonAttr, "alt", true) + +macro article*(e: varargs[untyped]): untyped = + ## generates the HTML ``article`` element. + let e = callsite() + result = xmlCheckedTag(e, "article", commonAttr) + +macro aside*(e: varargs[untyped]): untyped = + ## generates the HTML ``aside`` element. + let e = callsite() + result = xmlCheckedTag(e, "aside", commonAttr) + +macro audio*(e: varargs[untyped]): untyped = + ## generates the HTML ``audio`` element. + let e = callsite() + result = xmlCheckedTag(e, "audio", "src crossorigin preload " & + "autoplay mediagroup loop muted controls" & commonAttr) macro b*(e: varargs[untyped]): untyped = ## generates the HTML ``b`` element. @@ -136,7 +152,17 @@ macro b*(e: varargs[untyped]): untyped = macro base*(e: varargs[untyped]): untyped = ## generates the HTML ``base`` element. let e = callsite() - result = xmlCheckedTag(e, "base", "", "href", true) + result = xmlCheckedTag(e, "base", "href target" & commonAttr, "", true) + +macro bdi*(e: varargs[untyped]): untyped = + ## generates the HTML ``bdi`` element. + let e = callsite() + result = xmlCheckedTag(e, "bdi", commonAttr) + +macro bdo*(e: varargs[untyped]): untyped = + ## generates the HTML ``bdo`` element. + let e = callsite() + result = xmlCheckedTag(e, "bdo", commonAttr) macro big*(e: varargs[untyped]): untyped = ## generates the HTML ``big`` element. @@ -151,18 +177,26 @@ macro blockquote*(e: varargs[untyped]): untyped = macro body*(e: varargs[untyped]): untyped = ## generates the HTML ``body`` element. let e = callsite() - result = xmlCheckedTag(e, "body", commonAttr) + result = xmlCheckedTag(e, "body", "onafterprint onbeforeprint " & + "onbeforeunload onhashchange onmessage onoffline ononline onpagehide " & + "onpageshow onpopstate onstorage onunload" & commonAttr) macro br*(e: varargs[untyped]): untyped = ## generates the HTML ``br`` element. let e = callsite() - result = xmlCheckedTag(e, "br", "", "", true) + result = xmlCheckedTag(e, "br", commonAttr, "", true) macro button*(e: varargs[untyped]): untyped = ## generates the HTML ``button`` element. let e = callsite() - result = xmlCheckedTag(e, "button", "accesskey tabindex " & - "disabled name type value" & commonAttr) + result = xmlCheckedTag(e, "button", "autofocus disabled form formaction " & + "formenctype formmethod formnovalidate formtarget menu name type value" & + commonAttr) + +macro canvas*(e: varargs[untyped]): untyped = + ## generates the HTML ``canvas`` element. + let e = callsite() + result = xmlCheckedTag(e, "canvas", "width height" & commonAttr) macro caption*(e: varargs[untyped]): untyped = ## generates the HTML ``caption`` element. @@ -182,12 +216,22 @@ macro code*(e: varargs[untyped]): untyped = macro col*(e: varargs[untyped]): untyped = ## generates the HTML ``col`` element. let e = callsite() - result = xmlCheckedTag(e, "col", "span align valign" & commonAttr, "", true) + result = xmlCheckedTag(e, "col", "span" & commonAttr, "", true) macro colgroup*(e: varargs[untyped]): untyped = ## generates the HTML ``colgroup`` element. let e = callsite() - result = xmlCheckedTag(e, "colgroup", "span align valign" & commonAttr) + result = xmlCheckedTag(e, "colgroup", "span" & commonAttr) + +macro data*(e: varargs[untyped]): untyped = + ## generates the HTML ``data`` element. + let e = callsite() + result = xmlCheckedTag(e, "data", "value" & commonAttr) + +macro datalist*(e: varargs[untyped]): untyped = + ## generates the HTML ``datalist`` element. + let e = callsite() + result = xmlCheckedTag(e, "datalist", commonAttr) macro dd*(e: varargs[untyped]): untyped = ## generates the HTML ``dd`` element. @@ -224,16 +268,37 @@ macro em*(e: varargs[untyped]): untyped = let e = callsite() result = xmlCheckedTag(e, "em", commonAttr) +macro embed*(e: varargs[untyped]): untyped = + ## generates the HTML ``embed`` element. + let e = callsite() + result = xmlCheckedTag(e, "embed", "src type height width" & + commonAttr, "", true) + macro fieldset*(e: varargs[untyped]): untyped = ## generates the HTML ``fieldset`` element. let e = callsite() - result = xmlCheckedTag(e, "fieldset", commonAttr) + result = xmlCheckedTag(e, "fieldset", "disabled form name" & commonAttr) + +macro figure*(e: varargs[untyped]): untyped = + ## generates the HTML ``figure`` element. + let e = callsite() + result = xmlCheckedTag(e, "figure", commonAttr) + +macro figcaption*(e: varargs[untyped]): untyped = + ## generates the HTML ``figcaption`` element. + let e = callsite() + result = xmlCheckedTag(e, "figcaption", commonAttr) + +macro footer*(e: varargs[untyped]): untyped = + ## generates the HTML ``footer`` element. + let e = callsite() + result = xmlCheckedTag(e, "footer", commonAttr) macro form*(e: varargs[untyped]): untyped = ## generates the HTML ``form`` element. let e = callsite() - result = xmlCheckedTag(e, "form", "method encype accept accept-charset" & - commonAttr, "action") + result = xmlCheckedTag(e, "form", "accept-charset action autocomplete " & + "enctype method name novalidate target" & commonAttr) macro h1*(e: varargs[untyped]): untyped = ## generates the HTML ``h1`` element. @@ -268,7 +333,12 @@ macro h6*(e: varargs[untyped]): untyped = macro head*(e: varargs[untyped]): untyped = ## generates the HTML ``head`` element. let e = callsite() - result = xmlCheckedTag(e, "head", "profile") + result = xmlCheckedTag(e, "head", commonAttr) + +macro header*(e: varargs[untyped]): untyped = + ## generates the HTML ``header`` element. + let e = callsite() + result = xmlCheckedTag(e, "header", commonAttr) macro html*(e: varargs[untyped]): untyped = ## generates the HTML ``html`` element. @@ -285,16 +355,26 @@ macro i*(e: varargs[untyped]): untyped = let e = callsite() result = xmlCheckedTag(e, "i", commonAttr) +macro iframe*(e: varargs[untyped]): untyped = + ## generates the HTML ``iframe`` element. + let e = callsite() + result = xmlCheckedTag(e, "iframe", "src srcdoc name sandbox width height" & + commonAttr) + macro img*(e: varargs[untyped]): untyped = ## generates the HTML ``img`` element. let e = callsite() - result = xmlCheckedTag(e, "img", "longdesc height width", "src alt", true) + result = xmlCheckedTag(e, "img", "crossorigin usemap ismap height width" & + commonAttr, "src alt", true) macro input*(e: varargs[untyped]): untyped = ## generates the HTML ``input`` element. let e = callsite() - result = xmlCheckedTag(e, "input", "name type value checked maxlength src" & - " alt accept disabled readonly accesskey tabindex" & commonAttr, "", true) + result = xmlCheckedTag(e, "input", "accept alt autocomplete autofocus " & + "checked dirname disabled form formaction formenctype formmethod " & + "formnovalidate formtarget height inputmode list max maxlength min " & + "minlength multiple name pattern placeholder readonly required size " & + "src step type value width" & commonAttr, "", true) macro ins*(e: varargs[untyped]): untyped = ## generates the HTML ``ins`` element. @@ -306,36 +386,64 @@ macro kbd*(e: varargs[untyped]): untyped = let e = callsite() result = xmlCheckedTag(e, "kbd", commonAttr) +macro keygen*(e: varargs[untyped]): untyped = + ## generates the HTML ``keygen`` element. + let e = callsite() + result = xmlCheckedTag(e, "keygen", "autofocus challenge disabled " & + "form keytype name" & commonAttr) + macro label*(e: varargs[untyped]): untyped = ## generates the HTML ``label`` element. let e = callsite() - result = xmlCheckedTag(e, "label", "for accesskey" & commonAttr) + result = xmlCheckedTag(e, "label", "form for" & commonAttr) macro legend*(e: varargs[untyped]): untyped = ## generates the HTML ``legend`` element. let e = callsite() - result = xmlCheckedTag(e, "legend", "accesskey" & commonAttr) + result = xmlCheckedTag(e, "legend", commonAttr) macro li*(e: varargs[untyped]): untyped = ## generates the HTML ``li`` element. let e = callsite() - result = xmlCheckedTag(e, "li", commonAttr) + result = xmlCheckedTag(e, "li", "value" & commonAttr) macro link*(e: varargs[untyped]): untyped = ## generates the HTML ``link`` element. let e = callsite() - result = xmlCheckedTag(e, "link", "href charset hreflang type rel rev media" & - commonAttr, "", true) + result = xmlCheckedTag(e, "link", "href crossorigin rel media hreflang " & + "type sizes" & commonAttr, "", true) + +macro main*(e: varargs[untyped]): untyped = + ## generates the HTML ``main`` element. + let e = callsite() + result = xmlCheckedTag(e, "main", commonAttr) macro map*(e: varargs[untyped]): untyped = ## generates the HTML ``map`` element. let e = callsite() - result = xmlCheckedTag(e, "map", "class title" & eventAttr, "id", false) + result = xmlCheckedTag(e, "map", "name" & commonAttr) + +macro mark*(e: varargs[untyped]): untyped = + ## generates the HTML ``mark`` element. + let e = callsite() + result = xmlCheckedTag(e, "mark", commonAttr) macro meta*(e: varargs[untyped]): untyped = ## generates the HTML ``meta`` element. let e = callsite() - result = xmlCheckedTag(e, "meta", "name http-equiv scheme", "content", true) + result = xmlCheckedTag(e, "meta", "name http-equiv content charset" & + commonAttr, "", true) + +macro meter*(e: varargs[untyped]): untyped = + ## generates the HTML ``meter`` element. + let e = callsite() + result = xmlCheckedTag(e, "meter", "value min max low high optimum" & + commonAttr) + +macro nav*(e: varargs[untyped]): untyped = + ## generates the HTML ``nav`` element. + let e = callsite() + result = xmlCheckedTag(e, "nav", commonAttr) macro noscript*(e: varargs[untyped]): untyped = ## generates the HTML ``noscript`` element. @@ -345,13 +453,13 @@ macro noscript*(e: varargs[untyped]): untyped = macro `object`*(e: varargs[untyped]): untyped = ## generates the HTML ``object`` element. let e = callsite() - result = xmlCheckedTag(e, "object", "classid data codebase declare type " & - "codetype archive standby width height name tabindex" & commonAttr) + result = xmlCheckedTag(e, "object", "data type typemustmatch name usemap " & + "form width height" & commonAttr) macro ol*(e: varargs[untyped]): untyped = ## generates the HTML ``ol`` element. let e = callsite() - result = xmlCheckedTag(e, "ol", commonAttr) + result = xmlCheckedTag(e, "ol", "reversed start type" & commonAttr) macro optgroup*(e: varargs[untyped]): untyped = ## generates the HTML ``optgroup`` element. @@ -361,7 +469,13 @@ macro optgroup*(e: varargs[untyped]): untyped = macro option*(e: varargs[untyped]): untyped = ## generates the HTML ``option`` element. let e = callsite() - result = xmlCheckedTag(e, "option", "selected value" & commonAttr) + result = xmlCheckedTag(e, "option", "disabled label selected value" & + commonAttr) + +macro output*(e: varargs[untyped]): untyped = + ## generates the HTML ``output`` element. + let e = callsite() + result = xmlCheckedTag(e, "output", "for form name" & commonAttr) macro p*(e: varargs[untyped]): untyped = ## generates the HTML ``p`` element. @@ -371,18 +485,53 @@ macro p*(e: varargs[untyped]): untyped = macro param*(e: varargs[untyped]): untyped = ## generates the HTML ``param`` element. let e = callsite() - result = xmlCheckedTag(e, "param", "value id type valuetype", "name", true) + result = xmlCheckedTag(e, "param", commonAttr, "name value", true) macro pre*(e: varargs[untyped]): untyped = ## generates the HTML ``pre`` element. let e = callsite() result = xmlCheckedTag(e, "pre", commonAttr) +macro progress*(e: varargs[untyped]): untyped = + ## generates the HTML ``progress`` element. + let e = callsite() + result = xmlCheckedTag(e, "progress", "value max" & commonAttr) + macro q*(e: varargs[untyped]): untyped = ## generates the HTML ``q`` element. let e = callsite() result = xmlCheckedTag(e, "q", "cite" & commonAttr) +macro rb*(e: varargs[untyped]): untyped = + ## generates the HTML ``rb`` element. + let e = callsite() + result = xmlCheckedTag(e, "rb", commonAttr) + +macro rp*(e: varargs[untyped]): untyped = + ## generates the HTML ``rp`` element. + let e = callsite() + result = xmlCheckedTag(e, "rp", commonAttr) + +macro rt*(e: varargs[untyped]): untyped = + ## generates the HTML ``rt`` element. + let e = callsite() + result = xmlCheckedTag(e, "rt", commonAttr) + +macro rtc*(e: varargs[untyped]): untyped = + ## generates the HTML ``rtc`` element. + let e = callsite() + result = xmlCheckedTag(e, "rtc", commonAttr) + +macro ruby*(e: varargs[untyped]): untyped = + ## generates the HTML ``ruby`` element. + let e = callsite() + result = xmlCheckedTag(e, "ruby", commonAttr) + +macro s*(e: varargs[untyped]): untyped = + ## generates the HTML ``s`` element. + let e = callsite() + result = xmlCheckedTag(e, "s", commonAttr) + macro samp*(e: varargs[untyped]): untyped = ## generates the HTML ``samp`` element. let e = callsite() @@ -391,19 +540,30 @@ macro samp*(e: varargs[untyped]): untyped = macro script*(e: varargs[untyped]): untyped = ## generates the HTML ``script`` element. let e = callsite() - result = xmlCheckedTag(e, "script", "src charset defer", "type", false) + result = xmlCheckedTag(e, "script", "src type charset async defer " & + "crossorigin" & commonAttr) + +macro section*(e: varargs[untyped]): untyped = + ## generates the HTML ``section`` element. + let e = callsite() + result = xmlCheckedTag(e, "section", commonAttr) macro select*(e: varargs[untyped]): untyped = ## generates the HTML ``select`` element. let e = callsite() - result = xmlCheckedTag(e, "select", "name size multiple disabled tabindex" & - commonAttr) + result = xmlCheckedTag(e, "select", "autofocus disabled form multiple " & + "name required size" & commonAttr) macro small*(e: varargs[untyped]): untyped = ## generates the HTML ``small`` element. let e = callsite() result = xmlCheckedTag(e, "small", commonAttr) +macro source*(e: varargs[untyped]): untyped = + ## generates the HTML ``source`` element. + let e = callsite() + result = xmlCheckedTag(e, "source", "type" & commonAttr, "src", true) + macro span*(e: varargs[untyped]): untyped = ## generates the HTML ``span`` element. let e = callsite() @@ -417,7 +577,7 @@ macro strong*(e: varargs[untyped]): untyped = macro style*(e: varargs[untyped]): untyped = ## generates the HTML ``style`` element. let e = callsite() - result = xmlCheckedTag(e, "style", "media title", "type") + result = xmlCheckedTag(e, "style", "media type" & commonAttr) macro sub*(e: varargs[untyped]): untyped = ## generates the HTML ``sub`` element. @@ -432,57 +592,77 @@ macro sup*(e: varargs[untyped]): untyped = macro table*(e: varargs[untyped]): untyped = ## generates the HTML ``table`` element. let e = callsite() - result = xmlCheckedTag(e, "table", "summary border cellpadding cellspacing" & - " frame rules width" & commonAttr) + result = xmlCheckedTag(e, "table", "border sortable" & commonAttr) macro tbody*(e: varargs[untyped]): untyped = ## generates the HTML ``tbody`` element. let e = callsite() - result = xmlCheckedTag(e, "tbody", "align valign" & commonAttr) + result = xmlCheckedTag(e, "tbody", commonAttr) macro td*(e: varargs[untyped]): untyped = ## generates the HTML ``td`` element. let e = callsite() - result = xmlCheckedTag(e, "td", "colspan rowspan abbr axis headers scope" & - " align valign" & commonAttr) + result = xmlCheckedTag(e, "td", "colspan rowspan headers" & commonAttr) + +macro `template`*(e: varargs[untyped]): untyped = + ## generates the HTML ``template`` element. + let e = callsite() + result = xmlCheckedTag(e, "template", commonAttr) macro textarea*(e: varargs[untyped]): untyped = ## generates the HTML ``textarea`` element. let e = callsite() - result = xmlCheckedTag(e, "textarea", " name disabled readonly accesskey" & - " tabindex" & commonAttr, "rows cols", false) + result = xmlCheckedTag(e, "textarea", "autocomplete autofocus cols " & + "dirname disabled form inputmode maxlength minlength name placeholder " & + "readonly required rows wrap" & commonAttr) macro tfoot*(e: varargs[untyped]): untyped = ## generates the HTML ``tfoot`` element. let e = callsite() - result = xmlCheckedTag(e, "tfoot", "align valign" & commonAttr) + result = xmlCheckedTag(e, "tfoot", commonAttr) macro th*(e: varargs[untyped]): untyped = ## generates the HTML ``th`` element. let e = callsite() - result = xmlCheckedTag(e, "th", "colspan rowspan abbr axis headers scope" & - " align valign" & commonAttr) + result = xmlCheckedTag(e, "th", "colspan rowspan headers abbr scope axis" & + " sorted" & commonAttr) macro thead*(e: varargs[untyped]): untyped = ## generates the HTML ``thead`` element. let e = callsite() - result = xmlCheckedTag(e, "thead", "align valign" & commonAttr) + result = xmlCheckedTag(e, "thead", commonAttr) + +macro time*(e: varargs[untyped]): untyped = + ## generates the HTML ``time`` element. + let e = callsite() + result = xmlCheckedTag(e, "time", "datetime" & commonAttr) macro title*(e: varargs[untyped]): untyped = ## generates the HTML ``title`` element. let e = callsite() - result = xmlCheckedTag(e, "title") + result = xmlCheckedTag(e, "title", commonAttr) macro tr*(e: varargs[untyped]): untyped = ## generates the HTML ``tr`` element. let e = callsite() - result = xmlCheckedTag(e, "tr", "align valign" & commonAttr) + result = xmlCheckedTag(e, "tr", commonAttr) + +macro track*(e: varargs[untyped]): untyped = + ## generates the HTML ``track`` element. + let e = callsite() + result = xmlCheckedTag(e, "track", "kind srclang label default" & + commonAttr, "src", true) macro tt*(e: varargs[untyped]): untyped = ## generates the HTML ``tt`` element. let e = callsite() result = xmlCheckedTag(e, "tt", commonAttr) +macro u*(e: varargs[untyped]): untyped = + ## generates the HTML ``u`` element. + let e = callsite() + result = xmlCheckedTag(e, "u", commonAttr) + macro ul*(e: varargs[untyped]): untyped = ## generates the HTML ``ul`` element. let e = callsite() @@ -493,6 +673,17 @@ macro `var`*(e: varargs[untyped]): untyped = let e = callsite() result = xmlCheckedTag(e, "var", commonAttr) +macro video*(e: varargs[untyped]): untyped = + ## generates the HTML ``video`` element. + let e = callsite() + result = xmlCheckedTag(e, "video", "src crossorigin poster preload " & + "autoplay mediagroup loop muted controls width height" & commonAttr) + +macro wbr*(e: varargs[untyped]): untyped = + ## generates the HTML ``wbr`` element. + let e = callsite() + result = xmlCheckedTag(e, "wbr", commonAttr, "", true) + when isMainModule: let nim = "Nim" assert h1(a(href="http://nim-lang.org", nim)) == From b74faf354e3d998156ab73bbc7367e359c16de41 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Fri, 31 Aug 2018 12:16:46 +0200 Subject: [PATCH 107/145] Do not materialize empty varargs[untyped] arrays (#8715) When an empty nkArgList `varargs[untyped]` is passed around it is now reused for efficiency sake and to prevent the introduction of a spurious element: before this commit we'd pass the caller a nkArgList[nkHiddenStdConv[nkBracket]] node instead of just an empty nkArgList. Fixes #8706 --- compiler/sigmatch.nim | 23 +++++++++++++++++------ tests/macros/t8706.nim | 21 +++++++++++++++++++++ 2 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 tests/macros/t8706.nim diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 0cd55068ce..e59496cca3 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -2231,12 +2231,20 @@ proc matchesAux(c: PContext, n, nOrig: PNode, if a >= formalLen-1 and f < formalLen and m.callee.n[f].typ.isVarargsUntyped: formal = m.callee.n.sons[f].sym incl(marker, formal.position) - if container.isNil: - container = newNodeIT(nkArgList, n.sons[a].info, arrayConstr(c, n.info)) - setSon(m.call, formal.position + 1, container) + + if n.sons[a].kind == nkHiddenStdConv: + doAssert n.sons[a].sons[0].kind == nkEmpty and + n.sons[a].sons[1].kind == nkArgList and + n.sons[a].sons[1].len == 0 + # Steal the container and pass it along + setSon(m.call, formal.position + 1, n.sons[a].sons[1]) else: - incrIndexType(container.typ) - addSon(container, n.sons[a]) + if container.isNil: + container = newNodeIT(nkArgList, n.sons[a].info, arrayConstr(c, n.info)) + setSon(m.call, formal.position + 1, container) + else: + incrIndexType(container.typ) + addSon(container, n.sons[a]) elif n.sons[a].kind == nkExprEqExpr: # named param # check if m.callee has such a param: @@ -2400,7 +2408,10 @@ proc matches*(c: PContext, n, nOrig: PNode, m: var TCandidate) = if not containsOrIncl(marker, formal.position): if formal.ast == nil: if formal.typ.kind == tyVarargs: - var container = newNodeIT(nkBracket, n.info, arrayConstr(c, n.info)) + # For consistency with what happens in `matchesAux` select the + # container node kind accordingly + let cnKind = if formal.typ.isVarargsUntyped: nkArgList else: nkBracket + var container = newNodeIT(cnKind, n.info, arrayConstr(c, n.info)) setSon(m.call, formal.position + 1, implicitConv(nkHiddenStdConv, formal.typ, container, m, c)) else: diff --git a/tests/macros/t8706.nim b/tests/macros/t8706.nim new file mode 100644 index 0000000000..b8640a80db --- /dev/null +++ b/tests/macros/t8706.nim @@ -0,0 +1,21 @@ +discard """ + output: '''0 +0 +''' +""" + +import macros + +macro varargsLen(args:varargs[untyped]): untyped = + doAssert args.kind == nnkArglist + doAssert args.len == 0 + result = newLit(args.len) + +template bar(a0:varargs[untyped]): untyped = + varargsLen(a0) + +template foo(x: int, a0:varargs[untyped]): untyped = + bar(a0) + +echo foo(42) +echo bar() From 2c8361bd39f98c869df7b23ee682c25a9929f64f Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Fri, 31 Aug 2018 13:45:42 +0200 Subject: [PATCH 108/145] Constant folding for integer casts (#8095) --- compiler/semfold.nim | 32 +++++++++++--- lib/posix/posix_linux_amd64_consts.nim | 2 +- tests/arithm/tcast.nim | 60 ++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 8 deletions(-) create mode 100644 tests/arithm/tcast.nim diff --git a/compiler/semfold.nim b/compiler/semfold.nim index 4449401440..fe18718813 100644 --- a/compiler/semfold.nim +++ b/compiler/semfold.nim @@ -450,21 +450,38 @@ proc rangeCheck(n: PNode, value: BiggestInt; g: ModuleGraph) = localError(g.config, n.info, "cannot convert " & $value & " to " & typeToString(n.typ)) -proc foldConv*(n, a: PNode; g: ModuleGraph; check = false): PNode = +proc foldConv(n, a: PNode; g: ModuleGraph; check = false): PNode = + let dstTyp = skipTypes(n.typ, abstractRange) + let srcTyp = skipTypes(a.typ, abstractRange) + # XXX range checks? - case skipTypes(n.typ, abstractRange).kind - of tyInt..tyInt64, tyUInt..tyUInt64: - case skipTypes(a.typ, abstractRange).kind + case dstTyp.kind + of tyInt..tyInt64, tyUint..tyUInt64: + case srcTyp.kind of tyFloat..tyFloat64: result = newIntNodeT(int(getFloat(a)), n, g) - of tyChar: result = newIntNodeT(getOrdValue(a), n, g) + of tyChar: + result = newIntNodeT(getOrdValue(a), n, g) + of tyUInt8..tyUInt32, tyInt8..tyInt32: + let fromSigned = srcTyp.kind in tyInt..tyInt64 + let toSigned = dstTyp.kind in tyInt..tyInt64 + + let mask = lastOrd(g.config, dstTyp, fixedUnsigned=true) + + var val = + if toSigned: + a.getOrdValue mod mask + else: + a.getOrdValue and mask + + result = newIntNodeT(val, n, g) else: result = a result.typ = n.typ if check and result.kind in {nkCharLit..nkUInt64Lit}: rangeCheck(n, result.intVal, g) of tyFloat..tyFloat64: - case skipTypes(a.typ, abstractRange).kind + case srcTyp.kind of tyInt..tyInt64, tyEnum, tyBool, tyChar: result = newFloatNodeT(toBiggestFloat(getOrdValue(a)), n, g) else: @@ -742,7 +759,8 @@ proc getConstExpr(m: PSym, n: PNode; g: ModuleGraph): PNode = of nkHiddenStdConv, nkHiddenSubConv, nkConv: var a = getConstExpr(m, n.sons[1], g) if a == nil: return - result = foldConv(n, a, g, check=n.kind == nkHiddenStdConv) + # XXX: we should enable `check` for other conversion types too + result = foldConv(n, a, g, check=n.kind == nkHiddenSubConv) of nkCast: var a = getConstExpr(m, n.sons[1], g) if a == nil: return diff --git a/lib/posix/posix_linux_amd64_consts.nim b/lib/posix/posix_linux_amd64_consts.nim index ee4fac1e86..50b2276350 100644 --- a/lib/posix/posix_linux_amd64_consts.nim +++ b/lib/posix/posix_linux_amd64_consts.nim @@ -300,7 +300,7 @@ const IPPROTO_TCP* = cint(6) const IPPROTO_UDP* = cint(17) const INADDR_ANY* = InAddrScalar(0) const INADDR_LOOPBACK* = InAddrScalar(2130706433) -const INADDR_BROADCAST* = InAddrScalar(-1) +const INADDR_BROADCAST* = InAddrScalar(4294967295) const INET_ADDRSTRLEN* = cint(16) const INET6_ADDRSTRLEN* = cint(46) const IPV6_JOIN_GROUP* = cint(20) diff --git a/tests/arithm/tcast.nim b/tests/arithm/tcast.nim new file mode 100644 index 0000000000..954e2e677f --- /dev/null +++ b/tests/arithm/tcast.nim @@ -0,0 +1,60 @@ +discard """ + output: ''' +B0 +B1 +B2 +B3 +''' +""" + +template crossCheck(ty: untyped, exp: untyped) = + let rt = ty(exp) + const ct = ty(exp) + if $rt != $ct: + echo "Got ", ct + echo "Expected ", rt + +block: + when true: + echo "B0" + crossCheck(int8, 0'i16 - 5'i16) + crossCheck(int16, 0'i32 - 5'i32) + crossCheck(int32, 0'i64 - 5'i64) + + echo "B1" + crossCheck(uint8, 0'u8 - 5'u8) + crossCheck(uint16, 0'u16 - 5'u16) + crossCheck(uint32, 0'u32 - 5'u32) + crossCheck(uint64, 0'u64 - 5'u64) + + echo "B2" + crossCheck(uint8, uint8.high + 5'u8) + crossCheck(uint16, uint16.high + 5'u16) + crossCheck(uint32, uint32.high + 5'u32) + crossCheck(uint64, (-1).uint64 + 5'u64) + + echo "B3" + crossCheck(int8, 0'u8 - 5'u8) + crossCheck(int16, 0'u16 - 5'u16) + crossCheck(int32, 0'u32 - 5'u32) + crossCheck(int64, 0'u64 - 5'u64) + + # crossCheck(int8, 0'u16 - 129'u16) + # crossCheck(uint8, 0'i16 + 257'i16) + + # Signed integer {under,over}flow is guarded against + + # crossCheck(int8, int8.high + 5'i8) + # crossCheck(int16, int16.high + 5'i16) + # crossCheck(int32, int32.high + 5'i32) + # crossCheck(int64, int64.high + 5'i64) + + # crossCheck(int8, int8.low - 5'i8) + # crossCheck(int16, int16.low - 5'i16) + # crossCheck(int32, int32.low - 5'i32) + # crossCheck(int64, int64.low - 5'i64) + + # crossCheck(uint8, 0'i8 - 5'i8) + # crossCheck(uint16, 0'i16 - 5'i16) + # crossCheck(uint32, 0'i32 - 5'i32) + # crossCheck(uint64, 0'i64 - 5'i64) From e09eeb02bf92b4bdcfb7a821014bedf71c753a95 Mon Sep 17 00:00:00 2001 From: Araq Date: Fri, 31 Aug 2018 17:27:57 +0200 Subject: [PATCH 109/145] fixes #8052 --- compiler/semtempl.nim | 2 +- tests/template/tnested_template.nim | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 tests/template/tnested_template.nim diff --git a/compiler/semtempl.nim b/compiler/semtempl.nim index 2952831e9e..3966964220 100644 --- a/compiler/semtempl.nim +++ b/compiler/semtempl.nim @@ -210,7 +210,7 @@ proc addLocalDecl(c: var TemplCtx, n: var PNode, k: TSymKind) = if s != nil and s.owner == c.owner and sfGenSym in s.flags: styleCheckUse(n.info, s) replaceIdentBySym(c.c, n, newSymNode(s, n.info)) - else: + elif not (n.kind == nkSym and sfGenSym in n.sym.flags): let local = newGenSym(k, ident, c) addPrelimDecl(c.c, local) styleCheckDef(c.c.config, n.info, local) diff --git a/tests/template/tnested_template.nim b/tests/template/tnested_template.nim new file mode 100644 index 0000000000..37166009d8 --- /dev/null +++ b/tests/template/tnested_template.nim @@ -0,0 +1,23 @@ +# bug #8052 + +type + UintImpl*[N: static[int], T: SomeUnsignedInt] = object + raw_data*: array[N, T] + +template genLoHi(TypeImpl: untyped): untyped = + template loImpl[N: static[int], T: SomeUnsignedInt](dst: TypeImpl[N div 2, T], src: TypeImpl[N, T]) = + let halfSize = N div 2 + for i in 0 ..< halfSize: + dst.raw_data[i] = src.raw_data[i] + + proc lo*[N: static[int], T: SomeUnsignedInt](x: TypeImpl[N,T]): TypeImpl[N div 2, T] {.inline.}= + loImpl(result, x) + +genLoHi(UintImpl) + +var a: UintImpl[4, uint32] + +a.raw_data = [1'u32, 2'u32, 3'u32, 4'u32] +assert a.lo.raw_data.len == 2 +assert a.lo.raw_data[0] == 1 +assert a.lo.raw_data[1] == 2 From 06e6c38d994ec801e06312826127a75586581eee Mon Sep 17 00:00:00 2001 From: Araq Date: Fri, 31 Aug 2018 17:30:58 +0200 Subject: [PATCH 110/145] strutils: don't deprecate escape/unescape, too much code uses it --- lib/pure/strutils.nim | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/pure/strutils.nim b/lib/pure/strutils.nim index 33f1535870..7730aa7a2e 100644 --- a/lib/pure/strutils.nim +++ b/lib/pure/strutils.nim @@ -1692,14 +1692,12 @@ proc insertSep*(s: string, sep = '_', digits = 3): string {.noSideEffect, dec(L) proc escape*(s: string, prefix = "\"", suffix = "\""): string {.noSideEffect, - rtl, extern: "nsuEscape", deprecated.} = + rtl, extern: "nsuEscape".} = ## Escapes a string `s`. See `system.addEscapedChar `_ ## for the escaping scheme. ## ## The resulting string is prefixed with `prefix` and suffixed with `suffix`. ## Both may be empty strings. - ## - ## **Warning:** This procedure is deprecated because it's to easy to missuse. result = newStringOfCap(s.len + s.len shr 2) result.add(prefix) for c in items(s): @@ -1714,7 +1712,7 @@ proc escape*(s: string, prefix = "\"", suffix = "\""): string {.noSideEffect, add(result, suffix) proc unescape*(s: string, prefix = "\"", suffix = "\""): string {.noSideEffect, - rtl, extern: "nsuUnescape", deprecated.} = + rtl, extern: "nsuUnescape".} = ## Unescapes a string `s`. ## ## This complements `escape <#escape>`_ as it performs the opposite @@ -1722,8 +1720,6 @@ proc unescape*(s: string, prefix = "\"", suffix = "\""): string {.noSideEffect, ## ## If `s` does not begin with ``prefix`` and end with ``suffix`` a ## ValueError exception will be raised. - ## - ## **Warning:** This procedure is deprecated because it's to easy to missuse. result = newStringOfCap(s.len) var i = prefix.len if not s.startsWith(prefix): From d06da9ccf01d41d06849f890e2821b8e791535ac Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Fri, 31 Aug 2018 23:24:09 +0100 Subject: [PATCH 111/145] Exports dom.Style (#8444) --- lib/js/dom.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/js/dom.nim b/lib/js/dom.nim index fd81fdf3f1..cf219df3de 100644 --- a/lib/js/dom.nim +++ b/lib/js/dom.nim @@ -201,7 +201,7 @@ type vspace*: int width*: int - Style = ref StyleObj + Style* = ref StyleObj StyleObj {.importc.} = object of RootObj background*: cstring backgroundAttachment*: cstring From ac066c5db0d04ebc40180ba6e10bcde7a305198c Mon Sep 17 00:00:00 2001 From: Jedrzej Nowak Date: Sun, 2 Sep 2018 01:49:03 +0200 Subject: [PATCH 112/145] Handle fut.failed in asyncdispatch.WithTimeout Fixes: #8839 --- lib/pure/asyncdispatch.nim | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/pure/asyncdispatch.nim b/lib/pure/asyncdispatch.nim index 093bf58af5..820f347035 100644 --- a/lib/pure/asyncdispatch.nim +++ b/lib/pure/asyncdispatch.nim @@ -1536,7 +1536,11 @@ proc withTimeout*[T](fut: Future[T], timeout: int): Future[bool] = var timeoutFuture = sleepAsync(timeout) fut.callback = proc () = - if not retFuture.finished: retFuture.complete(true) + if not retFuture.finished: + if fut.failed: + retFuture.fail(fut.error) + else: + retFuture.complete(true) timeoutFuture.callback = proc () = if not retFuture.finished: retFuture.complete(false) From 4cf704bb3e26e002c5ff479a01fffcd3e33f1cb2 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Sun, 2 Sep 2018 22:44:48 +0200 Subject: [PATCH 113/145] fixes #8694 --- compiler/semgnrc.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/semgnrc.nim b/compiler/semgnrc.nim index e3c750f5b7..7be0610a2c 100644 --- a/compiler/semgnrc.nim +++ b/compiler/semgnrc.nim @@ -215,7 +215,7 @@ proc semGenericStmt(c: PContext, n: PNode, checkMinSonsLen(n, 1, c.config) let fn = n.sons[0] var s = qualifiedLookUp(c, fn, {}) - if s == nil and + if s == nil and {withinMixin, withinConcept}*flags == {} and fn.kind in {nkIdent, nkAccQuoted} and considerQuotedIdent(c, fn).id notin ctx.toMixin: @@ -225,7 +225,7 @@ proc semGenericStmt(c: PContext, n: PNode, var mixinContext = false if s != nil: incl(s.flags, sfUsed) - mixinContext = s.magic in {mDefined, mDefinedInScope, mCompiles} + mixinContext = s.magic in {mDefined, mDefinedInScope, mCompiles, mRunnableExamples} let sc = symChoice(c, fn, s, if s.isMixedIn: scForceOpen else: scOpen) case s.kind of skMacro: From 1948eadc24c8964b581240dc841e4eb369a1ad36 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Sun, 2 Sep 2018 22:56:26 +0200 Subject: [PATCH 114/145] change runnableExamples implementation; fixes #8641; fixes #7135; runnableExamples works for templates and generics --- compiler/docgen.nim | 59 ++++++++++++++++++++++++++++++++++++++++++- compiler/docgen2.nim | 1 + compiler/sem.nim | 23 ----------------- compiler/semdata.nim | 1 - compiler/semexprs.nim | 28 ++++++++------------ 5 files changed, 70 insertions(+), 42 deletions(-) diff --git a/compiler/docgen.nim b/compiler/docgen.nim index 3842f0ad4e..2910f22538 100644 --- a/compiler/docgen.nim +++ b/compiler/docgen.nim @@ -31,6 +31,7 @@ type isPureRst: bool conf*: ConfigRef cache*: IdentCache + runnableExamples*: PNode PDoc* = ref TDocumentor ## Alias to type less. @@ -284,11 +285,60 @@ proc nodeToHighlightedHtml(d: PDoc; n: PNode; result: var Rope; renderFlags: TRe dispA(d.conf, result, "$1", "\\spanOther{$1}", [rope(esc(d.target, literal))]) +proc testExamples*(d: PDoc) = + if d.runnableExamples == nil: return + let outputDir = d.conf.getNimcacheDir / "runnableExamples" + createDir(outputDir) + let inp = toFullPath(d.conf, d.runnableExamples.info) + let outp = outputDir / extractFilename(inp.changeFileExt"" & "_examples.nim") + let nimcache = outp.changeFileExt"" & "_nimcache" + renderModule(d.runnableExamples, inp, outp, conf = d.conf) + let backend = if isDefined(d.conf, "js"): "js" + elif isDefined(d.conf, "cpp"): "cpp" + elif isDefined(d.conf, "objc"): "objc" + else: "c" + if os.execShellCmd(os.getAppFilename() & " " & backend & + " --nimcache:" & nimcache & " -r " & outp) != 0: + quit "[Examples] failed: see " & outp + else: + # keep generated source file `outp` to allow inspection. + rawMessage(d.conf, hintSuccess, ["runnableExamples: " & outp]) + removeFile(outp.changeFileExt(ExeExt)) + try: + removeDir(nimcache) + except OSError: + discard + +proc extractImports(n: PNode; result: PNode) = + if n.kind in {nkImportStmt, nkImportExceptStmt, nkFromStmt}: + result.add copyTree(n) + n.kind = nkEmpty + return + for i in 0..= 2 and n.lastSon.kind == nkStmtList: + prepareExamples(d, n) dispA(d.conf, dest, "\n

    $1

    \n", "\n\\textbf{$1}\n", [rope"Examples:"]) inc d.listingCounter @@ -627,6 +677,10 @@ proc generateDoc*(d: PDoc, n: PNode) = of nkImportStmt: for i in 0 .. sonsLen(n)-1: traceDeps(d, n.sons[i]) of nkFromStmt, nkImportExceptStmt: traceDeps(d, n.sons[0]) + of nkCallKinds: + var comm: Rope = nil + getAllRunnableExamples(d, n, comm) + if comm > nil: add(d.modDesc, comm) else: discard proc add(d: PDoc; j: JsonNode) = @@ -819,6 +873,7 @@ proc commandDoc*(cache: IdentCache, conf: ConfigRef) = generateDoc(d, ast) writeOutput(d, conf.projectFull, HtmlExt) generateIndex(d) + testExamples(d) proc commandRstAux(cache: IdentCache, conf: ConfigRef; filename, outExt: string) = var filen = addFileExt(filename, "txt") @@ -853,6 +908,7 @@ proc commandRstAux(cache: IdentCache, conf: ConfigRef; filename, outExt: string) d.modDesc = rope(modDesc) writeOutput(d, filename, outExt) generateIndex(d) + testExamples(d) proc commandRst2Html*(cache: IdentCache, conf: ConfigRef) = commandRstAux(cache, conf, conf.projectFull, HtmlExt) @@ -876,6 +932,7 @@ proc commandJson*(cache: IdentCache, conf: ConfigRef) = let filename = getOutFile(conf, conf.projectFull, JsonExt) if not writeRope(content, filename): rawMessage(conf, errCannotOpenFile, filename) + testExamples(d) proc commandTags*(cache: IdentCache, conf: ConfigRef) = var ast = parseFile(conf.projectMainIdx, cache, conf) diff --git a/compiler/docgen2.nim b/compiler/docgen2.nim index 068c47bb3c..aa61dbd27b 100644 --- a/compiler/docgen2.nim +++ b/compiler/docgen2.nim @@ -30,6 +30,7 @@ template closeImpl(body: untyped) {.dirty.} = body try: generateIndex(g.doc) + testExamples(g.doc) except IOError: discard diff --git a/compiler/sem.nim b/compiler/sem.nim index 6128c02d15..7a83c30799 100644 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -607,28 +607,6 @@ proc myProcess(context: PPassContext, n: PNode): PNode = #if c.config.cmd == cmdIdeTools: findSuggest(c, n) rod.storeNode(c.graph, c.module, result) -proc testExamples(c: PContext) = - let outputDir = c.config.getNimcacheDir / "runnableExamples" - createDir(outputDir) - let inp = toFullPath(c.config, c.module.info) - let outp = outputDir / extractFilename(inp.changeFileExt"" & "_examples.nim") - let nimcache = outp.changeFileExt"" & "_nimcache" - renderModule(c.runnableExamples, inp, outp, conf = c.config) - let backend = if isDefined(c.config, "js"): "js" - elif isDefined(c.config, "cpp"): "cpp" - elif isDefined(c.config, "objc"): "objc" - else: "c" - if os.execShellCmd(os.getAppFilename() & " " & backend & " --nimcache:" & nimcache & " -r " & outp) != 0: - quit "[Examples] failed: see " & outp - else: - # keep generated source file `outp` to allow inspection. - rawMessage(c.config, hintSuccess, ["runnableExamples: " & outp]) - removeFile(outp.changeFileExt(ExeExt)) - try: - removeDir(nimcache) - except OSError: - discard - proc myClose(graph: ModuleGraph; context: PPassContext, n: PNode): PNode = var c = PContext(context) if c.config.cmd == cmdIdeTools and not c.suggestionsMade: @@ -644,7 +622,6 @@ proc myClose(graph: ModuleGraph; context: PPassContext, n: PNode): PNode = popOwner(c) popProcCon(c) storeRemaining(c.graph, c.module) - if c.runnableExamples != nil: testExamples(c) const semPass* = makePass(myOpen, myProcess, myClose, isFrontend = true) diff --git a/compiler/semdata.nim b/compiler/semdata.nim index 2e59c07b00..6d6627690c 100644 --- a/compiler/semdata.nim +++ b/compiler/semdata.nim @@ -141,7 +141,6 @@ type # the generic type has been constructed completely. See # tests/destructor/topttree.nim for an example that # would otherwise fail. - runnableExamples*: PNode template config*(c: PContext): ConfigRef = c.graph.config diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 04e76102b8..ce953f17c7 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -1953,13 +1953,6 @@ proc setMs(n: PNode, s: PSym): PNode = n.sons[0] = newSymNode(s) n.sons[0].info = n.info -proc extractImports(n: PNode; result: PNode) = - if n.kind in {nkImportStmt, nkImportExceptStmt, nkFromStmt}: - result.add copyTree(n) - n.kind = nkEmpty - return - for i in 0..= 2 and n.lastSon.kind == nkStmtList: - if sfMainModule in c.module.flags: - let inp = toFullPath(c.config, c.module.info) - if c.runnableExamples == nil: - c.runnableExamples = newTree(nkStmtList, - newTree(nkImportStmt, newStrNode(nkStrLit, expandFilename(inp)))) - let imports = newTree(nkStmtList) - var saved_lastSon = copyTree n.lastSon - extractImports(saved_lastSon, imports) - for imp in imports: c.runnableExamples.add imp - c.runnableExamples.add newTree(nkBlockStmt, c.graph.emptyNode, copyTree saved_lastSon) + when false: + if sfMainModule in c.module.flags: + let inp = toFullPath(c.config, c.module.info) + if c.runnableExamples == nil: + c.runnableExamples = newTree(nkStmtList, + newTree(nkImportStmt, newStrNode(nkStrLit, expandFilename(inp)))) + let imports = newTree(nkStmtList) + var savedLastSon = copyTree n.lastSon + extractImports(savedLastSon, imports) + for imp in imports: c.runnableExamples.add imp + c.runnableExamples.add newTree(nkBlockStmt, c.graph.emptyNode, copyTree savedLastSon) result = setMs(n, s) else: result = c.graph.emptyNode From fd7fd1819c602e2bc986d2cf10dc26ce2ed9ac2e Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Mon, 3 Sep 2018 00:32:26 +0200 Subject: [PATCH 115/145] Make sure addGotoOut always inserts its node (#8843) Fixes #8773 --- compiler/closureiters.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/closureiters.nim b/compiler/closureiters.nim index 9e4885b666..71c755d6c1 100644 --- a/compiler/closureiters.nim +++ b/compiler/closureiters.nim @@ -239,7 +239,7 @@ proc toStmtList(n: PNode): PNode = proc addGotoOut(n: PNode, gotoOut: PNode): PNode = # Make sure `n` is a stmtlist, and ends with `gotoOut` result = toStmtList(n) - if result.len != 0 and result.sons[^1].kind != nkGotoState: + if result.len == 0 or result.sons[^1].kind != nkGotoState: result.add(gotoOut) proc newTempVar(ctx: var Ctx, typ: PType): PSym = From 06dbe9697ff6b688bfe75156357b57f24cf08184 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Sun, 2 Sep 2018 23:29:06 +0200 Subject: [PATCH 116/145] fixes #8831 --- compiler/docgen.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/docgen.nim b/compiler/docgen.nim index 2910f22538..968a955f6b 100644 --- a/compiler/docgen.nim +++ b/compiler/docgen.nim @@ -286,7 +286,7 @@ proc nodeToHighlightedHtml(d: PDoc; n: PNode; result: var Rope; renderFlags: TRe [rope(esc(d.target, literal))]) proc testExamples*(d: PDoc) = - if d.runnableExamples == nil: return + if d.runnableExamples == nil or d.conf.errorCounter > 0: return let outputDir = d.conf.getNimcacheDir / "runnableExamples" createDir(outputDir) let inp = toFullPath(d.conf, d.runnableExamples.info) From 0d68ef9f1135e934e6b7af4d69fa6e4e5f61d15b Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Mon, 3 Sep 2018 00:40:56 +0200 Subject: [PATCH 117/145] runnableExample: put each example to its own file; fixes #7285 --- compiler/docgen.nim | 37 +++++++++++++++---------------------- compiler/docgen2.nim | 20 ++++++++++++-------- 2 files changed, 27 insertions(+), 30 deletions(-) diff --git a/compiler/docgen.nim b/compiler/docgen.nim index 968a955f6b..c38b9b87ce 100644 --- a/compiler/docgen.nim +++ b/compiler/docgen.nim @@ -31,7 +31,7 @@ type isPureRst: bool conf*: ConfigRef cache*: IdentCache - runnableExamples*: PNode + exampleCounter: int PDoc* = ref TDocumentor ## Alias to type less. @@ -285,29 +285,26 @@ proc nodeToHighlightedHtml(d: PDoc; n: PNode; result: var Rope; renderFlags: TRe dispA(d.conf, result, "$1", "\\spanOther{$1}", [rope(esc(d.target, literal))]) -proc testExamples*(d: PDoc) = - if d.runnableExamples == nil or d.conf.errorCounter > 0: return +proc testExample(d: PDoc; ex: PNode) = + if d.conf.errorCounter > 0: return let outputDir = d.conf.getNimcacheDir / "runnableExamples" createDir(outputDir) - let inp = toFullPath(d.conf, d.runnableExamples.info) - let outp = outputDir / extractFilename(inp.changeFileExt"" & "_examples.nim") - let nimcache = outp.changeFileExt"" & "_nimcache" - renderModule(d.runnableExamples, inp, outp, conf = d.conf) + inc d.exampleCounter + let outp = outputDir / extractFilename(d.filename.changeFileExt"" & + "_examples" & $d.exampleCounter & ".nim") + #let nimcache = outp.changeFileExt"" & "_nimcache" + renderModule(ex, d.filename, outp, conf = d.conf) let backend = if isDefined(d.conf, "js"): "js" elif isDefined(d.conf, "cpp"): "cpp" elif isDefined(d.conf, "objc"): "objc" else: "c" if os.execShellCmd(os.getAppFilename() & " " & backend & - " --nimcache:" & nimcache & " -r " & outp) != 0: + " --nimcache:" & outputDir & " -r " & outp) != 0: quit "[Examples] failed: see " & outp else: # keep generated source file `outp` to allow inspection. rawMessage(d.conf, hintSuccess, ["runnableExamples: " & outp]) removeFile(outp.changeFileExt(ExeExt)) - try: - removeDir(nimcache) - except OSError: - discard proc extractImports(n: PNode; result: PNode) = if n.kind in {nkImportStmt, nkImportExceptStmt, nkFromStmt}: @@ -317,16 +314,15 @@ proc extractImports(n: PNode; result: PNode) = for i in 0.. Date: Mon, 3 Sep 2018 01:35:45 +0200 Subject: [PATCH 118/145] fixes #8028 --- compiler/semstmts.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 425bb24dc1..fb01127fc9 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -804,7 +804,7 @@ proc semRaise(c: PContext, n: PNode): PNode = if not isImportedException(typ, c.config): if typ.kind != tyRef or typ.lastSon.kind != tyObject: localError(c.config, n.info, errExprCannotBeRaised) - if not isException(typ.lastSon): + if typ.len > 0 and not isException(typ.lastSon): localError(c.config, n.info, "raised object of type $1 does not inherit from Exception", [typeToString(typ)]) From fa338768a3f6aac03e4c76bcfdd660716a9bf926 Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 3 Sep 2018 08:37:32 +0200 Subject: [PATCH 119/145] fixes #8847 --- lib/system.nim | 2 +- tests/system/tostring.nim | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/system.nim b/lib/system.nim index 92f51fe7e8..bfd8a31e5c 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -3972,7 +3972,7 @@ proc addQuoted*[T](s: var string, x: T) = ## tmp.add(", ") ## tmp.addQuoted('c') ## assert(tmp == """1, "string", 'c'""") - when T is string: + when T is string or T is cstring: s.add("\"") for c in x: # Only ASCII chars are escaped to avoid butchering diff --git a/tests/system/tostring.nim b/tests/system/tostring.nim index 42c07c0a41..04b37f133f 100644 --- a/tests/system/tostring.nim +++ b/tests/system/tostring.nim @@ -106,4 +106,12 @@ var nilstring: string bar(nilstring) static: - stringCompare() \ No newline at end of file + stringCompare() + +# bug 8847 +var a2: cstring = "fo\"o2" + +block: + var s: string + s.addQuoted a2 + doAssert s == "\"fo\\\"o2\"" From cfbf9dcc597a1465c106975f506e7f6221bb99e6 Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 3 Sep 2018 09:06:52 +0200 Subject: [PATCH 120/145] fixes #8740 --- compiler/vm.nim | 2 +- tests/vm/{trgba.nim => tmisc_vm.nim} | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) rename tests/vm/{trgba.nim => tmisc_vm.nim} (77%) diff --git a/compiler/vm.nim b/compiler/vm.nim index 8271857370..312a2085b8 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -273,7 +273,7 @@ proc cleanUpOnException(c: PCtx; tos: PStackFrame): abstractPtrs) else: nil #echo typeToString(exceptType), " ", typeToString(raisedType) - if exceptType.isNil or inheritanceDiff(exceptType, raisedType) <= 0: + if exceptType.isNil or inheritanceDiff(raisedType, exceptType) <= 0: # mark exception as handled but keep it in B for # the getCurrentException() builtin: c.currentExceptionB = c.currentExceptionA diff --git a/tests/vm/trgba.nim b/tests/vm/tmisc_vm.nim similarity index 77% rename from tests/vm/trgba.nim rename to tests/vm/tmisc_vm.nim index 923ea1b2e8..6eb3dd6273 100644 --- a/tests/vm/trgba.nim +++ b/tests/vm/tmisc_vm.nim @@ -2,6 +2,8 @@ discard """ output: '''[127, 127, 0, 255] [127, 127, 0, 255] ''' + + nimout: '''caught Exception''' """ #bug #1009 @@ -34,3 +36,16 @@ proc ABGR*(val: int| int64): TAggRgba8 = const c1 = ABGR(0xFF007F7F) echo ABGR(0xFF007F7F).repr, c1.repr + + +# bug 8740 + +static: + try: + raise newException(ValueError, "foo") + except Exception: + echo "caught Exception" + except Defect: + echo "caught Defect" + except ValueError: + echo "caught ValueError" From 077f24ab2dd2564799272b3cb673e17b33596b4f Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 3 Sep 2018 09:14:12 +0200 Subject: [PATCH 121/145] fixes #8797 --- doc/manual.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/manual.rst b/doc/manual.rst index b2d66f6844..653a7115e6 100644 --- a/doc/manual.rst +++ b/doc/manual.rst @@ -504,7 +504,7 @@ following characters:: These keywords are also operators: ``and or not xor shl shr div mod in notin is isnot of``. -`=`:tok:, `:`:tok:, `::`:tok: are not available as general operators; they +`.`:tok: `=`:tok:, `:`:tok:, `::`:tok: are not available as general operators; they are used for other notational purposes. ``*:`` is as a special case treated as the two tokens `*`:tok: and `:`:tok: @@ -4633,7 +4633,7 @@ type is an instance of it: .. code-block:: nim :test: "nim c $1" - import future, typetraits + import sugar, typetraits type Functor[A] = concept f From 7ace82440fe230ee6959971ff1aaaccdad85d21d Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 3 Sep 2018 09:22:19 +0200 Subject: [PATCH 122/145] deprecate system.onRaise; fixes #1652 --- lib/system.nim | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/system.nim b/lib/system.nim index bfd8a31e5c..973a09e994 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -3386,12 +3386,15 @@ when not defined(JS): #and not defined(nimscript): var e = getCurrentException() return if e == nil: "" else: e.msg - proc onRaise*(action: proc(e: ref Exception): bool{.closure.}) = + proc onRaise*(action: proc(e: ref Exception): bool{.closure.}) {.deprecated.} = ## can be used in a ``try`` statement to setup a Lisp-like ## `condition system`:idx:\: This prevents the 'raise' statement to ## raise an exception but instead calls ``action``. ## If ``action`` returns false, the exception has been handled and ## does not propagate further through the call stack. + ## + ## *Deprecated since version 0.18.1*: No good usages of this + ## feature are known. if not isNil(excHandler): excHandler.hasRaiseAction = true excHandler.raiseAction = action From 7278f28740a1bce4bb8896b4f7553694e7970f8f Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 3 Sep 2018 09:34:31 +0200 Subject: [PATCH 123/145] fixes the remaining fixable Nimrod->Nim renamings; closes #2032 --- compiler/tccgen.nim | 22 +++++++++++----------- compiler/vm.nim | 2 +- compiler/vmdef.nim | 2 +- compiler/vmgen.nim | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/compiler/tccgen.nim b/compiler/tccgen.nim index ea0fb590fc..2301ad4049 100644 --- a/compiler/tccgen.nim +++ b/compiler/tccgen.nim @@ -39,24 +39,24 @@ proc setupEnvironment = addIncludePath(gTinyC, libpath) when defined(windows): - addSysincludePath(gTinyC, nimrodDir / "tinyc/win32/include") - addSysincludePath(gTinyC, nimrodDir / "tinyc/include") + addSysincludePath(gTinyC, nimDir / "tinyc/win32/include") + addSysincludePath(gTinyC, nimDir / "tinyc/include") when defined(windows): defineSymbol(gTinyC, "_WIN32", nil) # we need Mingw's headers too: var gccbin = getConfigVar("gcc.path") % ["nim", nimDir] addSysincludePath(gTinyC, gccbin /../ "include") - #addFile(nimrodDir / r"tinyc\win32\wincrt1.o") - addFile(nimrodDir / r"tinyc\win32\alloca86.o") - addFile(nimrodDir / r"tinyc\win32\chkstk.o") - #addFile(nimrodDir / r"tinyc\win32\crt1.o") + #addFile(nimDir / r"tinyc\win32\wincrt1.o") + addFile(nimDir / r"tinyc\win32\alloca86.o") + addFile(nimDir / r"tinyc\win32\chkstk.o") + #addFile(nimDir / r"tinyc\win32\crt1.o") - #addFile(nimrodDir / r"tinyc\win32\dllcrt1.o") - #addFile(nimrodDir / r"tinyc\win32\dllmain.o") - addFile(nimrodDir / r"tinyc\win32\libtcc1.o") + #addFile(nimDir / r"tinyc\win32\dllcrt1.o") + #addFile(nimDir / r"tinyc\win32\dllmain.o") + addFile(nimDir / r"tinyc\win32\libtcc1.o") - #addFile(nimrodDir / r"tinyc\win32\lib\crt1.c") - #addFile(nimrodDir / r"tinyc\lib\libtcc1.c") + #addFile(nimDir / r"tinyc\win32\lib\crt1.c") + #addFile(nimDir / r"tinyc\lib\libtcc1.c") else: addSysincludePath(gTinyC, "/usr/include") when defined(amd64): diff --git a/compiler/vm.nim b/compiler/vm.nim index 312a2085b8..9143051a95 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -820,7 +820,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg = regs[ra].intVal = ord((regs[rb].node.kind == nkNilLit and regs[rc].node.kind == nkNilLit) or regs[rb].node == regs[rc].node) - of opcEqNimrodNode: + of opcEqNimNode: decodeBC(rkInt) regs[ra].intVal = ord(exprStructuralEquivalent(regs[rb].node, regs[rc].node, diff --git a/compiler/vmdef.nim b/compiler/vmdef.nim index 1abd9ae4ad..0aee079f56 100644 --- a/compiler/vmdef.nim +++ b/compiler/vmdef.nim @@ -62,7 +62,7 @@ type opcBitandInt, opcBitorInt, opcBitxorInt, opcAddu, opcSubu, opcMulu, opcDivu, opcModu, opcEqInt, opcLeInt, opcLtInt, opcEqFloat, opcLeFloat, opcLtFloat, opcLeu, opcLtu, - opcEqRef, opcEqNimrodNode, opcSameNodeType, + opcEqRef, opcEqNimNode, opcSameNodeType, opcXor, opcNot, opcUnaryMinusInt, opcUnaryMinusFloat, opcBitnotInt, opcEqStr, opcLeStr, opcLtStr, opcEqSet, opcLeSet, opcLtSet, opcMulSet, opcPlusSet, opcMinusSet, opcSymdiffSet, opcConcatStr, diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim index cb46031643..dcf76f639f 100644 --- a/compiler/vmgen.nim +++ b/compiler/vmgen.nim @@ -1178,7 +1178,7 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest; m: TMagic) = of mNBindSym: genBindSym(c, n, dest) of mStrToIdent: genUnaryABC(c, n, dest, opcStrToIdent) of mEqIdent: genBinaryABC(c, n, dest, opcEqIdent) - of mEqNimrodNode: genBinaryABC(c, n, dest, opcEqNimrodNode) + of mEqNimrodNode: genBinaryABC(c, n, dest, opcEqNimNode) of mSameNodeType: genBinaryABC(c, n, dest, opcSameNodeType) of mNLineInfo: case n[0].sym.name.s From ef771cde1ae9cf2da9b39c7444a6cae98575d255 Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 3 Sep 2018 09:44:44 +0200 Subject: [PATCH 124/145] document usage of marshal.to; fixes #3150 --- lib/pure/marshal.nim | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/pure/marshal.nim b/lib/pure/marshal.nim index 9804397597..b0bcfe535a 100644 --- a/lib/pure/marshal.nim +++ b/lib/pure/marshal.nim @@ -280,6 +280,17 @@ proc `$$`*[T](x: T): string = proc to*[T](data: string): T = ## reads data and transforms it to a ``T``. + runnableExamples: + type + Foo = object + id: int + bar: string + + let x = Foo(id: 1, bar: "baz") + # serialize + let y = ($$x) + # deserialize back to type 'Foo': + let z = y.to[:Foo] var tab = initTable[BiggestInt, pointer]() loadAny(newStringStream(data), toAny(result), tab) From 9e48999567d3d5c309262ce548dfe20893a207e8 Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 3 Sep 2018 10:02:37 +0200 Subject: [PATCH 125/145] closes #4750 --- tests/template/tprocparshadow.nim | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/template/tprocparshadow.nim b/tests/template/tprocparshadow.nim index b99cd0b6cf..de1c2d9412 100644 --- a/tests/template/tprocparshadow.nim +++ b/tests/template/tprocparshadow.nim @@ -9,3 +9,22 @@ template something(name: untyped) = something(what) what(10) + +# bug #4750 + +type + O = object + i: int + + OP = ptr O + +template alf(p: pointer): untyped = + cast[OP](p) + + +proc t1(al: pointer) = + var o = alf(al) + +proc t2(alf: pointer) = + var x = alf + var o = alf(x) From 7cea0c1765177abaa20902fddfbd3ee50992210f Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 3 Sep 2018 10:16:11 +0200 Subject: [PATCH 126/145] closes #5252 --- tests/stdlib/tunittest.nim | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/stdlib/tunittest.nim b/tests/stdlib/tunittest.nim index 86b9fd0370..c8656bbff5 100644 --- a/tests/stdlib/tunittest.nim +++ b/tests/stdlib/tunittest.nim @@ -13,6 +13,8 @@ discard """ [Suite] bug #5784 +[Suite] test suite + [Suite] test name filtering ''' @@ -123,6 +125,23 @@ suite "bug #5784": var obj: Obj check obj.isNil or obj.field == 0 +type + SomeType = object + value: int + children: seq[SomeType] + +# bug #5252 + +proc `==`(a, b: SomeType): bool = + return a.value == b.value + +suite "test suite": + test "test": + let a = SomeType(value: 10) + let b = SomeType(value: 10) + + check(a == b) + when defined(testing): suite "test name filtering": test "test name": From b3c3a463177ebb0aeb6e9eb11788230ab91c3f08 Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 3 Sep 2018 10:50:39 +0200 Subject: [PATCH 127/145] fixes #5745 --- compiler/ast.nim | 12 ++++++++---- compiler/lineinfos.nim | 3 +++ compiler/msgs.nim | 3 --- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/compiler/ast.nim b/compiler/ast.nim index 6591105d49..001d96060c 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -1594,15 +1594,17 @@ proc getInt*(a: PNode): BiggestInt = case a.kind of nkCharLit..nkUInt64Lit: result = a.intVal else: + raiseRecoverableError("cannot extract number from invalid AST node") #internalError(a.info, "getInt") - doAssert false, "getInt" + #doAssert false, "getInt" #result = 0 proc getFloat*(a: PNode): BiggestFloat = case a.kind of nkFloatLiterals: result = a.floatVal else: - doAssert false, "getFloat" + raiseRecoverableError("cannot extract number from invalid AST node") + #doAssert false, "getFloat" #internalError(a.info, "getFloat") #result = 0.0 @@ -1616,7 +1618,8 @@ proc getStr*(a: PNode): string = else: result = nil else: - doAssert false, "getStr" + raiseRecoverableError("cannot extract string from invalid AST node") + #doAssert false, "getStr" #internalError(a.info, "getStr") #result = "" @@ -1625,7 +1628,8 @@ proc getStrOrChar*(a: PNode): string = of nkStrLit..nkTripleStrLit: result = a.strVal of nkCharLit..nkUInt64Lit: result = $chr(int(a.intVal)) else: - doAssert false, "getStrOrChar" + raiseRecoverableError("cannot extract string from invalid AST node") + #doAssert false, "getStrOrChar" #internalError(a.info, "getStrOrChar") #result = "" diff --git a/compiler/lineinfos.nim b/compiler/lineinfos.nim index c5a6417138..41f3806d42 100644 --- a/compiler/lineinfos.nim +++ b/compiler/lineinfos.nim @@ -223,6 +223,9 @@ type proc `==`*(a, b: FileIndex): bool {.borrow.} +proc raiseRecoverableError*(msg: string) {.noinline, noreturn.} = + raise newException(ERecoverableError, msg) + const InvalidFileIDX* = FileIndex(-1) diff --git a/compiler/msgs.nim b/compiler/msgs.nim index 47ab878f1a..b7b7c84746 100644 --- a/compiler/msgs.nim +++ b/compiler/msgs.nim @@ -102,9 +102,6 @@ proc newLineInfo*(fileInfoIdx: FileIndex, line, col: int): TLineInfo = proc newLineInfo*(conf: ConfigRef; filename: string, line, col: int): TLineInfo {.inline.} = result = newLineInfo(fileInfoIdx(conf, filename), line, col) -proc raiseRecoverableError*(msg: string) {.noinline, noreturn.} = - raise newException(ERecoverableError, msg) - proc concat(strings: openarray[string]): string = var totalLen = 0 From e0fd1cdb5fda1dd3e2e38d7741dcb899c9c5d5bb Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 3 Sep 2018 11:13:59 +0200 Subject: [PATCH 128/145] fix items for cstring for the JS target; makes tests green again --- lib/system.nim | 15 +++++++++++---- tests/js/tseqops.nim | 4 ++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/system.nim b/lib/system.nim index 973a09e994..3a18a715c0 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -2195,10 +2195,17 @@ iterator items*[T](a: set[T]): T {.inline.} = iterator items*(a: cstring): char {.inline.} = ## iterates over each item of `a`. - var i = 0 - while a[i] != '\0': - yield a[i] - inc(i) + when defined(js): + var i = 0 + var L = len(a) + while i < L: + yield a[i] + inc(i) + else: + var i = 0 + while a[i] != '\0': + yield a[i] + inc(i) iterator mitems*(a: var cstring): var char {.inline.} = ## iterates over each item of `a` so that you can modify the yielded value. diff --git a/tests/js/tseqops.nim b/tests/js/tseqops.nim index d10e1ca6a7..af664222cc 100644 --- a/tests/js/tseqops.nim +++ b/tests/js/tseqops.nim @@ -1,8 +1,8 @@ discard """ output: '''(x: 0, y: 0) (x: 5, y: 0) -@[(x: 2, y: 4), (x: 4, y: 5), (x: 4, y: 5)] -@[(a: 3, b: 3), (a: 1, b: 1), (a: 2, b: 2)] +@[(x: "2", y: 4), (x: "4", y: 5), (x: "4", y: 5)] +@[(a: "3", b: 3), (a: "1", b: 1), (a: "2", b: 2)] ''' """ From 47cbe0e54db77b262205fb0bd209d4c8e0345b58 Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 3 Sep 2018 11:19:18 +0200 Subject: [PATCH 129/145] fixes #8852 --- compiler/importer.nim | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/importer.nim b/compiler/importer.nim index 7397597940..73d2e65991 100644 --- a/compiler/importer.nim +++ b/compiler/importer.nim @@ -170,8 +170,8 @@ proc myImportModule(c: PContext, n: PNode; importStmtResult: PNode): PSym = suggestSym(c.config, n.info, result, c.graph.usageSym, false) importStmtResult.add newStrNode(toFullPath(c.config, f), n.info) -proc transformImportAs(n: PNode): PNode = - if n.kind == nkInfix and n.sons[0].ident.s == "as": +proc transformImportAs(c: PContext; n: PNode): PNode = + if n.kind == nkInfix and considerQuotedIdent(c, n[0]).s == "as": result = newNodeI(nkImportAs, n.info) result.add n.sons[1] result.add n.sons[2] @@ -179,7 +179,7 @@ proc transformImportAs(n: PNode): PNode = result = n proc impMod(c: PContext; it: PNode; importStmtResult: PNode) = - let it = transformImportAs(it) + let it = transformImportAs(c, it) let m = myImportModule(c, it, importStmtResult) if m != nil: var emptySet: IntSet @@ -215,7 +215,7 @@ proc evalImport(c: PContext, n: PNode): PNode = proc evalFrom(c: PContext, n: PNode): PNode = result = newNodeI(nkImportStmt, n.info) checkMinSonsLen(n, 2, c.config) - n.sons[0] = transformImportAs(n.sons[0]) + n.sons[0] = transformImportAs(c, n.sons[0]) var m = myImportModule(c, n.sons[0], result) if m != nil: n.sons[0] = newSymNode(m) @@ -227,7 +227,7 @@ proc evalFrom(c: PContext, n: PNode): PNode = proc evalImportExcept*(c: PContext, n: PNode): PNode = result = newNodeI(nkImportStmt, n.info) checkMinSonsLen(n, 2, c.config) - n.sons[0] = transformImportAs(n.sons[0]) + n.sons[0] = transformImportAs(c, n.sons[0]) var m = myImportModule(c, n.sons[0], result) if m != nil: n.sons[0] = newSymNode(m) From 4993274f2fd41eaa23ed83a85777df4320fadbf9 Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 3 Sep 2018 11:38:15 +0200 Subject: [PATCH 130/145] document 'var T' and 'typedesc' restriction in generics; closes #1156 --- doc/manual.rst | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/doc/manual.rst b/doc/manual.rst index 653a7115e6..6e1030e7e6 100644 --- a/doc/manual.rst +++ b/doc/manual.rst @@ -4387,6 +4387,34 @@ be inferred to have the equivalent of the `any` type class and thus they will match anything without discrimination. +Generic inference restrictions +------------------------------ + +The types ``var T`` and ``typedesc[T]`` cannot be inferred in a generic +instantiation. The following is not allowed: + +.. code-block:: nim + :test: "nim c $1" + :status: 1 + + proc g[T](f: proc(x: T); x: T) = + f(x) + + proc c(y: int) = echo y + proc v(y: var int) = + y += 100 + var i: int + + # allowed: infers 'T' to be of type 'int' + g(c, 42) + + # not valid: 'T' is not inferred to be of type 'var int' + g(v, i) + + # also not allowed: explict instantiation via 'var int' + g[var int](v, i) + + Concepts -------- From 602aeef4d4d70b9fe8c6a1e318538697b3e23bfc Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 3 Sep 2018 11:40:14 +0200 Subject: [PATCH 131/145] manual: document the 'unsafeAddr' operator; closes #5038 --- doc/manual.rst | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/doc/manual.rst b/doc/manual.rst index 6e1030e7e6..e3199cecff 100644 --- a/doc/manual.rst +++ b/doc/manual.rst @@ -3105,6 +3105,19 @@ the address of variables, but one can't use it on variables declared through # Error: expression has no address +The unsafeAddr operator +----------------------- + +For easier interoperability with other compiled languages such as C, retrieving +the address of a ``let`` variable, a parameter or a ``for`` loop variable, the +``unsafeAddr`` operation can be used: + +.. code-block:: nim + + let myArray = [1, 2, 3] + foreignProcThatTakesAnAddr(unsafeAddr myArray) + + Procedures ========== From 4b823b2825beb9732fbd70109ae77a229cfe54f2 Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 3 Sep 2018 11:51:15 +0200 Subject: [PATCH 132/145] manual: more documentation for the 'using' statement; closes #8565 --- doc/manual.rst | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/doc/manual.rst b/doc/manual.rst index e3199cecff..7a765ef630 100644 --- a/doc/manual.rst +++ b/doc/manual.rst @@ -17,8 +17,7 @@ About this document =================== **Note**: This document is a draft! Several of Nim's features may need more -precise wording. This manual is constantly evolving until the 1.0 release and is -not to be considered as the final proper specification. +precise wording. This manual is constantly evolving into a proper specification. This document describes the lexis, the syntax, and the semantics of Nim. @@ -2985,6 +2984,10 @@ name ``c`` should default to type ``Context``, ``n`` should default to proc bar(c, n, counter) = ... proc baz(c, n) = ... + proc mixedMode(c, n; x, y: int) = + # 'c' is inferred to be of the type 'Context' + # 'n' is inferred to be of the type 'Node' + # But 'x' and 'y' are of type 'int'. The ``using`` section uses the same indentation based grouping syntax as a ``var`` or ``let`` section. @@ -2992,6 +2995,9 @@ a ``var`` or ``let`` section. Note that ``using`` is not applied for ``template`` since untyped template parameters default to the type ``system.untyped``. +Mixing parameters that should use the ``using`` declaration with parameters +that are explicitly typed is possible and requires a semicolon between them. + If expression ------------- From d1e3a7c827e528c8169387936f41cc03fb4ebe9f Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 3 Sep 2018 12:02:56 +0200 Subject: [PATCH 133/145] document Nim's signal handling briefly; closes #8224 --- doc/nimc.rst | 79 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 34 deletions(-) diff --git a/doc/nimc.rst b/doc/nimc.rst index 0682fac03d..0346b98e93 100644 --- a/doc/nimc.rst +++ b/doc/nimc.rst @@ -326,40 +326,41 @@ The standard library supports a growing number of ``useX`` conditional defines affecting how some features are implemented. This section tries to give a complete list. -================== ========================================================= -Define Effect -================== ========================================================= -``release`` Turns off runtime checks and turns on the optimizer. -``useWinAnsi`` Modules like ``os`` and ``osproc`` use the Ansi versions - of the Windows API. The default build uses the Unicode - version. -``useFork`` Makes ``osproc`` use ``fork`` instead of ``posix_spawn``. -``useNimRtl`` Compile and link against ``nimrtl.dll``. -``useMalloc`` Makes Nim use C's `malloc`:idx: instead of Nim's - own memory manager, ableit prefixing each allocation with - its size to support clearing memory on reallocation. - This only works with ``gc:none``. -``useRealtimeGC`` Enables support of Nim's GC for *soft* realtime - systems. See the documentation of the `gc `_ - for further information. -``nodejs`` The JS target is actually ``node.js``. -``ssl`` Enables OpenSSL support for the sockets module. -``memProfiler`` Enables memory profiling for the native GC. -``uClibc`` Use uClibc instead of libc. (Relevant for Unix-like OSes) -``checkAbi`` When using types from C headers, add checks that compare - what's in the Nim file with what's in the C header - (requires a C compiler with _Static_assert support, like - any C11 compiler) -``tempDir`` This symbol takes a string as its value, like - ``--define:tempDir:/some/temp/path`` to override the - temporary directory returned by ``os.getTempDir()``. - The value **should** end with a directory separator - character. (Relevant for the Android platform) -``useShPath`` This symbol takes a string as its value, like - ``--define:useShPath:/opt/sh/bin/sh`` to override the - path for the ``sh`` binary, in cases where it is not - located in the default location ``/bin/sh`` -================== ========================================================= +====================== ========================================================= +Define Effect +====================== ========================================================= +``release`` Turns off runtime checks and turns on the optimizer. +``useWinAnsi`` Modules like ``os`` and ``osproc`` use the Ansi versions + of the Windows API. The default build uses the Unicode + version. +``useFork`` Makes ``osproc`` use ``fork`` instead of ``posix_spawn``. +``useNimRtl`` Compile and link against ``nimrtl.dll``. +``useMalloc`` Makes Nim use C's `malloc`:idx: instead of Nim's + own memory manager, ableit prefixing each allocation with + its size to support clearing memory on reallocation. + This only works with ``gc:none``. +``useRealtimeGC`` Enables support of Nim's GC for *soft* realtime + systems. See the documentation of the `gc `_ + for further information. +``nodejs`` The JS target is actually ``node.js``. +``ssl`` Enables OpenSSL support for the sockets module. +``memProfiler`` Enables memory profiling for the native GC. +``uClibc`` Use uClibc instead of libc. (Relevant for Unix-like OSes) +``checkAbi`` When using types from C headers, add checks that compare + what's in the Nim file with what's in the C header + (requires a C compiler with _Static_assert support, like + any C11 compiler) +``tempDir`` This symbol takes a string as its value, like + ``--define:tempDir:/some/temp/path`` to override the + temporary directory returned by ``os.getTempDir()``. + The value **should** end with a directory separator + character. (Relevant for the Android platform) +``useShPath`` This symbol takes a string as its value, like + ``--define:useShPath:/opt/sh/bin/sh`` to override the + path for the ``sh`` binary, in cases where it is not + located in the default location ``/bin/sh``. +``noSignalHandler`` Disable the crash handler from ``system.nim``. +====================== ========================================================= @@ -529,6 +530,16 @@ See the documentation of Nim's soft realtime `GC `_ for further information. +Signal handling in Nim +====================== + +The Nim programming language has no concept of Posix's signal handling +mechanisms. However, the standard library offers some rudimentary support +for signal handling, in particular, segmentation faults are turned into +fatal errors that produce a stack trace. This can be disabled with the +``-d:noSignalHandler`` switch. + + Debugging with Nim ================== From 4e05bca96fb13780b98b2779db6382d7d35ed354 Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 3 Sep 2018 12:06:34 +0200 Subject: [PATCH 134/145] manual: add a note about the terminating zero for strings; refs #5596 --- doc/manual.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/manual.rst b/doc/manual.rst index 7a765ef630..6dc6794f12 100644 --- a/doc/manual.rst +++ b/doc/manual.rst @@ -1004,6 +1004,11 @@ All string literals are of the type ``string``. A string in Nim is very similar to a sequence of characters. However, strings in Nim are both zero-terminated and have a length field. One can retrieve the length with the builtin ``len`` procedure; the length never counts the terminating zero. + +The terminating zero cannot be accessed unless the string is converted +to the ``cstring`` type first. The terminating zero assures that this +conversion can be done in O(1) and without any allocations. + The assignment operator for strings always copies the string. The ``&`` operator concatenates strings. From 6261309d1b329537d8b968c8d9a9d7ae0be36178 Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 3 Sep 2018 12:09:14 +0200 Subject: [PATCH 135/145] document the fact that --define symbols are completely case insensitive; closes #7506 --- doc/nimc.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/nimc.rst b/doc/nimc.rst index 0346b98e93..4082b53785 100644 --- a/doc/nimc.rst +++ b/doc/nimc.rst @@ -143,6 +143,9 @@ which may be used in conjunction with the `compile time define pragmas`_ to override symbols during build time. +Compile time symbols are completely **case insensitive** and underscores are +ignored too. ``--define:FOO`` and ``--define:foo`` are identical. + Configuration files ------------------- From 1abef2dc59e812f7aee41620bf5cd298f5cc8270 Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 3 Sep 2018 12:27:23 +0200 Subject: [PATCH 136/145] improve the error message for 'addQuitProc' etc; fixes #5794 --- compiler/renderer.nim | 24 ++++++++++++------------ tests/errmsgs/tgcsafety.nim | 3 ++- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/compiler/renderer.nim b/compiler/renderer.nim index 8a25d76e8c..a8f3f4afc0 100644 --- a/compiler/renderer.nim +++ b/compiler/renderer.nim @@ -752,7 +752,8 @@ proc gproc(g: var TSrcGen, n: PNode) = gsub(g, n.sons[genericParamsPos]) g.inGenericParams = oldInGenericParams gsub(g, n.sons[paramsPos]) - gsub(g, n.sons[pragmasPos]) + if renderNoPragmas notin g.flags: + gsub(g, n.sons[pragmasPos]) if renderNoBody notin g.flags: if n.sons[bodyPos].kind != nkEmpty: put(g, tkSpaces, Space) @@ -1297,17 +1298,16 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext) = putWithSpace(g, tkContinue, "continue") gsub(g, n, 0) of nkPragma: - if renderNoPragmas notin g.flags: - if g.inPragma <= 0: - inc g.inPragma - #if not previousNL(g): - put(g, tkSpaces, Space) - put(g, tkCurlyDotLe, "{.") - gcomma(g, n, emptyContext) - put(g, tkCurlyDotRi, ".}") - dec g.inPragma - else: - gcomma(g, n, emptyContext) + if g.inPragma <= 0: + inc g.inPragma + #if not previousNL(g): + put(g, tkSpaces, Space) + put(g, tkCurlyDotLe, "{.") + gcomma(g, n, emptyContext) + put(g, tkCurlyDotRi, ".}") + dec g.inPragma + else: + gcomma(g, n, emptyContext) of nkImportStmt, nkExportStmt: if n.kind == nkImportStmt: putWithSpace(g, tkImport, "import") diff --git a/tests/errmsgs/tgcsafety.nim b/tests/errmsgs/tgcsafety.nim index 4d192db904..ffc6905b07 100644 --- a/tests/errmsgs/tgcsafety.nim +++ b/tests/errmsgs/tgcsafety.nim @@ -5,7 +5,8 @@ nimout: ''' type mismatch: got .}> but expected one of: proc serve(server: AsyncHttpServer; port: Port; - callback: proc (request: Request): Future[void]; address = ""): Future[void] + callback: proc (request: Request): Future[void] {.closure, gcsafe.}; + address = ""): Future[void] first type mismatch at position: 3 required type: proc (request: Request): Future[system.void]{.closure, gcsafe.} but expression 'cb' is of type: proc (req: Request): Future[system.void]{.locks: .} From e63c66b8104225cefe0413471410ef4c072f9954 Mon Sep 17 00:00:00 2001 From: cooldome Date: Mon, 3 Sep 2018 12:25:59 +0100 Subject: [PATCH 137/145] Add sym owner to macros (#8253) --- compiler/ast.nim | 2 +- compiler/condsyms.nim | 1 + compiler/vm.nim | 9 +++++++++ compiler/vmdef.nim | 3 ++- compiler/vmgen.nim | 1 + lib/core/macros.nim | 6 ++++++ tests/macros/tgetimpl.nim | 31 ++++++++++++++++++++++++++++++- 7 files changed, 50 insertions(+), 3 deletions(-) diff --git a/compiler/ast.nim b/compiler/ast.nim index 001d96060c..6949446312 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -657,7 +657,7 @@ type mNHint, mNWarning, mNError, mInstantiationInfo, mGetTypeInfo, mNimvm, mIntDefine, mStrDefine, mRunnableExamples, - mException, mBuiltinType + mException, mBuiltinType, mSymOwner # things that we can evaluate safely at compile time, even if not asked for it: const diff --git a/compiler/condsyms.nim b/compiler/condsyms.nim index 78645b6fde..a22b613f04 100644 --- a/compiler/condsyms.nim +++ b/compiler/condsyms.nim @@ -75,6 +75,7 @@ proc initDefines*(symbols: StringTableRef) = defineSymbol("nimNoZeroTerminator") defineSymbol("nimNotNil") defineSymbol("nimVmExportFixed") + defineSymbol("nimHasSymOwnerInMacro") defineSymbol("nimNewRuntime") defineSymbol("nimIncrSeqV3") defineSymbol("nimAshr") diff --git a/compiler/vm.nim b/compiler/vm.nim index 9143051a95..e38642de82 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -920,6 +920,15 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg = regs[ra].node.flags.incl nfIsRef else: stackTrace(c, tos, pc, "node is not a symbol") + of opcSymOwner: + decodeB(rkNode) + let a = regs[rb].node + if a.kind == nkSym: + regs[ra].node = if a.sym.owner.isNil: newNode(nkNilLit) + else: newSymNode(a.sym.skipGenericOwner) + regs[ra].node.flags.incl nfIsRef + else: + stackTrace(c, tos, pc, "node is not a symbol") of opcEcho: let rb = instr.regB if rb == 1: diff --git a/compiler/vmdef.nim b/compiler/vmdef.nim index 0aee079f56..d642043dcf 100644 --- a/compiler/vmdef.nim +++ b/compiler/vmdef.nim @@ -141,7 +141,8 @@ type opcSetType, # dest.typ = types[Bx] opcTypeTrait, opcMarshalLoad, opcMarshalStore, - opcToNarrowInt + opcToNarrowInt, + opcSymOwner TBlock* = object label*: PSym diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim index dcf76f639f..e87347ec87 100644 --- a/compiler/vmgen.nim +++ b/compiler/vmgen.nim @@ -1118,6 +1118,7 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest; m: TMagic) = of mStaticExec: genBinaryABCD(c, n, dest, opcGorge) of mNLen: genUnaryABI(c, n, dest, opcLenSeq, nimNodeFlag) of mGetImpl: genUnaryABC(c, n, dest, opcGetImpl) + of mSymOwner: genUnaryABC(c, n, dest, opcSymOwner) of mNChild: genBinaryABC(c, n, dest, opcNChild) of mNSetChild: genVoidABC(c, n, dest, opcNSetChild) of mNDel: genVoidABC(c, n, dest, opcNDel) diff --git a/lib/core/macros.nim b/lib/core/macros.nim index 5b29d5e94e..4d76d60c2e 100644 --- a/lib/core/macros.nim +++ b/lib/core/macros.nim @@ -237,6 +237,12 @@ else: # bootstrapping substitute else: n.strValOld +when defined(nimHasSymOwnerInMacro): + proc owner*(sym: NimNode): NimNode {.magic: "SymOwner", noSideEffect.} + ## accepts node of kind nnkSym and returns its owner's symbol. + ## result is also mnde of kind nnkSym if owner exists otherwise + ## nnkNilLit is returned + proc getType*(n: NimNode): NimNode {.magic: "NGetType", noSideEffect.} ## with 'getType' you can access the node's `type`:idx:. A Nim type is ## mapped to a Nim AST too, so it's slightly confusing but it means the same diff --git a/tests/macros/tgetimpl.nim b/tests/macros/tgetimpl.nim index d384929346..715c969f32 100644 --- a/tests/macros/tgetimpl.nim +++ b/tests/macros/tgetimpl.nim @@ -1,6 +1,7 @@ discard """ msg: '''"muhaha" proc poo(x, y: int) = + let y = x echo ["poo"]''' """ @@ -10,11 +11,39 @@ const foo = "muhaha" proc poo(x, y: int) = + let y = x echo "poo" macro m(x: typed): untyped = - echo repr x.symbol.getImpl + echo repr x.getImpl result = x discard m foo discard m poo + +#------------ + +macro checkOwner(x: typed, check_id: static[int]): untyped = + let sym = case check_id: + of 0: x + of 1: x.getImpl.body[0][0][0] + of 2: x.getImpl.body[0][0][^1] + of 3: x.getImpl.body[1][0] + else: x + result = newStrLitNode($sym.owner.symKind) + +macro isSameOwner(x, y: typed): untyped = + result = + if x.owner == y.owner: bindSym"true" + else: bindSym"false" + + +static: + doAssert checkOwner(foo, 0) == "nskModule" + doAssert checkOwner(poo, 0) == "nskModule" + doAssert checkOwner(poo, 1) == "nskProc" + doAssert checkOwner(poo, 2) == "nskProc" + doAssert checkOwner(poo, 3) == "nskModule" + doAssert isSameOwner(foo, poo) + doAssert isSameOwner(foo, echo) == false + doAssert isSameOwner(poo, len) == false From 0694c9080f85b59e86ddfb0bd3c799fe9d9e30ae Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 3 Sep 2018 16:07:35 +0200 Subject: [PATCH 138/145] fixes #8043 --- compiler/semcall.nim | 11 ++++++---- compiler/sigmatch.nim | 3 +++ tests/errmsgs/tunknown_named_parameter.nim | 24 ++++++++++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 tests/errmsgs/tunknown_named_parameter.nim diff --git a/compiler/semcall.nim b/compiler/semcall.nim index 9e75f8cd46..53f7045dd7 100644 --- a/compiler/semcall.nim +++ b/compiler/semcall.nim @@ -189,15 +189,18 @@ proc presentFailedCandidates(c: PContext, n: PNode, errors: CandidateErrors): if err.firstMismatch != 0 and n.len > 1: let cond = n.len > 2 if cond: - candidates.add(" first type mismatch at position: " & $err.firstMismatch & - "\n required type: ") + candidates.add(" first type mismatch at position: " & $abs(err.firstMismatch)) + if err.firstMismatch >= 0: candidates.add("\n required type: ") + else: candidates.add("\n unknown named parameter: " & $n[-err.firstMismatch][0]) var wanted, got: PType = nil - if err.firstMismatch < err.sym.typ.len: + if err.firstMismatch < 0: + discard + elif err.firstMismatch < err.sym.typ.len: wanted = err.sym.typ.sons[err.firstMismatch] if cond: candidates.add typeToString(wanted) else: if cond: candidates.add "none" - if err.firstMismatch < n.len: + if err.firstMismatch > 0 and err.firstMismatch < n.len: if cond: candidates.add "\n but expression '" candidates.add renderTree(n[err.firstMismatch]) diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index e59496cca3..407e346191 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -2252,11 +2252,13 @@ proc matchesAux(c: PContext, n, nOrig: PNode, if n.sons[a].sons[0].kind != nkIdent: localError(c.config, n.sons[a].info, "named parameter has to be an identifier") m.state = csNoMatch + m.firstMismatch = -a return formal = getSymFromList(m.callee.n, n.sons[a].sons[0].ident, 1) if formal == nil: # no error message! m.state = csNoMatch + m.firstMismatch = -a return if containsOrIncl(marker, formal.position): # already in namedParams, so no match @@ -2274,6 +2276,7 @@ proc matchesAux(c: PContext, n, nOrig: PNode, n.sons[a].sons[1], n.sons[a].sons[1]) if arg == nil: m.state = csNoMatch + m.firstMismatch = a return checkConstraint(n.sons[a].sons[1]) if m.baseTypeMatch: diff --git a/tests/errmsgs/tunknown_named_parameter.nim b/tests/errmsgs/tunknown_named_parameter.nim new file mode 100644 index 0000000000..b6b855136c --- /dev/null +++ b/tests/errmsgs/tunknown_named_parameter.nim @@ -0,0 +1,24 @@ +discard """ +cmd: "nim check $file" +errormsg: "type mismatch: got " +nimout: ''' +proc rsplit(s: string; sep: string; maxsplit: int = -1): seq[string] + first type mismatch at position: 2 + required type: string + but expression '{':'}' is of type: set[char] +proc rsplit(s: string; sep: char; maxsplit: int = -1): seq[string] + first type mismatch at position: 2 + required type: char + but expression '{':'}' is of type: set[char] +proc rsplit(s: string; seps: set[char] = Whitespace; maxsplit: int = -1): seq[string] + first type mismatch at position: 3 + unknown named parameter: maxsplits + +expression: rsplit("abc:def", {':'}, maxsplits = 1) +''' +""" + +# bug #8043 + +import strutils +"abc:def".rsplit({':'}, maxsplits = 1) From 1a60ffcf1dc265c6b92dfd757e1bfd5e904c1f3d Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Mon, 3 Sep 2018 17:51:30 +0200 Subject: [PATCH 139/145] Correctly mangle `this` in the JS backend (#8853) As shown in pragmagic/karax#67 using `this` as parameter name made the codegen output wrong code (and the user didn't notice the errors in the browser console). --- compiler/jsgen.nim | 3 ++- tests/js/tjsffi.nim | 4 ++-- tests/js/tthismangle.nim | 23 +++++++++++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 tests/js/tthismangle.nim diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim index b9b22d825e..1b00ddbfa5 100644 --- a/compiler/jsgen.nim +++ b/compiler/jsgen.nim @@ -243,7 +243,8 @@ proc mangleName(m: BModule, s: PSym): Rope = x.add("HEX" & toHex(ord(c), 2)) inc i result = rope(x) - if s.name.s != "this" and s.kind != skField: + # From ES5 on reserved words can be used as object field names + if s.kind != skField: if optHotCodeReloading in m.config.options: # When hot reloading is enabled, we must ensure that the names # of functions and types will be preserved across rebuilds: diff --git a/tests/js/tjsffi.nim b/tests/js/tjsffi.nim index 156ca89e32..213d059641 100644 --- a/tests/js/tjsffi.nim +++ b/tests/js/tjsffi.nim @@ -267,8 +267,8 @@ block: type TestObject = object a: int onWhatever: proc(e: int): int - proc handleWhatever(that: TestObject, e: int): int = - e + that.a + proc handleWhatever(this: TestObject, e: int): int = + e + this.a proc test(): bool = let obj = TestObject(a: 9, onWhatever: bindMethod(handleWhatever)) obj.onWhatever(1) == 10 diff --git a/tests/js/tthismangle.nim b/tests/js/tthismangle.nim new file mode 100644 index 0000000000..880abcc834 --- /dev/null +++ b/tests/js/tthismangle.nim @@ -0,0 +1,23 @@ +proc moo1(this: int) = + doAssert this == 42 + +proc moo2(x: int) = + var this = x + doAssert this == 42 + +proc moo3() = + for this in [1,1,1]: + doAssert this == 1 + +proc moo4() = + type + X = object + this: int + + var q = X(this: 42) + doAssert q.this == 42 + +moo1(42) +moo2(42) +moo3() +moo4() From 320582a55c9ba1f91d70a3f120413e305fda2962 Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 3 Sep 2018 18:29:00 +0200 Subject: [PATCH 140/145] cleanup Nim's examples/ directory; closes #7725 --- examples/c++iface/irrlichtex.nim | 114 - examples/cgi/cgi_server.py | 11 - examples/cgi/cgi_stacktrace.nim | 5 - examples/cgi/example.nim | 7 - examples/cgiex.nim | 12 - examples/cross_calculator/.gitignore | 12 - .../android/AndroidManifest.xml | 18 - examples/cross_calculator/android/build.xml | 92 - .../cross_calculator/android/custom_rules.xml | 17 - .../cross_calculator/android/jni/Android.mk | 32 - .../android/jni/backend-jni.c | 42 - .../android/project.properties | 14 - examples/cross_calculator/android/readme.txt | 24 - .../android/res/layout/cross_calculator.xml | 72 - .../android/res/values/strings.xml | 4 - .../android/scripts/jnibuild.sh | 22 - .../android/scripts/nimbuild.sh | 34 - .../cross_calculator/android/scripts/tags.sh | 13 - .../crosscalculator/CrossCalculator.java | 80 - .../project.pbxproj | 337 -- examples/cross_calculator/ios/readme.txt | 13 - .../plist/cross-calculator-Info.plist | 30 - .../ios/resources/ui/NRViewController.xib | 479 -- examples/cross_calculator/ios/scripts/tags.sh | 13 - .../ios/scripts/xcode_prebuild.sh | 35 - .../cross_calculator/ios/src/AppDelegate.h | 7 - .../cross_calculator/ios/src/AppDelegate.m | 39 - .../ios/src/NRViewController.h | 11 - .../ios/src/NRViewController.m | 210 - .../ios/src/cross-calculator-Prefix.pch | 10 - examples/cross_calculator/ios/src/main.m | 13 - examples/cross_calculator/lazarus/nimlaz.lpi | 140 - examples/cross_calculator/lazarus/nimlaz.lpr | 21 - examples/cross_calculator/lazarus/nimlaz.lrs | 5222 ----------------- examples/cross_calculator/lazarus/nimlaz.rc | 6 - examples/cross_calculator/lazarus/readme.txt | 8 - examples/cross_calculator/lazarus/unit1.lfm | 46 - examples/cross_calculator/lazarus/unit1.pas | 58 - .../cross_calculator/nim_backend/backend.nim | 5 - .../cross_calculator/nim_commandline/nim.cfg | 4 - .../nim_commandline/nimcalculator.nim | 109 - .../nim_commandline/readme.txt | 10 - examples/cross_calculator/readme.txt | 13 - examples/cross_todo/nim_backend/backend.nim | 195 - examples/cross_todo/nim_backend/readme.txt | 14 - .../cross_todo/nim_backend/testbackend.nim | 74 - examples/cross_todo/nim_commandline/nim.cfg | 4 - .../cross_todo/nim_commandline/nimtodo.nim | 297 - .../cross_todo/nim_commandline/readme.txt | 19 - examples/cross_todo/readme.txt | 5 - examples/debugging.nim | 17 - ...val2.nim => extract_keyval_pairs_pegs.nim} | 0 ...keyval.nim => extract_keyval_pairs_re.nim} | 0 examples/filterex.nim | 23 - examples/fizzbuzz.nim | 14 - examples/htmlrefs.nim | 57 - examples/htmltitle.nim | 36 - examples/httpserver2.nim | 247 - examples/maximum.nim | 2 +- examples/objciface/gnustepex.nim | 40 - examples/parsecfgex.nim | 25 - examples/readme.txt | 2 +- examples/ssl/extradata.nim | 26 - examples/ssl/pskclient.nim | 16 - examples/ssl/pskserver.nim | 20 - examples/transff.nim | 8 - examples/unix_socket/client.nim | 6 - examples/unix_socket/server.nim | 14 - 68 files changed, 2 insertions(+), 8623 deletions(-) delete mode 100644 examples/c++iface/irrlichtex.nim delete mode 100644 examples/cgi/cgi_server.py delete mode 100644 examples/cgi/cgi_stacktrace.nim delete mode 100644 examples/cgi/example.nim delete mode 100644 examples/cgiex.nim delete mode 100644 examples/cross_calculator/.gitignore delete mode 100644 examples/cross_calculator/android/AndroidManifest.xml delete mode 100644 examples/cross_calculator/android/build.xml delete mode 100644 examples/cross_calculator/android/custom_rules.xml delete mode 100644 examples/cross_calculator/android/jni/Android.mk delete mode 100644 examples/cross_calculator/android/jni/backend-jni.c delete mode 100644 examples/cross_calculator/android/project.properties delete mode 100644 examples/cross_calculator/android/readme.txt delete mode 100644 examples/cross_calculator/android/res/layout/cross_calculator.xml delete mode 100644 examples/cross_calculator/android/res/values/strings.xml delete mode 100644 examples/cross_calculator/android/scripts/jnibuild.sh delete mode 100644 examples/cross_calculator/android/scripts/nimbuild.sh delete mode 100644 examples/cross_calculator/android/scripts/tags.sh delete mode 100644 examples/cross_calculator/android/src/com/github/nimrod/crosscalculator/CrossCalculator.java delete mode 100644 examples/cross_calculator/ios/cross-calculator.xcodeproj/project.pbxproj delete mode 100644 examples/cross_calculator/ios/readme.txt delete mode 100644 examples/cross_calculator/ios/resources/plist/cross-calculator-Info.plist delete mode 100644 examples/cross_calculator/ios/resources/ui/NRViewController.xib delete mode 100644 examples/cross_calculator/ios/scripts/tags.sh delete mode 100644 examples/cross_calculator/ios/scripts/xcode_prebuild.sh delete mode 100644 examples/cross_calculator/ios/src/AppDelegate.h delete mode 100644 examples/cross_calculator/ios/src/AppDelegate.m delete mode 100644 examples/cross_calculator/ios/src/NRViewController.h delete mode 100644 examples/cross_calculator/ios/src/NRViewController.m delete mode 100644 examples/cross_calculator/ios/src/cross-calculator-Prefix.pch delete mode 100644 examples/cross_calculator/ios/src/main.m delete mode 100644 examples/cross_calculator/lazarus/nimlaz.lpi delete mode 100644 examples/cross_calculator/lazarus/nimlaz.lpr delete mode 100644 examples/cross_calculator/lazarus/nimlaz.lrs delete mode 100644 examples/cross_calculator/lazarus/nimlaz.rc delete mode 100644 examples/cross_calculator/lazarus/readme.txt delete mode 100644 examples/cross_calculator/lazarus/unit1.lfm delete mode 100644 examples/cross_calculator/lazarus/unit1.pas delete mode 100644 examples/cross_calculator/nim_backend/backend.nim delete mode 100644 examples/cross_calculator/nim_commandline/nim.cfg delete mode 100644 examples/cross_calculator/nim_commandline/nimcalculator.nim delete mode 100644 examples/cross_calculator/nim_commandline/readme.txt delete mode 100644 examples/cross_calculator/readme.txt delete mode 100644 examples/cross_todo/nim_backend/backend.nim delete mode 100644 examples/cross_todo/nim_backend/readme.txt delete mode 100644 examples/cross_todo/nim_backend/testbackend.nim delete mode 100644 examples/cross_todo/nim_commandline/nim.cfg delete mode 100644 examples/cross_todo/nim_commandline/nimtodo.nim delete mode 100644 examples/cross_todo/nim_commandline/readme.txt delete mode 100644 examples/cross_todo/readme.txt delete mode 100644 examples/debugging.nim rename examples/{keyval2.nim => extract_keyval_pairs_pegs.nim} (100%) rename examples/{keyval.nim => extract_keyval_pairs_re.nim} (100%) delete mode 100644 examples/filterex.nim delete mode 100644 examples/fizzbuzz.nim delete mode 100644 examples/htmlrefs.nim delete mode 100644 examples/htmltitle.nim delete mode 100644 examples/httpserver2.nim delete mode 100644 examples/objciface/gnustepex.nim delete mode 100644 examples/parsecfgex.nim delete mode 100644 examples/ssl/extradata.nim delete mode 100644 examples/ssl/pskclient.nim delete mode 100644 examples/ssl/pskserver.nim delete mode 100644 examples/transff.nim delete mode 100644 examples/unix_socket/client.nim delete mode 100644 examples/unix_socket/server.nim diff --git a/examples/c++iface/irrlichtex.nim b/examples/c++iface/irrlichtex.nim deleted file mode 100644 index 373a78ce7a..0000000000 --- a/examples/c++iface/irrlichtex.nim +++ /dev/null @@ -1,114 +0,0 @@ -# Horrible example of how to interface with a C++ engine ... ;-) - -{.link: "/usr/lib/libIrrlicht.so".} - -{.emit: """ -using namespace irr; -using namespace core; -using namespace scene; -using namespace video; -using namespace io; -using namespace gui; -""".} - -const - irr = "" - -type - TDimension2d {.final, header: irr, importc: "dimension2d".} = object - Tvector3df {.final, header: irr, importc: "vector3df".} = object - TColor {.final, header: irr, importc: "SColor".} = object - - TIrrlichtDevice {.final, header: irr, importc: "IrrlichtDevice".} = object - TIVideoDriver {.final, header: irr, importc: "IVideoDriver".} = object - TISceneManager {.final, header: irr, importc: "ISceneManager".} = object - TIGUIEnvironment {.final, header: irr, importc: "IGUIEnvironment".} = object - TIAnimatedMesh {.final, header: irr, importc: "IAnimatedMesh".} = object - TIAnimatedMeshSceneNode {.final, header: irr, - importc: "IAnimatedMeshSceneNode".} = object - TITexture {.final, header: irr, importc: "ITexture".} = object - - PIrrlichtDevice = ptr TIrrlichtDevice - PIVideoDriver = ptr TIVideoDriver - PISceneManager = ptr TISceneManager - PIGUIEnvironment = ptr TIGUIEnvironment - PIAnimatedMesh = ptr TIAnimatedMesh - PIAnimatedMeshSceneNode = ptr TIAnimatedMeshSceneNode - PITexture = ptr TITexture - -proc dimension2d(x, y: cint): TDimension2d {. - header: irr, importc: "dimension2d".} -proc vector3df(x,y,z: cint): Tvector3df {. - header: irr, importc: "vector3df".} -proc SColor(r,g,b,a: cint): TColor {. - header: irr, importc: "SColor".} - -proc createDevice(): PIrrlichtDevice {. - header: irr, importc: "createDevice".} -proc run(device: PIrrlichtDevice): bool {. - header: irr, importcpp: "run".} - -proc getVideoDriver(dev: PIrrlichtDevice): PIVideoDriver {. - header: irr, importcpp: "getVideoDriver".} -proc getSceneManager(dev: PIrrlichtDevice): PISceneManager {. - header: irr, importcpp: "getSceneManager".} -proc getGUIEnvironment(dev: PIrrlichtDevice): PIGUIEnvironment {. - header: irr, importcpp: "getGUIEnvironment".} - -proc getMesh(smgr: PISceneManager, path: cstring): PIAnimatedMesh {. - header: irr, importcpp: "getMesh".} - -proc drawAll(smgr: PISceneManager) {. - header: irr, importcpp: "drawAll".} -proc drawAll(guienv: PIGUIEnvironment) {. - header: irr, importcpp: "drawAll".} - -proc drop(dev: PIrrlichtDevice) {. - header: irr, importcpp: "drop".} - -proc getTexture(driver: PIVideoDriver, path: cstring): PITexture {. - header: irr, importcpp: "getTexture".} -proc endScene(driver: PIVideoDriver) {. - header: irr, importcpp: "endScene".} -proc beginScene(driver: PIVideoDriver, a, b: bool, c: TColor) {. - header: irr, importcpp: "beginScene".} - -proc addAnimatedMeshSceneNode( - smgr: PISceneManager, mesh: PIAnimatedMesh): PIAnimatedMeshSceneNode {. - header: irr, importcpp: "addAnimatedMeshSceneNode".} - -proc setMaterialTexture(n: PIAnimatedMeshSceneNode, x: cint, t: PITexture) {. - header: irr, importcpp: "setMaterialTexture".} -proc addCameraSceneNode(smgr: PISceneManager, x: cint, a, b: TVector3df) {. - header: irr, importcpp: "addCameraSceneNode".} - - -var device = createDevice() -if device == nil: quit "device is nil" - -var driver = device.getVideoDriver() -var smgr = device.getSceneManager() -var guienv = device.getGUIEnvironment() - -var mesh = smgr.getMesh("/home/andreas/download/irrlicht-1.7.2/media/sydney.md2") -if mesh == nil: - device.drop() - quit "no mesh!" - -var node = smgr.addAnimatedMeshSceneNode(mesh) - -if node != nil: - #node->setMaterialFlag(EMF_LIGHTING, false) - #node->setMD2Animation(scene::EMAT_STAND) - node.setMaterialTexture(0, - driver.getTexture( - "/home/andreas/download/irrlicht-1.7.2/media/media/sydney.bmp")) - -smgr.addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0)) -while device.run(): - driver.beginScene(true, true, SColor(255,100,101,140)) - smgr.drawAll() - guienv.drawAll() - driver.endScene() -device.drop() - diff --git a/examples/cgi/cgi_server.py b/examples/cgi/cgi_server.py deleted file mode 100644 index 1907515e80..0000000000 --- a/examples/cgi/cgi_server.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python -import BaseHTTPServer -import CGIHTTPServer - -server = BaseHTTPServer.HTTPServer -handler = CGIHTTPServer.CGIHTTPRequestHandler -server_address = ('localhost', 8008) -handler.cgi_directories = ['/'] - -httpd = server(server_address, handler) -httpd.serve_forever() diff --git a/examples/cgi/cgi_stacktrace.nim b/examples/cgi/cgi_stacktrace.nim deleted file mode 100644 index e9f2f567c2..0000000000 --- a/examples/cgi/cgi_stacktrace.nim +++ /dev/null @@ -1,5 +0,0 @@ -import cgi -cgi.setStackTraceStdout() - -var a: string = nil -a.add "foobar" diff --git a/examples/cgi/example.nim b/examples/cgi/example.nim deleted file mode 100644 index 761197cdbc..0000000000 --- a/examples/cgi/example.nim +++ /dev/null @@ -1,7 +0,0 @@ -import cgi - -write(stdout, "Content-type: text/html\n\n") -write(stdout, "\n") -write(stdout, "Test\n") -write(stdout, "Hello!") -writeLine(stdout, "") diff --git a/examples/cgiex.nim b/examples/cgiex.nim deleted file mode 100644 index fb55a731a5..0000000000 --- a/examples/cgiex.nim +++ /dev/null @@ -1,12 +0,0 @@ -# Test/show CGI module -import strtabs, cgi - -var myData = readData() -validateData(myData, "name", "password") -writeContentType() - -write(stdout, "\n") -write(stdout, "Test\n") -writeLine(stdout, "name: " & myData["name"]) -writeLine(stdout, "password: " & myData["password"]) -writeLine(stdout, "") diff --git a/examples/cross_calculator/.gitignore b/examples/cross_calculator/.gitignore deleted file mode 100644 index e521bf3389..0000000000 --- a/examples/cross_calculator/.gitignore +++ /dev/null @@ -1,12 +0,0 @@ -# Android specific absolute paths. -android/bin/ -android/gen/ -android/jni/backend-jni.h -android/libs/ -android/local.properties -android/obj/ -android/tags -# iOS specific absolute paths -ios/resources/ui/*.m -ios/tags - diff --git a/examples/cross_calculator/android/AndroidManifest.xml b/examples/cross_calculator/android/AndroidManifest.xml deleted file mode 100644 index 05b96fb503..0000000000 --- a/examples/cross_calculator/android/AndroidManifest.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - diff --git a/examples/cross_calculator/android/build.xml b/examples/cross_calculator/android/build.xml deleted file mode 100644 index d7c88432a7..0000000000 --- a/examples/cross_calculator/android/build.xml +++ /dev/null @@ -1,92 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/cross_calculator/android/custom_rules.xml b/examples/cross_calculator/android/custom_rules.xml deleted file mode 100644 index 91783a50e4..0000000000 --- a/examples/cross_calculator/android/custom_rules.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/examples/cross_calculator/android/jni/Android.mk b/examples/cross_calculator/android/jni/Android.mk deleted file mode 100644 index c1a0feac3a..0000000000 --- a/examples/cross_calculator/android/jni/Android.mk +++ /dev/null @@ -1,32 +0,0 @@ -# Copyright (C) 2009 The Android Open Source Project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_MODULE := nimrod -LOCAL_SRC_FILES := nimcache/backend.c nimcache/system.c -LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/nimcache - -include $(BUILD_STATIC_LIBRARY) - -include $(CLEAR_VARS) - -LOCAL_MODULE := backend-jni -LOCAL_SRC_FILES := backend-jni.c -LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog -LOCAL_STATIC_LIBRARIES := nimrod - -include $(BUILD_SHARED_LIBRARY) diff --git a/examples/cross_calculator/android/jni/backend-jni.c b/examples/cross_calculator/android/jni/backend-jni.c deleted file mode 100644 index 3d65458ec8..0000000000 --- a/examples/cross_calculator/android/jni/backend-jni.c +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2009 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -#include -#include -#include "backend-jni.h" -#include "backend.h" - -#define TAG "backend-jni.c" - -jint JNICALL Java_com_github_nimrod_crosscalculator_CrossCalculator_myAdd - (JNIEnv *env, jobject thiz, jint a, jint b) -{ - char buf[256]; - const jint ret = myAdd(a, b); - // Using logging from inside the native bridge to log-debug. - sprintf(buf, "a %d + b %d = ret %d", a, b, ret); - __android_log_write(ANDROID_LOG_DEBUG, TAG, buf); - return ret; -} - -void JNICALL Java_com_github_nimrod_crosscalculator_CrossCalculator_initNimMain - (JNIEnv *env, jclass thiz) -{ - NimMain(); - __android_log_write(ANDROID_LOG_DEBUG, TAG, "Nimrod initialised"); -} - -// vim:tabstop=2 shiftwidth=2 syntax=c diff --git a/examples/cross_calculator/android/project.properties b/examples/cross_calculator/android/project.properties deleted file mode 100644 index 9fb894d9b4..0000000000 --- a/examples/cross_calculator/android/project.properties +++ /dev/null @@ -1,14 +0,0 @@ -# This file is automatically generated by Android Tools. -# Do not modify this file -- YOUR CHANGES WILL BE ERASED! -# -# This file must be checked in Version Control Systems. -# -# To customize properties used by the Ant build system edit -# "ant.properties", and override values to adapt the script to your -# project structure. -# -# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): -#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt - -# Project target. -target=android-3 diff --git a/examples/cross_calculator/android/readme.txt b/examples/cross_calculator/android/readme.txt deleted file mode 100644 index 96bd403ca9..0000000000 --- a/examples/cross_calculator/android/readme.txt +++ /dev/null @@ -1,24 +0,0 @@ -In this directory you will find the Android platform cross-calculator sample. - -Due to the nature of Android being java and Nim generating C code, the build -process is slightly more complex because jni code has to be written to bridge -both languages. In a distant future it may be possible for Nim to generate -the whole jni bridge, but for the moment this is manual work. - -For the jni bridge to work first the java code is compiled with the Nim code -just declared as a native method which will be resolved at runtime. The scripts -nimbuild.sh and jnibuild.sh are in charge of building the Nim code and -generating the jni bridge from the java code respectively. Finally, the -ndk-build command from the android ndk tools has to be run to build the binary -library which will be installed along the final apk. - -All these steps are wrapped in the ant build script through the customization -of the -post-compile rule. If you have the android ndk tools installed and you -modify scripts/nimbuild.sh to point to the directory where you have Nim -installed on your system, you can simply run "ant debug" to build everything. - -Once the apk is built you can install it on your device or emulator with the -command "adb install bin/CrossCalculator-debug.apk". - -This example runs against the Android level 3 API, meaning devices from -Android 1.5 and above should be able to run the generated binary. diff --git a/examples/cross_calculator/android/res/layout/cross_calculator.xml b/examples/cross_calculator/android/res/layout/cross_calculator.xml deleted file mode 100644 index 11531334c5..0000000000 --- a/examples/cross_calculator/android/res/layout/cross_calculator.xml +++ /dev/null @@ -1,72 +0,0 @@ - - - - - - - - - - - - - - - - - -