diff --git a/changelogs/changelog_0_18_1.md b/changelogs/changelog_0_18_1.md index d0b7fd8ee5..01767ac40e 100644 --- a/changelogs/changelog_0_18_1.md +++ b/changelogs/changelog_0_18_1.md @@ -53,7 +53,7 @@ - [``joyent_http_parser``](https://github.com/nim-lang/joyent_http_parser) - Proc [toCountTable](https://nim-lang.org/docs/tables.html#toCountTable,openArray[A]) - now produces a `CountTable` with values correspoding to the number of occurrences + now produces a `CountTable` with values corresponding to the number of occurrences of the key in the input. It used to produce a table with all values set to `1`. Counting occurrences in a sequence used to be: @@ -339,7 +339,7 @@ for i in a..b: - Fixed "ReraiseError when using try/except within finally block" ([#5871](https://github.com/nim-lang/Nim/issues/5871)) -- Fixed "Range type inference leads to counter-intuitive behvaiour" +- Fixed "Range type inference leads to counter-intuitive behaviour" ([#5854](https://github.com/nim-lang/Nim/issues/5854)) - Fixed "JSON % operator can fail in extern procs with dynamic types" ([#6385](https://github.com/nim-lang/Nim/issues/6385)) @@ -403,7 +403,7 @@ for i in a..b: ([#6589](https://github.com/nim-lang/Nim/issues/6589)) - Fixed "Generated c code calls function twice" ([#6292](https://github.com/nim-lang/Nim/issues/6292)) -- Fixed "Range type inference leads to counter-intuitive behvaiour" +- Fixed "Range type inference leads to counter-intuitive behaviour" ([#5854](https://github.com/nim-lang/Nim/issues/5854)) - Fixed "New backward indexing is too limited" ([#6631](https://github.com/nim-lang/Nim/issues/6631)) diff --git a/changelogs/changelog_1_0_2.md b/changelogs/changelog_1_0_2.md index aa01c503f6..88fca18b53 100644 --- a/changelogs/changelog_1_0_2.md +++ b/changelogs/changelog_1_0_2.md @@ -11,7 +11,7 @@ * Fixed "Assertion error when running `nim check` on compiler/nim.nim" [#12281](https://github.com/nim-lang/Nim/issues/12281) * Fixed "Compiler crash with empty array and generic instantiation with int as parameter" [#12264](https://github.com/nim-lang/Nim/issues/12264) * Fixed "Regression in JS backend codegen "Error: request to generate code for .compileTime proc"" [#12240](https://github.com/nim-lang/Nim/issues/12240) -* Fix how `relativePath` handle case sensitiviy +* Fix how `relativePath` handles case sensitivity * Fixed "SIGSEGV in compiler when using generic types and seqs" [#12336](https://github.com/nim-lang/Nim/issues/12336) * Fixed "[1.0.0] weird interaction between `import os` and casting integer to char on macosx trigger bad codegen" [#12291](https://github.com/nim-lang/Nim/issues/12291) * VM: no special casing for big endian machines @@ -43,7 +43,7 @@ * threadpool: fix link in docs (#12258) * Fix spellings (#12277) * fix #12278, don't expose internal PCRE documentation -* Fixed "Documentation of quitprocs is wrong" [#12279(https://github.com/nim-lang/Nim/issues/12279) +* Fixed "Documentation of quitprocs is wrong" [#12279](https://github.com/nim-lang/Nim/issues/12279) * Fix typo in docs * Fix reference to parseSpec proc in readme * [doc/tut1] removed discard discussion in comments diff --git a/compiler/isolation_check.nim b/compiler/isolation_check.nim index 17fbde29ee..0a27a4b815 100644 --- a/compiler/isolation_check.nim +++ b/compiler/isolation_check.nim @@ -166,7 +166,7 @@ proc containsVariable(n: PNode): bool = proc checkIsolate*(n: PNode): bool = if types.containsTyRef(n.typ): # XXX Maybe require that 'n.typ' is acyclic. This is not much - # worse than the already exisiting inheritance and closure restrictions. + # worse than the already existing inheritance and closure restrictions. case n.kind of nkCharLit..nkNilLit: result = true diff --git a/compiler/options.nim b/compiler/options.nim index 7002eb05f6..2f903819ba 100644 --- a/compiler/options.nim +++ b/compiler/options.nim @@ -25,7 +25,7 @@ const useEffectSystem* = true useWriteTracking* = false hasFFI* = defined(nimHasLibFFI) - copyrightYear* = "2024" + copyrightYear* = "2025" nimEnableCovariance* = defined(nimEnableCovariance) diff --git a/compiler/semtypinst.nim b/compiler/semtypinst.nim index 217488cb8d..6c81f8ac7b 100644 --- a/compiler/semtypinst.nim +++ b/compiler/semtypinst.nim @@ -344,7 +344,7 @@ proc replaceTypeVarsS(cl: var TReplTypeVars, s: PSym, t: PType): PSym = #[ We cannot naively check for symbol recursions, because otherwise - object types A, B whould share their fields! + object types A, B would share their fields! import tables diff --git a/copying.txt b/copying.txt index 6707dad448..4025beacba 100644 --- a/copying.txt +++ b/copying.txt @@ -1,7 +1,7 @@ ===================================================== Nim -- a Compiler for Nim. https://nim-lang.org/ -Copyright (C) 2006-2024 Andreas Rumpf. All rights reserved. +Copyright (C) 2006-2025 Andreas Rumpf. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/doc/backends.md b/doc/backends.md index a8db83fb59..bf51e546ae 100644 --- a/doc/backends.md +++ b/doc/backends.md @@ -358,7 +358,7 @@ Memory management In the previous sections, the `NimMain()` function reared its head. Since JavaScript already provides automatic memory management, you can freely pass -objects between the two languages without problems. In C and derivate languages +objects between the two languages without problems. In C and derivative languages you need to be careful about what you do and how you share memory. The previous examples only dealt with simple scalar values, but passing a Nim string to C, or reading back a C string in Nim already requires you to be diff --git a/doc/manual.md b/doc/manual.md index a35a67851b..d90e654264 100644 --- a/doc/manual.md +++ b/doc/manual.md @@ -6264,7 +6264,7 @@ The default for symbols of entity `type`, `var`, `let` and `const` is `gensym`. For `proc`, `iterator`, `converter`, `template`, `macro`, the default is `inject`, but if a `gensym` symbol with the same name is defined in the same syntax-level scope, it will be `gensym` by default. -This can be overriden by marking the routine as `inject`. +This can be overridden by marking the routine as `inject`. If the name of the entity is passed as a template parameter, it is an `inject`'ed symbol: diff --git a/lib/core/macros.nim b/lib/core/macros.nim index a95968f14d..8a44fbc833 100644 --- a/lib/core/macros.nim +++ b/lib/core/macros.nim @@ -1327,7 +1327,7 @@ proc `name=`*(someProc: NimNode; val: NimNode) = else: someProc[0] = val proc params*(someProc: NimNode): NimNode = - if someProc.kind == nnkProcTy: + if someProc.kind in {nnkProcTy, nnkIteratorTy}: someProc[0] else: someProc.expectRoutine @@ -1335,7 +1335,7 @@ proc params*(someProc: NimNode): NimNode = proc `params=`* (someProc: NimNode; params: NimNode) = expectKind(params, nnkFormalParams) - if someProc.kind == nnkProcTy: + if someProc.kind in {nnkProcTy, nnkIteratorTy}: someProc[0] = params else: someProc.expectRoutine @@ -1344,7 +1344,7 @@ proc `params=`* (someProc: NimNode; params: NimNode) = proc pragma*(someProc: NimNode): NimNode = ## Get the pragma of a proc type. ## These will be expanded. - if someProc.kind == nnkProcTy: + if someProc.kind in {nnkProcTy, nnkIteratorTy}: result = someProc[1] else: someProc.expectRoutine @@ -1352,7 +1352,7 @@ proc pragma*(someProc: NimNode): NimNode = proc `pragma=`*(someProc: NimNode; val: NimNode) = ## Set the pragma of a proc type. expectKind(val, {nnkEmpty, nnkPragma}) - if someProc.kind == nnkProcTy: + if someProc.kind in {nnkProcTy, nnkIteratorTy}: someProc[1] = val else: someProc.expectRoutine diff --git a/lib/pure/memfiles.nim b/lib/pure/memfiles.nim index bb9b4b02c9..8430dde8b3 100644 --- a/lib/pure/memfiles.nim +++ b/lib/pure/memfiles.nim @@ -30,6 +30,7 @@ import std/oserrors when defined(nimPreviewSlimSystem): import std/[syncio, assertions] +from system/ansi_c import c_memchr proc newEIO(msg: string): ref IOError = result = (ref IOError)(msg: msg) @@ -448,14 +449,12 @@ iterator memSlices*(mfile: MemFile, delim = '\l', eat = '\r'): MemSlice {.inline ## echo count ## ``` - proc c_memchr(cstr: pointer, c: char, n: csize_t): pointer {. - importc: "memchr", header: "".} proc `-!`(p, q: pointer): int {.inline.} = return cast[int](p) -% cast[int](q) var ending: pointer var ms = MemSlice(data: mfile.mem, size: 0) var remaining = mfile.size while remaining > 0: - ending = c_memchr(ms.data, delim, csize_t(remaining)) + ending = c_memchr(ms.data, cint(delim), csize_t(remaining)) if ending == nil: # unterminated final slice ms.size = remaining # Weird case..check eat? yield ms diff --git a/lib/pure/strutils.nim b/lib/pure/strutils.nim index 9cb6294fe6..687dedd514 100644 --- a/lib/pure/strutils.nim +++ b/lib/pure/strutils.nim @@ -1950,8 +1950,8 @@ func find*(a: SkipTable, s, sub: string, start: Natural = 0, last = -1): int {. inc skip, a[s[skip + subLast]] when not (defined(js) or defined(nimdoc) or defined(nimscript)): - func c_memchr(cstr: pointer, c: char, n: csize_t): pointer {. - importc: "memchr", header: "".} + from system/ansi_c import c_memchr + const hasCStringBuiltin = true else: const hasCStringBuiltin = false @@ -1982,7 +1982,7 @@ func find*(s: string, sub: char, start: Natural = 0, last = -1): int {.rtl, when hasCStringBuiltin: let length = last-start+1 if length > 0: - let found = c_memchr(s[start].unsafeAddr, sub, cast[csize_t](length)) + let found = c_memchr(s[start].unsafeAddr, cint(sub), cast[csize_t](length)) if not found.isNil: return cast[int](found) -% cast[int](s.cstring) else: diff --git a/lib/std/formatfloat.nim b/lib/std/formatfloat.nim index d8e6489262..c35adfd7cb 100644 --- a/lib/std/formatfloat.nim +++ b/lib/std/formatfloat.nim @@ -12,7 +12,7 @@ when defined(nimPreviewSlimSystem): import std/assertions -proc c_memcpy(a, b: pointer, size: csize_t): pointer {.importc: "memcpy", header: "", discardable.} +from system/ansi_c import c_memcpy proc addCstringN(result: var string, buf: cstring; buflen: int) = # no nimvm support needed, so it doesn't need to be fast here either diff --git a/lib/std/private/strimpl.nim b/lib/std/private/strimpl.nim index d1732bf365..8ddb39cf0c 100644 --- a/lib/std/private/strimpl.nim +++ b/lib/std/private/strimpl.nim @@ -75,11 +75,7 @@ template endsWithImpl*[T: string | cstring](s, suffix: T) = func cmpNimIdentifier*[T: string | cstring](a, b: T): int = cmpIgnoreStyleImpl(a, b, true) -func c_memchr(cstr: pointer, c: char, n: csize_t): pointer {. - importc: "memchr", header: "".} -func c_strstr(haystack, needle: cstring): cstring {. - importc: "strstr", header: "".} - +from system/ansi_c import c_memchr, c_strstr func find*(s: cstring, sub: char, start: Natural = 0, last = 0): int = ## Searches for `sub` in `s` inside the range `start..last` (both ends included). @@ -91,7 +87,7 @@ func find*(s: cstring, sub: char, start: Natural = 0, last = 0): int = let last = if last == 0: s.high else: last let L = last-start+1 if L > 0: - let found = c_memchr(s[start].unsafeAddr, sub, cast[csize_t](L)) + let found = c_memchr(s[start].unsafeAddr, cint(sub), cast[csize_t](L)) if not found.isNil: return cast[int](found) -% cast[int](s) return -1 diff --git a/lib/std/syncio.nim b/lib/std/syncio.nim index 5c97712a43..911bff276e 100644 --- a/lib/std/syncio.nim +++ b/lib/std/syncio.nim @@ -15,6 +15,8 @@ import std/formatfloat when defined(windows): import std/widestrs +from system/ansi_c import c_memchr + # ----------------- IO Part ------------------------------------------------ type CFile {.importc: "FILE", header: "", @@ -401,9 +403,6 @@ proc readLine*(f: File, line: var string): bool {.tags: [ReadIOEffect], ## `false` is returned `line` contains no new data. result = false - proc c_memchr(s: pointer, c: cint, n: csize_t): pointer {. - importc: "memchr", header: "".} - when defined(windows): proc readConsole(hConsoleInput: FileHandle, lpBuffer: pointer, nNumberOfCharsToRead: int32, @@ -491,7 +490,7 @@ proc readLine*(f: File, line: var string): bool {.tags: [ReadIOEffect], checkErr(f) break - let m = c_memchr(addr line[pos], '\L'.ord, cast[csize_t](sp)) + let m = c_memchr(addr line[pos], cint('\L'), cast[csize_t](sp)) if m != nil: # \l found: Could be our own or the one by fgets, in any case, we're done var last = cast[int](m) - cast[int](addr line[0]) diff --git a/lib/std/tasks.nim b/lib/std/tasks.nim index 7e59747f55..6082e9b43d 100644 --- a/lib/std/tasks.nim +++ b/lib/std/tasks.nim @@ -190,7 +190,7 @@ macro toTask*(e: typed{nkCall | nkInfix | nkPrefix | nkPostfix | nkCommand | nkC # passing by static parameters # so we pass them directly instead of passing by scratchObj callNode.add nnkExprEqExpr.newTree(formalParams[i][0], e[i]) - of nnkSym, nnkPtrTy, nnkProcTy, nnkTupleConstr: + of nnkSym, nnkPtrTy, nnkProcTy, nnkTupleTy, nnkTupleConstr: addAllNode(param, e[i]) of nnkCharLit..nnkNilLit: callNode.add nnkExprEqExpr.newTree(formalParams[i][0], e[i]) diff --git a/lib/std/varints.nim b/lib/std/varints.nim index 88144a06c1..7adab9c37c 100644 --- a/lib/std/varints.nim +++ b/lib/std/varints.nim @@ -107,15 +107,9 @@ proc writeVu64*(z: var openArray[byte], x: uint64): int = varintWrite32(toOpenArray(z, 5, 8), y) return 9 -proc sar(a, b: int64): int64 {.noinit.} = - {.emit: [result, " = ", a, " >> ", b, ";"].} - -proc sal(a, b: int64): int64 {.noinit.} = - {.emit: [result, " = ", a, " << ", b, ";"].} - proc encodeZigzag*(x: int64): uint64 {.inline.} = - uint64(sal(x, 1)) xor uint64(sar(x, 63)) + let xu = uint64(x) + (xu shl 1) xor (xu shr 63) proc decodeZigzag*(x: uint64): int64 {.inline.} = - let casted = cast[int64](x) - result = (`shr`(casted, 1)) xor (-(casted and 1)) + cast[int64]((x shr 1) xor (x shl 63)) diff --git a/lib/system/ansi_c.nim b/lib/system/ansi_c.nim index 3098e17d69..ed1a8aedf1 100644 --- a/lib/system/ansi_c.nim +++ b/lib/system/ansi_c.nim @@ -27,6 +27,8 @@ proc c_strcmp*(a, b: cstring): cint {. importc: "strcmp", header: "", noSideEffect.} proc c_strlen*(a: cstring): csize_t {. importc: "strlen", header: "", noSideEffect.} +proc c_strstr*(haystack, needle: cstring): cstring {. + importc: "strstr", header: "", noSideEffect.} proc c_abort*() {. importc: "abort", header: "", noSideEffect, noreturn.} @@ -76,19 +78,14 @@ elif defined(haiku): SIGTERM* = cint(15) SIGPIPE* = cint(7) SIG_DFL* = CSighandlerT(nil) -else: - when defined(nimscript): - {.error: "SIGABRT not ported to your platform".} - else: - var - SIGINT* {.importc: "SIGINT", nodecl.}: cint - SIGSEGV* {.importc: "SIGSEGV", nodecl.}: cint - SIGABRT* {.importc: "SIGABRT", nodecl.}: cint - SIGFPE* {.importc: "SIGFPE", nodecl.}: cint - SIGILL* {.importc: "SIGILL", nodecl.}: cint - SIG_DFL* {.importc: "SIG_DFL", nodecl.}: CSighandlerT - when defined(macosx) or defined(linux): - var SIGPIPE* {.importc: "SIGPIPE", nodecl.}: cint +elif not defined(nimscript): + var + SIGINT* {.importc: "SIGINT", nodecl.}: cint + SIGSEGV* {.importc: "SIGSEGV", nodecl.}: cint + SIGABRT* {.importc: "SIGABRT", nodecl.}: cint + SIGFPE* {.importc: "SIGFPE", nodecl.}: cint + SIGILL* {.importc: "SIGILL", nodecl.}: cint + SIG_DFL* {.importc: "SIG_DFL", nodecl.}: CSighandlerT when defined(macosx): const SIGBUS* = cint(10) diff --git a/readme.md b/readme.md index 88f0b05d89..69899da71b 100644 --- a/readme.md +++ b/readme.md @@ -202,7 +202,7 @@ Nim. You are explicitly permitted to develop commercial applications using Nim. Please read the [copying.txt](copying.txt) file for more details. -Copyright © 2006-2024 Andreas Rumpf, all rights reserved. +Copyright © 2006-2025 Andreas Rumpf, all rights reserved. [nim-site]: https://nim-lang.org [nim-forum]: https://forum.nim-lang.org