Merge branch 'devel' into pr-remove-encode-overload

This commit is contained in:
AmjadHD
2022-09-21 23:40:48 +01:00
47 changed files with 599 additions and 415 deletions

View File

@@ -2,6 +2,7 @@
## Changes affecting backward compatibility
- `httpclient.contentLength` default to `-1` if the Content-Length header is not set in the response, it followed Apache HttpClient(Java), http(go) and .Net HttpWebResponse(C#) behavior. Previously raise `ValueError`.
- `addr` is now available for all addressable locations,
`unsafeAddr` is now deprecated and an alias for `addr`.
@@ -26,16 +27,26 @@
- `shallowCopy` is removed for ARC/ORC. Use `move` when possible or combine assignment and
`sink` for optimization purposes.
- `nimPreviewDotLikeOps` is going to be removed or deprecated.
- The `nimPreviewDotLikeOps` define is going to be removed or deprecated.
- The `{.this.}` pragma, deprecated since 0.19, has been removed.
- `nil` is no longer a valid value for distinct pointer types.
- `nil` literals can no longer be directly assigned to variables or fields of `distinct` pointer types. They must be converted instead.
```nim
type Foo = distinct ptr int
# Before:
var x: Foo = nil
# After:
var x: Foo = Foo(nil)
```
- Removed two type pragma syntaxes deprecated since 0.20, namely
`type Foo = object {.final.}`, and `type Foo {.final.} [T] = object`.
- [Overloadable enums](https://nim-lang.github.io/Nim/manual_experimental.html#overloadable-enum-value-names)
are no longer experimental.
- Removed the `nimIncrSeqV3` define.
- Static linking against OpenSSL versions below 1.1, previously done by
setting `-d:openssl10`, is no longer supported.
@@ -69,6 +80,13 @@
in `jscore` for JavaScript targets.
- Added `UppercaseLetters`, `LowercaseLetters`, `PunctuationChars`, `PrintableChars` sets to `std/strutils`.
- Added `complex.sgn` for obtaining the phase of complex numbers.
- Added `insertAdjacentText`, `insertAdjacentElement`, `insertAdjacentHTML`,
`after`, `before`, `closest`, `append`, `hasAttributeNS`, `removeAttributeNS`,
`hasPointerCapture`, `releasePointerCapture`, `requestPointerLock`,
`replaceChildren`, `replaceWith`, `scrollIntoViewIfNeeded`, `setHTML`,
`toggleAttribute`, and `matches` to `std/dom`.
- Added [`jsre.hasIndices`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/hasIndices)
- Added `capacity` for `string` and `seq` to return the current capacity, see https://github.com/nim-lang/RFCs/issues/460
[//]: # "Deprecations:"
- Deprecated `selfExe` for Nimscript.
@@ -137,10 +155,10 @@
added to make this work explicitly, and a warning is generated in the case
where it is implicit. This behavior only applies to templates, redefinition
is generally disallowed for other symbols.
- A new form of type inference called [top-down inference](https://nim-lang.github.io/Nim/manual_experimental.html#topminusdown-type-inference)
has been implemented for a variety of basic cases. For example, code like the following now compiles:
```nim
let foo: seq[(float, byte, cstring)] = @[(1, 2, "abc")]
```
@@ -153,7 +171,7 @@
- The `gc` switch has been renamed to `mm` ("memory management") in order to reflect the
reality better. (Nim moved away from all techniques based on "tracing".)
- Defines the `gcRefc` symbol which allows writing specific code for the refc GC.
- `nim` can now compile version 1.4.0 as follows: `nim c --lib:lib --stylecheck:off compiler/nim`,
@@ -171,4 +189,3 @@
- Nim now supports Nimble version 0.14 which added support for lock-files. This is done by
a simple configuration change setting that you can do yourself too. In `$nim/config/nim.cfg`
replace `pkgs` by `pkgs2`.

View File

@@ -1280,7 +1280,7 @@ proc genTypeInfo2Name(m: BModule; t: PType): Rope =
var it = t
while it != nil:
it = it.skipTypes(skipPtrs)
if it.sym != nil:
if it.sym != nil and tfFromGeneric notin it.flags:
var m = it.sym.owner
while m != nil and m.kind != skModule: m = m.owner
if m == nil or sfSystemModule in m.flags:

View File

@@ -70,7 +70,7 @@ proc initDefines*(symbols: StringTableRef) =
defineSymbol("nimVmExportFixed") # deadcode
defineSymbol("nimHasSymOwnerInMacro") # deadcode
defineSymbol("nimNewRuntime") # deadcode
defineSymbol("nimIncrSeqV3") # xxx: turn this into deadcode
defineSymbol("nimIncrSeqV3") # deadcode
defineSymbol("nimAshr") # deadcode
defineSymbol("nimNoNilSeqs") # deadcode
defineSymbol("nimNoNilSeqs2") # deadcode

View File

@@ -971,12 +971,12 @@ proc genBlock(p: PProc, n: PNode, r: var TCompRes) =
sym.loc.k = locOther
sym.position = idx+1
let labl = p.unique
lineF(p, "Label$1: do {$n", [labl.rope])
lineF(p, "Label$1: {$n", [labl.rope])
setLen(p.blocks, idx + 1)
p.blocks[idx].id = - p.unique # negative because it isn't used yet
gen(p, n[1], r)
setLen(p.blocks, idx)
lineF(p, "} while (false);$n", [labl.rope])
lineF(p, "};$n", [labl.rope])
proc genBreakStmt(p: PProc, n: PNode) =
var idx: int
@@ -2426,9 +2426,9 @@ proc genProcBody(p: PProc, prc: PSym): Rope =
else:
result = nil
if p.beforeRetNeeded:
result.add p.indentLine(~"BeforeRet: do {$n")
result.add p.indentLine(~"BeforeRet: {$n")
result.add p.body
result.add p.indentLine(~"} while (false);$n")
result.add p.indentLine(~"};$n")
else:
result.add(p.body)
if prc.typ.callConv == ccSysCall:

View File

@@ -93,6 +93,7 @@ proc nep1CheckDefImpl(conf: ConfigRef; info: TLineInfo; s: PSym; k: TSymKind) =
template styleCheckDef*(ctx: PContext; info: TLineInfo; sym: PSym; k: TSymKind) =
## Check symbol definitions adhere to NEP1 style rules.
if optStyleCheck in ctx.config.options and # ignore if styleChecks are off
{optStyleHint, optStyleError} * ctx.config.globalOptions != {} and # check only if hint/error is enabled
hintName in ctx.config.notes and # ignore if name checks are not requested
ctx.config.belongsToProjectPackage(ctx.module) and # ignore foreign packages
optStyleUsages notin ctx.config.globalOptions and # ignore if requested to only check name usage

View File

@@ -11,6 +11,7 @@ define:nimPreviewSlimSystem
@if windows:
cincludes: "$lib/wrappers/libffi/common"
tlsEmulation:off
@end
define:useStdoutAsStdmsg

View File

@@ -86,8 +86,12 @@ proc newRope(data: string = ""): Rope =
result.L = -data.len
result.data = data
var
cache {.threadvar.} : array[0..2048*2 - 1, Rope]
when compileOption("tlsEmulation"): # fixme: be careful if you want to make ropes support multiple threads
var
cache: array[0..2048*2 - 1, Rope]
else:
var
cache {.threadvar.} : array[0..2048*2 - 1, Rope]
proc resetRopeCache* =
for i in low(cache)..high(cache):

View File

@@ -54,7 +54,8 @@ iterator instantiateGenericParamList(c: PContext, n: PNode, pt: TIdTable): PSym
# later by semAsgn in return type inference scenario
t = q.typ
else:
localError(c.config, a.info, errCannotInstantiateX % s.name.s)
if q.typ.kind != tyCompositeTypeClass:
localError(c.config, a.info, errCannotInstantiateX % s.name.s)
t = errorType(c)
elif t.kind in {tyGenericParam, tyConcept}:
localError(c.config, a.info, errCannotInstantiateX % q.name.s)

View File

@@ -139,6 +139,9 @@ proc discardCheck(c: PContext, result: PNode, flags: TExprFlags) =
var n = newNodeI(nkDiscardStmt, result.info, 1)
n[0] = result
elif result.typ.kind != tyError and c.config.cmd != cmdInteractive:
if result.typ.kind == tyNone:
localError(c.config, result.info, "expression has no type: " &
renderTree(result, {renderNoComments}))
var n = result
while n.kind in skipForDiscardable:
if n.kind == nkTryStmt: n = n[0]

View File

@@ -169,6 +169,9 @@ nimblepath="$home/.nimble/pkgs/"
# Configuration for the GNU C/C++ compiler:
@if windows:
#gcc.path = r"$nim\dist\mingw\bin"
@if gcc or tcc:
tlsEmulation:on
@end
@end
gcc.maxerrorsimpl = "-fmax-errors=3"

View File

@@ -1,38 +1,38 @@
The documentation consists of several documents:
- | `Tutorial (part I) <tut1.html>`_
- | [Tutorial (part I)](tut1.html)
| The Nim tutorial part one deals with the basics.
- | `Tutorial (part II) <tut2.html>`_
- | [Tutorial (part II)](tut2.html)
| The Nim tutorial part two deals with the advanced language constructs.
- | `Tutorial (part III) <tut3.html>`_
- | [Tutorial (part III)](tut3.html)
| The Nim tutorial part three about Nim's macro system.
- | `Language Manual <manual.html>`_
- | [Language Manual](manual.html)
| The Nim manual is a draft that will evolve into a proper specification.
- | `Library documentation <lib.html>`_
- | [Library documentation](lib.html)
| This document describes Nim's standard library.
- | `Compiler user guide <nimc.html>`_
- | [Compiler user guide](nimc.html)
| The user guide lists command line arguments, special features of the
compiler, etc.
- | `Tools documentation <tools.html>`_
- | [Tools documentation](tools.html)
| Description of some tools that come with the standard distribution.
- | `Memory management <mm.html>`_
- | [Memory management](mm.html)
| Additional documentation about Nim's memory management strategies
| and how to operate them in a realtime setting.
- | `Source code filters <filters.html>`_
- | [Source code filters](filters.html)
| The Nim compiler supports source code filters as a simple yet powerful
builtin templating system.
- | `Internal documentation <intern.html>`_
- | [Internal documentation](intern.html)
| The internal documentation describes how the compiler is implemented. Read
this if you want to hack the compiler.
- | `Index <theindex.html>`_
- | [Index](theindex.html)
| The generated index. **Index + (Ctrl+F) == Joy**

View File

@@ -4,7 +4,7 @@ Documentation Style
General Guidelines
------------------
* See also `nep1<https://nim-lang.github.io/Nim/nep1.html>`_ which should probably be merged here.
* See also [nep1](nep1.html) which should probably be merged here.
* Authors should document anything that is exported; documentation for private
procs can be useful too (visible via `nim doc --docInternal foo.nim`:cmd:).
* Within documentation, a period (`.`) should follow each sentence (or sentence fragment) in a comment block.

View File

@@ -14,7 +14,7 @@ Introduction
============
This document describes the usage of the *DrNim* tool. DrNim combines
the Nim frontend with the `Z3 <https://github.com/Z3Prover/z3>`_ proof
the Nim frontend with the [Z3](https://github.com/Z3Prover/z3) proof
engine, in order to allow verify/validate software written in Nim.
DrNim's command-line options are the same as the Nim compiler's.

View File

@@ -12,19 +12,19 @@
> "yes, I'm the creator" -- Araq, 2013-07-26 19:28:32.
Note: this is mostly outdated, see instead `nimsuggest <nimsuggest.html>`_
Note: this is mostly outdated, see instead [nimsuggest](nimsuggest.html)
Nim differs from many other compilers in that it is really fast,
and being so fast makes it suited to provide external queries for
text editors about the source code being written. Through the
`idetools` command of `the compiler <nimc.html>`_, any IDE
`idetools` command of [the compiler](nimc.html), any IDE
can query a `.nim` source file and obtain useful information like
definition of symbols or suggestions for completion.
This document will guide you through the available options. If you
want to look at practical examples of idetools support you can look
at the test files found in the `Test suite`_ or `various editor
integrations <https://github.com/Araq/Nim/wiki/Editor-Support>`_
at the test files found in the [Test suite] or [various editor
integrations](https://github.com/Araq/Nim/wiki/Editor-Support)
already available.
@@ -124,8 +124,8 @@ to the case insensitiveness of the language (plus underscores as
separators!).
The typical usage scenario for this option is to call it after the
user has typed the dot character for `the object oriented call
syntax <tut2.html#object-oriented-programming-method-call-syntax>`_.
user has typed the dot character for [the object oriented call
syntax](tut2.html#object-oriented-programming-method-call-syntax).
Idetools will try to return the suggestions sorted first by scope
(from innermost to outermost) and then by item name.
@@ -196,7 +196,7 @@ of text it thinks necessary plus an empty line to indicate the end
of the answer.
You can find examples of client/server communication in the idetools
tests found in the `Test suite`_.
tests found in the [Test suite].
Parsing idetools output
@@ -367,8 +367,8 @@ defined, since at that point in the file the parser hasn't processed
the full line yet. The signature will be returned complete in
posterior instances of the method.
Methods imply `dynamic dispatch
<tut2.html#object-oriented-programming-dynamic-dispatch>`_ and
Methods imply [dynamic dispatch](
tut2.html#object-oriented-programming-dynamic-dispatch) and
idetools performs a static analysis on the code. For this reason
idetools may not return the definition of the correct method you
are querying because it may be impossible to know until the code
@@ -590,7 +590,7 @@ All the `tests/caas/*.txt` files encode a session with the compiler:
modes, you can prefix a line with the mode and the line will be
processed only in that mode.
* The rest of the line is treated as a `regular expression <re.html>`_,
* The rest of the line is treated as a [regular expression](re.html),
so be careful escaping metacharacters like parenthesis.
Before the line is processed as a regular expression, some basic

View File

@@ -64,7 +64,7 @@ And for a debug version compatible with GDB:
The `koch`:cmd: program is Nim's maintenance script. It is a replacement for
make and shell scripting with the advantage that it is much more portable.
More information about its options can be found in the `koch <koch.html>`_
More information about its options can be found in the [koch](koch.html)
documentation.
@@ -105,7 +105,7 @@ current commit:
You can also bisect using custom options to build the compiler, for example if
you don't need a debug version of the compiler (which runs slower), you can replace
`./koch temp`:cmd: by explicit compilation command, see `Bootstrapping the compiler`_.
`./koch temp`:cmd: by explicit compilation command, see [Bootstrapping the compiler].
Building an instrumented compiler
@@ -269,7 +269,7 @@ Native debugging
Stepping through the compiler with a native debugger is a very powerful tool to
both learn and debug it. However, there is still the need to constrain when
breakpoints are triggered. The same methods as in `Debug logging`_ can be applied
breakpoints are triggered. The same methods as in [Debug logging] can be applied
here when combined with calls to the debug helpers `enteringDebugSection()`:nim:
and `exitingDebugSection()`:nim:.
@@ -309,7 +309,7 @@ The syntax tree consists of nodes which may have an arbitrary number of
children. Types and symbols are represented by other nodes, because they
may contain cycles. The AST changes its shape after semantic checking. This
is needed to make life easier for the code generators. See the "ast" module
for the type definitions. The `macros <macros.html>`_ module contains many
for the type definitions. The [macros](macros.html) module contains many
examples how the AST represents each syntactic structure.
@@ -324,7 +324,7 @@ ARC/ORC. The new runtime is active `when defined(nimV2)`.
Coding Guidelines
=================
* We follow Nim's official style guide, see `<nep1.html>`_.
* We follow Nim's official style guide, see [NEP1](nep1.html).
* Max line length is 100 characters.
* Provide spaces around binary operators if that enhances readability.
* Use a space after a colon, but not before it.
@@ -332,7 +332,7 @@ Coding Guidelines
pointers/references which start with `P`.
* Prefer `import package`:nim: over `from package import symbol`:nim:.
See also the `API naming design <apis.html>`_ document.
See also the [API naming design](apis.html) document.
Porting to new platforms
@@ -452,7 +452,7 @@ could stem from a complex expression:
receivesClosure(returnsDefaultCC[i])
```
A thunk would need to call 'returnsDefaultCC[i]' somehow and that would require
A thunk would need to call `returnsDefaultCC[i]` somehow and that would require
an *additional* closure generation... Ok, not really, but it requires to pass
the function to call. So we'd end up with 2 indirect calls instead of one.
Another much more severe problem with this solution is that it's not GC-safe

View File

@@ -48,16 +48,16 @@ csource command
---------------
The `csource`:idx: command builds the C sources for installation. It accepts
the same options as you would pass to the `boot command
<#commands-boot-command>`_.
the same options as you would pass to the [boot command](
#commands-boot-command).
temp command
------------
The temp command builds the Nim compiler but with a different final name
(`nim_temp`:cmd:), so it doesn't overwrite your normal compiler. You can use
this command to test different options, the same you would issue for the `boot
command <#commands-boot-command>`_.
this command to test different options, the same you would issue for the [boot
command](#commands-boot-command).
test command
------------
@@ -88,4 +88,4 @@ pdf command
The `pdf`:idx: command builds PDF versions of Nim documentation: Manual,
Tutorial and a few other documents. To run it one needs to
`install Latex/xelatex <https://www.latex-project.org/get>`_ first.
[install Latex/xelatex](https://www.latex-project.org/get) first.

View File

@@ -15,14 +15,14 @@ Pure libraries do not depend on any external ``*.dll`` or ``lib*.so`` binary
while impure libraries do. A wrapper is an impure library that is a very
low-level interface to a C library.
Read this `document <apis.html>`_ for a quick overview of the API design.
Read [this document](apis.html) for a quick overview of the API design.
Nimble
======
Nim's standard library only covers the basics, check
out `<https://nimble.directory/>`_ for a list of 3rd party packages.
out https://nimble.directory/ for a list of 3rd party packages.
Pure libraries
@@ -31,17 +31,17 @@ Pure libraries
Automatic imports
-----------------
* `system <system.html>`_
* [system](system.html)
Basic procs and operators that every program needs. It also provides IO
facilities for reading and writing text and binary files. It is imported
implicitly by the compiler. Do not import it directly. It relies on compiler
magic to work.
* `threads <threads.html>`_
* [threads](threads.html)
Basic Nim thread support. **Note:** This is part of the system module. Do not
import it explicitly. Enabled with `--threads:on`:option:.
* `channels_builtin <channels_builtin.html>`_
* [channels_builtin](channels_builtin.html)
Nim message passing support for threads. **Note:** This is part of the
system module. Do not import it explicitly. Enabled with `--threads:on`:option:.
@@ -49,40 +49,40 @@ Automatic imports
Core
----
* `atomics <atomics.html>`_
* [atomics](atomics.html)
Types and operations for atomic operations and lockless algorithms.
* `bitops <bitops.html>`_
* [bitops](bitops.html)
Provides a series of low-level methods for bit manipulation.
* `cpuinfo <cpuinfo.html>`_
* [cpuinfo](cpuinfo.html)
This module implements procs to determine the number of CPUs / cores.
* `endians <endians.html>`_
* [endians](endians.html)
This module contains helpers that deal with different byte orders.
* `lenientops <lenientops.html>`_
* [lenientops](lenientops.html)
Provides binary operators for mixed integer/float expressions for convenience.
* `locks <locks.html>`_
* [locks](locks.html)
Locks and condition variables for Nim.
* `macrocache <macrocache.html>`_
* [macrocache](macrocache.html)
Provides an API for macros to collect compile-time information across modules.
* `macros <macros.html>`_
* [macros](macros.html)
Contains the AST API and documentation of Nim for writing macros.
* `rlocks <rlocks.html>`_
* [rlocks](rlocks.html)
Reentrant locks for Nim.
* `typeinfo <typeinfo.html>`_
* [typeinfo](typeinfo.html)
Provides (unsafe) access to Nim's run-time type information.
* `typetraits <typetraits.html>`_
* [typetraits](typetraits.html)
This module defines compile-time reflection procs for working with types.
* `volatile <volatile.html>`_
* [volatile](volatile.html)
This module contains code for generating volatile loads and stores,
which are useful in embedded and systems programming.
@@ -90,169 +90,169 @@ Core
Algorithms
----------
* `algorithm <algorithm.html>`_
* [algorithm](algorithm.html)
This module implements some common generic algorithms like sort or binary search.
* `enumutils <enumutils.html>`_
* [enumutils](enumutils.html)
This module adds functionality for the built-in `enum` type.
* `sequtils <sequtils.html>`_
* [sequtils](sequtils.html)
This module implements operations for the built-in `seq` type
which were inspired by functional programming languages.
* `setutils <setutils.html>`_
* [setutils](setutils.html)
This module adds functionality for the built-in `set` type.
Collections
-----------
* `critbits <critbits.html>`_
* [critbits](critbits.html)
This module implements a *crit bit tree* which is an efficient
container for a sorted set of strings, or a sorted mapping of strings.
* `deques <deques.html>`_
* [deques](deques.html)
Implementation of a double-ended queue.
The underlying implementation uses a `seq`.
* `heapqueue <heapqueue.html>`_
* [heapqueue](heapqueue.html)
Implementation of a binary heap data structure that can be used as a priority queue.
* `intsets <intsets.html>`_
* [intsets](intsets.html)
Efficient implementation of a set of ints as a sparse bit set.
* `lists <lists.html>`_
* [lists](lists.html)
Nim linked list support. Contains singly and doubly linked lists and
circular lists ("rings").
* `options <options.html>`_
* [options](options.html)
The option type encapsulates an optional value.
* `packedsets <packedsets.html>`_
* [packedsets](packedsets.html)
Efficient implementation of a set of ordinals as a sparse bit set.
* `sets <sets.html>`_
* [sets](sets.html)
Nim hash set support.
* `tables <tables.html>`_
* [tables](tables.html)
Nim hash table support. Contains tables, ordered tables, and count tables.
String handling
---------------
* `cstrutils <cstrutils.html>`_
* [cstrutils](cstrutils.html)
Utilities for `cstring` handling.
* `editdistance <editdistance.html>`_
* [editdistance](editdistance.html)
This module contains an algorithm to compute the edit distance between two
Unicode strings.
* `encodings <encodings.html>`_
* [encodings](encodings.html)
Converts between different character encodings. On UNIX, this uses
the `iconv` library, on Windows the Windows API.
* `parseutils <parseutils.html>`_
* [parseutils](parseutils.html)
This module contains helpers for parsing tokens, numbers, identifiers, etc.
* `pegs <pegs.html>`_
* [pegs](pegs.html)
This module contains procedures and operators for handling PEGs.
* `punycode <punycode.html>`_
* [punycode](punycode.html)
Implements a representation of Unicode with the limited ASCII character subset.
* `ropes <ropes.html>`_
* [ropes](ropes.html)
This module contains support for a *rope* data type.
Ropes can represent very long strings efficiently;
in particular, concatenation is done in O(1) instead of O(n).
* `strbasics <strbasics.html>`_
* [strbasics](strbasics.html)
This module provides some high performance string operations.
* `strformat <strformat.html>`_
* [strformat](strformat.html)
Macro based standard string interpolation/formatting. Inspired by
Python's f-strings.
* `strmisc <strmisc.html>`_
* [strmisc](strmisc.html)
This module contains uncommon string handling operations that do not
fit with the commonly used operations in strutils.
* `strscans <strscans.html>`_
* [strscans](strscans.html)
This module contains a `scanf` macro for convenient parsing of mini languages.
* `strtabs <strtabs.html>`_
* [strtabs](strtabs.html)
The `strtabs` module implements an efficient hash table that is a mapping
from strings to strings. Supports a case-sensitive, case-insensitive and
style-insensitive modes.
* `strutils <strutils.html>`_
* [strutils](strutils.html)
This module contains common string handling operations like changing
case of a string, splitting a string into substrings, searching for
substrings, replacing substrings.
* `unicode <unicode.html>`_
* [unicode](unicode.html)
This module provides support to handle the Unicode UTF-8 encoding.
* `unidecode <unidecode.html>`_
* [unidecode](unidecode.html)
It provides a single proc that does Unicode to ASCII transliterations.
Based on Python's Unidecode module.
* `wordwrap <wordwrap.html>`_
* [wordwrap](wordwrap.html)
This module contains an algorithm to wordwrap a Unicode string.
Time handling
-------------
* `monotimes <monotimes.html>`_
* [monotimes](monotimes.html)
The `monotimes` module implements monotonic timestamps.
* `times <times.html>`_
* [times](times.html)
The `times` module contains support for working with time.
Generic Operating System Services
---------------------------------
* `distros <distros.html>`_
* [distros](distros.html)
This module implements the basics for OS distribution ("distro") detection
and the OS's native package manager.
Its primary purpose is to produce output for Nimble packages,
but it also contains the widely used **Distribution** enum
that is useful for writing platform-specific code.
See `packaging <packaging.html>`_ for hints on distributing Nim using OS packages.
See [packaging](packaging.html) for hints on distributing Nim using OS packages.
* `dynlib <dynlib.html>`_
* [dynlib](dynlib.html)
This module implements the ability to access symbols from shared libraries.
* `marshal <marshal.html>`_
* [marshal](marshal.html)
Contains procs for serialization and deserialization of arbitrary Nim
data structures.
* `memfiles <memfiles.html>`_
* [memfiles](memfiles.html)
This module provides support for memory-mapped files (Posix's `mmap`)
on the different operating systems.
* `os <os.html>`_
* [os](os.html)
Basic operating system facilities like retrieving environment variables,
reading command line arguments, working with directories, running shell
commands, etc.
* `osproc <osproc.html>`_
* [osproc](osproc.html)
Module for process communication beyond `os.execShellCmd`.
* `streams <streams.html>`_
* [streams](streams.html)
This module provides a stream interface and two implementations thereof:
the `FileStream` and the `StringStream` which implement the stream
interface for Nim file objects (`File`) and strings. Other modules
may provide other implementations for this standard stream interface.
* `terminal <terminal.html>`_
* [terminal](terminal.html)
This module contains a few procedures to control the *terminal*
(also called *console*). The implementation simply uses ANSI escape
sequences and does not depend on any other module.
* `tempfiles <tempfiles.html>`_
* [tempfiles](tempfiles.html)
This module provides some utils to generate temporary path names and
create temporary files and directories.
@@ -260,131 +260,131 @@ Generic Operating System Services
Math libraries
--------------
* `complex <complex.html>`_
* [complex](complex.html)
This module implements complex numbers and relevant mathematical operations.
* `fenv <fenv.html>`_
* [fenv](fenv.html)
Floating-point environment. Handling of floating-point rounding and
exceptions (overflow, zero-divide, etc.).
* `math <math.html>`_
* [math](math.html)
Mathematical operations like cosine, square root.
* `random <random.html>`_
* [random](random.html)
Fast and tiny random number generator.
* `rationals <rationals.html>`_
* [rationals](rationals.html)
This module implements rational numbers and relevant mathematical operations.
* `stats <stats.html>`_
* [stats](stats.html)
Statistical analysis.
* `sums <sums.html>`_
* [sums](sums.html)
Accurate summation functions.
* `sysrand <sysrand.html>`_
* [sysrand](sysrand.html)
Cryptographically secure pseudorandom number generator.
Internet Protocols and Support
------------------------------
* `asyncdispatch <asyncdispatch.html>`_
* [asyncdispatch](asyncdispatch.html)
This module implements an asynchronous dispatcher for IO operations.
* `asyncfile <asyncfile.html>`_
* [asyncfile](asyncfile.html)
This module implements asynchronous file reading and writing using
`asyncdispatch`.
* `asyncftpclient <asyncftpclient.html>`_
This module implements an asynchronous FTP client using the `asyncnet`
* `asyncftpclient](asyncftpclient.html)
[his module implements an asynchronous FTP client using the `asyncnet`
module.
* `asynchttpserver <asynchttpserver.html>`_
This module implements an asynchronous HTTP server using the `asyncnet`
* `asynchttpserver](asynchttpserver.html)
[his module implements an asynchronous HTTP server using the `asyncnet`
module.
* `asyncnet <asyncnet.html>`_
* [asyncnet](asyncnet.html)
This module implements asynchronous sockets based on the `asyncdispatch`
module.
* `asyncstreams <asyncstreams.html>`_
* [asyncstreams](asyncstreams.html)
This module provides `FutureStream` - a future that acts as a queue.
* `cgi <cgi.html>`_
* [cgi](cgi.html)
This module implements helpers for CGI applications.
* `cookies <cookies.html>`_
* [cookies](cookies.html)
This module contains helper procs for parsing and generating cookies.
* `httpclient <httpclient.html>`_
* [httpclient](httpclient.html)
This module implements a simple HTTP client which supports both synchronous
and asynchronous retrieval of web pages.
* `mimetypes <mimetypes.html>`_
* [mimetypes](mimetypes.html)
This module implements a mimetypes database.
* `nativesockets <nativesockets.html>`_
* [nativesockets](nativesockets.html)
This module implements a low-level sockets API.
* `net <net.html>`_
* [net](net.html)
This module implements a high-level sockets API. It replaces the
`sockets` module.
* `selectors <selectors.html>`_
* [selectors](selectors.html)
This module implements a selector API with backends specific to each OS.
Currently, epoll on Linux and select on other operating systems.
* `smtp <smtp.html>`_
* [smtp](smtp.html)
This module implements a simple SMTP client.
* `uri <uri.html>`_
* [uri](uri.html)
This module provides functions for working with URIs.
Threading
---------
* `threadpool <threadpool.html>`_
Implements Nim's `spawn <manual_experimental.html#parallel-amp-spawn>`_.
* [threadpool](threadpool.html)
Implements Nim's [spawn](manual_experimental.html#parallel-amp-spawn).
Parsers
-------
* `htmlparser <htmlparser.html>`_
* [htmlparser](htmlparser.html)
This module parses an HTML document and creates its XML tree representation.
* `json <json.html>`_
* [json](json.html)
High-performance JSON parser.
* `jsonutils <jsonutils.html>`_
* [jsonutils](jsonutils.html)
This module implements a hookable (de)serialization for arbitrary types.
* `lexbase <lexbase.html>`_
* [lexbase](lexbase.html)
This is a low-level module that implements an extremely efficient buffering
scheme for lexers and parsers. This is used by the diverse parsing modules.
* `parsecfg <parsecfg.html>`_
* [parsecfg](parsecfg.html)
The `parsecfg` module implements a high-performance configuration file
parser. The configuration file's syntax is similar to the Windows ``.ini``
format, but much more powerful, as it is not a line based parser. String
literals, raw string literals, and triple quote string literals are supported
as in the Nim programming language.
* `parsecsv <parsecsv.html>`_
* [parsecsv](parsecsv.html)
The `parsecsv` module implements a simple high-performance CSV parser.
* `parsejson <parsejson.html>`_
This module implements a JSON parser. It is used and exported by the `json <json.html>`_ module, but can also be used in its own right.
* [parsejson](parsejson.html)
This module implements a JSON parser. It is used and exported by the [json](json.html) module, but can also be used in its own right.
* `parseopt <parseopt.html>`_
* [parseopt](parseopt.html)
The `parseopt` module implements a command line option parser.
* `parsesql <parsesql.html>`_
* [parsesql](parsesql.html)
The `parsesql` module implements a simple high-performance SQL parser.
* `parsexml <parsexml.html>`_
* [parsexml](parsexml.html)
The `parsexml` module implements a simple high performance XML/HTML parser.
The only encoding that is supported is UTF-8. The parser has been designed
to be somewhat error-correcting, so that even some "wild HTML" found on the
@@ -394,37 +394,37 @@ Parsers
Docutils
--------
* `packages/docutils/highlite <highlite.html>`_
* [packages/docutils/highlite](highlite.html)
Source highlighter for programming or markup languages. Currently,
only a few languages are supported, other languages may be added.
The interface supports one language nested in another.
* `packages/docutils/rst <rst.html>`_
* [packages/docutils/rst](rst.html)
This module implements a reStructuredText parser. A large subset
is implemented. Some features of the markdown wiki syntax are also supported.
* `packages/docutils/rstast <rstast.html>`_
* [packages/docutils/rstast](rstast.html)
This module implements an AST for the reStructuredText parser.
* `packages/docutils/rstgen <rstgen.html>`_
* [packages/docutils/rstgen](rstgen.html)
This module implements a generator of HTML/Latex from reStructuredText.
XML Processing
--------------
* `xmltree <xmltree.html>`_
* [xmltree](xmltree.html)
A simple XML tree. More efficient and simpler than the DOM. It also
contains a macro for XML/HTML code generation.
* `xmlparser <xmlparser.html>`_
* [xmlparser](xmlparser.html)
This module parses an XML document and creates its XML tree representation.
Generators
----------
* `htmlgen <htmlgen.html>`_
* [htmlgen](htmlgen.html)
This module implements a simple XML and HTML code
generator. Each commonly used HTML tag has a corresponding macro
that generates a string with its HTML representation.
@@ -433,81 +433,81 @@ Generators
Hashing
-------
* `base64 <base64.html>`_
* [base64](base64.html)
This module implements a Base64 encoder and decoder.
* `hashes <hashes.html>`_
* [hashes](hashes.html)
This module implements efficient computations of hash values for diverse
Nim types.
* `md5 <md5.html>`_
* [md5](md5.html)
This module implements the MD5 checksum algorithm.
* `oids <oids.html>`_
* [oids](oids.html)
An OID is a global ID that consists of a timestamp,
a unique counter, and a random value. This combination should suffice to
produce a globally distributed unique ID. This implementation was extracted
from the MongoDB interface and it thus binary compatible with a MongoDB OID.
* `sha1 <sha1.html>`_
* [sha1](sha1.html)
This module implements the SHA-1 checksum algorithm.
Miscellaneous
-------------
* `browsers <browsers.html>`_
* [browsers](browsers.html)
This module implements procs for opening URLs with the user's default
browser.
* `colors <colors.html>`_
* [colors](colors.html)
This module implements color handling for Nim.
* `coro <coro.html>`_
* [coro](coro.html)
This module implements experimental coroutines in Nim.
* `enumerate <enumerate.html>`_
* [enumerate](enumerate.html)
This module implements `enumerate` syntactic sugar based on Nim's macro system.
* `logging <logging.html>`_
* [logging](logging.html)
This module implements a simple logger.
* `segfaults <segfaults.html>`_
* [segfaults](segfaults.html)
Turns access violations or segfaults into a `NilAccessDefect` exception.
* `sugar <sugar.html>`_
* [sugar](sugar.html)
This module implements nice syntactic sugar based on Nim's macro system.
* `unittest <unittest.html>`_
* [unittest](unittest.html)
Implements a Unit testing DSL.
* `varints <varints.html>`_
* [varints](varints.html)
Decode variable-length integers that are compatible with SQLite.
* `with <with.html>`_
* [with](with.html)
This module implements the `with` macro for easy function chaining.
Modules for the JS backend
--------------------------
* `asyncjs <asyncjs.html>`_
* [asyncjs](asyncjs.html)
Types and macros for writing asynchronous procedures in JavaScript.
* `dom <dom.html>`_
* [dom](dom.html)
Declaration of the Document Object Model for the JS backend.
* `jsbigints <jsbigints.html>`_
* [jsbigints](jsbigints.html)
Arbitrary precision integers.
* `jsconsole <jsconsole.html>`_
* [jsconsole](jsconsole.html)
Wrapper for the `console` object.
* `jscore <jscore.html>`_
* [jscore](jscore.html)
The wrapper of core JavaScript functions. For most purposes, you should be using
the `math`, `json`, and `times` stdlib modules instead of this module.
* `jsffi <jsffi.html>`_
* [jsffi](jsffi.html)
Types and macros for easier interaction with JavaScript.
@@ -517,7 +517,7 @@ Impure libraries
Regular expressions
-------------------
* `re <re.html>`_
* [re](re.html)
This module contains procedures and operators for handling regular
expressions. The current implementation uses PCRE.
@@ -525,15 +525,15 @@ Regular expressions
Database support
----------------
* `db_postgres <db_postgres.html>`_
* [db_postgres](db_postgres.html)
A higher level PostgreSQL database wrapper. The same interface is implemented
for other databases too.
* `db_mysql <db_mysql.html>`_
* [db_mysql](db_mysql.html)
A higher level MySQL database wrapper. The same interface is implemented
for other databases too.
* `db_sqlite <db_sqlite.html>`_
* [db_sqlite](db_sqlite.html)
A higher level SQLite database wrapper. The same interface is implemented
for other databases too.
@@ -541,7 +541,7 @@ Database support
Generic Operating System Services
---------------------------------
* `rdstdin <rdstdin.html>`_
* [rdstdin](rdstdin.html)
This module contains code for reading from stdin.
@@ -555,43 +555,43 @@ not contained in the distribution. You can then find them on the website.
Windows-specific
----------------
* `winlean <winlean.html>`_
* [winlean](winlean.html)
Contains a wrapper for a small subset of the Win32 API.
* `registry <registry.html>`_
* [registry](registry.html)
Windows registry support.
UNIX specific
-------------
* `posix <posix.html>`_
* [posix](posix.html)
Contains a wrapper for the POSIX standard.
* `posix_utils <posix_utils.html>`_
* [posix_utils](posix_utils.html)
Contains helpers for the POSIX standard or specialized for Linux and BSDs.
Regular expressions
-------------------
* `pcre <pcre.html>`_
* [pcre](pcre.html)
Wrapper for the PCRE library.
Database support
----------------
* `postgres <postgres.html>`_
* [postgres](postgres.html)
Contains a wrapper for the PostgreSQL API.
* `mysql <mysql.html>`_
* [mysql](mysql.html)
Contains a wrapper for the mySQL API.
* `sqlite3 <sqlite3.html>`_
* [sqlite3](sqlite3.html)
Contains a wrapper for the SQLite 3 API.
* `odbcsql <odbcsql.html>`_
* [odbcsql](odbcsql.html)
interface to the ODBC driver.
Network Programming and Internet Protocols
------------------------------------------
* `openssl <openssl.html>`_
* [openssl](openssl.html)
Wrapper for OpenSSL.

View File

@@ -4248,16 +4248,16 @@ observable differences in behavior:
```
However, the current implementation produces a warning in these cases.
There are different ways to deal with this warning:
1. Disable the warning via `{.push warning[ObservableStores]: off.}` ... `{.pop.}`.
Then one may need to ensure that `p` only raises *before* any stores to `result`
happen.
2. One can use a temporary helper variable, for example instead of `x = p(8)`
use `let tmp = p(8); x = tmp`.
The compiler can produce a warning in these cases, however this behavior is
turned off by default. It can be enabled for a section of code via the
`warning[ObservableStores]` and `push`/`pop` pragmas. Take the above code
as an example:
```nim
{.push warning[ObservableStores]: on.}
main()
{.pop.}
```
Overloading of the subscript operator
-------------------------------------
@@ -4331,7 +4331,7 @@ dispatching:
Unit = ref object of Thing
x: int
method collide(a, b: Thing) {.inline.} =
method collide(a, b: Thing) {.base, inline.} =
quit "to override!"
method collide(a: Thing, b: Unit) {.inline.} =
@@ -4636,7 +4636,7 @@ the "implicitly convertible" type relation (see [Convertible relation]):
A converter can also be explicitly invoked for improved readability. Note that
implicit converter chaining is not supported: If there is a converter from
type A to type B and from type B to type C the implicit conversion from A to C
type A to type B and from type B to type C, the implicit conversion from A to C
is not provided.
@@ -4810,8 +4810,8 @@ Instead of a `try finally` statement a `defer` statement can be used, which
avoids lexical nesting and offers more flexibility in terms of scoping as shown
below.
Any statements following the `defer` in the current block will be considered
to be in an implicit try block:
Any statements following the `defer` will be considered
to be in an implicit try block in the current block:
```nim test = "nim c $1"
proc main =
@@ -4834,7 +4834,7 @@ Is rewritten to:
```
When `defer` is at the outermost scope of a template/macro, its scope extends
to the block where the template is called from:
to the block where the template/macro is called from:
```nim test = "nim c $1"
template safeOpenDefer(f, path) =
@@ -5002,7 +5002,7 @@ possibly raised exceptions; the algorithm operates on `p`'s call graph:
The call is optimistically assumed to have no effect.
Rule 2 compensates for this case.
2. Every expression `e` of some proc type within a call that is passed to parameter
marked as `.effectsOf` is assumed to be called indirectly and thus
marked as `.effectsOf` of proc `p` is assumed to be called indirectly and thus
its raises list is added to `p`'s raises list.
3. Every call to a proc `q` which has an unknown body (due to a forward
declaration) is assumed to
@@ -5149,14 +5149,15 @@ procedure types without such lists:
## this will fail because toBeCalled1 uses MyEffect which was forbidden by ProcType1:
caller1(toBeCalled1)
## this is OK because both toBeCalled1 and ProcType1 have the same requirements:
## this is OK because both toBeCalled2 and ProcType1 have the same requirements:
caller1(toBeCalled2)
## these are OK because ProcType2 doesn't have any effect requirement:
caller2(toBeCalled1)
caller2(toBeCalled2)
```
`ProcType2` is a subtype of `ProcType1`. Unlike with tags, the parent context - the function which calls other functions with forbidden effects - doesn't inherit the forbidden list of effects.
`ProcType2` is a subtype of `ProcType1`. Unlike with the `tags` pragma, the parent context - the
function which calls other functions with forbidden effects - doesn't inherit the forbidden list of effects.
Side effects

View File

@@ -35,7 +35,7 @@ the involved heap sizes.
The reference counting operations (= "RC ops") do not use atomic instructions and do not have to --
instead entire subgraphs are *moved* between threads. The Nim compiler also aggressively
optimizes away RC ops and exploits `move semantics <destructors.html#move-semantics>`_.
optimizes away RC ops and exploits [move semantics](destructors.html#move-semantics).
Nim performs a fair share of optimizations for ARC/ORC; you can inspect what it did
to your time critical function via `--expandArc:functionName`.
@@ -62,7 +62,7 @@ Other MM modes
--mm:refc This is the default memory management strategy. It's a
deferred reference counting based garbage collector
with a simple Mark&Sweep backup GC in order to collect cycles. Heaps are thread-local.
`This document <refc.html>`_ contains further information.
[This document](refc.html) contains further information.
--mm:markAndSweep Simple Mark-And-Sweep based garbage collector.
Heaps are thread-local.
--mm:boehm Boehm based garbage collector, it offers a shared heap.
@@ -89,7 +89,7 @@ None Manual Manual Manual `--mm:none`
.. default-role:: code
.. include:: rstcommon.rst
JavaScript's garbage collector is used for the `JavaScript and NodeJS
<backends.html#backends-the-javascript-target>`_ compilation targets.
The `NimScript <nims.html>`_ target uses the memory management strategy built into
JavaScript's garbage collector is used for the [JavaScript and NodeJS](
backends.html#backends-the-javascript-target) compilation targets.
The [NimScript](nims.html) target uses the memory management strategy built into
the Nim compiler.

View File

@@ -21,7 +21,7 @@ library should follow.
Note that there can be exceptions to these rules. Nim being as flexible as it
is, there will be parts of this style guide that don't make sense in certain
contexts. Furthermore, just as
`Python's style guide<http://legacy.python.org/dev/peps/pep-0008/>`_ changes
[Python's style guide](http://legacy.python.org/dev/peps/pep-0008/) changes
over time, this style guide will too.
These rules will only be enforced for contributions to the Nim

View File

@@ -21,10 +21,10 @@ Introduction
This document describes the usage of the *Nim compiler*
on the different supported platforms. It is not a definition of the Nim
programming language (which is covered in the `manual <manual.html>`_).
programming language (which is covered in the [manual](manual.html)).
Nim is free software; it is licensed under the
`MIT License <http://www.opensource.org/licenses/mit-license.php>`_.
[MIT License](http://www.opensource.org/licenses/mit-license.php).
Compiler Usage
@@ -130,13 +130,13 @@ Level Description
===== ============================================
0 Minimal output level for the compiler.
1 Displays compilation of all the compiled files, including those imported
by other modules or through the `compile pragma
<manual.html#implementation-specific-pragmas-compile-pragma>`_.
by other modules or through the [compile pragma](
manual.html#implementation-specific-pragmas-compile-pragma).
This is the default level.
2 Displays compilation statistics, enumerates the dynamic
libraries that will be loaded by the final binary, and dumps to
standard output the result of applying `a filter to the source code
<filters.html>`_ if any filter was used during compilation.
standard output the result of applying [a filter to the source code](
filters.html) if any filter was used during compilation.
3 In addition to the previous levels dumps a debug stack trace
for compiler developers.
===== ============================================
@@ -147,16 +147,16 @@ Compile-time symbols
Through the `-d:x`:option: or `--define:x`:option: switch you can define compile-time
symbols for conditional compilation. The defined switches can be checked in
source code with the `when statement
<manual.html#statements-and-expressions-when-statement>`_ and
`defined proc <system.html#defined,untyped>`_. The typical use of this switch is
source code with the [when statement](
manual.html#statements-and-expressions-when-statement) and
[defined proc](system.html#defined,untyped). The typical use of this switch is
to enable builds in release mode (`-d:release`:option:) where optimizations are
enabled for better performance. Another common use is the `-d:ssl`:option: switch to
activate SSL sockets.
Additionally, you may pass a value along with the symbol: `-d:x=y`:option:
which may be used in conjunction with the `compile-time define
pragmas<manual.html#implementation-specific-pragmas-compileminustime-define-pragmas>`_
which may be used in conjunction with the [compile-time define
pragmas](manual.html#implementation-specific-pragmas-compileminustime-define-pragmas)
to override symbols during build time.
Compile-time symbols are completely **case insensitive** and underscores are
@@ -268,7 +268,7 @@ The `_r` suffix is used for release builds, `_d` is for debug builds.
This makes it easy to delete all generated files.
The `--nimcache`:option:
`compiler switch <#compiler-usage-commandminusline-switches>`_ can be used to
[compiler switch][command-line switches] can be used to
to change the ``nimcache`` directory.
However, the generated C code is not platform-independent. C code generated for
@@ -355,7 +355,7 @@ There are two ways to compile for Android: terminal programs (Termux) and with
the NDK (Android Native Development Kit).
The first one is to treat Android as a simple Linux and use
`Termux <https://wiki.termux.com>`_ to connect and run the Nim compiler
[Termux](https://wiki.termux.com) to connect and run the Nim compiler
directly on android as if it was Linux. These programs are console-only
programs that can't be distributed in the Play Store.
@@ -363,8 +363,8 @@ Use regular `nim c`:cmd: inside termux to make Android terminal programs.
Normal Android apps are written in Java, to use Nim inside an Android app
you need a small Java stub that calls out to a native library written in
Nim using the `NDK <https://developer.android.com/ndk>`_. You can also use
`native-activity <https://developer.android.com/ndk/samples/sample_na>`_
Nim using the [NDK](https://developer.android.com/ndk). You can also use
[native-activity](https://developer.android.com/ndk/samples/sample_na)
to have the Java stub be auto-generated for you.
Use `nim c -c --cpu:arm --os:android -d:androidNDK --noMain:on`:cmd: to
@@ -444,8 +444,8 @@ or setup a ``nim.cfg`` file like so::
--passL="-specs=$DEVKITPRO/libnx/switch.specs -L$DEVKITPRO/libnx/lib -lnx"
The devkitPro setup must be the same as the default with their new installer
`here for Mac/Linux <https://github.com/devkitPro/pacman/releases>`_ or
`here for Windows <https://github.com/devkitPro/installer/releases>`_.
[here for Mac/Linux](https://github.com/devkitPro/pacman/releases) or
[here for Windows](https://github.com/devkitPro/installer/releases).
For example, with the above-mentioned config:
@@ -455,7 +455,7 @@ For example, with the above-mentioned config:
This will generate a file called ``switchhomebrew.elf`` which can then be turned into
an nro file with the `elf2nro`:cmd: tool in the devkitPro release. Examples can be found at
`the nim-libnx github repo <https://github.com/jyapayne/nim-libnx.git>`_.
[the nim-libnx github repo](https://github.com/jyapayne/nim-libnx.git).
There are a few things that don't work because the devkitPro libraries don't support them.
They are:
@@ -512,7 +512,7 @@ Define Effect
This only works with `--mm:none`:option:,
`--mm:arc`:option: and `--mm:orc`:option:.
`useRealtimeGC` Enables support of Nim's GC for *soft* realtime
systems. See the documentation of the `mm <mm.html>`_
systems. See the documentation of the [mm](mm.html)
for further information.
`logGC` Enable GC logging to stdout.
`nodejs` The JS target is actually ``node.js``.
@@ -591,7 +591,7 @@ The typical compiler usage involves using the `compile`:option: or `c`:option:
command to transform a ``.nim`` file into one or more ``.c`` files which are then
compiled with the platform's C compiler into a static binary. However, there
are other commands to compile to C++, Objective-C, or JavaScript. More details
can be read in the `Nim Backend Integration document <backends.html>`_.
can be read in the [Nim Backend Integration document](backends.html).
Nim documentation tools
@@ -599,13 +599,13 @@ Nim documentation tools
Nim provides the `doc`:idx: command to generate HTML
documentation from ``.nim`` source files. Only exported symbols will appear in
the output. For more details `see the docgen documentation <docgen.html>`_.
the output. For more details see [the docgen documentation](docgen.html).
Nim idetools integration
========================
Nim provides language integration with external IDEs through the
idetools command. See the documentation of `idetools <idetools.html>`_
idetools command. See the documentation of [idetools](idetools.html)
for further information.
..
@@ -666,7 +666,7 @@ The `--opt:size`:option: flag instructs Nim to optimize code generation for smal
size (with the help of the C compiler), the `-flto`:option: flags enable link-time
optimization in the compiler and linker.
Check the `Cross-compilation`_ section for instructions on how to compile the
Check the [Cross-compilation] section for instructions on how to compile the
program for your target.
@@ -717,8 +717,8 @@ Currently only Zephyr and FreeRTOS support these configurations.
Nim for realtime systems
========================
See the `--mm:arc` or `--mm:orc` memory management settings in `MM <mm.html>`_ for further
information.
See the `--mm:arc` or `--mm:orc` memory management settings in
[MM](mm.html) for further information.
Signal handling in Nim

View File

@@ -14,7 +14,7 @@ Introduction
niminst is a tool to generate an installer for a Nim program. Currently
it can create an installer for Windows
via `Inno Setup <http://www.jrsoftware.org/isinfo.php>`_ as well as
via [Inno Setup](http://www.jrsoftware.org/isinfo.php) as well as
installation/deinstallation scripts for UNIX. Later versions will support
Linux' package management systems.
@@ -26,7 +26,7 @@ systems.
Configuration file
==================
niminst uses the Nim `parsecfg <parsecfg.html>`_ module to parse the
niminst uses the Nim [parsecfg](parsecfg.html) module to parse the
configuration file. Here's an example of how the syntax looks like:
.. include:: mytest.cfg

View File

@@ -29,7 +29,7 @@ previous settings):
``$project.nim``. This file can be skipped with the same
`--skipProjCfg`:option: command line option.
For available procs and implementation details see `nimscript <nimscript.html>`_.
For available procs and implementation details see [nimscript](nimscript.html).
Limitations
@@ -61,52 +61,53 @@ Standard library modules
At least the following standard library modules are available:
* `macros <macros.html>`_
* `os <os.html>`_
* `strutils <strutils.html>`_
* `math <math.html>`_
* `distros <distros.html>`_
* `sugar <sugar.html>`_
* `algorithm <algorithm.html>`_
* `base64 <base64.html>`_
* `bitops <bitops.html>`_
* `chains <chains.html>`_
* `colors <colors.html>`_
* `complex <complex.html>`_
* `htmlgen <htmlgen.html>`_
* `httpcore <httpcore.html>`_
* `lenientops <lenientops.html>`_
* `mersenne <mersenne.html>`_
* `options <options.html>`_
* `parseutils <parseutils.html>`_
* `punycode <punycode.html>`_
* `random <punycode.html>`_
* `stats <stats.html>`_
* `strformat <strformat.html>`_
* `strmisc <strmisc.html>`_
* `strscans <strscans.html>`_
* `unicode <unicode.html>`_
* `uri <uri.html>`_
* `std/editdistance <editdistance.html>`_
* `std/wordwrap <wordwrap.html>`_
* `std/sums <sums.html>`_
* `parsecsv <parsecsv.html>`_
* `parsecfg <parsecfg.html>`_
* `parsesql <parsesql.html>`_
* `xmlparser <xmlparser.html>`_
* `htmlparser <htmlparser.html>`_
* `ropes <ropes.html>`_
* `json <json.html>`_
* `parsejson <parsejson.html>`_
* `strtabs <strtabs.html>`_
* `unidecode <unidecode.html>`_
* [macros](macros.html)
* [os](os.html)
* [strutils](strutils.html)
* [math](math.html)
* [distros](distros.html)
* [sugar](sugar.html)
* [algorithm](algorithm.html)
* [base64](base64.html)
* [bitops](bitops.html)
* [chains](chains.html)
* [colors](colors.html)
* [complex](complex.html)
* [htmlgen](htmlgen.html)
* [httpcore](httpcore.html)
* [lenientops](lenientops.html)
* [mersenne](mersenne.html)
* [options](options.html)
* [parseutils](parseutils.html)
* [punycode](punycode.html)
* [random](punycode.html)
* [stats](stats.html)
* [strformat](strformat.html)
* [strmisc](strmisc.html)
* [strscans](strscans.html)
* [unicode](unicode.html)
* [uri](uri.html)
* [std/editdistance](editdistance.html)
* [std/wordwrap](wordwrap.html)
* [std/sums](sums.html)
* [parsecsv](parsecsv.html)
* [parsecfg](parsecfg.html)
* [parsesql](parsesql.html)
* [xmlparser](xmlparser.html)
* [htmlparser](htmlparser.html)
* [ropes](ropes.html)
* [json](json.html)
* [parsejson](parsejson.html)
* [strtabs](strtabs.html)
* [unidecode](unidecode.html)
In addition to the standard Nim syntax (`system <system.html>`_ module),
In addition to the standard Nim syntax ([system](system.html) module),
NimScripts support the procs and templates defined in the
`nimscript <nimscript.html>`_ module too.
[nimscript](nimscript.html) module too.
See also:
* `Check the tests for more information about modules compatible with NimScript. <https://github.com/nim-lang/Nim/blob/devel/tests/test_nimscript.nims>`_
* [Check the tests for more information about modules compatible with NimScript](
https://github.com/nim-lang/Nim/blob/devel/tests/test_nimscript.nims)
NimScript as a configuration file
@@ -169,14 +170,14 @@ Task Description
========= ===================================================
Look at the module `distros <distros.html>`_ for some support of the
Look at the module [distros](distros.html) for some support of the
OS's native package managers.
Nimble integration
==================
See the `Nimble readme <https://github.com/nim-lang/nimble#readme>`_
See the [Nimble readme](https://github.com/nim-lang/nimble#readme)
for more information.
@@ -297,7 +298,7 @@ translations.cfg
```
* `Nimterlingua <https://nimble.directory/pkg/nimterlingua>`_
* [Nimterlingua](https://nimble.directory/pkg/nimterlingua)
Graceful Fallback
@@ -329,14 +330,15 @@ Evolving Scripting language
---------------------------
NimScript evolves together with Nim,
`occasionally new features might become available on NimScript <https://github.com/nim-lang/Nim/pulls?utf8=%E2%9C%93&q=nimscript>`_ ,
[occasionally new features might become available on NimScript](
https://github.com/nim-lang/Nim/pulls?utf8=%E2%9C%93&q=nimscript),
adapted from compiled Nim or added as new features on both.
Scripting Language with a Package Manager
-----------------------------------------
You can create your own modules to be compatible with NimScript,
and check `Nimble <https://nimble.directory>`_
and check [Nimble](https://nimble.directory)
to search for third party modules that may work on NimScript.
DevOps Scripting
@@ -345,4 +347,5 @@ DevOps Scripting
You can use NimScript to deploy to production, run tests, build projects, do benchmarks,
generate documentation, and all kinds of DevOps/SysAdmin specific tasks.
* `An example of a third party NimScript that can be used as a project-agnostic tool. <https://github.com/kaushalmodi/nim_config#list-available-tasks>`_
* [An example of a third party NimScript that can be used as a project-agnostic
tool.](https://github.com/kaushalmodi/nim_config#list-available-tasks)

View File

@@ -20,7 +20,7 @@ definition of symbols or suggestions for completion.
This document will guide you through the available options. If you
want to look at practical examples of nimsuggest support you can look
at the
`various editor integrations <https://github.com/Araq/Nim/wiki/Editor-Support>`_
[various editor integrations](https://github.com/Araq/Nim/wiki/Editor-Support)
already available.
@@ -49,7 +49,7 @@ via sockets is more reasonable so that is the default. It listens to port 6000
by default.
Nimsuggest is basically a frontend for the nim compiler so `--path`:option: flags and
`config files <https://nim-lang.org/docs/nimc.html#compiler-usage-configuration-files>`_
[config files](https://nim-lang.org/docs/nimc.html#compiler-usage-configuration-files)
can be used to specify additional dependencies like
`nimsuggest --stdin --debug --path:"dependencies" myproject.nim`:cmd:.
@@ -113,8 +113,8 @@ The `sug` Nimsuggest command performs a query about possible
completion symbols at some point in the file.
The typical usage scenario for this option is to call it after the
user has typed the dot character for `the object oriented call
syntax <tut2.html#object-oriented-programming-method-call-syntax>`_.
user has typed the dot character for [the object oriented call
syntax](tut2.html#object-oriented-programming-method-call-syntax).
Nimsuggest will try to return the suggestions sorted first by scope
(from innermost to outermost) and then by item name.

View File

@@ -4,9 +4,9 @@ Packaging Nim
This page provide hints on distributing Nim using OS packages.
See `distros <distros.html>`_ for tools to detect Linux distribution at runtime.
See [distros](distros.html) for tools to detect Linux distribution at runtime.
See `here <intern.html#bootstrapping-the-compiler-reproducible-builds>`_ for how to
See [here](intern.html#bootstrapping-the-compiler-reproducible-builds) for how to
compile reproducible builds.
Supported architectures

View File

@@ -121,7 +121,7 @@ Keeping track of memory
If you need to pass around memory allocated by Nim to C, you can use the
procs `GC_ref` and `GC_unref` to mark objects as referenced to avoid them
being freed by the garbage collector.
Other useful procs from `system <system.html>`_ you can use to keep track of memory are:
Other useful procs from [system](system.html) you can use to keep track of memory are:
* `getTotalMem()` Returns the amount of total memory managed by the garbage collector.
* `getOccupiedMem()` Bytes reserved by the garbage collector and used by objects.

View File

@@ -6,7 +6,7 @@ Nim has two flavors of parallelism:
1) `Structured`:idx parallelism via the ``parallel`` statement.
2) `Unstructured`:idx: parallelism via the standalone ``spawn`` statement.
Both need the `threadpool <threadpool.html>`_ module to work.
Both need the [threadpool](threadpool.html) module to work.
Somewhat confusingly, ``spawn`` is also used in the ``parallel`` statement
with slightly different semantics. ``spawn`` always takes a call expression of

View File

@@ -9,7 +9,7 @@
Testament is an advanced automatic unittests runner for Nim tests, is used for the development of Nim itself,
offers process isolation for your tests, it can generate statistics about test cases,
supports multiple targets (C, C++, ObjectiveC, JavaScript, etc.),
simulated `Dry-Runs <https://en.wikipedia.org/wiki/Dry_run_(testing)>`_,
simulated [Dry-Runs](https://en.wikipedia.org/wiki/Dry_run_(testing)),
has logging, can generate HTML reports, skip tests from a file, and more,
so can be useful to run your tests, even the most complex ones.
@@ -185,8 +185,10 @@ Example "template" **to edit** and write a Testament unittest:
* As you can see the "Spec" is just a `discard """ """`.
* Spec has sane defaults, so you don't need to provide them all, any simple assert will work just fine.
* `This is not the full spec of Testament, check the Testament Spec on GitHub, see parseSpec(). <https://github.com/nim-lang/Nim/blob/devel/testament/specs.nim#L238>`_
* `Nim itself uses Testament, so there are plenty of test examples. <https://github.com/nim-lang/Nim/tree/devel/tests>`_
* This is not the full spec of Testament, check [the Testament Spec on GitHub,
see parseSpec()](https://github.com/nim-lang/Nim/blob/devel/testament/specs.nim#L315).
* Nim itself uses Testament, so [there are plenty of test examples](
https://github.com/nim-lang/Nim/tree/devel/tests).
* Has some built-in CI compatibility, like Azure Pipelines, etc.
@@ -195,11 +197,10 @@ Inline hints, warnings and errors (notes)
Testing the line, column, kind and message of hints, warnings and errors can
be written inline like so:
.. code-block:: nim
```nim
{.warning: "warning!!"} #[tt.Warning
^ warning!! [User] ]#
```
The opening `#[tt.` marks the message line.
The `^` marks the message column.
@@ -207,18 +208,17 @@ The `^` marks the message column.
Inline messages can be combined with `nimout` when `nimoutFull` is false (default).
This allows testing for expected messages from other modules:
.. code-block:: nim
```nim
discard """
nimout: "config.nims(1, 1) Hint: some hint message [User]"
"""
{.warning: "warning!!"} #[tt.Warning
^ warning!! [User] ]#
```
Multiple messages for a line can be checked by delimiting messages with ';':
.. code-block:: nim
```nim
discard """
matrix: "--errorMax:0 --styleCheck:error"
"""
@@ -227,6 +227,7 @@ Multiple messages for a line can be checked by delimiting messages with ';':
^ 'generic_proc' should be: 'genericProc'; tt.Error
^ 'a_a' should be: 'aA' ]#
discard
```
Use `--errorMax:0` in `matrix`, or `cmd: "nim check $file"` when testing
for multiple 'Error' messages.
@@ -327,4 +328,4 @@ Tests without Spec:
See also:
* `Unittest <unittest.html>`_
* [Unittest](unittest.html)

View File

@@ -7,36 +7,36 @@ Tools available with Nim
The standard distribution ships with the following tools:
- | `Hot code reloading <hcr.html>`_
- | [Hot code reloading](hcr.html)
| The "Hot code reloading" feature is built into the compiler but has its own
document explaining how it works.
- | `Documentation generator <docgen.html>`_
- | [Documentation generator](docgen.html)
| The builtin document generator `nim doc`:cmd: generates HTML documentation
from ``.nim`` source files.
- | `Nimsuggest for IDE support <nimsuggest.html>`_
- | [Nimsuggest for IDE support](nimsuggest.html)
| Through the `nimsuggest`:cmd: tool, any IDE can query a ``.nim`` source file
and obtain useful information like the definition of symbols or suggestions for
completion.
- | `C2nim <https://github.com/nim-lang/c2nim/blob/master/doc/c2nim.rst>`_
- | [C2nim](https://github.com/nim-lang/c2nim/blob/master/doc/c2nim.rst)
| C to Nim source converter. Translates C header files to Nim.
- | `niminst <niminst.html>`_
- | [niminst](niminst.html)
| niminst is a tool to generate an installer for a Nim program.
- | `nimgrep <nimgrep.html>`_
- | [nimgrep](nimgrep.html)
| Nim search and replace utility.
- | nimpretty
| `nimpretty`:cmd: is a Nim source code beautifier,
to format code according to the official style guide.
- | `testament <https://nim-lang.github.io/Nim/testament.html>`_
- | [testament](https://nim-lang.github.io/Nim/testament.html)
| `testament`:cmd: is an advanced automatic *unittests runner* for Nim tests,
is used for the development of Nim itself, offers process isolation for your tests,
it can generate statistics about test cases, supports multiple targets (C, JS, etc),
`simulated Dry-Runs <https://en.wikipedia.org/wiki/Dry_run_(testing)>`_,
[simulated Dry-Runs](https://en.wikipedia.org/wiki/Dry_run_(testing)),
has logging, can generate HTML reports, skip tests from a file, and more,
so can be useful to run your tests, even the most complex ones.

View File

@@ -1782,3 +1782,60 @@ since (1, 3):
since (1, 5):
proc elementsFromPoint*(n: DocumentOrShadowRoot; x, y: float): seq[Element] {.importcpp.}
since (1, 7):
proc insertAdjacentText*(self: Node; position, data: cstring) {.importjs: "#.$1(#, #)".}
## https://developer.mozilla.org/en-US/docs/Web/API/Element/insertAdjacentText
proc insertAdjacentElement*(self: Node; position: cstring; element: Node) {.importjs: "#.$1(#, #)".}
## https://developer.mozilla.org/en-US/docs/Web/API/Element/insertAdjacentElement
proc insertAdjacentHTML*(self: Node; position, html: cstring) {.importjs: "#.$1(#, #)".}
## https://developer.mozilla.org/en-US/docs/Web/API/Element/insertAdjacentHTML
proc after*(self: Node; element: Node): Node {.importjs: "#.$1(@)", varargs.}
## https://developer.mozilla.org/en-US/docs/Web/API/Element/after
proc before*(self: Node; element: Node): Node {.importjs: "#.$1(@)", varargs.}
## https://developer.mozilla.org/en-US/docs/Web/API/Element/before
proc append*(self: Node; element: Node): Node {.importjs: "#.$1(@)", varargs.}
## https://developer.mozilla.org/en-US/docs/Web/API/Element/append
proc closest*(self: Node; cssSelector: cstring): Node {.importjs: "#.$1(#)".}
## https://developer.mozilla.org/en-US/docs/Web/API/Element/closest
proc hasAttributeNS*(self: Node; namespace, localName: cstring): bool {.importjs: "(#.$1(#, #) || false)".}
## https://developer.mozilla.org/en-US/docs/Web/API/Element/hasAttributeNS
proc removeAttributeNS*(self: Node; namespace, attributeName: cstring) {.importjs: "#.$1(#, #)".}
## https://developer.mozilla.org/en-US/docs/Web/API/Element/removeAttributeNS
proc hasPointerCapture*(self: Node; pointerId: SomeNumber): bool {.importjs: "(#.$1(#) || false)".}
## https://developer.mozilla.org/en-US/docs/Web/API/Element/hasPointerCapture
proc releasePointerCapture*(self: Node; pointerId: SomeNumber) {.importjs: "#.$1(#)".}
## https://developer.mozilla.org/en-US/docs/Web/API/Element/releasePointerCapture
proc requestPointerLock*(self: Node) {.importjs: "#.$1()".}
## https://developer.mozilla.org/en-US/docs/Web/API/Element/requestPointerLock
proc replaceChildren*(self: Node; replacements: Node) {.importjs: "#.$1(@)", varargs.}
## https://developer.mozilla.org/en-US/docs/Web/API/Element/replaceChildren
proc replaceWith*(self: Node; replacements: Node) {.importjs: "#.$1(@)", varargs.}
## https://developer.mozilla.org/en-US/docs/Web/API/Element/replaceWith
proc scrollIntoViewIfNeeded*(self: Node; centerIfNeeded: bool) {.importjs: "#.$1(#)".}
## https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoViewIfNeeded
proc setHTML*(self: Node; html: cstring) {.importjs: "#.$1(#)".}
## https://developer.mozilla.org/en-US/docs/Web/API/Element/setHTML
proc toggleAttribute*(self: Node; name: cstring; force = false): bool {.importjs: "(#.$1(#, #) || false)".}
## https://developer.mozilla.org/en-US/docs/Web/API/Element/toggleAttribute
proc matches*(self: Node; cssSelector: cstring): bool {.importjs: "(#.$1(#) || false)".}
## https://developer.mozilla.org/en-US/docs/Web/API/Element/matches

View File

@@ -20,6 +20,7 @@ type RegExp* = ref object of JsRoot
lastParen*: cstring ## Ditto.
leftContext*: cstring ## Ditto.
rightContext*: cstring ## Ditto.
hasIndices*: bool ## https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/hasIndices
func newRegExp*(pattern: cstring; flags: cstring): RegExp {.importjs: "new RegExp(@)".}

View File

@@ -274,9 +274,9 @@ proc contentLength*(response: Response | AsyncResponse): int =
## This is effectively the value of the "Content-Length" header.
##
## A `ValueError` exception will be raised if the value is not an integer.
var contentLengthHeader = response.headers.getOrDefault("Content-Length")
## If the Content-Length header is not set in the response, ContentLength is set to the value -1.
var contentLengthHeader = response.headers.getOrDefault("Content-Length", @["-1"])
result = contentLengthHeader.parseInt()
doAssert(result >= 0 and result <= high(int32))
proc lastModified*(response: Response | AsyncResponse): DateTime =
## Retrieves the specified response's last modified time.

View File

@@ -391,6 +391,10 @@ macro collect*(init, body: untyped): untyped {.since: (1, 1).} =
macro collect*(body: untyped): untyped {.since: (1, 5).} =
## Same as `collect` but without an `init` parameter.
##
## **See also:**
## * `sequtils.toSeq proc<sequtils.html#toSeq.t%2Cuntyped>`_
## * `sequtils.mapIt template<sequtils.html#mapIt.t%2Ctyped%2Cuntyped>`_
runnableExamples:
import std/[sets, tables]
let data = @["bird", "word"]
@@ -411,10 +415,4 @@ macro collect*(body: untyped): untyped {.since: (1, 5).} =
for i, d in data.pairs: {i: d}
assert m == {0: "bird", 1: "word"}.toTable
# avoid `collect` when `sequtils.toSeq` suffices:
assert collect(for i in 1..3: i*i) == @[1, 4, 9] # ok in this case
assert collect(for i in 1..3: i) == @[1, 2, 3] # overkill in this case
from std/sequtils import toSeq
assert toSeq(1..3) == @[1, 2, 3] # simpler
result = collectImpl(nil, body)

View File

@@ -561,35 +561,8 @@ proc growObj(old: pointer, newsize: int, gch: var GcHeap): pointer =
gcTrace(res, csAllocated)
track("growObj old", ol, 0)
track("growObj new", res, newsize)
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:
if (ol.refcount and ZctFlag) != 0:
var j = gch.zct.len-1
var d = gch.zct.d
while j >= 0:
if d[j] == ol:
d[j] = res
break
dec(j)
beforeDealloc(gch, ol, "growObj stack trash")
decTypeSize(ol, ol.typ)
rawDealloc(gch.region, ol)
else:
# we split the old refcount in 2 parts. XXX This is still not entirely
# correct if the pointer that receives growObj's result is on the stack.
# A better fix would be to emit the location specific write barrier for
# 'growObj', but this is lots of more work and who knows what new problems
# this would create.
res.refcount = rcIncrement
decRef(ol)
else:
sysAssert(ol.typ != nil, "growObj: 5")
zeroMem(ol, sizeof(Cell))
# since we steal the old seq's contents, we set the old length to 0.
cast[PGenericSeq](old).len = 0
when useCellIds:
inc gch.idGenerator
res.id = gch.idGenerator * 1000_000 + gch.gcThreadId

View File

@@ -129,3 +129,19 @@ proc setLen[T](s: var seq[T], newlen: Natural) =
proc newSeq[T](s: var seq[T], len: Natural) =
shrink(s, 0)
setLen(s, len)
template capacityImpl(sek: NimSeqV2): int =
if sek.p != nil: sek.p.cap else: 0
func capacity*[T](self: seq[T]): int {.inline.} =
## Returns the current capacity of the seq.
# See https://github.com/nim-lang/RFCs/issues/460
runnableExamples:
var lst = newSeqOfCap[string](cap = 42)
lst.add "Nim"
assert lst.capacity == 42
{.cast(noSideEffect).}:
let sek = unsafeAddr self
result = capacityImpl(cast[ptr NimSeqV2](sek)[])

View File

@@ -175,3 +175,19 @@ proc prepareMutation*(s: var string) {.inline.} =
{.cast(noSideEffect).}:
let s = unsafeAddr s
nimPrepareStrMutationV2(cast[ptr NimStringV2](s)[])
template capacityImpl(str: NimStringV2): int =
if str.p != nil: str.p.cap else: 0
func capacity*(self: string): int {.inline.} =
## Returns the current capacity of the string.
# See https://github.com/nim-lang/RFCs/issues/460
runnableExamples:
var str = newStringOfCap(cap = 42)
str.add "Nim"
assert str.capacity == 42
{.cast(noSideEffect).}:
let str = unsafeAddr self
result = capacityImpl(cast[ptr NimStringV2](str)[])

View File

@@ -160,13 +160,9 @@ proc addChar(s: NimString, c: char): NimString =
result = s
if result.len >= result.space:
let r = resize(result.space)
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 = rawNewStringNoInit(r)
result.len = s.len
copyMem(addr result.data[0], unsafeAddr(s.data[0]), s.len+1)
result.reserved = r
result.data[result.len] = c
result.data[result.len+1] = '\0'
@@ -210,12 +206,9 @@ proc resizeString(dest: NimString, addlen: int): NimString {.compilerRtl.} =
result = dest
else: # slow path:
let sp = max(resize(dest.space), dest.len + addlen)
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 = rawNewStringNoInit(sp)
result.len = dest.len
copyMem(addr result.data[0], unsafeAddr(dest.data[0]), dest.len+1)
result.reserved = sp
#result = rawNewString(sp)
#copyMem(result, dest, dest.len + sizeof(TGenericSeq))
@@ -239,14 +232,11 @@ proc setLengthStr(s: NimString, newLen: int): NimString {.compilerRtl.} =
result = s
else:
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)
result.reserved = sp
else:
result = resizeString(s, n)
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)
result.reserved = sp
result.len = n
result.data[n] = '\0'
@@ -282,15 +272,11 @@ proc incrSeqV3(s: PGenericSeq, typ: PNimType): PGenericSeq {.compilerproc.} =
result = s
if result.len >= result.space:
let r = resize(result.space)
when defined(nimIncrSeqV3):
result = cast[PGenericSeq](newSeq(typ, r))
result.len = s.len
copyMem(dataPointer(result, typ.base.align), dataPointer(s, typ.base.align), 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, align(GenericSeqSize, typ.base.align) + typ.base.size * r))
result.reserved = r
result = cast[PGenericSeq](newSeq(typ, r))
result.len = s.len
copyMem(dataPointer(result, typ.base.align), dataPointer(s, typ.base.align), 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
proc setLengthSeq(seq: PGenericSeq, elemSize, elemAlign, newLen: int): PGenericSeq {.
compilerRtl, inl.} =
@@ -324,36 +310,33 @@ proc setLengthSeqV2(s: PGenericSeq, typ: PNimType, newLen: int): PGenericSeq {.
if s == nil:
result = cast[PGenericSeq](newSeq(typ, newLen))
else:
when defined(nimIncrSeqV3):
let elemSize = typ.base.size
let elemAlign = typ.base.align
if s.space < newLen:
let r = max(resize(s.space), newLen)
result = cast[PGenericSeq](newSeq(typ, r))
copyMem(dataPointer(result, elemAlign), dataPointer(s, elemAlign), 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(dataPointer(result, elemAlign, elemSize, i),
extGetCellType(result).base, waZctDecRef)
let elemSize = typ.base.size
let elemAlign = typ.base.align
if s.space < newLen:
let r = max(resize(s.space), newLen)
result = cast[PGenericSeq](newSeq(typ, r))
copyMem(dataPointer(result, elemAlign), dataPointer(s, elemAlign), 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(dataPointer(result, elemAlign, elemSize, i),
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 destroy the cell in the
# finalizer of the sequence, but this makes destruction non-deterministic.
zeroMem(dataPointer(result, elemAlign, elemSize, newLen), (result.len-%newLen) *% elemSize)
else:
result = s
zeroMem(dataPointer(result, elemAlign, elemSize, result.len), (newLen-%result.len) *% elemSize)
result.len = newLen
# 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 destroy the cell in the
# finalizer of the sequence, but this makes destruction non-deterministic.
zeroMem(dataPointer(result, elemAlign, elemSize, newLen), (result.len-%newLen) *% elemSize)
else:
result = setLengthSeq(s, typ.base.size, newLen)
result = s
zeroMem(dataPointer(result, elemAlign, elemSize, result.len), (newLen-%result.len) *% elemSize)
result.len = newLen

View File

@@ -141,7 +141,7 @@ else:
header: "<pthread.h>".} = cint
else:
type
SysThread* {.importc: "pthread_t", header: "<sys/types.h>".} = object
SysThread* {.importc: "pthread_t", header: "<sys/types.h>".} = int
Pthread_attr {.importc: "pthread_attr_t",
header: "<sys/types.h>".} = object
ThreadVarSlot {.importc: "pthread_key_t",

View File

@@ -40,3 +40,5 @@ switch("define", "nimPreviewFloatRoundtrip")
switch("define", "nimPreviewDotLikeOps")
switch("define", "nimPreviewJsonutilsHoleyEnum")
switch("define", "nimPreviewHashRef")
when defined(windows):
switch("tlsEmulation", "off")

10
tests/errmsgs/t19882.nim Normal file
View File

@@ -0,0 +1,10 @@
discard """
errormsg: "cannot instantiate 'A[T, P]' inside of type definition: 'init'; Maybe generic arguments are missing?"
"""
type A[T,P] = object
b:T
c:P
proc init(): ref A =
new(result)
var a = init()

6
tests/errmsgs/t8064.nim Normal file
View File

@@ -0,0 +1,6 @@
discard """
errormsg: "expression has no type: values"
"""
import tables
values

View File

@@ -1,5 +1,5 @@
discard """
cmd: "nim $target --hints:on --threads:on $options $file"
matrix: "--mm:refc; --mm:orc"
action: compile
"""

View File

@@ -160,3 +160,11 @@ proc main() =
main()
block: # bug #20391
type Container[T] = ref object of RootRef
item: T
let a = Container[int]()
doAssert a of Container[int]
doAssert not (a of Container[string])

View File

@@ -88,6 +88,66 @@ block:
doAssert y.b == {}
block:
type
X = object
a: string
b: int
var y = X(b: 1314)
reset(y)
doAssert y.b == 0
block:
type
X = object
a: string
b: float
var y = X(b: 1314.521)
reset(y)
doAssert y.b == 0.0
block:
type
X = object
a: string
b: string
var y = X(b: "1314")
reset(y)
doAssert y.b == ""
block:
type
X = object
a: string
b: seq[int]
var y = X(b: @[1, 3])
reset(y)
doAssert y.b == @[]
block:
type
X = object
a: string
b: tuple[a: int, b: string]
var y = X(b: (1, "cc"))
reset(y)
doAssert y.b == (0, "")
block:
type
Color = enum

View File

@@ -0,0 +1,4 @@
{.hintAsError[Name]:on.}
var a_b = 1
discard a_b
{.hintAsError[Name]:off.}

View File

@@ -0,0 +1,8 @@
discard """
matrix: "--styleCheck:off"
"""
{.hintAsError[Name]:on.}
var a_b = 1
discard a_b
{.hintAsError[Name]:off.}

View File

@@ -0,0 +1,7 @@
discard """
errormsg: "'a_b' should be: 'aB'"
matrix: "--styleCheck:error"
"""
var a_b = 1
discard a_b