mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-14 08:45:37 +00:00
Merge remote-tracking branch 'origin/devel' into wenvFix
This commit is contained in:
@@ -1,33 +0,0 @@
|
||||
## DO NO EDIT DIRECTLY! auto-generated by `nim r tools/ci_generate.nim`
|
||||
|
||||
# see https://man.sr.ht/builds.sr.ht/compatibility.md#freebsd
|
||||
image: freebsd/latest
|
||||
packages:
|
||||
- databases/sqlite3
|
||||
- devel/boehm-gc-threaded
|
||||
- devel/pcre
|
||||
- devel/sdl20
|
||||
- devel/sfml
|
||||
- www/node
|
||||
- devel/gmake
|
||||
|
||||
|
||||
sources:
|
||||
- https://github.com/nim-lang/Nim
|
||||
environment:
|
||||
NIM_TESTAMENT_BATCH: "0_1"
|
||||
CC: /usr/bin/clang
|
||||
tasks:
|
||||
- setup: |
|
||||
set -e
|
||||
cd Nim
|
||||
. ci/funs.sh && nimBuildCsourcesIfNeeded
|
||||
echo 'export PATH=$HOME/Nim/bin:$PATH' >> $HOME/.buildenv
|
||||
- test: |
|
||||
set -e
|
||||
cd Nim
|
||||
. ci/funs.sh && nimInternalBuildKochAndRunCI
|
||||
triggers:
|
||||
- action: email
|
||||
condition: failure
|
||||
to: Andreas Rumpf <rumpf_a@web.de>
|
||||
@@ -1,33 +0,0 @@
|
||||
## DO NO EDIT DIRECTLY! auto-generated by `nim r tools/ci_generate.nim`
|
||||
|
||||
image: openbsd/latest
|
||||
packages:
|
||||
- gmake
|
||||
- sqlite3
|
||||
- node
|
||||
- boehm-gc
|
||||
- pcre
|
||||
- sfml
|
||||
- sdl2
|
||||
- libffi
|
||||
|
||||
|
||||
sources:
|
||||
- https://github.com/nim-lang/Nim
|
||||
environment:
|
||||
NIM_TESTAMENT_BATCH: "0_2"
|
||||
CC: /usr/bin/clang
|
||||
tasks:
|
||||
- setup: |
|
||||
set -e
|
||||
cd Nim
|
||||
. ci/funs.sh && nimBuildCsourcesIfNeeded
|
||||
echo 'export PATH=$HOME/Nim/bin:$PATH' >> $HOME/.buildenv
|
||||
- test: |
|
||||
set -e
|
||||
cd Nim
|
||||
. ci/funs.sh && nimInternalBuildKochAndRunCI
|
||||
triggers:
|
||||
- action: email
|
||||
condition: failure
|
||||
to: Andreas Rumpf <rumpf_a@web.de>
|
||||
@@ -1,33 +0,0 @@
|
||||
## DO NO EDIT DIRECTLY! auto-generated by `nim r tools/ci_generate.nim`
|
||||
|
||||
image: openbsd/latest
|
||||
packages:
|
||||
- gmake
|
||||
- sqlite3
|
||||
- node
|
||||
- boehm-gc
|
||||
- pcre
|
||||
- sfml
|
||||
- sdl2
|
||||
- libffi
|
||||
|
||||
|
||||
sources:
|
||||
- https://github.com/nim-lang/Nim
|
||||
environment:
|
||||
NIM_TESTAMENT_BATCH: "1_2"
|
||||
CC: /usr/bin/clang
|
||||
tasks:
|
||||
- setup: |
|
||||
set -e
|
||||
cd Nim
|
||||
. ci/funs.sh && nimBuildCsourcesIfNeeded
|
||||
echo 'export PATH=$HOME/Nim/bin:$PATH' >> $HOME/.buildenv
|
||||
- test: |
|
||||
set -e
|
||||
cd Nim
|
||||
. ci/funs.sh && nimInternalBuildKochAndRunCI
|
||||
triggers:
|
||||
- action: email
|
||||
condition: failure
|
||||
to: Andreas Rumpf <rumpf_a@web.de>
|
||||
53
.github/ISSUE_TEMPLATE/bug_report.md
vendored
53
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@@ -1,53 +0,0 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Have you found an unexpected behavior? Use this template.
|
||||
title: Think about the title, twice
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
(Consider writing a PR targetting devel branch after filing this, see [contributing.html](https://nim-lang.github.io/Nim/contributing.html)).
|
||||
|
||||
Function `echo` outputs the wrong string.
|
||||
|
||||
### Example
|
||||
```nim
|
||||
echo "Hello World!"
|
||||
# This code should be a minimum reproducible example:
|
||||
# try to simplify and minimize as much as possible. If it's a compiler
|
||||
# issue, try to minimize further by removing any imports if possible.
|
||||
```
|
||||
|
||||
### Current Output
|
||||
please check whether the problem still exists in git head before posting,
|
||||
see [rebuilding the compiler](https://nim-lang.github.io/Nim/intern.html#rebuilding-the-compiler).
|
||||
```
|
||||
Hola mundo!
|
||||
```
|
||||
|
||||
### Expected Output
|
||||
```
|
||||
Hello World!
|
||||
```
|
||||
|
||||
### Possible Solution
|
||||
|
||||
* In file xyz there is a call that might be the cause of it.
|
||||
|
||||
### Additional Information
|
||||
If it's a regression, you can help us by identifying which version introduced
|
||||
the bug, see [Bisecting for regressions](https://nim-lang.github.io/Nim/intern.html#bisecting-for-regressions),
|
||||
or at least try known past releases (eg `choosenim 1.2.0`).
|
||||
|
||||
If it's a pre-existing compiler bug, see [Debugging the compiler](https://nim-lang.github.io/Nim/intern.html#debugging-the-compiler)
|
||||
which should give more context on a compiler crash.
|
||||
|
||||
* Issue #abc is related, but different because of ...
|
||||
* This issue is blocking my project xyz
|
||||
|
||||
```
|
||||
$ nim -v
|
||||
Nim Compiler Version 0.1.2
|
||||
# make sure to include the git hash if not using a tagged release
|
||||
```
|
||||
75
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
Normal file
75
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
name: "Bug Report"
|
||||
description: "Create a new bug report. Have you found an unexpected behavior? Use this form."
|
||||
title: "Think about the title, twice."
|
||||
labels: ["unconfirmed"]
|
||||
body:
|
||||
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
- **Please provide a minimal code example that reproduces the Bug!** :bug:
|
||||
Reports with a reproducible example and descriptive detailed information will likely receive fixes faster.
|
||||
|
||||
- type: textarea
|
||||
id: what-happened
|
||||
attributes:
|
||||
label: What happened?
|
||||
description: |
|
||||
Use DETAILED DESCRIPTIVE information about the problem.
|
||||
Here, you go into more details about your Bug report. This section can be a few paragraphs long.
|
||||
placeholder: Bug reports with full repro code and detailed information will be fixed faster.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
id: nim-version
|
||||
attributes:
|
||||
label: Nim Version
|
||||
description: Please run `nim -v` on the command line.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
id: current-logs
|
||||
attributes:
|
||||
label: Current Standard Output Logs
|
||||
description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks.
|
||||
placeholder: Bug reports with full repro code and detailed information will be fixed faster.
|
||||
render: shell
|
||||
|
||||
- type: textarea
|
||||
id: expected-logs
|
||||
attributes:
|
||||
label: Expected Standard Output Logs
|
||||
description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks.
|
||||
placeholder: Bug reports with full repro code and detailed information will be fixed faster.
|
||||
render: shell
|
||||
|
||||
- type: textarea
|
||||
id: possible-solution
|
||||
attributes:
|
||||
label: Possible Solution
|
||||
description: Propose a possible solution.
|
||||
validations:
|
||||
required: false
|
||||
|
||||
- type: textarea
|
||||
id: extra-info
|
||||
attributes:
|
||||
label: Additional Information
|
||||
description: Any additional relevant information.
|
||||
validations:
|
||||
required: false
|
||||
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
- Thanks for your contributions!, your Bug report will receive feedback from the community soon...
|
||||
- Please check whether the problem still exists in the devel branch, see [rebuilding the compiler](https://nim-lang.github.io/Nim/intern.html#rebuilding-the-compiler).
|
||||
- Consider writing a PR targetting devel branch after filing this, see [contributing](https://nim-lang.github.io/Nim/contributing.html).
|
||||
- If it's a pre-existing compiler bug, see [Debugging the compiler](https://nim-lang.github.io/Nim/intern.html#debugging-the-compiler)
|
||||
which should give more context on a compiler crash.
|
||||
- If it's a regression, you can help us by identifying which version introduced the bug,
|
||||
see [Bisecting for regressions](https://nim-lang.github.io/Nim/intern.html#bisecting-for-regressions),
|
||||
or at least try known past releases (eg `choosenim 1.2.0`).
|
||||
- [Please, consider a Donation for the Nim project.](https://nim-lang.org/donate.html)
|
||||
35
.github/ISSUE_TEMPLATE/feature_request.md
vendored
35
.github/ISSUE_TEMPLATE/feature_request.md
vendored
@@ -1,35 +0,0 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Do you want to suggest a new feature? Use this template.
|
||||
title: ''
|
||||
labels: ["Feature"]
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
<!---
|
||||
Notice there is now a separate repository for the detailed RFCs and proposals:
|
||||
https://github.com/nim-lang/RFCs
|
||||
|
||||
If you have a simple feature request, you can post it here using this template,
|
||||
but bear in mind that adding new features to the language is currently a low priority.
|
||||
-->
|
||||
|
||||
|
||||
### Summary
|
||||
<!--- Short summary of your proposed feature -->
|
||||
|
||||
|
||||
### Description
|
||||
<!--- Describe your solution, what problem does it fix? -->
|
||||
|
||||
|
||||
### Alternatives
|
||||
<!--- Are there any alternatives you've considered? -->
|
||||
|
||||
|
||||
### Additional Information
|
||||
<!--- For Example:
|
||||
* A link to a project where the issue is relevant.
|
||||
* A link to a related issue or discussion.
|
||||
-->
|
||||
73
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
Normal file
73
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
name: "Feature request"
|
||||
description: "Create a new Feature Request. Do you want to suggest a new feature? Use this form."
|
||||
title: "Think about the title, twice."
|
||||
labels: ["unconfirmed"]
|
||||
body:
|
||||
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
- Please provide a minimal code example that illustrates the basic idea behind your feature request.
|
||||
Reports with full repro code and descriptive detailed information will likely receive feedback faster.
|
||||
- There is a separate repository for the detailed RFCs and proposals: https://github.com/nim-lang/RFCs.
|
||||
If you have a simple feature request, you can post it here using this form,
|
||||
but bear in mind that adding new features to the language is currently a low priority.
|
||||
|
||||
- type: textarea
|
||||
id: summary
|
||||
attributes:
|
||||
label: Summary
|
||||
description: |
|
||||
Use DETAILED DESCRIPTIVE information about the feature request.
|
||||
Here, you go into more details about your ideas. This section can be a few paragraphs long.
|
||||
placeholder: Short summary of your proposed feature.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
id: description
|
||||
attributes:
|
||||
label: Description
|
||||
description: Describe your solution, what problem does it fix?
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
id: alternatives
|
||||
attributes:
|
||||
label: Alternatives
|
||||
description: Are there any alternatives you've considered?
|
||||
validations:
|
||||
required: false
|
||||
|
||||
- type: textarea
|
||||
id: Examples
|
||||
attributes:
|
||||
label: Standard Output Examples
|
||||
description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks.
|
||||
placeholder: Example code here.
|
||||
render: shell
|
||||
|
||||
- type: textarea
|
||||
id: incompatibility
|
||||
attributes:
|
||||
label: Backwards Compatibility
|
||||
description: If your Feature Request introduces backward-incompatible changes, describe them and propose how to deal with them.
|
||||
validations:
|
||||
required: false
|
||||
|
||||
- type: textarea
|
||||
id: links
|
||||
attributes:
|
||||
label: Links
|
||||
description: Please copy and paste any relevant links to projects, issues, discussions, technical documentations, code samples, etc.
|
||||
validations:
|
||||
required: false
|
||||
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
- Thanks for your contributions!, your ideas will receive feedback from the community soon...
|
||||
- **Remember to :star: Star the Nim project on GitHub!.**
|
||||
- Consider writing a PR targetting devel branch after filing this, see [contributing](https://nim-lang.github.io/Nim/contributing.html).
|
||||
- [Please, consider a Donation for the Nim project.](https://nim-lang.org/donate.html)
|
||||
2
.github/workflows/ci_docs.yml
vendored
2
.github/workflows/ci_docs.yml
vendored
@@ -40,7 +40,7 @@ jobs:
|
||||
- target: windows
|
||||
os: windows-2019
|
||||
- target: osx
|
||||
os: macos-10.15
|
||||
os: macos-11
|
||||
|
||||
name: ${{ matrix.target }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
2
.github/workflows/ci_packages.yml
vendored
2
.github/workflows/ci_packages.yml
vendored
@@ -6,7 +6,7 @@ jobs:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-20.04, macos-10.15]
|
||||
os: [ubuntu-20.04, macos-11]
|
||||
cpu: [amd64]
|
||||
batch: ["allowed_failures", "0_3", "1_3", "2_3"] # list of `index_num`
|
||||
name: '${{ matrix.os }} (batch: ${{ matrix.batch }})'
|
||||
|
||||
@@ -28,10 +28,10 @@ jobs:
|
||||
vmImage: 'ubuntu-18.04'
|
||||
CPU: i386
|
||||
OSX_amd64:
|
||||
vmImage: 'macOS-10.15'
|
||||
vmImage: 'macOS-11'
|
||||
CPU: amd64
|
||||
OSX_amd64_cpp:
|
||||
vmImage: 'macOS-10.15'
|
||||
vmImage: 'macOS-11'
|
||||
CPU: amd64
|
||||
NIM_COMPILE_TO_CPP: true
|
||||
Windows_amd64_batch0_3:
|
||||
|
||||
57
changelog.md
57
changelog.md
@@ -3,6 +3,20 @@
|
||||
|
||||
## Changes affecting backward compatibility
|
||||
|
||||
- `addr` is now available for all addressable locations,
|
||||
`unsafeAddr` is now deprecated and an alias for `addr`.
|
||||
|
||||
- `io` and `assertions` are about to move out of the `system` module.
|
||||
You may instead import `std/syncio` and `std/assertions`.
|
||||
The `-d:nimPreviewSlimSystem` option makes these imports required.
|
||||
|
||||
- The `gc:v2` option is removed.
|
||||
|
||||
- The `threads:on` option is now the default.
|
||||
|
||||
- Optional parameters in combination with `: body` syntax (RFC #405) are now opt-in via
|
||||
`experimental:flexibleOptionalParams`.
|
||||
|
||||
- The `Math.trunc` polyfill for targeting Internet Explorer was
|
||||
previously emitted for every JavaScript output file except if
|
||||
the symbol `nodejs` was defined via `-d:nodejs`. Now, it is only
|
||||
@@ -11,51 +25,44 @@
|
||||
or define your own `Math.trunc` polyfill using the [`emit` pragma](https://nim-lang.org/docs/manual.html#implementation-specific-pragmas-emit-pragma). Nim uses
|
||||
`Math.trunc` for the division and modulo operators for integers.
|
||||
|
||||
- Deprecated `std/sums`.
|
||||
- `shallowCopy` is removed for ARC/ORC. Use `move` when possible or combine assignment and
|
||||
`sink` for optimization purposes.
|
||||
|
||||
- Optional parameters in combination with `: body` syntax (RFC #405) are now opt-in via
|
||||
`experimental:flexibleOptionalParams`.
|
||||
|
||||
- `std/sharedstrings` module is removed.
|
||||
- Constants `colors.colPaleVioletRed` and `colors.colMediumPurple` changed to match the CSS color standard.
|
||||
|
||||
- `addr` is now available for all addressable locations, `unsafeAddr` is deprecated and
|
||||
becomes an alias for `addr`.
|
||||
|
||||
- `io` and `assertions` are about to move out of system; use `-d:nimPreviewSlimSystem`, import `std/syncio` and import `std/assertions`.
|
||||
|
||||
- The `gc:v2` option is removed.
|
||||
|
||||
- The `threads:on` option becomes the default.
|
||||
- `nimPreviewDotLikeOps` is going to be removed or deprecated.
|
||||
|
||||
## Standard library additions and changes
|
||||
|
||||
[//]: # "Changes:"
|
||||
- `macros.parseExpr` and `macros.parseStmt` now accept an optional.
|
||||
- `macros.parseExpr` and `macros.parseStmt` now accept an optional
|
||||
filename argument for more informative errors.
|
||||
- Module `colors` expanded with missing colors from the CSS color standard.
|
||||
`colPaleVioletRed` and `colMediumPurple` have also been changed to match the CSS color standard.
|
||||
- Fixed `lists.SinglyLinkedList` being broken after removing the last node ([#19353](https://github.com/nim-lang/Nim/pull/19353)).
|
||||
- `md5` now works at compile time and in JavaScript.
|
||||
- `std/smtp` sends `ehlo` first. If the mail server does not understand, it sends `helo` as a fallback.
|
||||
- Changed mimedb to use an `OrderedTable` instead of `OrderedTableRef`, to use it in a const.
|
||||
- Changed `mimedb` to use an `OrderedTable` instead of `OrderedTableRef` to support `const` tables.
|
||||
- `strutils.find` now use and default to `last=-1` for whole string searches, making limiting it to just the first char (`last=0`) valid.
|
||||
- `random.rand` now works with `Ordinal`s.
|
||||
|
||||
[//]: # "Additions:"
|
||||
- Added `IsoWeekRange`, a range type to represent the number of weeks in an ISO week-based year.
|
||||
- Added `IsoYear`, a distinct int type to prevent bugs from confusing the week-based year and the regular year.
|
||||
- Added `initDateTime` in `times` to create a datetime from a weekday, and ISO 8601 week number and week-based year.
|
||||
- Added `getIsoWeekAndYear` in `times` to get an ISO week number along with the corresponding ISO week-based year from a datetime.
|
||||
- Added `getIsoWeeksInYear` in `times` to return the number of weeks in an ISO week-based year.
|
||||
- Added `times.IsoWeekRange`, a range type to represent the number of weeks in an ISO week-based year.
|
||||
- Added `times.IsoYear`, a distinct int type to prevent bugs from confusing the week-based year and the regular year.
|
||||
- Added `times.initDateTime` to create a datetime from a weekday, and ISO 8601 week number and week-based year.
|
||||
- Added `times.getIsoWeekAndYear` to get an ISO week number along with the corresponding ISO week-based year from a datetime.
|
||||
- Added `times.getIsoWeeksInYear` to return the number of weeks in an ISO week-based year.
|
||||
- Added `std/oserrors` for OS error reporting. Added `std/envvars` for environment variables handling.
|
||||
- Added `sep` parameter in `std/uri` to specify the query separator.
|
||||
- Added [`Array.shift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift) for JavaScript targets.
|
||||
- Added [`queueMicrotask`](https://developer.mozilla.org/en-US/docs/Web/API/queueMicrotask) for JavaScript targets.
|
||||
- Added bindings to [`Array.shift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift)
|
||||
and [`queueMicrotask`](https://developer.mozilla.org/en-US/docs/Web/API/queueMicrotask)
|
||||
in `jscore` for JavaScript targets.
|
||||
- Added `UppercaseLetters`, `LowercaseLetters`, `PunctuationChars`, `PrintableChars` sets to `std/strutils`.
|
||||
|
||||
[//]: # "Deprecations:"
|
||||
- Deprecated `selfExe` for Nimscript.
|
||||
- Deprecated `std/sums`.
|
||||
|
||||
[//]: # "Removals:"
|
||||
- Removed deprecated `std/sharedstrings`.
|
||||
- Removed deprecated `oids.oidToString`.
|
||||
- Removed define `nimExperimentalAsyncjsThen` for `std/asyncjs.then` and `std/jsfetch`.
|
||||
- Removed deprecated `jsre.test` and `jsre.toString`.
|
||||
@@ -67,6 +74,8 @@ becomes an alias for `addr`.
|
||||
|
||||
## Language changes
|
||||
|
||||
- [Tag tracking](manual.html#tag-tracking) supports the definition of forbidden tags by the `.forbids` pragma
|
||||
which can be used to disable certain effects in proc types.
|
||||
- [Case statement macros](manual.html#macros-case-statement-macros) are no longer experimental,
|
||||
meaning you no longer need to enable the experimental switch `caseStmtMacros` to use them.
|
||||
- Templates now accept [macro pragmas](https://nim-lang.github.io/Nim/manual.html#userminusdefined-pragmas-macro-pragmas).
|
||||
|
||||
@@ -9,9 +9,7 @@ proc main() =
|
||||
|
||||
doAssert exitCode == 0, output
|
||||
|
||||
var start = rfind(output, "Hint: gc")
|
||||
if start < 0:
|
||||
start = rfind(output, "Hint: mm")
|
||||
let start = rfind(output, "Hint: mm")
|
||||
doAssert parseUntil(output, msg, "; proj", start) > 0, output
|
||||
|
||||
let (commitHash, _) = execCmdEx("""git log --format="%H" -n 1""")
|
||||
@@ -25,4 +23,4 @@ The lines below are statistics of the Nim compiler built from {commitHash}
|
||||
writeFile "ci/nimcache/results.txt", welcomeMessage
|
||||
|
||||
when isMainModule:
|
||||
main()
|
||||
main()
|
||||
|
||||
@@ -347,7 +347,8 @@ const
|
||||
ensuresEffects* = 2 # 'ensures' annotation
|
||||
tagEffects* = 3 # user defined tag ('gc', 'time' etc.)
|
||||
pragmasEffects* = 4 # not an effect, but a slot for pragmas in proc type
|
||||
effectListLen* = 5 # list of effects list
|
||||
forbiddenEffects* = 5 # list of illegal effects
|
||||
effectListLen* = 6 # list of effects list
|
||||
nkLastBlockStmts* = {nkRaiseStmt, nkReturnStmt, nkBreakStmt, nkContinueStmt}
|
||||
# these must be last statements in a block
|
||||
|
||||
|
||||
@@ -68,7 +68,10 @@ proc copyHalf[Key, Val](h, result: Node[Key, Val]) =
|
||||
result.links[j] = h.links[Mhalf + j]
|
||||
else:
|
||||
for j in 0..<Mhalf:
|
||||
shallowCopy(result.vals[j], h.vals[Mhalf + j])
|
||||
when defined(gcArc) or defined(gcOrc):
|
||||
result.vals[j] = move h.vals[Mhalf + j]
|
||||
else:
|
||||
shallowCopy(result.vals[j], h.vals[Mhalf + j])
|
||||
|
||||
proc split[Key, Val](h: Node[Key, Val]): Node[Key, Val] =
|
||||
## split node in half
|
||||
@@ -88,7 +91,10 @@ proc insert[Key, Val](h: Node[Key, Val], key: Key, val: Val): Node[Key, Val] =
|
||||
if less(key, h.keys[j]): break
|
||||
inc j
|
||||
for i in countdown(h.entries, j+1):
|
||||
shallowCopy(h.vals[i], h.vals[i-1])
|
||||
when defined(gcArc) or defined(gcOrc):
|
||||
h.vals[i] = move h.vals[i-1]
|
||||
else:
|
||||
shallowCopy(h.vals[i], h.vals[i-1])
|
||||
h.vals[j] = val
|
||||
else:
|
||||
var newLink: Node[Key, Val] = nil
|
||||
|
||||
@@ -405,7 +405,7 @@ proc genClosureVar(p: BProc, a: PNode) =
|
||||
genLineDir(p, a)
|
||||
if immediateAsgn:
|
||||
loadInto(p, a[0], a[2], v)
|
||||
else:
|
||||
elif sfNoInit notin a[0][1].sym.flags:
|
||||
constructLoc(p, v)
|
||||
|
||||
proc genVarStmt(p: BProc, n: PNode) =
|
||||
|
||||
@@ -825,10 +825,13 @@ proc newEndFinallyNode(ctx: var Ctx, info: TLineInfo): PNode =
|
||||
let retStmt =
|
||||
if ctx.nearestFinally == 0:
|
||||
# last finally, we can return
|
||||
let asgn = newTree(nkFastAsgn,
|
||||
newSymNode(getClosureIterResult(ctx.g, ctx.fn, ctx.idgen), info),
|
||||
ctx.newTmpResultAccess())
|
||||
newTree(nkReturnStmt, asgn)
|
||||
let retValue = if ctx.fn.typ[0].isNil:
|
||||
ctx.g.emptyNode
|
||||
else:
|
||||
newTree(nkFastAsgn,
|
||||
newSymNode(getClosureIterResult(ctx.g, ctx.fn, ctx.idgen), info),
|
||||
ctx.newTmpResultAccess())
|
||||
newTree(nkReturnStmt, retValue)
|
||||
else:
|
||||
# bubble up to next finally
|
||||
newTree(nkGotoState, ctx.g.newIntLit(info, ctx.nearestFinally))
|
||||
|
||||
@@ -1212,8 +1212,9 @@ proc documentRaises*(cache: IdentCache; n: PNode) =
|
||||
let p3 = documentWriteEffect(cache, n, sfWrittenTo, "writes")
|
||||
let p4 = documentNewEffect(cache, n)
|
||||
let p5 = documentWriteEffect(cache, n, sfEscapes, "escapes")
|
||||
let p6 = documentEffect(cache, n, pragmas, wForbids, forbiddenEffects)
|
||||
|
||||
if p1 != nil or p2 != nil or p3 != nil or p4 != nil or p5 != nil:
|
||||
if p1 != nil or p2 != nil or p3 != nil or p4 != nil or p5 != nil or p6 != nil:
|
||||
if pragmas.kind == nkEmpty:
|
||||
n[pragmasPos] = newNodeI(nkPragma, n.info)
|
||||
if p1 != nil: n[pragmasPos].add p1
|
||||
@@ -1221,6 +1222,7 @@ proc documentRaises*(cache: IdentCache; n: PNode) =
|
||||
if p3 != nil: n[pragmasPos].add p3
|
||||
if p4 != nil: n[pragmasPos].add p4
|
||||
if p5 != nil: n[pragmasPos].add p5
|
||||
if p6 != nil: n[pragmasPos].add p6
|
||||
|
||||
proc generateDoc*(d: PDoc, n, orig: PNode, docFlags: DocFlags = kDefault) =
|
||||
## Goes through nim nodes recursively and collects doc comments.
|
||||
@@ -1358,9 +1360,10 @@ proc finishGenerateDoc*(d: var PDoc) =
|
||||
var str: string
|
||||
renderRstToOut(d[], resolved, str)
|
||||
entry.json[entry.rstField] = %str
|
||||
d.jEntriesFinal.add entry.json
|
||||
d.jEntriesPre[i].rst = nil
|
||||
|
||||
d.jEntriesFinal.add entry.json # generates docs
|
||||
|
||||
proc add(d: PDoc; j: JsonItem) =
|
||||
if j.json != nil or j.rst != nil: d.jEntriesPre.add j
|
||||
|
||||
|
||||
@@ -80,6 +80,7 @@ type
|
||||
warnHoleEnumConv = "HoleEnumConv",
|
||||
warnCstringConv = "CStringConv",
|
||||
warnEffect = "Effect",
|
||||
warnCastSizes = "CastSizes"
|
||||
warnUser = "User",
|
||||
# hints
|
||||
hintSuccess = "Success", hintSuccessX = "SuccessX",
|
||||
@@ -173,6 +174,7 @@ const
|
||||
warnHoleEnumConv: "$1",
|
||||
warnCstringConv: "$1",
|
||||
warnEffect: "$1",
|
||||
warnCastSizes: "$1",
|
||||
warnUser: "$1",
|
||||
hintSuccess: "operation successful: $#",
|
||||
# keep in sync with `testament.isSuccess`
|
||||
|
||||
@@ -241,7 +241,8 @@ proc addField*(obj: PType; s: PSym; cache: IdentCache; idgen: IdGenerator): PSym
|
||||
assert t.kind != tyTyped
|
||||
propagateToOwner(obj, t)
|
||||
field.position = obj.n.len
|
||||
field.flags = s.flags * {sfCursor}
|
||||
# sfNoInit flag for skField is used in closureiterator codegen
|
||||
field.flags = s.flags * {sfCursor, sfNoInit}
|
||||
obj.n.add newSymNode(field)
|
||||
fieldCheck()
|
||||
result = field
|
||||
|
||||
@@ -218,11 +218,18 @@ proc setDirtyFile*(conf: ConfigRef; fileIdx: FileIndex; filename: AbsoluteFile)
|
||||
|
||||
proc setHash*(conf: ConfigRef; fileIdx: FileIndex; hash: string) =
|
||||
assert fileIdx.int32 >= 0
|
||||
shallowCopy(conf.m.fileInfos[fileIdx.int32].hash, hash)
|
||||
when defined(gcArc) or defined(gcOrc):
|
||||
conf.m.fileInfos[fileIdx.int32].hash = hash
|
||||
else:
|
||||
shallowCopy(conf.m.fileInfos[fileIdx.int32].hash, hash)
|
||||
|
||||
|
||||
proc getHash*(conf: ConfigRef; fileIdx: FileIndex): string =
|
||||
assert fileIdx.int32 >= 0
|
||||
shallowCopy(result, conf.m.fileInfos[fileIdx.int32].hash)
|
||||
when defined(gcArc) or defined(gcOrc):
|
||||
result = conf.m.fileInfos[fileIdx.int32].hash
|
||||
else:
|
||||
shallowCopy(result, conf.m.fileInfos[fileIdx.int32].hash)
|
||||
|
||||
proc toFullPathConsiderDirty*(conf: ConfigRef; fileIdx: FileIndex): AbsoluteFile =
|
||||
if fileIdx.int32 < 0:
|
||||
|
||||
@@ -22,7 +22,10 @@ proc replaceDeprecated*(conf: ConfigRef; info: TLineInfo; oldSym, newSym: PIdent
|
||||
let last = first+identLen(line, first)-1
|
||||
if cmpIgnoreStyle(line[first..last], oldSym.s) == 0:
|
||||
var x = line.substr(0, first-1) & newSym.s & line.substr(last+1)
|
||||
system.shallowCopy(conf.m.fileInfos[info.fileIndex.int32].lines[info.line.int-1], x)
|
||||
when defined(gcArc) or defined(gcOrc):
|
||||
conf.m.fileInfos[info.fileIndex.int32].lines[info.line.int-1] = move x
|
||||
else:
|
||||
system.shallowCopy(conf.m.fileInfos[info.fileIndex.int32].lines[info.line.int-1], x)
|
||||
conf.m.fileInfos[info.fileIndex.int32].dirty = true
|
||||
#if newSym.s == "File": writeStackTrace()
|
||||
|
||||
@@ -35,5 +38,8 @@ proc replaceComment*(conf: ConfigRef; info: TLineInfo) =
|
||||
if line[first] != '#': inc first
|
||||
|
||||
var x = line.substr(0, first-1) & "discard " & line.substr(first+1).escape
|
||||
system.shallowCopy(conf.m.fileInfos[info.fileIndex.int32].lines[info.line.int-1], x)
|
||||
when defined(gcArc) or defined(gcOrc):
|
||||
conf.m.fileInfos[info.fileIndex.int32].lines[info.line.int-1] = move x
|
||||
else:
|
||||
system.shallowCopy(conf.m.fileInfos[info.fileIndex.int32].lines[info.line.int-1], x)
|
||||
conf.m.fileInfos[info.fileIndex.int32].dirty = true
|
||||
|
||||
@@ -32,7 +32,7 @@ const
|
||||
wCompilerProc, wNonReloadable, wCore, wProcVar, wVarargs, wCompileTime, wMerge,
|
||||
wBorrow, wImportCompilerProc, wThread,
|
||||
wAsmNoStackFrame, wDiscardable, wNoInit, wCodegenDecl,
|
||||
wGensym, wInject, wRaises, wEffectsOf, wTags, wLocks, wDelegator, wGcSafe,
|
||||
wGensym, wInject, wRaises, wEffectsOf, wTags, wForbids, wLocks, wDelegator, wGcSafe,
|
||||
wConstructor, wLiftLocals, wStackTrace, wLineTrace, wNoDestroy,
|
||||
wRequires, wEnsures, wEnforceNoRaises}
|
||||
converterPragmas* = procPragmas
|
||||
@@ -45,7 +45,7 @@ const
|
||||
iteratorPragmas* = declPragmas + {FirstCallConv..LastCallConv, wNoSideEffect, wSideEffect,
|
||||
wMagic, wBorrow,
|
||||
wDiscardable, wGensym, wInject, wRaises, wEffectsOf,
|
||||
wTags, wLocks, wGcSafe, wRequires, wEnsures}
|
||||
wTags, wForbids, wLocks, wGcSafe, wRequires, wEnsures}
|
||||
exprPragmas* = {wLine, wLocks, wNoRewrite, wGcSafe, wNoSideEffect}
|
||||
stmtPragmas* = {
|
||||
wHint, wWarning, wError,
|
||||
@@ -65,7 +65,7 @@ const
|
||||
lambdaPragmas* = {FirstCallConv..LastCallConv,
|
||||
wNoSideEffect, wSideEffect, wNoreturn, wNosinks, wDynlib, wHeader,
|
||||
wThread, wAsmNoStackFrame,
|
||||
wRaises, wLocks, wTags, wRequires, wEnsures, wEffectsOf,
|
||||
wRaises, wLocks, wTags, wForbids, wRequires, wEnsures, wEffectsOf,
|
||||
wGcSafe, wCodegenDecl, wNoInit, wCompileTime}
|
||||
typePragmas* = declPragmas + {wMagic, wAcyclic,
|
||||
wPure, wHeader, wCompilerProc, wCore, wFinal, wSize, wShallow,
|
||||
@@ -85,7 +85,7 @@ const
|
||||
paramPragmas* = {wNoalias, wInject, wGensym}
|
||||
letPragmas* = varPragmas
|
||||
procTypePragmas* = {FirstCallConv..LastCallConv, wVarargs, wNoSideEffect,
|
||||
wThread, wRaises, wEffectsOf, wLocks, wTags, wGcSafe,
|
||||
wThread, wRaises, wEffectsOf, wLocks, wTags, wForbids, wGcSafe,
|
||||
wRequires, wEnsures}
|
||||
forVarPragmas* = {wInject, wGensym}
|
||||
allRoutinePragmas* = methodPragmas + iteratorPragmas + lambdaPragmas
|
||||
@@ -511,7 +511,10 @@ proc processCompile(c: PContext, n: PNode) =
|
||||
n[i] = c.semConstExpr(c, n[i])
|
||||
case n[i].kind
|
||||
of nkStrLit, nkRStrLit, nkTripleStrLit:
|
||||
shallowCopy(result, n[i].strVal)
|
||||
when defined(gcArc) or defined(gcOrc):
|
||||
result = n[i].strVal
|
||||
else:
|
||||
shallowCopy(result, n[i].strVal)
|
||||
else:
|
||||
localError(c.config, n.info, errStringLiteralExpected)
|
||||
result = ""
|
||||
@@ -820,7 +823,7 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int,
|
||||
elif not isStatement:
|
||||
localError(c.config, n.info, "'cast' pragma only allowed in a statement context")
|
||||
case whichPragma(key[1])
|
||||
of wRaises, wTags: pragmaRaisesOrTags(c, key[1])
|
||||
of wRaises, wTags, wForbids: pragmaRaisesOrTags(c, key[1])
|
||||
else: discard
|
||||
return
|
||||
elif key.kind notin nkIdentKinds:
|
||||
@@ -1184,7 +1187,7 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int,
|
||||
noVal(c, it)
|
||||
if sym == nil: invalidPragma(c, it)
|
||||
of wLine: pragmaLine(c, it)
|
||||
of wRaises, wTags: pragmaRaisesOrTags(c, it)
|
||||
of wRaises, wTags, wForbids: pragmaRaisesOrTags(c, it)
|
||||
of wLocks:
|
||||
if sym == nil: pragmaLockStmt(c, it)
|
||||
elif sym.typ == nil: invalidPragma(c, it)
|
||||
|
||||
@@ -154,6 +154,8 @@ proc effectProblem(f, a: PType; result: var string; c: PContext) =
|
||||
"proc with {.locks: 0.} to get extended error information."
|
||||
of efEffectsDelayed:
|
||||
result.add "\n The `.effectsOf` annotations differ."
|
||||
of efTagsIllegal:
|
||||
result.add "\n The `.forbids` requirements caught an illegal tag."
|
||||
when defined(drnim):
|
||||
if not c.graph.compatibleProps(c.graph, f, a):
|
||||
result.add "\n The `.requires` or `.ensures` properties are incompatible."
|
||||
@@ -730,4 +732,4 @@ proc searchForBorrowProc(c: PContext, startScope: PScope, fn: PSym): PSym =
|
||||
result = nil
|
||||
elif result.magic in {mArrPut, mArrGet}:
|
||||
# cannot borrow these magics for now
|
||||
result = nil
|
||||
result = nil
|
||||
|
||||
@@ -196,10 +196,10 @@ proc checkConvertible(c: PContext, targetTyp: PType, src: PNode): TConvStatus =
|
||||
else:
|
||||
discard
|
||||
|
||||
proc isCastable(c: PContext; dst, src: PType): bool =
|
||||
proc isCastable(c: PContext; dst, src: PType, info: TLineInfo): bool =
|
||||
## Checks whether the source type can be cast to the destination type.
|
||||
## Casting is very unrestrictive; casts are allowed as long as
|
||||
## castDest.size >= src.size, and typeAllowed(dst, skParam)
|
||||
## dst.size >= src.size, and typeAllowed(dst, skParam)
|
||||
#const
|
||||
# castableTypeKinds = {tyInt, tyPtr, tyRef, tyCstring, tyString,
|
||||
# tySequence, tyPointer, tyNil, tyOpenArray,
|
||||
@@ -228,19 +228,21 @@ proc isCastable(c: PContext; dst, src: PType): bool =
|
||||
# Just assume the programmer knows what he is doing.
|
||||
return true
|
||||
if dstSize < 0:
|
||||
result = false
|
||||
return false
|
||||
elif srcSize < 0:
|
||||
result = false
|
||||
return false
|
||||
elif typeAllowed(dst, skParam, c) != nil:
|
||||
result = false
|
||||
return false
|
||||
elif dst.kind == tyProc and dst.callConv == ccClosure:
|
||||
result = src.kind == tyProc and src.callConv == ccClosure
|
||||
return src.kind == tyProc and src.callConv == ccClosure
|
||||
else:
|
||||
result = (dstSize >= srcSize) or
|
||||
(skipTypes(dst, abstractInst).kind in IntegralTypes) or
|
||||
(skipTypes(src, abstractInst-{tyTypeDesc}).kind in IntegralTypes)
|
||||
if result and (dstSize > srcSize):
|
||||
message(conf, info, warnCastSizes, "target type is larger than source type")
|
||||
if result and src.kind == tyNil:
|
||||
result = dst.size <= conf.target.ptrSize
|
||||
return dst.size <= conf.target.ptrSize
|
||||
|
||||
proc isSymChoice(n: PNode): bool {.inline.} =
|
||||
result = n.kind in nkSymChoices
|
||||
@@ -359,7 +361,7 @@ proc semCast(c: PContext, n: PNode): PNode =
|
||||
let castedExpr = semExprWithType(c, n[1])
|
||||
if tfHasMeta in targetType.flags:
|
||||
localError(c.config, n[0].info, "cannot cast to a non concrete type: '$1'" % $targetType)
|
||||
if not isCastable(c, targetType, castedExpr.typ):
|
||||
if not isCastable(c, targetType, castedExpr.typ, n.info):
|
||||
let tar = $targetType
|
||||
let alt = typeToString(targetType, preferDesc)
|
||||
let msg = if tar != alt: tar & "=" & alt else: tar
|
||||
|
||||
@@ -66,6 +66,7 @@ type
|
||||
TEffects = object
|
||||
exc: PNode # stack of exceptions
|
||||
tags: PNode # list of tags
|
||||
forbids: PNode # list of tags
|
||||
bottom, inTryStmt, inExceptOrFinallyStmt, leftPartOfAsgn: int
|
||||
owner: PSym
|
||||
ownerModule: PSym
|
||||
@@ -388,6 +389,12 @@ proc addTag(a: PEffects, e, comesFrom: PNode) =
|
||||
if sameType(aa[i].typ.skipTypes(skipPtrs), e.typ.skipTypes(skipPtrs)): return
|
||||
throws(a.tags, e, comesFrom)
|
||||
|
||||
proc addNotTag(a: PEffects, e, comesFrom: PNode) =
|
||||
var aa = a.forbids
|
||||
for i in 0..<aa.len:
|
||||
if sameType(aa[i].typ.skipTypes(skipPtrs), e.typ.skipTypes(skipPtrs)): return
|
||||
throws(a.forbids, e, comesFrom)
|
||||
|
||||
proc mergeRaises(a: PEffects, b, comesFrom: PNode) =
|
||||
if b.isNil:
|
||||
addRaiseEffect(a, createRaise(a.graph, comesFrom), comesFrom)
|
||||
@@ -403,6 +410,7 @@ proc mergeTags(a: PEffects, b, comesFrom: PNode) =
|
||||
proc listEffects(a: PEffects) =
|
||||
for e in items(a.exc): message(a.config, e.info, hintUser, typeToString(e.typ))
|
||||
for e in items(a.tags): message(a.config, e.info, hintUser, typeToString(e.typ))
|
||||
for e in items(a.forbids): message(a.config, e.info, hintUser, typeToString(e.typ))
|
||||
#if a.maxLockLevel != 0:
|
||||
# message(e.info, hintUser, "lockLevel: " & a.maxLockLevel)
|
||||
|
||||
@@ -604,7 +612,7 @@ proc isOwnedProcVar(tracked: PEffects; n: PNode): bool =
|
||||
|
||||
proc isNoEffectList(n: PNode): bool {.inline.} =
|
||||
assert n.kind == nkEffectList
|
||||
n.len == 0 or (n[tagEffects] == nil and n[exceptionEffects] == nil)
|
||||
n.len == 0 or (n[tagEffects] == nil and n[exceptionEffects] == nil and n[forbiddenEffects] == nil)
|
||||
|
||||
proc isTrival(caller: PNode): bool {.inline.} =
|
||||
result = caller.kind == nkSym and caller.sym.magic in {mEqProc, mIsNil, mMove, mWasMoved, mSwap}
|
||||
@@ -924,14 +932,17 @@ type
|
||||
oldLocked: int
|
||||
oldLockLevel: TLockLevel
|
||||
enforcedGcSafety, enforceNoSideEffects: bool
|
||||
oldExc, oldTags: int
|
||||
exc, tags: PNode
|
||||
oldExc, oldTags, oldForbids: int
|
||||
exc, tags, forbids: PNode
|
||||
|
||||
proc createBlockContext(tracked: PEffects): PragmaBlockContext =
|
||||
var oldForbidsLen = 0
|
||||
if tracked.forbids != nil: oldForbidsLen = tracked.forbids.len
|
||||
result = PragmaBlockContext(oldLocked: tracked.locked.len,
|
||||
oldLockLevel: tracked.currLockLevel,
|
||||
enforcedGcSafety: false, enforceNoSideEffects: false,
|
||||
oldExc: tracked.exc.len, oldTags: tracked.tags.len)
|
||||
oldExc: tracked.exc.len, oldTags: tracked.tags.len,
|
||||
oldForbids: oldForbidsLen)
|
||||
|
||||
proc applyBlockContext(tracked: PEffects, bc: PragmaBlockContext) =
|
||||
if bc.enforcedGcSafety: tracked.inEnforcedGcSafe = true
|
||||
@@ -952,6 +963,10 @@ proc unapplyBlockContext(tracked: PEffects; bc: PragmaBlockContext) =
|
||||
setLen(tracked.tags.sons, bc.oldTags)
|
||||
for t in bc.tags:
|
||||
addTag(tracked, t, t)
|
||||
if bc.forbids != nil:
|
||||
setLen(tracked.forbids.sons, bc.oldForbids)
|
||||
for t in bc.forbids:
|
||||
addNotTag(tracked, t, t)
|
||||
|
||||
proc castBlock(tracked: PEffects, pragma: PNode, bc: var PragmaBlockContext) =
|
||||
case whichPragma(pragma)
|
||||
@@ -966,6 +981,13 @@ proc castBlock(tracked: PEffects, pragma: PNode, bc: var PragmaBlockContext) =
|
||||
else:
|
||||
bc.tags = newNodeI(nkArgList, pragma.info)
|
||||
bc.tags.add n
|
||||
of wForbids:
|
||||
let n = pragma[1]
|
||||
if n.kind in {nkCurly, nkBracket}:
|
||||
bc.forbids = n
|
||||
else:
|
||||
bc.forbids = newNodeI(nkArgList, pragma.info)
|
||||
bc.forbids.add n
|
||||
of wRaises:
|
||||
let n = pragma[1]
|
||||
if n.kind in {nkCurly, nkBracket}:
|
||||
@@ -1274,7 +1296,7 @@ proc subtypeRelation(g: ModuleGraph; spec, real: PNode): bool =
|
||||
|
||||
proc checkRaisesSpec(g: ModuleGraph; emitWarnings: bool; spec, real: PNode, msg: string, hints: bool;
|
||||
effectPredicate: proc (g: ModuleGraph; a, b: PNode): bool {.nimcall.};
|
||||
hintsArg: PNode = nil) =
|
||||
hintsArg: PNode = nil; isForbids: bool = false) =
|
||||
# check that any real exception is listed in 'spec'; mark those as used;
|
||||
# report any unused exception
|
||||
var used = initIntSet()
|
||||
@@ -1282,8 +1304,11 @@ proc checkRaisesSpec(g: ModuleGraph; emitWarnings: bool; spec, real: PNode, msg:
|
||||
block search:
|
||||
for s in 0..<spec.len:
|
||||
if effectPredicate(g, spec[s], r):
|
||||
if isForbids: break
|
||||
used.incl(s)
|
||||
break search
|
||||
if isForbids:
|
||||
break search
|
||||
# XXX call graph analysis would be nice here!
|
||||
pushInfoContext(g.config, spec.info)
|
||||
var rr = if r.kind == nkRaiseStmt: r[0] else: r
|
||||
@@ -1312,6 +1337,10 @@ proc checkMethodEffects*(g: ModuleGraph; disp, branch: PSym) =
|
||||
if not isNil(tagsSpec):
|
||||
checkRaisesSpec(g, false, tagsSpec, actual[tagEffects],
|
||||
"can have an unlisted effect: ", hints=off, subtypeRelation)
|
||||
let forbidsSpec = effectSpec(p, wForbids)
|
||||
if not isNil(forbidsSpec):
|
||||
checkRaisesSpec(g, false, forbidsSpec, actual[tagEffects],
|
||||
"has an illegal effect: ", hints=off, subtypeRelation, isForbids=true)
|
||||
if sfThread in disp.flags and notGcSafe(branch.typ):
|
||||
localError(g.config, branch.info, "base method is GC-safe, but '$1' is not" %
|
||||
branch.name.s)
|
||||
@@ -1349,6 +1378,12 @@ proc setEffectsForProcType*(g: ModuleGraph; t: PType, n: PNode; s: PSym = nil) =
|
||||
elif s != nil and (s.magic != mNone or {sfImportc, sfExportc} * s.flags == {sfImportc}):
|
||||
effects[tagEffects] = newNodeI(nkArgList, effects.info)
|
||||
|
||||
let forbidsSpec = effectSpec(n, wForbids)
|
||||
if not isNil(forbidsSpec):
|
||||
effects[forbiddenEffects] = forbidsSpec
|
||||
elif s != nil and (s.magic != mNone or {sfImportc, sfExportc} * s.flags == {sfImportc}):
|
||||
effects[forbiddenEffects] = newNodeI(nkArgList, effects.info)
|
||||
|
||||
let requiresSpec = propSpec(n, wRequires)
|
||||
if not isNil(requiresSpec):
|
||||
effects[requiresEffects] = requiresSpec
|
||||
@@ -1365,6 +1400,7 @@ proc rawInitEffects(g: ModuleGraph; effects: PNode) =
|
||||
newSeq(effects.sons, effectListLen)
|
||||
effects[exceptionEffects] = newNodeI(nkArgList, effects.info)
|
||||
effects[tagEffects] = newNodeI(nkArgList, effects.info)
|
||||
effects[forbiddenEffects] = newNodeI(nkArgList, effects.info)
|
||||
effects[requiresEffects] = g.emptyNode
|
||||
effects[ensuresEffects] = g.emptyNode
|
||||
effects[pragmasEffects] = g.emptyNode
|
||||
@@ -1374,6 +1410,7 @@ proc initEffects(g: ModuleGraph; effects: PNode; s: PSym; t: var TEffects; c: PC
|
||||
|
||||
t.exc = effects[exceptionEffects]
|
||||
t.tags = effects[tagEffects]
|
||||
t.forbids = effects[forbiddenEffects]
|
||||
t.owner = s
|
||||
t.ownerModule = s.getModule
|
||||
t.init = @[]
|
||||
@@ -1448,6 +1485,15 @@ proc trackProc*(c: PContext; s: PSym, body: PNode) =
|
||||
else:
|
||||
effects[tagEffects] = t.tags
|
||||
|
||||
let forbidsSpec = effectSpec(p, wForbids)
|
||||
if not isNil(forbidsSpec):
|
||||
checkRaisesSpec(g, false, forbidsSpec, t.tags, "has an illegal effect: ",
|
||||
hints=off, subtypeRelation, isForbids=true)
|
||||
# after the check, use the formal spec:
|
||||
effects[forbiddenEffects] = forbidsSpec
|
||||
else:
|
||||
effects[forbiddenEffects] = t.forbids
|
||||
|
||||
let requiresSpec = propSpec(p, wRequires)
|
||||
if not isNil(requiresSpec):
|
||||
effects[requiresEffects] = requiresSpec
|
||||
|
||||
@@ -1050,7 +1050,7 @@ proc semCase(c: PContext, n: PNode; flags: TExprFlags): PNode =
|
||||
var typ = commonTypeBegin
|
||||
var hasElse = false
|
||||
let caseTyp = skipTypes(n[0].typ, abstractVar-{tyTypeDesc})
|
||||
const shouldChckCovered = {tyInt..tyInt64, tyChar, tyEnum, tyUInt..tyUInt32, tyBool}
|
||||
const shouldChckCovered = {tyInt..tyInt64, tyChar, tyEnum, tyUInt..tyUInt64, tyBool}
|
||||
case caseTyp.kind
|
||||
of shouldChckCovered:
|
||||
chckCovered = true
|
||||
@@ -2300,7 +2300,7 @@ proc semPragmaBlock(c: PContext, n: PNode): PNode =
|
||||
for p in pragmaList:
|
||||
if whichPragma(p) == wCast:
|
||||
case whichPragma(p[1])
|
||||
of wGcSafe, wNoSideEffect, wTags, wRaises:
|
||||
of wGcSafe, wNoSideEffect, wTags, wForbids, wRaises:
|
||||
discard "handled in sempass2"
|
||||
of wUncheckedAssign:
|
||||
inUncheckedAssignSection = 1
|
||||
|
||||
@@ -1372,6 +1372,13 @@ proc compatibleEffectsAux(se, re: PNode): bool =
|
||||
return false
|
||||
result = true
|
||||
|
||||
proc hasIncompatibleEffect(se, re: PNode): bool =
|
||||
if re.isNil: return false
|
||||
for r in items(re):
|
||||
for s in items(se):
|
||||
if safeInheritanceDiff(r.typ, s.typ) != high(int):
|
||||
return true
|
||||
|
||||
type
|
||||
EffectsCompat* = enum
|
||||
efCompat
|
||||
@@ -1381,6 +1388,7 @@ type
|
||||
efTagsUnknown
|
||||
efLockLevelsDiffer
|
||||
efEffectsDelayed
|
||||
efTagsIllegal
|
||||
|
||||
proc compatibleEffects*(formal, actual: PType): EffectsCompat =
|
||||
# for proc type compatibility checking:
|
||||
@@ -1414,6 +1422,14 @@ proc compatibleEffects*(formal, actual: PType): EffectsCompat =
|
||||
if not res:
|
||||
#if tfEffectSystemWorkaround notin actual.flags:
|
||||
return efTagsDiffer
|
||||
|
||||
let sn = spec[forbiddenEffects]
|
||||
if not isNil(sn) and sn.kind != nkArgList:
|
||||
if 0 == real.len:
|
||||
return efTagsUnknown
|
||||
elif hasIncompatibleEffect(sn, real[tagEffects]):
|
||||
return efTagsIllegal
|
||||
|
||||
if formal.lockLevel.ord < 0 or
|
||||
actual.lockLevel.ord <= formal.lockLevel.ord:
|
||||
|
||||
@@ -1627,6 +1643,8 @@ proc typeMismatch*(conf: ConfigRef; info: TLineInfo, formal, actual: PType, n: P
|
||||
msg.add "\nlock levels differ"
|
||||
of efEffectsDelayed:
|
||||
msg.add "\n.effectsOf annotations differ"
|
||||
of efTagsIllegal:
|
||||
msg.add "\n.notTag catched an illegal effect"
|
||||
localError(conf, info, msg)
|
||||
|
||||
proc isTupleRecursive(t: PType, cycleDetector: var IntSet): bool =
|
||||
|
||||
@@ -114,8 +114,12 @@ template decodeBx(k: untyped) {.dirty.} =
|
||||
let rbx = instr.regBx - wordExcess
|
||||
ensureKind(k)
|
||||
|
||||
template move(a, b: untyped) {.dirty.} = system.shallowCopy(a, b)
|
||||
# XXX fix minor 'shallowCopy' overloading bug in compiler
|
||||
template move(a, b: untyped) {.dirty.} =
|
||||
when defined(gcArc) or defined(gcOrc):
|
||||
a = move b
|
||||
else:
|
||||
system.shallowCopy(a, b)
|
||||
# XXX fix minor 'shallowCopy' overloading bug in compiler
|
||||
|
||||
proc derefPtrToReg(address: BiggestInt, typ: PType, r: var TFullReg, isAssign: bool): bool =
|
||||
# nim bug: `isAssign: static bool` doesn't work, giving odd compiler error
|
||||
|
||||
@@ -324,6 +324,8 @@ proc registerAdditionalOps*(c: PCtx) =
|
||||
getEffectList(c, a, exceptionEffects)
|
||||
registerCallback c, "stdlib.effecttraits.getTagsListImpl", proc (a: VmArgs) =
|
||||
getEffectList(c, a, tagEffects)
|
||||
registerCallback c, "stdlib.effecttraits.getForbidsListImpl", proc (a: VmArgs) =
|
||||
getEffectList(c, a, forbiddenEffects)
|
||||
|
||||
registerCallback c, "stdlib.effecttraits.isGcSafeImpl", proc (a: VmArgs) =
|
||||
let fn = getNode(a, 0)
|
||||
|
||||
@@ -71,7 +71,7 @@ type
|
||||
wSinkInference = "sinkInference", wWarnings = "warnings",
|
||||
wHints = "hints", wOptimization = "optimization", wRaises = "raises",
|
||||
wWrites = "writes", wReads = "reads", wSize = "size", wEffects = "effects", wTags = "tags",
|
||||
wRequires = "requires", wEnsures = "ensures", wInvariant = "invariant",
|
||||
wForbids = "forbids", wRequires = "requires", wEnsures = "ensures", wInvariant = "invariant",
|
||||
wAssume = "assume", wAssert = "assert",
|
||||
wDeadCodeElimUnused = "deadCodeElim", # deprecated, dead code elim always happens
|
||||
wSafecode = "safecode", wPackage = "package", wNoForward = "noforward", wReorder = "reorder",
|
||||
@@ -145,4 +145,4 @@ else:
|
||||
for i in a..b:
|
||||
if cmpIgnoreStyle($i, s) == 0:
|
||||
return i
|
||||
result = default
|
||||
result = default
|
||||
|
||||
@@ -26,4 +26,3 @@ when defined(windows) and not defined(booting):
|
||||
switch("define", "nimRawSetjmp")
|
||||
|
||||
switch("define", "nimVersion:" & NimVersion)
|
||||
switch("define", "nimPreviewDotLikeOps")
|
||||
|
||||
400
doc/astspec.txt
400
doc/astspec.txt
File diff suppressed because it is too large
Load Diff
@@ -57,11 +57,11 @@ project. This allows you to take the generated code and place it directly
|
||||
into a project using any of these languages. Here are some typical command-
|
||||
line invocations:
|
||||
|
||||
.. code:: cmd
|
||||
|
||||
nim c hallo.nim
|
||||
nim cpp hallo.nim
|
||||
nim objc hallo.nim
|
||||
```cmd
|
||||
nim c hallo.nim
|
||||
nim cpp hallo.nim
|
||||
nim objc hallo.nim
|
||||
```
|
||||
|
||||
The compiler commands select the target backend, but if needed you can
|
||||
`specify additional switches for cross-compilation
|
||||
@@ -99,9 +99,9 @@ default is a ``.js`` file that is supposed to be referenced in an ``.html``
|
||||
file. However, you can also run the code with `nodejs`:idx:
|
||||
(`<http://nodejs.org>`_):
|
||||
|
||||
.. code:: cmd
|
||||
|
||||
```cmd
|
||||
nim js -d:nodejs -r examples/hallo.nim
|
||||
```
|
||||
|
||||
If you experience errors saying that `globalThis` is not defined, be
|
||||
sure to run a recent version of Node.js (at least 12.0).
|
||||
@@ -155,26 +155,26 @@ To wrap native code, take a look at the `c2nim tool <https://github.com/nim-lang
|
||||
with the process of scanning and transforming header files into a Nim
|
||||
interface.
|
||||
|
||||
C invocation example
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
### C invocation example
|
||||
|
||||
Create a ``logic.c`` file with the following content:
|
||||
|
||||
.. code-block:: c
|
||||
```c
|
||||
int addTwoIntegers(int a, int b)
|
||||
{
|
||||
return a + b;
|
||||
}
|
||||
```
|
||||
|
||||
Create a ``calculator.nim`` file with the following content:
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
```nim
|
||||
{.compile: "logic.c".}
|
||||
proc addTwoIntegers(a, b: cint): cint {.importc.}
|
||||
|
||||
when isMainModule:
|
||||
echo addTwoIntegers(3, 7)
|
||||
```
|
||||
|
||||
With these two files in place, you can run `nim c -r calculator.nim`:cmd: and
|
||||
the Nim compiler will compile the ``logic.c`` file in addition to
|
||||
@@ -183,19 +183,18 @@ run. Another way to link the C file statically and get the same effect would
|
||||
be to remove the line with the `compile` pragma and run the following
|
||||
typical Unix commands:
|
||||
|
||||
.. code:: cmd
|
||||
|
||||
gcc -c logic.c
|
||||
ar rvs mylib.a logic.o
|
||||
nim c --passL:mylib.a -r calculator.nim
|
||||
```cmd
|
||||
gcc -c logic.c
|
||||
ar rvs mylib.a logic.o
|
||||
nim c --passL:mylib.a -r calculator.nim
|
||||
```
|
||||
|
||||
Just like in this example we pass the path to the ``mylib.a`` library (and we
|
||||
could as well pass ``logic.o``) we could be passing switches to link any other
|
||||
static C library.
|
||||
|
||||
|
||||
JavaScript invocation example
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
### JavaScript invocation example
|
||||
|
||||
Create a ``host.html`` file with the following content:
|
||||
|
||||
@@ -214,12 +213,12 @@ Create a ``host.html`` file with the following content:
|
||||
Create a ``calculator.nim`` file with the following content (or reuse the one
|
||||
from the previous section):
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
```nim
|
||||
proc addTwoIntegers(a, b: int): int {.importc.}
|
||||
|
||||
when isMainModule:
|
||||
echo addTwoIntegers(3, 7)
|
||||
```
|
||||
|
||||
Compile the Nim code to JavaScript with `nim js -o:calculator.js
|
||||
calculator.nim`:cmd: and open ``host.html`` in a browser. If the browser supports
|
||||
@@ -251,23 +250,21 @@ The name `NimMain` can be influenced via the `--nimMainPrefix:prefix` switch.
|
||||
Use `--nimMainPrefix:MyLib` and the function to call is named `MyLibNimMain`.
|
||||
|
||||
|
||||
Nim invocation example from C
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
### Nim invocation example from C
|
||||
|
||||
Create a ``fib.nim`` file with the following content:
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
```nim
|
||||
proc fib(a: cint): cint {.exportc.} =
|
||||
if a <= 2:
|
||||
result = 1
|
||||
else:
|
||||
result = fib(a - 1) + fib(a - 2)
|
||||
```
|
||||
|
||||
Create a ``maths.c`` file with the following content:
|
||||
|
||||
.. code-block:: c
|
||||
|
||||
```c
|
||||
#include <stdio.h>
|
||||
|
||||
int fib(int a);
|
||||
@@ -280,15 +277,16 @@ Create a ``maths.c`` file with the following content:
|
||||
printf("Fib of %d is %d\n", f, fib(f));
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
Now you can run the following Unix like commands to first generate C sources
|
||||
from the Nim code, then link them into a static binary along your main C
|
||||
program:
|
||||
|
||||
.. code:: cmd
|
||||
|
||||
```cmd
|
||||
nim c --noMain --noLinking fib.nim
|
||||
gcc -o m -I$HOME/.cache/nim/fib_d -Ipath/to/nim/lib $HOME/.cache/nim/fib_d/*.c maths.c
|
||||
```
|
||||
|
||||
The first command runs the Nim compiler with three special options to avoid
|
||||
generating a `main()`:c: function in the generated files and to avoid linking the
|
||||
@@ -300,10 +298,10 @@ have to tell the C compiler where to find Nim's ``nimbase.h`` header file.
|
||||
Instead of depending on the generation of the individual ``.c`` files you can
|
||||
also ask the Nim compiler to generate a statically linked library:
|
||||
|
||||
.. code:: cmd
|
||||
|
||||
```cmd
|
||||
nim c --app:staticLib --noMain fib.nim
|
||||
gcc -o m -Inimcache -Ipath/to/nim/lib maths.c libfib.nim.a
|
||||
```
|
||||
|
||||
The Nim compiler will handle linking the source files generated in the
|
||||
``nimcache`` directory into the ``libfib.nim.a`` static library, which you can
|
||||
@@ -312,30 +310,29 @@ vary for each system. For instance, on Linux systems you will likely need to
|
||||
use `-ldl`:option: too to link in required dlopen functionality.
|
||||
|
||||
|
||||
Nim invocation example from JavaScript
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
### Nim invocation example from JavaScript
|
||||
|
||||
Create a ``mhost.html`` file with the following content:
|
||||
|
||||
.. code-block::
|
||||
|
||||
```
|
||||
<html><body>
|
||||
<script type="text/javascript" src="fib.js"></script>
|
||||
<script type="text/javascript">
|
||||
alert("Fib for 9 is " + fib(9));
|
||||
</script>
|
||||
</body></html>
|
||||
```
|
||||
|
||||
Create a ``fib.nim`` file with the following content (or reuse the one
|
||||
from the previous section):
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
```nim
|
||||
proc fib(a: cint): cint {.exportc.} =
|
||||
if a <= 2:
|
||||
result = 1
|
||||
else:
|
||||
result = fib(a - 1) + fib(a - 2)
|
||||
```
|
||||
|
||||
Compile the Nim code to JavaScript with `nim js -o:fib.js fib.nim`:cmd: and
|
||||
open ``mhost.html`` in a browser. If the browser supports javascript, you
|
||||
@@ -382,10 +379,10 @@ from being freed with `GC_ref <system.html#GC_ref,string>`_ and `GC_unref
|
||||
A similar thing happens with C code invoking Nim code which returns a
|
||||
`cstring`. Consider the following proc:
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
```nim
|
||||
proc gimme(): cstring {.exportc.} =
|
||||
result = "Hey there C code! " & $rand(100)
|
||||
```
|
||||
|
||||
Since Nim's reference counting mechanism is not aware of the C code, once the
|
||||
`gimme` proc has finished it can reclaim the memory of the `cstring`.
|
||||
|
||||
@@ -59,8 +59,7 @@ things like `echo "done"`. Don't use `unittest.suite` and `unittest.test`.
|
||||
|
||||
Sample test:
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
```nim
|
||||
block: # foo
|
||||
doAssert foo(1) == 10
|
||||
|
||||
@@ -76,6 +75,7 @@ Sample test:
|
||||
@[false, false], @[false, false]]
|
||||
# doAssert with `not` can now be done as follows:
|
||||
doAssert not (1 == 2)
|
||||
```
|
||||
|
||||
Always refer to a GitHub issue using the following exact syntax: ``bug #1234`` as shown
|
||||
above, so that it's consistent and easier to search or for tooling. Some browser
|
||||
@@ -110,8 +110,7 @@ For a full spec, see here: ``testament/specs.nim``
|
||||
|
||||
An example of a test:
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
```nim
|
||||
discard """
|
||||
errormsg: "type mismatch: got (PTest)"
|
||||
"""
|
||||
@@ -123,6 +122,7 @@ An example of a test:
|
||||
|
||||
var buf: PTest
|
||||
buf.test()
|
||||
```
|
||||
|
||||
|
||||
Running tests
|
||||
@@ -130,9 +130,9 @@ Running tests
|
||||
|
||||
You can run the tests with
|
||||
|
||||
.. code-block:: cmd
|
||||
|
||||
```cmd
|
||||
./koch tests
|
||||
```
|
||||
|
||||
which will run a good subset of tests. Some tests may fail. If you
|
||||
only want to see the output of failing tests, go for
|
||||
@@ -145,17 +145,17 @@ You can also run only a single category of tests. A category is a subdirectory
|
||||
in the ``tests/`` directory. There are a couple of special categories; for a
|
||||
list of these, see ``testament/categories.nim``, at the bottom.
|
||||
|
||||
.. code:: cmd
|
||||
|
||||
```cmd
|
||||
./koch tests c lib # compiles / runs stdlib modules, including `isMainModule` tests
|
||||
./koch tests c megatest # runs a set of tests that can be combined into 1
|
||||
```
|
||||
|
||||
To run a single test:
|
||||
|
||||
.. code:: cmd
|
||||
|
||||
```cmd
|
||||
./koch test run <category>/<name> # e.g.: tuples/ttuples_issues
|
||||
./koch test run tests/stdlib/tos.nim # can also provide relative path
|
||||
```
|
||||
|
||||
For reproducible tests (to reproduce an environment more similar to the one
|
||||
run by Continuous Integration on github actions/azure pipelines), you may want to disable your
|
||||
@@ -174,25 +174,25 @@ The tester can compare two test runs. First, you need to create a
|
||||
reference test. You'll also need to the commit id, because that's what
|
||||
the tester needs to know in order to compare the two.
|
||||
|
||||
.. code:: cmd
|
||||
|
||||
```cmd
|
||||
git checkout devel
|
||||
DEVEL_COMMIT=$(git rev-parse HEAD)
|
||||
./koch tests
|
||||
```
|
||||
|
||||
Then switch over to your changes and run the tester again.
|
||||
|
||||
.. code:: cmd
|
||||
|
||||
```cmd
|
||||
git checkout your-changes
|
||||
./koch tests
|
||||
```
|
||||
|
||||
Then you can ask the tester to create a ``testresults.html`` which will
|
||||
tell you if any new tests passed/failed.
|
||||
|
||||
.. code:: cmd
|
||||
|
||||
```cmd
|
||||
./koch tests --print html $DEVEL_COMMIT
|
||||
```
|
||||
|
||||
|
||||
Deprecation
|
||||
@@ -201,8 +201,7 @@ Deprecation
|
||||
Backward compatibility is important, so instead of a rename you need to deprecate
|
||||
the old name and introduce a new name:
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
```nim
|
||||
# for routines (proc/template/macro/iterator) and types:
|
||||
proc oldProc(a: int, b: float): bool {.deprecated:
|
||||
"deprecated since v1.2.3; use `newImpl: string -> int` instead".} = discard
|
||||
@@ -214,6 +213,7 @@ the old name and introduce a new name:
|
||||
# (likewise with object types and their fields):
|
||||
type Bar {.deprecated.} = enum bar0, bar1
|
||||
type Barz = enum baz0, baz1 {.deprecated.}, baz2
|
||||
```
|
||||
|
||||
|
||||
See also `Deprecated <manual.html#pragmas-deprecated-pragma>`_
|
||||
@@ -234,12 +234,13 @@ test cases (typically 1 to 3 `assert` statements, depending on complexity).
|
||||
These `runnableExamples` are automatically run by `nim doc mymodule.nim`:cmd:
|
||||
as well as `testament`:cmd: and guarantee they stay in sync.
|
||||
|
||||
.. code-block:: nim
|
||||
```nim
|
||||
proc addBar*(a: string): string =
|
||||
## Adds "Bar" to `a`.
|
||||
runnableExamples:
|
||||
assert "baz".addBar == "bazBar"
|
||||
result = a & "Bar"
|
||||
```
|
||||
|
||||
See `parentDir <os.html#parentDir,string>`_ example.
|
||||
|
||||
@@ -247,47 +248,49 @@ The RestructuredText Nim uses has a special syntax for including code snippets
|
||||
embedded in documentation; these are not run by `nim doc`:cmd: and therefore are
|
||||
not guaranteed to stay in sync, so `runnableExamples` is almost always preferred:
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
````nim
|
||||
proc someProc*(): string =
|
||||
## Returns "something"
|
||||
##
|
||||
## .. code-block::
|
||||
## echo someProc() # "something"
|
||||
## ```
|
||||
## echo someProc() # "something"
|
||||
## ```
|
||||
result = "something" # single-hash comments do not produce documentation
|
||||
````
|
||||
|
||||
The ``.. code-block:: nim`` followed by a newline and an indentation instructs the
|
||||
The \`\`\` followed by a newline and an indentation instructs the
|
||||
`nim doc`:cmd: command to produce syntax-highlighted example code with the
|
||||
documentation (``.. code-block::`` is sufficient from inside a nim module).
|
||||
documentation (\`\`\` is sufficient inside a ``.nim`` module, while from
|
||||
a ``.md`` one needs to set the language explicitly as \`\`\`nim).
|
||||
|
||||
When forward declaration is used, the documentation should be included with the
|
||||
first appearance of the proc.
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
```nim
|
||||
proc hello*(): string
|
||||
## Put documentation here
|
||||
proc nothing() = discard
|
||||
proc hello*(): string =
|
||||
## ignore this
|
||||
echo "hello"
|
||||
```
|
||||
|
||||
The preferred documentation style is to begin with a capital letter and use
|
||||
the third-person singular. That is, between:
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
```nim
|
||||
proc hello*(): string =
|
||||
## Returns "hello"
|
||||
result = "hello"
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
```nim
|
||||
proc hello*(): string =
|
||||
## say hello
|
||||
result = "hello"
|
||||
```
|
||||
|
||||
the first is preferred.
|
||||
|
||||
@@ -296,8 +299,9 @@ in the postfix form for uniformity, that is after \`text in backticks\`.
|
||||
For example an ``:idx:`` role for referencing a topic ("SQLite" in the
|
||||
example below) from `Nim Index`_ can be used in doc comment this way:
|
||||
|
||||
.. code-block:: nim
|
||||
```nim
|
||||
## A higher level `SQLite`:idx: database wrapper.
|
||||
```
|
||||
|
||||
.. _`Nim Index`: https://nim-lang.org/docs/theindex.html
|
||||
|
||||
@@ -355,50 +359,50 @@ New `defined(foo)` symbols need to be prefixed by the nimble package name, or
|
||||
by `nim` for symbols in nim sources (e.g. compiler, standard library). This is
|
||||
to avoid name conflicts across packages.
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
```nim
|
||||
# if in nim sources
|
||||
when defined(allocStats): discard # bad, can cause conflicts
|
||||
when defined(nimAllocStats): discard # preferred
|
||||
# if in a package `cligen`:
|
||||
when defined(debug): discard # bad, can cause conflicts
|
||||
when defined(cligenDebug): discard # preferred
|
||||
```
|
||||
|
||||
.. _noimplicitbool:
|
||||
Take advantage of no implicit bool conversion
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
```nim
|
||||
doAssert isValid() == true
|
||||
doAssert isValid() # preferred
|
||||
```
|
||||
|
||||
.. _design_for_mcs:
|
||||
Design with method call syntax chaining in mind
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
```nim
|
||||
proc foo(cond: bool, lines: seq[string]) # bad
|
||||
proc foo(lines: seq[string], cond: bool) # preferred
|
||||
# can be called as: `getLines().foo(false)`
|
||||
```
|
||||
|
||||
.. _avoid_quit:
|
||||
Use exceptions (including `assert` / `doAssert`) instead of `quit`
|
||||
rationale: https://forum.nim-lang.org/t/4089
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
```nim
|
||||
quit() # bad in almost all cases
|
||||
doAssert() # preferred
|
||||
```
|
||||
|
||||
.. _tests_use_doAssert:
|
||||
Use `doAssert` (or `unittest.check`, `unittest.require`), not `assert` in all
|
||||
tests so they'll be enabled even with `--assertions:off`:option:.
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
```nim
|
||||
block: # foo
|
||||
assert foo() # bad
|
||||
doAssert foo() # preferred
|
||||
```
|
||||
|
||||
.. _runnableExamples_use_assert:
|
||||
An exception to the above rule is `runnableExamples` and ``code-block`` rst blocks
|
||||
@@ -407,33 +411,33 @@ instead of `doAssert`. Note that `nim doc -d:danger main`:cmd: won't pass `-d:da
|
||||
`runnableExamples`, but `nim doc --doccmd:-d:danger main`:cmd: would, and so would the
|
||||
second example below:
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
```nim
|
||||
runnableExamples:
|
||||
doAssert foo() # bad
|
||||
assert foo() # preferred
|
||||
|
||||
runnableExamples("-d:danger"):
|
||||
doAssert foo() # `assert` would be disabled here, so `doAssert` makes more sense
|
||||
```
|
||||
|
||||
.. _delegate_printing:
|
||||
Delegate printing to caller: return `string` instead of calling `echo`
|
||||
rationale: it's more flexible (e.g. allows the caller to call custom printing,
|
||||
including prepending location info, writing to log files, etc).
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
```nim
|
||||
proc foo() = echo "bar" # bad
|
||||
proc foo(): string = "bar" # preferred (usually)
|
||||
```
|
||||
|
||||
.. _use_Option:
|
||||
[Ongoing debate] Consider using Option instead of return bool + var argument,
|
||||
unless stack allocation is needed (e.g. for efficiency).
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
```nim
|
||||
proc foo(a: var Bar): bool
|
||||
proc foo(): Option[Bar]
|
||||
```
|
||||
|
||||
.. _use_doAssert_not_echo:
|
||||
Tests (including in testament) should always prefer assertions over `echo`,
|
||||
@@ -441,10 +445,10 @@ except when that's not possible. It's more precise, easier for readers and
|
||||
maintainers to where expected values refer to. See for example
|
||||
https://github.com/nim-lang/Nim/pull/9335 and https://forum.nim-lang.org/t/4089
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
```nim
|
||||
echo foo() # adds a line for testament in `output:` block inside `discard`.
|
||||
doAssert foo() == [1, 2] # preferred, except when not possible to do so.
|
||||
```
|
||||
|
||||
|
||||
The `git`:cmd: stuff
|
||||
@@ -480,10 +484,10 @@ General commit rules
|
||||
Always check your changes for whitespace errors using `git diff --check`:cmd:
|
||||
or add the following ``pre-commit`` hook:
|
||||
|
||||
.. code:: cmd
|
||||
|
||||
#!/bin/sh
|
||||
git diff --check --cached || exit $?
|
||||
```cmd
|
||||
#!/bin/sh
|
||||
git diff --check --cached || exit $?
|
||||
```
|
||||
5. Describe your commit and use your common sense.
|
||||
Example commit message::
|
||||
|
||||
@@ -565,10 +569,10 @@ Code reviews
|
||||
doesn't help much as it doesn't highlight moves. Instead, you can use something
|
||||
like this, see visual results `here <https://github.com/nim-lang/Nim/pull/10431#issuecomment-456968196>`_:
|
||||
|
||||
.. code:: cmd
|
||||
|
||||
git fetch origin pull/10431/head && git checkout FETCH_HEAD
|
||||
git diff --color-moved-ws=allow-indentation-change --color-moved=blocks HEAD^
|
||||
```cmd
|
||||
git fetch origin pull/10431/head && git checkout FETCH_HEAD
|
||||
git diff --color-moved-ws=allow-indentation-change --color-moved=blocks HEAD^
|
||||
```
|
||||
|
||||
3. In addition, you can view GitHub-like diffs locally to identify what was changed
|
||||
within a code block using `diff-highlight`:cmd: or `diff-so-fancy`:cmd:, e.g.:
|
||||
|
||||
@@ -30,8 +30,7 @@ Motivating example
|
||||
With the language mechanisms described here, a custom seq could be
|
||||
written as:
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
```nim
|
||||
type
|
||||
myseq*[T] = object
|
||||
len, cap: int
|
||||
@@ -91,7 +90,7 @@ written as:
|
||||
for i in 0..<result.len: result.data[i] = elems[i]
|
||||
|
||||
proc len*[T](x: myseq[T]): int {.inline.} = x.len
|
||||
|
||||
```
|
||||
|
||||
|
||||
Lifetime-tracking hooks
|
||||
@@ -119,20 +118,18 @@ to return.
|
||||
|
||||
The prototype of this hook for a type `T` needs to be:
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
```nim
|
||||
proc `=destroy`(x: var T)
|
||||
|
||||
```
|
||||
|
||||
The general pattern in `=destroy` looks like:
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
```nim
|
||||
proc `=destroy`(x: var T) =
|
||||
# first check if 'x' was moved to somewhere else:
|
||||
if x.field != nil:
|
||||
freeResource(x.field)
|
||||
|
||||
```
|
||||
|
||||
|
||||
`=sink` hook
|
||||
@@ -149,20 +146,19 @@ provide `=destroy` and `=copy`, the compiler will take care of the rest.
|
||||
|
||||
The prototype of this hook for a type `T` needs to be:
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
```nim
|
||||
proc `=sink`(dest: var T; source: T)
|
||||
|
||||
```
|
||||
|
||||
The general pattern in `=sink` looks like:
|
||||
|
||||
.. code-block:: nim
|
||||
```nim
|
||||
|
||||
proc `=sink`(dest: var T; source: T) =
|
||||
`=destroy`(dest)
|
||||
wasMoved(dest)
|
||||
dest.field = source.field
|
||||
|
||||
```
|
||||
|
||||
**Note**: `=sink` does not need to check for self-assignments.
|
||||
How self-assignments are handled is explained later in this document.
|
||||
@@ -177,29 +173,27 @@ operations.
|
||||
|
||||
The prototype of this hook for a type `T` needs to be:
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
```nim
|
||||
proc `=copy`(dest: var T; source: T)
|
||||
|
||||
```
|
||||
|
||||
The general pattern in `=copy` looks like:
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
```nim
|
||||
proc `=copy`(dest: var T; source: T) =
|
||||
# protect against self-assignments:
|
||||
if dest.field != source.field:
|
||||
`=destroy`(dest)
|
||||
wasMoved(dest)
|
||||
dest.field = duplicateResource(source.field)
|
||||
|
||||
```
|
||||
|
||||
The `=copy` proc can be marked with the `{.error.}` pragma. Then any assignment
|
||||
that otherwise would lead to a copy is prevented at compile-time. This looks like:
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
```nim
|
||||
proc `=copy`(dest: var T; source: T) {.error.}
|
||||
```
|
||||
|
||||
but a custom error message (e.g., `{.error: "custom error".}`) will not be emitted
|
||||
by the compiler. Notice that there is no `=` before the `{.error.}` pragma.
|
||||
@@ -215,9 +209,9 @@ memory or resources, but memory safety is not compromised.
|
||||
|
||||
The prototype of this hook for a type `T` needs to be:
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
```nim
|
||||
proc `=trace`(dest: var T; env: pointer)
|
||||
```
|
||||
|
||||
`env` is used by ORC to keep track of its internal state, it should be passed around
|
||||
to calls of the built-in `=trace` operation.
|
||||
@@ -233,8 +227,7 @@ prevent the automatic creation.
|
||||
|
||||
The general pattern in using `=destroy` with `=trace` looks like:
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
```nim
|
||||
type
|
||||
Test[T] = object
|
||||
size: Natural
|
||||
@@ -255,6 +248,7 @@ The general pattern in using `=destroy` with `=trace` looks like:
|
||||
for i in 0 ..< dest.size: `=trace`(dest.arr[i], env)
|
||||
|
||||
# following may be other custom "hooks" as required...
|
||||
```
|
||||
|
||||
**Note**: The `=trace` hooks (which are only used by `--mm:orc`) are currently more experimental and less refined
|
||||
than the other hooks.
|
||||
@@ -307,8 +301,7 @@ not a linear type system.
|
||||
The employed static analysis is limited and only concerned with local variables;
|
||||
however, object and tuple fields are treated as separate entities:
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
```nim
|
||||
proc consume(x: sink Obj) = discard "no implementation"
|
||||
|
||||
proc main =
|
||||
@@ -316,16 +309,16 @@ however, object and tuple fields are treated as separate entities:
|
||||
consume tup[0]
|
||||
# ok, only tup[0] was consumed, tup[1] is still alive:
|
||||
echo tup[1]
|
||||
|
||||
```
|
||||
|
||||
Sometimes it is required to explicitly `move` a value into its final position:
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
```nim
|
||||
proc main =
|
||||
var dest, src: array[10, string]
|
||||
# ...
|
||||
for i in 0..high(dest): dest[i] = move(src[i])
|
||||
```
|
||||
|
||||
An implementation is allowed, but not required to implement even more move
|
||||
optimizations (and the current implementation does not).
|
||||
@@ -344,11 +337,10 @@ use `{.push sinkInference: on.}` ... `{.pop.}`.
|
||||
The `.nosinks`:idx: pragma can be used to disable this inference
|
||||
for a single routine:
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
```nim
|
||||
proc addX(x: T; child: T) {.nosinks.} =
|
||||
x.s.add child
|
||||
|
||||
```
|
||||
|
||||
The details of the inference algorithm are currently undocumented.
|
||||
|
||||
@@ -456,8 +448,7 @@ The complex case looks like a variant of `x = f(x)`, we consider
|
||||
`x = select(rand() < 0.5, x, y)` here:
|
||||
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
```nim
|
||||
proc select(cond: bool; a, b: sink string): string =
|
||||
if cond:
|
||||
result = a # moves a into result
|
||||
@@ -469,13 +460,11 @@ The complex case looks like a variant of `x = f(x)`, we consider
|
||||
var y = "xyz"
|
||||
# possible self-assignment:
|
||||
x = select(true, x, y)
|
||||
|
||||
```
|
||||
|
||||
Is transformed into:
|
||||
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
```nim
|
||||
proc select(cond: bool; a, b: sink string): string =
|
||||
try:
|
||||
if cond:
|
||||
@@ -506,6 +495,7 @@ Is transformed into:
|
||||
finally:
|
||||
`=destroy`(y)
|
||||
`=destroy`(x)
|
||||
```
|
||||
|
||||
As can be manually verified, this transformation is correct for
|
||||
self-assignments.
|
||||
@@ -527,8 +517,7 @@ that the pointer does not outlive its origin. No destructor call is injected
|
||||
for expressions of type `lent T` or of type `var T`.
|
||||
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
```nim
|
||||
type
|
||||
Tree = object
|
||||
kids: seq[Tree]
|
||||
@@ -553,6 +542,7 @@ for expressions of type `lent T` or of type `var T`.
|
||||
# everything turned into moves:
|
||||
let t = construct(@[construct(@[]), construct(@[])])
|
||||
echo t[0] # accessor does not copy the element!
|
||||
```
|
||||
|
||||
|
||||
The cursor pragma
|
||||
@@ -564,12 +554,12 @@ This means that cyclic structures cannot be freed
|
||||
immediately (`--mm:orc`:option: ships with a cycle collector).
|
||||
With the `cursor` pragma one can break up cycles declaratively:
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
```nim
|
||||
type
|
||||
Node = ref object
|
||||
left: Node # owning ref
|
||||
right {.cursor.}: Node # non-owning ref
|
||||
```
|
||||
|
||||
But please notice that this is not C++'s weak_ptr, it means the right field is not
|
||||
involved in the reference counting, it is a raw pointer without runtime checks.
|
||||
@@ -578,13 +568,12 @@ Automatic reference counting also has the disadvantage that it introduces overhe
|
||||
when iterating over linked structures. The `cursor` pragma can also be used
|
||||
to avoid this overhead:
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
```nim
|
||||
var it {.cursor.} = listRoot
|
||||
while it != nil:
|
||||
use(it)
|
||||
it = it.next
|
||||
|
||||
```
|
||||
|
||||
In fact, `cursor` more generally prevents object construction/destruction pairs
|
||||
and so can also be useful in other contexts. The alternative solution would be to
|
||||
@@ -609,13 +598,13 @@ words, we do a compile-time copy-on-write analysis.
|
||||
This means that "borrowed" views can be written naturally and without explicit pointer
|
||||
indirections:
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
```nim
|
||||
proc main(tab: Table[string, string]) =
|
||||
let v = tab["key"] # inferred as cursor because 'tab' is not mutated.
|
||||
# no copy into 'v', no destruction of 'v'.
|
||||
use(v)
|
||||
useItAgain(v)
|
||||
```
|
||||
|
||||
|
||||
Hook lifting
|
||||
@@ -639,8 +628,7 @@ Hook generation
|
||||
|
||||
The ability to override a hook leads to a phase ordering problem:
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
```nim
|
||||
type
|
||||
Foo[T] = object
|
||||
|
||||
@@ -651,7 +639,7 @@ The ability to override a hook leads to a phase ordering problem:
|
||||
|
||||
proc `=destroy`[T](f: var Foo[T]) =
|
||||
discard
|
||||
|
||||
```
|
||||
|
||||
The solution is to define ``proc `=destroy`[T](f: var Foo[T])`` before
|
||||
it is used. The compiler generates implicit
|
||||
@@ -674,8 +662,7 @@ The experimental `nodestroy`:idx: pragma inhibits hook injections. This can be
|
||||
used to specialize the object traversal in order to avoid deep recursions:
|
||||
|
||||
|
||||
.. code-block:: nim
|
||||
|
||||
```nim
|
||||
type Node = ref object
|
||||
x, y: int32
|
||||
left, right: Node
|
||||
@@ -695,6 +682,7 @@ used to specialize the object traversal in order to avoid deep recursions:
|
||||
# notice how even the destructor for 's' is not called implicitly
|
||||
# anymore thanks to .nodestroy, so we have to call it on our own:
|
||||
`=destroy`(s)
|
||||
```
|
||||
|
||||
|
||||
As can be seen from the example, this solution is hardly sufficient and
|
||||
@@ -712,19 +700,20 @@ The copy operation is deferred until the first write.
|
||||
|
||||
For example:
|
||||
|
||||
.. code-block:: nim
|
||||
```nim
|
||||
var x = "abc" # no copy
|
||||
var y = x # no copy
|
||||
y[0] = 'h' # copy
|
||||
|
||||
```
|
||||
|
||||
The abstraction fails for `addr x` because whether the address is going to be used for mutations is unknown.
|
||||
`prepareMutation` needs to be called before the "address of" operation. For example:
|
||||
|
||||
.. code-block:: nim
|
||||
```nim
|
||||
var x = "abc"
|
||||
var y = x
|
||||
|
||||
prepareMutation(y)
|
||||
moveMem(addr y[0], addr x[0], 3)
|
||||
assert y == "abc"
|
||||
```
|
||||
|
||||
1503
doc/manual.md
1503
doc/manual.md
File diff suppressed because it is too large
Load Diff
@@ -1463,8 +1463,7 @@ The operators `*`, `**`, `|`, `~` have a special meaning in patterns
|
||||
if they are written in infix notation.
|
||||
|
||||
|
||||
The `|` operator
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
### The `|` operator
|
||||
|
||||
The `|` operator if used as infix operator creates an ordered choice:
|
||||
|
||||
@@ -1490,8 +1489,7 @@ semantics anyway. In fact, they can be deactivated with the `--patterns:off`:opt
|
||||
command line option or temporarily with the `patterns` pragma.
|
||||
|
||||
|
||||
The `{}` operator
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
### The `{}` operator
|
||||
|
||||
A pattern expression can be bound to a pattern parameter via the `expr{param}`
|
||||
notation:
|
||||
@@ -1504,8 +1502,7 @@ notation:
|
||||
echo a
|
||||
|
||||
|
||||
The `~` operator
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
### The `~` operator
|
||||
|
||||
The `~` operator is the 'not' operator in patterns:
|
||||
|
||||
@@ -1523,8 +1520,7 @@ The `~` operator is the 'not' operator in patterns:
|
||||
echo a
|
||||
|
||||
|
||||
The `*` operator
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
### The `*` operator
|
||||
|
||||
The `*` operator can *flatten* a nested binary expression like `a & b & c`
|
||||
to `&(a, b, c)`:
|
||||
@@ -1559,8 +1555,7 @@ produces:
|
||||
`&&`("my", space & "awe", "some ", "concat")
|
||||
|
||||
|
||||
The `**` operator
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
### The `**` operator
|
||||
|
||||
The `**` is much like the `*` operator, except that it gathers not only
|
||||
all the arguments, but also the matched operators in reverse polish notation:
|
||||
|
||||
@@ -52,8 +52,7 @@ operation meaning
|
||||
`excl(A, elem)` same as `A = A - {elem}`
|
||||
================== ========================================================
|
||||
|
||||
Bit fields
|
||||
~~~~~~~~~~
|
||||
### Bit fields
|
||||
|
||||
Sets are often used to define a type for the *flags* of a procedure.
|
||||
This is a cleaner (and type safe) solution than defining integer
|
||||
|
||||
@@ -117,7 +117,7 @@ when false:
|
||||
discard mysql_stmt_close(stmt)
|
||||
|
||||
proc dbQuote*(s: string): string =
|
||||
## DB quotes the string.
|
||||
## DB quotes the string. Note that this doesn't escape `%` and `_`.
|
||||
result = newStringOfCap(s.len + 2)
|
||||
result.add "'"
|
||||
for c in items(s):
|
||||
@@ -132,7 +132,6 @@ proc dbQuote*(s: string): string =
|
||||
of '"': result.add "\\\""
|
||||
of '\'': result.add "\\'"
|
||||
of '\\': result.add "\\\\"
|
||||
of '_': result.add "\\_"
|
||||
else: result.add c
|
||||
add(result, '\'')
|
||||
|
||||
|
||||
@@ -11,9 +11,9 @@
|
||||
## packages/docutils/rst
|
||||
## ==================================
|
||||
##
|
||||
## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
## ------------------------------------------
|
||||
## Nim-flavored reStructuredText and Markdown
|
||||
## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
## ------------------------------------------
|
||||
##
|
||||
## This module implements a `reStructuredText`:idx: (RST) and
|
||||
## `Markdown`:idx: parser.
|
||||
@@ -290,7 +290,7 @@ type
|
||||
|
||||
proc rstnodeToRefname*(n: PRstNode): string
|
||||
proc addNodes*(n: PRstNode): string
|
||||
proc getFieldValue*(n: PRstNode, fieldname: string): string
|
||||
proc getFieldValue*(n: PRstNode, fieldname: string): string {.gcsafe.}
|
||||
proc getArgument*(n: PRstNode): string
|
||||
|
||||
# ----------------------------- scanner part --------------------------------
|
||||
@@ -1675,19 +1675,45 @@ proc parseMarkdownCodeblockFields(p: var RstParser): PRstNode =
|
||||
field.add(fieldBody)
|
||||
result.add(field)
|
||||
|
||||
proc mayLoadFile(p: RstParser, result: var PRstNode) =
|
||||
var filename = strip(getFieldValue(result, "file"),
|
||||
chars = Whitespace + {'"'})
|
||||
if filename != "":
|
||||
if roSandboxDisabled notin p.s.options:
|
||||
let tok = p.tok[p.idx-2]
|
||||
rstMessage(p, meSandboxedDirective, "file", tok.line, tok.col)
|
||||
var path = p.findRelativeFile(filename)
|
||||
if path == "": rstMessage(p, meCannotOpenFile, filename)
|
||||
var n = newRstNode(rnLiteralBlock)
|
||||
n.add newLeaf(readFile(path))
|
||||
result.sons[2] = n
|
||||
|
||||
proc defaultCodeLangNim(p: RstParser, result: var PRstNode) =
|
||||
# Create a field block if the input block didn't have any.
|
||||
if result.sons[1].isNil: result.sons[1] = newRstNode(rnFieldList)
|
||||
assert result.sons[1].kind == rnFieldList
|
||||
# Hook the extra field and specify the Nim language as value.
|
||||
var extraNode = newRstNode(rnField, info=lineInfo(p))
|
||||
extraNode.add(newRstNode(rnFieldName))
|
||||
extraNode.add(newRstNode(rnFieldBody))
|
||||
extraNode.sons[0].add newLeaf("default-language")
|
||||
extraNode.sons[1].add newLeaf("Nim")
|
||||
result.sons[1].add(extraNode)
|
||||
|
||||
proc parseMarkdownCodeblock(p: var RstParser): PRstNode =
|
||||
result = newRstNodeA(p, rnCodeBlock)
|
||||
result.sons.setLen(3)
|
||||
let line = curLine(p)
|
||||
let baseCol = currentTok(p).col
|
||||
let baseSym = currentTok(p).symbol # usually just ```
|
||||
inc p.idx
|
||||
result.info = lineInfo(p)
|
||||
var args = newRstNode(rnDirArg)
|
||||
var fields: PRstNode = nil
|
||||
if currentTok(p).kind == tkWord:
|
||||
args.add(newLeaf(p))
|
||||
inc p.idx
|
||||
fields = parseMarkdownCodeblockFields(p)
|
||||
result.sons[1] = parseMarkdownCodeblockFields(p)
|
||||
mayLoadFile(p, result)
|
||||
else:
|
||||
args = nil
|
||||
var n = newLeaf("")
|
||||
@@ -1712,11 +1738,13 @@ proc parseMarkdownCodeblock(p: var RstParser): PRstNode =
|
||||
else:
|
||||
n.text.add(currentTok(p).symbol)
|
||||
inc p.idx
|
||||
var lb = newRstNode(rnLiteralBlock)
|
||||
lb.add(n)
|
||||
result.add(args)
|
||||
result.add(fields)
|
||||
result.add(lb)
|
||||
result.sons[0] = args
|
||||
if result.sons[2] == nil:
|
||||
var lb = newRstNode(rnLiteralBlock)
|
||||
lb.add(n)
|
||||
result.sons[2] = lb
|
||||
if result.sons[0].isNil and roNimFile in p.s.options:
|
||||
defaultCodeLangNim(p, result)
|
||||
|
||||
proc parseMarkdownLink(p: var RstParser; father: PRstNode): bool =
|
||||
var desc, link = ""
|
||||
@@ -1802,9 +1830,12 @@ proc parseFootnoteName(p: var RstParser, reference: bool): PRstNode =
|
||||
p.idx = i
|
||||
|
||||
proc isMarkdownCodeBlock(p: RstParser): bool =
|
||||
template allowedSymbol: bool =
|
||||
(currentTok(p).symbol[0] == '`' or
|
||||
roPreferMarkdown in p.s.options and currentTok(p).symbol[0] == '~')
|
||||
result = (roSupportMarkdown in p.s.options and
|
||||
currentTok(p).kind in {tkPunct, tkAdornment} and
|
||||
currentTok(p).symbol[0] == '`' and # tilde ~ is not supported
|
||||
allowedSymbol and
|
||||
currentTok(p).symbol.len >= 3)
|
||||
|
||||
proc parseInline(p: var RstParser, father: PRstNode) =
|
||||
@@ -2580,9 +2611,7 @@ proc getColumns(p: RstParser, cols: var RstCols, startIdx: int): int =
|
||||
if p.tok[result].kind == tkIndent: inc result
|
||||
|
||||
proc checkColumns(p: RstParser, cols: RstCols) =
|
||||
var
|
||||
i = p.idx
|
||||
col = 0
|
||||
var i = p.idx
|
||||
if p.tok[i].symbol[0] != '=':
|
||||
rstMessage(p, mwRstStyle,
|
||||
"only tables with `=` columns specification are allowed")
|
||||
@@ -3208,29 +3237,11 @@ proc dirCodeBlock(p: var RstParser, nimExtension = false): PRstNode =
|
||||
## file. This behaviour is disabled in sandboxed mode and can be re-enabled
|
||||
## with the `roSandboxDisabled` flag.
|
||||
result = parseDirective(p, rnCodeBlock, {hasArg, hasOptions}, parseLiteralBlock)
|
||||
var filename = strip(getFieldValue(result, "file"))
|
||||
if filename != "":
|
||||
if roSandboxDisabled notin p.s.options:
|
||||
let tok = p.tok[p.idx-2]
|
||||
rstMessage(p, meSandboxedDirective, "file", tok.line, tok.col)
|
||||
var path = p.findRelativeFile(filename)
|
||||
if path == "": rstMessage(p, meCannotOpenFile, filename)
|
||||
var n = newRstNode(rnLiteralBlock)
|
||||
n.add newLeaf(readFile(path))
|
||||
result.sons[2] = n
|
||||
mayLoadFile(p, result)
|
||||
|
||||
# Extend the field block if we are using our custom Nim extension.
|
||||
if nimExtension:
|
||||
# Create a field block if the input block didn't have any.
|
||||
if result.sons[1].isNil: result.sons[1] = newRstNode(rnFieldList)
|
||||
assert result.sons[1].kind == rnFieldList
|
||||
# Hook the extra field and specify the Nim language as value.
|
||||
var extraNode = newRstNode(rnField, info=lineInfo(p))
|
||||
extraNode.add(newRstNode(rnFieldName))
|
||||
extraNode.add(newRstNode(rnFieldBody))
|
||||
extraNode.sons[0].add newLeaf("default-language")
|
||||
extraNode.sons[1].add newLeaf("Nim")
|
||||
result.sons[1].add(extraNode)
|
||||
defaultCodeLangNim(p, result)
|
||||
|
||||
proc dirContainer(p: var RstParser): PRstNode =
|
||||
result = parseDirective(p, rnContainer, {hasArg}, parseSectionWrapper)
|
||||
|
||||
@@ -1074,7 +1074,7 @@ proc renderCode(d: PDoc, n: PRstNode, result: var string) =
|
||||
blockEnd = "}"
|
||||
dispA(d.target, result, blockStart, blockStart, [])
|
||||
if params.lang == langNone:
|
||||
if len(params.langStr) > 0:
|
||||
if len(params.langStr) > 0 and params.langStr.toLowerAscii != "none":
|
||||
rstMessage(d.filenames, d.msgHandler, n.info, mwUnsupportedLanguage,
|
||||
params.langStr)
|
||||
for letter in m.text: escChar(d.target, result, letter, emText)
|
||||
|
||||
@@ -170,7 +170,7 @@ proc processRequest(
|
||||
server: AsyncHttpServer,
|
||||
req: FutureVar[Request],
|
||||
client: AsyncSocket,
|
||||
address: string,
|
||||
address: sink string,
|
||||
lineFut: FutureVar[string],
|
||||
callback: proc (request: Request): Future[void] {.closure, gcsafe.},
|
||||
): Future[bool] {.async.} =
|
||||
@@ -184,7 +184,10 @@ proc processRequest(
|
||||
# \n
|
||||
request.headers.clear()
|
||||
request.body = ""
|
||||
request.hostname.shallowCopy(address)
|
||||
when defined(gcArc) or defined(gcOrc):
|
||||
request.hostname = address
|
||||
else:
|
||||
request.hostname.shallowCopy(address)
|
||||
assert client != nil
|
||||
request.client = client
|
||||
|
||||
|
||||
@@ -19,7 +19,10 @@
|
||||
## .. code-block:: Nim
|
||||
## import std/httpclient
|
||||
## var client = newHttpClient()
|
||||
## echo client.getContent("http://google.com")
|
||||
## try:
|
||||
## echo client.getContent("http://google.com")
|
||||
## finally:
|
||||
## client.close()
|
||||
##
|
||||
## The same action can also be performed asynchronously, simply use the
|
||||
## `AsyncHttpClient`:
|
||||
@@ -29,7 +32,10 @@
|
||||
##
|
||||
## proc asyncProc(): Future[string] {.async.} =
|
||||
## var client = newAsyncHttpClient()
|
||||
## return await client.getContent("http://example.com")
|
||||
## try:
|
||||
## return await client.getContent("http://example.com")
|
||||
## finally:
|
||||
## client.close()
|
||||
##
|
||||
## echo waitFor asyncProc()
|
||||
##
|
||||
@@ -53,8 +59,10 @@
|
||||
## data["output"] = "soap12"
|
||||
## data["uploaded_file"] = ("test.html", "text/html",
|
||||
## "<html><head></head><body><p>test</p></body></html>")
|
||||
##
|
||||
## echo client.postContent("http://validator.w3.org/check", multipart=data)
|
||||
## try:
|
||||
## echo client.postContent("http://validator.w3.org/check", multipart=data)
|
||||
## finally:
|
||||
## client.close()
|
||||
##
|
||||
## To stream files from disk when performing the request, use `addFiles`.
|
||||
##
|
||||
@@ -66,8 +74,10 @@
|
||||
## var client = newHttpClient()
|
||||
## var data = newMultipartData()
|
||||
## data.addFiles({"uploaded_file": "test.html"}, mimeDb = mimes)
|
||||
##
|
||||
## echo client.postContent("http://validator.w3.org/check", multipart=data)
|
||||
## try:
|
||||
## echo client.postContent("http://validator.w3.org/check", multipart=data)
|
||||
## finally:
|
||||
## client.close()
|
||||
##
|
||||
## You can also make post requests with custom headers.
|
||||
## This example sets `Content-Type` to `application/json`
|
||||
@@ -81,8 +91,11 @@
|
||||
## let body = %*{
|
||||
## "data": "some text"
|
||||
## }
|
||||
## let response = client.request("http://some.api", httpMethod = HttpPost, body = $body)
|
||||
## echo response.status
|
||||
## try:
|
||||
## let response = client.request("http://some.api", httpMethod = HttpPost, body = $body)
|
||||
## echo response.status
|
||||
## finally:
|
||||
## client.close()
|
||||
##
|
||||
## Progress reporting
|
||||
## ==================
|
||||
@@ -101,7 +114,10 @@
|
||||
## proc asyncProc() {.async.} =
|
||||
## var client = newAsyncHttpClient()
|
||||
## client.onProgressChanged = onProgressChanged
|
||||
## discard await client.getContent("http://speedtest-ams2.digitalocean.com/100mb.test")
|
||||
## try:
|
||||
## discard await client.getContent("http://speedtest-ams2.digitalocean.com/100mb.test")
|
||||
## finally:
|
||||
## client.close()
|
||||
##
|
||||
## waitFor asyncProc()
|
||||
##
|
||||
|
||||
@@ -163,7 +163,10 @@ proc loadAny(p: var JsonParser, a: Any, t: var Table[BiggestInt, pointer]) =
|
||||
of akSequence:
|
||||
case p.kind
|
||||
of jsonNull:
|
||||
setPointer(a, nil)
|
||||
when defined(nimSeqsV2):
|
||||
invokeNewSeq(a, 0)
|
||||
else:
|
||||
setPointer(a, nil)
|
||||
next(p)
|
||||
of jsonArrayStart:
|
||||
next(p)
|
||||
@@ -230,7 +233,10 @@ proc loadAny(p: var JsonParser, a: Any, t: var Table[BiggestInt, pointer]) =
|
||||
of akString:
|
||||
case p.kind
|
||||
of jsonNull:
|
||||
setPointer(a, nil)
|
||||
when defined(nimSeqsV2):
|
||||
setString(a, "")
|
||||
else:
|
||||
setPointer(a, nil)
|
||||
next(p)
|
||||
of jsonString:
|
||||
setString(a, p.str)
|
||||
@@ -282,7 +288,7 @@ proc load*[T](s: Stream, data: var T) =
|
||||
var tab = initTable[BiggestInt, pointer]()
|
||||
loadAny(s, toAny(data), tab)
|
||||
|
||||
proc store*[T](s: Stream, data: T) =
|
||||
proc store*[T](s: Stream, data: sink T) =
|
||||
## Stores `data` into the stream `s`. Raises `IOError` in case of an error.
|
||||
runnableExamples:
|
||||
import std/streams
|
||||
@@ -295,13 +301,16 @@ proc store*[T](s: Stream, data: T) =
|
||||
|
||||
var stored = initIntSet()
|
||||
var d: T
|
||||
shallowCopy(d, data)
|
||||
when defined(gcArc) or defined(gcOrc):
|
||||
d = data
|
||||
else:
|
||||
shallowCopy(d, data)
|
||||
storeAny(s, toAny(d), stored)
|
||||
|
||||
proc loadVM[T](typ: typedesc[T], x: T): string =
|
||||
discard "the implementation is in the compiler/vmops"
|
||||
|
||||
proc `$$`*[T](x: T): string =
|
||||
proc `$$`*[T](x: sink T): string =
|
||||
## Returns a string representation of `x` (serialization, marshalling).
|
||||
##
|
||||
## **Note:** to serialize `x` to JSON use `%x` from the `json` module
|
||||
@@ -321,7 +330,10 @@ proc `$$`*[T](x: T): string =
|
||||
else:
|
||||
var stored = initIntSet()
|
||||
var d: T
|
||||
shallowCopy(d, x)
|
||||
when defined(gcArc) or defined(gcOrc):
|
||||
d = x
|
||||
else:
|
||||
shallowCopy(d, x)
|
||||
var s = newStringStream()
|
||||
storeAny(s, toAny(d), stored)
|
||||
result = s.data
|
||||
|
||||
@@ -178,24 +178,33 @@ proc skipRandomNumbers*(s: var Rand) =
|
||||
## **See also:**
|
||||
## * `next proc<#next,Rand>`_
|
||||
runnableExamples("--threads:on"):
|
||||
import std/[random, threadpool]
|
||||
import std/random
|
||||
|
||||
const spawns = 4
|
||||
const numbers = 100000
|
||||
|
||||
proc randomSum(r: Rand): int =
|
||||
var r = r
|
||||
var
|
||||
thr: array[0..3, Thread[(Rand, int)]]
|
||||
vals: array[0..3, int]
|
||||
|
||||
proc randomSum(params: tuple[r: Rand, index: int]) {.thread.} =
|
||||
var r = params.r
|
||||
var s = 0 # avoid cache thrashing
|
||||
for i in 1..numbers:
|
||||
result += r.rand(0..10)
|
||||
s += r.rand(0..10)
|
||||
vals[params.index] = s
|
||||
|
||||
var r = initRand(2019)
|
||||
var vals: array[spawns, FlowVar[int]]
|
||||
for val in vals.mitems:
|
||||
val = spawn randomSum(r)
|
||||
for i in 0..<thr.len:
|
||||
createThread(thr[i], randomSum, (r, i))
|
||||
r.skipRandomNumbers()
|
||||
|
||||
joinThreads(thr)
|
||||
|
||||
for val in vals:
|
||||
doAssert abs(^val - numbers * 5) / numbers < 0.1
|
||||
doAssert abs(val - numbers * 5) / numbers < 0.1
|
||||
|
||||
doAssert vals == [501737, 497901, 500683, 500157]
|
||||
|
||||
|
||||
when defined(js):
|
||||
const helper = [0xbeac0467u32, 0xd86b048bu32]
|
||||
|
||||
@@ -80,7 +80,8 @@ export toLower, toUpper
|
||||
|
||||
include "system/inclrtl"
|
||||
import std/private/since
|
||||
from std/private/strimpl import cmpIgnoreStyleImpl, cmpIgnoreCaseImpl, startsWithImpl, endsWithImpl
|
||||
from std/private/strimpl import cmpIgnoreStyleImpl, cmpIgnoreCaseImpl,
|
||||
startsWithImpl, endsWithImpl
|
||||
|
||||
when defined(nimPreviewSlimSystem):
|
||||
import std/assertions
|
||||
@@ -94,6 +95,15 @@ const
|
||||
Letters* = {'A'..'Z', 'a'..'z'}
|
||||
## The set of letters.
|
||||
|
||||
UppercaseLetters* = {'A'..'Z'}
|
||||
## The set of uppercase ASCII letters.
|
||||
|
||||
LowercaseLetters* = {'a'..'z'}
|
||||
## The set of lowercase ASCII letters.
|
||||
|
||||
PunctuationChars* = {'!'..'/', ':'..'@', '['..'`', '{'..'~'}
|
||||
## The set of all ASCII punctuation characters.
|
||||
|
||||
Digits* = {'0'..'9'}
|
||||
## The set of digits.
|
||||
|
||||
@@ -110,6 +120,9 @@ const
|
||||
## The set of characters a newline terminator can start with (carriage
|
||||
## return, line feed).
|
||||
|
||||
PrintableChars* = Letters + Digits + PunctuationChars + Whitespace
|
||||
## The set of all printable ASCII characters (letters, digits, whitespace, and punctuation characters).
|
||||
|
||||
AllChars* = {'\x00'..'\xFF'}
|
||||
## A set with all the possible characters.
|
||||
##
|
||||
@@ -172,7 +185,7 @@ func isLowerAscii*(c: char): bool {.rtl, extern: "nsuIsLowerAsciiChar".} =
|
||||
doAssert isLowerAscii('e') == true
|
||||
doAssert isLowerAscii('E') == false
|
||||
doAssert isLowerAscii('7') == false
|
||||
return c in {'a'..'z'}
|
||||
return c in LowercaseLetters
|
||||
|
||||
func isUpperAscii*(c: char): bool {.rtl, extern: "nsuIsUpperAsciiChar".} =
|
||||
## Checks whether or not `c` is an upper case character.
|
||||
@@ -186,8 +199,7 @@ func isUpperAscii*(c: char): bool {.rtl, extern: "nsuIsUpperAsciiChar".} =
|
||||
doAssert isUpperAscii('e') == false
|
||||
doAssert isUpperAscii('E') == true
|
||||
doAssert isUpperAscii('7') == false
|
||||
return c in {'A'..'Z'}
|
||||
|
||||
return c in UppercaseLetters
|
||||
|
||||
func toLowerAscii*(c: char): char {.rtl, extern: "nsuToLowerAsciiChar".} =
|
||||
## Returns the lower case version of character `c`.
|
||||
@@ -202,7 +214,7 @@ func toLowerAscii*(c: char): char {.rtl, extern: "nsuToLowerAsciiChar".} =
|
||||
runnableExamples:
|
||||
doAssert toLowerAscii('A') == 'a'
|
||||
doAssert toLowerAscii('e') == 'e'
|
||||
if c in {'A'..'Z'}:
|
||||
if c in UppercaseLetters:
|
||||
result = char(uint8(c) xor 0b0010_0000'u8)
|
||||
else:
|
||||
result = c
|
||||
@@ -239,7 +251,7 @@ func toUpperAscii*(c: char): char {.rtl, extern: "nsuToUpperAsciiChar".} =
|
||||
runnableExamples:
|
||||
doAssert toUpperAscii('a') == 'A'
|
||||
doAssert toUpperAscii('E') == 'E'
|
||||
if c in {'a'..'z'}:
|
||||
if c in LowercaseLetters:
|
||||
result = char(uint8(c) xor 0b0010_0000'u8)
|
||||
else:
|
||||
result = c
|
||||
@@ -289,7 +301,7 @@ func nimIdentNormalize*(s: string): string =
|
||||
result[0] = s[0]
|
||||
var j = 1
|
||||
for i in 1..len(s) - 1:
|
||||
if s[i] in {'A'..'Z'}:
|
||||
if s[i] in UppercaseLetters:
|
||||
result[j] = chr(ord(s[i]) + (ord('a') - ord('A')))
|
||||
inc j
|
||||
elif s[i] != '_':
|
||||
@@ -311,7 +323,7 @@ func normalize*(s: string): string {.rtl, extern: "nsuNormalize".} =
|
||||
result = newString(s.len)
|
||||
var j = 0
|
||||
for i in 0..len(s) - 1:
|
||||
if s[i] in {'A'..'Z'}:
|
||||
if s[i] in UppercaseLetters:
|
||||
result[j] = chr(ord(s[i]) + (ord('a') - ord('A')))
|
||||
inc j
|
||||
elif s[i] != '_':
|
||||
@@ -1515,7 +1527,8 @@ func delete*(s: var string, slice: Slice[int]) =
|
||||
inc(j)
|
||||
setLen(s, newLen)
|
||||
|
||||
func delete*(s: var string, first, last: int) {.rtl, extern: "nsuDelete", deprecated: "use `delete(s, first..last)`".} =
|
||||
func delete*(s: var string, first, last: int) {.rtl, extern: "nsuDelete",
|
||||
deprecated: "use `delete(s, first..last)`".} =
|
||||
## Deletes in `s` the characters at positions `first .. last` (both ends included).
|
||||
runnableExamples("--warning:deprecated:off"):
|
||||
var a = "abracadabra"
|
||||
@@ -2239,7 +2252,7 @@ func insertSep*(s: string, sep = '_', digits = 3): string {.rtl,
|
||||
doAssert insertSep("1000000") == "1_000_000"
|
||||
result = newStringOfCap(s.len)
|
||||
let hasPrefix = isDigit(s[s.low]) == false
|
||||
var idx:int
|
||||
var idx: int
|
||||
if hasPrefix:
|
||||
result.add s[s.low]
|
||||
for i in (s.low + 1)..s.high:
|
||||
@@ -2253,7 +2266,7 @@ func insertSep*(s: string, sep = '_', digits = 3): string {.rtl,
|
||||
result.setLen(L + idx)
|
||||
var j = 0
|
||||
dec(L)
|
||||
for i in countdown(partsLen-1,0):
|
||||
for i in countdown(partsLen-1, 0):
|
||||
if j == digits:
|
||||
result[L + idx] = sep
|
||||
dec(L)
|
||||
@@ -2354,7 +2367,7 @@ func validIdentifier*(s: string): bool {.rtl, extern: "nsuValidIdentifier".} =
|
||||
# floating point formatting:
|
||||
when not defined(js):
|
||||
func c_sprintf(buf, frmt: cstring): cint {.header: "<stdio.h>",
|
||||
importc: "sprintf", varargs}
|
||||
importc: "sprintf", varargs.}
|
||||
|
||||
type
|
||||
FloatFormatMode* = enum
|
||||
@@ -2685,8 +2698,8 @@ func findNormalized(x: string, inArray: openArray[string]): int =
|
||||
# security hole...
|
||||
return -1
|
||||
|
||||
func invalidFormatString() {.noinline.} =
|
||||
raise newException(ValueError, "invalid format string")
|
||||
func invalidFormatString(formatstr: string) {.noinline.} =
|
||||
raise newException(ValueError, "invalid format string: " & formatstr)
|
||||
|
||||
func addf*(s: var string, formatstr: string, a: varargs[string, `$`]) {.rtl,
|
||||
extern: "nsuAddf".} =
|
||||
@@ -2698,7 +2711,7 @@ func addf*(s: var string, formatstr: string, a: varargs[string, `$`]) {.rtl,
|
||||
if formatstr[i] == '$' and i+1 < len(formatstr):
|
||||
case formatstr[i+1]
|
||||
of '#':
|
||||
if num > a.high: invalidFormatString()
|
||||
if num > a.high: invalidFormatString(formatstr)
|
||||
add s, a[num]
|
||||
inc i, 2
|
||||
inc num
|
||||
@@ -2714,7 +2727,7 @@ func addf*(s: var string, formatstr: string, a: varargs[string, `$`]) {.rtl,
|
||||
j = j * 10 + ord(formatstr[i]) - ord('0')
|
||||
inc(i)
|
||||
let idx = if not negative: j-1 else: a.len-j
|
||||
if idx < 0 or idx > a.high: invalidFormatString()
|
||||
if idx < 0 or idx > a.high: invalidFormatString(formatstr)
|
||||
add s, a[idx]
|
||||
of '{':
|
||||
var j = i+2
|
||||
@@ -2731,22 +2744,22 @@ func addf*(s: var string, formatstr: string, a: varargs[string, `$`]) {.rtl,
|
||||
inc(j)
|
||||
if isNumber == 1:
|
||||
let idx = if not negative: k-1 else: a.len-k
|
||||
if idx < 0 or idx > a.high: invalidFormatString()
|
||||
if idx < 0 or idx > a.high: invalidFormatString(formatstr)
|
||||
add s, a[idx]
|
||||
else:
|
||||
var x = findNormalized(substr(formatstr, i+2, j-1), a)
|
||||
if x >= 0 and x < high(a): add s, a[x+1]
|
||||
else: invalidFormatString()
|
||||
else: invalidFormatString(formatstr)
|
||||
i = j+1
|
||||
of 'a'..'z', 'A'..'Z', '\128'..'\255', '_':
|
||||
var j = i+1
|
||||
while j < formatstr.len and formatstr[j] in PatternChars: inc(j)
|
||||
var x = findNormalized(substr(formatstr, i+1, j-1), a)
|
||||
if x >= 0 and x < high(a): add s, a[x+1]
|
||||
else: invalidFormatString()
|
||||
else: invalidFormatString(formatstr)
|
||||
i = j
|
||||
else:
|
||||
invalidFormatString()
|
||||
invalidFormatString(formatstr)
|
||||
else:
|
||||
add s, formatstr[i]
|
||||
inc(i)
|
||||
|
||||
@@ -18,6 +18,7 @@ import macros
|
||||
|
||||
proc getRaisesListImpl(n: NimNode): NimNode = discard "see compiler/vmops.nim"
|
||||
proc getTagsListImpl(n: NimNode): NimNode = discard "see compiler/vmops.nim"
|
||||
proc getForbidsListImpl(n: NimNode): NimNode = discard "see compiler/vmops.nim"
|
||||
proc isGcSafeImpl(n: NimNode): bool = discard "see compiler/vmops.nim"
|
||||
proc hasNoSideEffectsImpl(n: NimNode): bool = discard "see compiler/vmops.nim"
|
||||
|
||||
@@ -37,6 +38,14 @@ proc getTagsList*(fn: NimNode): NimNode =
|
||||
expectKind fn, nnkSym
|
||||
result = getTagsListImpl(fn)
|
||||
|
||||
proc getForbidsList*(fn: NimNode): NimNode =
|
||||
## Extracts the `.forbids` list of the func/proc/etc `fn`.
|
||||
## `fn` has to be a resolved symbol of kind `nnkSym`. This
|
||||
## implies that the macro that calls this proc should accept `typed`
|
||||
## arguments and not `untyped` arguments.
|
||||
expectKind fn, nnkSym
|
||||
result = getForbidsListImpl(fn)
|
||||
|
||||
proc isGcSafe*(fn: NimNode): bool =
|
||||
## Return true if the func/proc/etc `fn` is `gcsafe`.
|
||||
## `fn` has to be a resolved symbol of kind `nnkSym`. This
|
||||
|
||||
@@ -464,17 +464,16 @@ proc low*(x: string): int {.magic: "Low", noSideEffect.}
|
||||
## var str = "Hello world!"
|
||||
## low(str) # => 0
|
||||
|
||||
proc shallowCopy*[T](x: var T, y: T) {.noSideEffect, magic: "ShallowCopy".}
|
||||
## Use this instead of `=` for a `shallow copy`:idx:.
|
||||
##
|
||||
## The shallow copy only changes the semantics for sequences and strings
|
||||
## (and types which contain those).
|
||||
##
|
||||
## Be careful with the changed semantics though!
|
||||
## There is a reason why the default assignment does a deep copy of sequences
|
||||
## and strings.
|
||||
##
|
||||
## .. warning:: `shallowCopy` does a deep copy with ARC/ORC.
|
||||
when not defined(gcArc) and not defined(gcOrc):
|
||||
proc shallowCopy*[T](x: var T, y: T) {.noSideEffect, magic: "ShallowCopy".}
|
||||
## Use this instead of `=` for a `shallow copy`:idx:.
|
||||
##
|
||||
## The shallow copy only changes the semantics for sequences and strings
|
||||
## (and types which contain those).
|
||||
##
|
||||
## Be careful with the changed semantics though!
|
||||
## There is a reason why the default assignment does a deep copy of sequences
|
||||
## and strings.
|
||||
|
||||
# :array|openArray|string|seq|cstring|tuple
|
||||
proc `[]`*[I: Ordinal;T](a: T; i: I): T {.
|
||||
@@ -492,9 +491,12 @@ proc arrPut[I: Ordinal;T,S](a: T; i: I;
|
||||
proc `=destroy`*[T](x: var T) {.inline, magic: "Destroy".} =
|
||||
## Generic `destructor`:idx: implementation that can be overridden.
|
||||
discard
|
||||
proc `=sink`*[T](x: var T; y: T) {.inline, magic: "Asgn".} =
|
||||
proc `=sink`*[T](x: var T; y: T) {.inline, nodestroy, magic: "Asgn".} =
|
||||
## Generic `sink`:idx: implementation that can be overridden.
|
||||
shallowCopy(x, y)
|
||||
when defined(gcArc) or defined(gcOrc):
|
||||
x = y
|
||||
else:
|
||||
shallowCopy(x, y)
|
||||
|
||||
when defined(nimHasTrace):
|
||||
proc `=trace`*[T](x: var T; env: pointer) {.inline, magic: "Trace".} =
|
||||
@@ -2852,7 +2854,10 @@ when hasAlloc or defined(nimscript):
|
||||
setLen(x, xl+item.len)
|
||||
var j = xl-1
|
||||
while j >= i:
|
||||
shallowCopy(x[j+item.len], x[j])
|
||||
when defined(gcArc) or defined(gcOrc):
|
||||
x[j+item.len] = move x[j]
|
||||
else:
|
||||
shallowCopy(x[j+item.len], x[j])
|
||||
dec(j)
|
||||
j = 0
|
||||
while j < item.len:
|
||||
|
||||
@@ -28,8 +28,8 @@ ObjectA's ``name`` is "|ObjectA|RootObj|".
|
||||
ObjectB's ``name`` is "|ObjectB|ObjectA|RootObj|".
|
||||
|
||||
Now to check for ``x of ObjectB`` we need to check
|
||||
for ``x.typ.name.hasSubstring("|ObjectB|")``. In the actual implementation,
|
||||
however, we could also use a
|
||||
for ``x.typ.name.endsWith("|ObjectB|ObjectA|RootObj|")``.
|
||||
In the actual implementation, however, we could also use a
|
||||
hash of ``package & "." & module & "." & name`` to save space.
|
||||
|
||||
]#
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#
|
||||
|
||||
# Cycle collector based on
|
||||
# https://researcher.watson.ibm.com/researcher/files/us-bacon/Bacon01Concurrent.pdf
|
||||
# https://www.cs.purdue.edu/homes/hosking/690M/Bacon01Concurrent.pdf
|
||||
# And ideas from Lins' in 2008 by the notion of "critical links", see
|
||||
# "Cyclic reference counting" by Rafael Dueire Lins
|
||||
# R.D. Lins / Information Processing Letters 109 (2008) 71–78
|
||||
|
||||
@@ -76,7 +76,7 @@
|
||||
<dl class="item">
|
||||
<div id="foo-procs-all">
|
||||
<div id="foo">
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#foo"><span class="Identifier">foo</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#foo"><span class="Identifier">foo</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
I do foo
|
||||
|
||||
@@ -278,7 +278,7 @@ Ref. <a class="reference internal nimdoc" title="proc `[]`[T](x: G[T]): T" href=
|
||||
</div>
|
||||
<div id="'big-procs-all">
|
||||
<div id="'big,string">
|
||||
<dt><pre><span class="Keyword">func</span> <a href="#%27big%2Cstring"><span class="Identifier">`'big`</span></a><span class="Other">(</span><span class="Identifier">a</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">)</span><span class="Other">:</span> <a href="utils.html#SomeType"><span class="Identifier">SomeType</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">func</span> <a href="#%27big%2Cstring"><span class="Identifier">`'big`</span></a><span class="Other">(</span><span class="Identifier">a</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">)</span><span class="Other">:</span> <a href="utils.html#SomeType"><span class="Identifier">SomeType</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
|
||||
@@ -323,7 +323,7 @@ Ref. <a class="reference internal nimdoc" title="proc `[]`[T](x: G[T]): T" href=
|
||||
</div>
|
||||
<div id="f-procs-all">
|
||||
<div id="f,G[int]">
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#f%2CG%5Bint%5D"><span class="Identifier">f</span></a><span class="Other">(</span><span class="Identifier">x</span><span class="Other">:</span> <a href="utils.html#G"><span class="Identifier">G</span></a><span class="Other">[</span><span class="Identifier">int</span><span class="Other">]</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#f%2CG%5Bint%5D"><span class="Identifier">f</span></a><span class="Other">(</span><span class="Identifier">x</span><span class="Other">:</span> <a href="utils.html#G"><span class="Identifier">G</span></a><span class="Other">[</span><span class="Identifier">int</span><span class="Other">]</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
There is also variant <a class="reference internal nimdoc" title="proc f(x: G[string])" href="#f,G[string]">f(G[string])</a>
|
||||
@@ -331,7 +331,7 @@ Ref. <a class="reference internal nimdoc" title="proc `[]`[T](x: G[T]): T" href=
|
||||
</dd>
|
||||
</div>
|
||||
<div id="f,G[string]">
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#f%2CG%5Bstring%5D"><span class="Identifier">f</span></a><span class="Other">(</span><span class="Identifier">x</span><span class="Other">:</span> <a href="utils.html#G"><span class="Identifier">G</span></a><span class="Other">[</span><span class="Identifier">string</span><span class="Other">]</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#f%2CG%5Bstring%5D"><span class="Identifier">f</span></a><span class="Other">(</span><span class="Identifier">x</span><span class="Other">:</span> <a href="utils.html#G"><span class="Identifier">G</span></a><span class="Other">[</span><span class="Identifier">string</span><span class="Other">]</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
See also <a class="reference internal nimdoc" title="proc f(x: G[int])" href="#f,G[int]">f(G[int])</a>.
|
||||
@@ -353,7 +353,7 @@ Ref. <a class="reference internal nimdoc" title="proc `[]`[T](x: G[T]): T" href=
|
||||
</div>
|
||||
<div id="fn2-procs-all">
|
||||
<div id="fn2">
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#fn2"><span class="Identifier">fn2</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#fn2"><span class="Identifier">fn2</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
comment
|
||||
@@ -361,7 +361,7 @@ Ref. <a class="reference internal nimdoc" title="proc `[]`[T](x: G[T]): T" href=
|
||||
</dd>
|
||||
</div>
|
||||
<div id="fn2,int">
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#fn2%2Cint"><span class="Identifier">fn2</span></a><span class="Other">(</span><span class="Identifier">x</span><span class="Other">:</span> <span class="Identifier">int</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#fn2%2Cint"><span class="Identifier">fn2</span></a><span class="Other">(</span><span class="Identifier">x</span><span class="Other">:</span> <span class="Identifier">int</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
fn2 comment
|
||||
@@ -369,7 +369,7 @@ Ref. <a class="reference internal nimdoc" title="proc `[]`[T](x: G[T]): T" href=
|
||||
</dd>
|
||||
</div>
|
||||
<div id="fn2,int,float">
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#fn2%2Cint%2Cfloat"><span class="Identifier">fn2</span></a><span class="Other">(</span><span class="Identifier">x</span><span class="Other">:</span> <span class="Identifier">int</span><span class="Other">;</span> <span class="Identifier">y</span><span class="Other">:</span> <span class="Identifier">float</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#fn2%2Cint%2Cfloat"><span class="Identifier">fn2</span></a><span class="Other">(</span><span class="Identifier">x</span><span class="Other">:</span> <span class="Identifier">int</span><span class="Other">;</span> <span class="Identifier">y</span><span class="Other">:</span> <span class="Identifier">float</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
|
||||
@@ -380,7 +380,7 @@ Ref. <a class="reference internal nimdoc" title="proc `[]`[T](x: G[T]): T" href=
|
||||
</div>
|
||||
<div id="fn3-procs-all">
|
||||
<div id="fn3">
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#fn3"><span class="Identifier">fn3</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">auto</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#fn3"><span class="Identifier">fn3</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">auto</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
comment
|
||||
@@ -391,7 +391,7 @@ Ref. <a class="reference internal nimdoc" title="proc `[]`[T](x: G[T]): T" href=
|
||||
</div>
|
||||
<div id="fn4-procs-all">
|
||||
<div id="fn4">
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#fn4"><span class="Identifier">fn4</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">auto</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#fn4"><span class="Identifier">fn4</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">auto</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
comment
|
||||
@@ -402,7 +402,7 @@ Ref. <a class="reference internal nimdoc" title="proc `[]`[T](x: G[T]): T" href=
|
||||
</div>
|
||||
<div id="fn5-procs-all">
|
||||
<div id="fn5">
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#fn5"><span class="Identifier">fn5</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#fn5"><span class="Identifier">fn5</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
comment
|
||||
@@ -413,7 +413,7 @@ Ref. <a class="reference internal nimdoc" title="proc `[]`[T](x: G[T]): T" href=
|
||||
</div>
|
||||
<div id="fn6-procs-all">
|
||||
<div id="fn6">
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#fn6"><span class="Identifier">fn6</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#fn6"><span class="Identifier">fn6</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
comment
|
||||
@@ -424,7 +424,7 @@ Ref. <a class="reference internal nimdoc" title="proc `[]`[T](x: G[T]): T" href=
|
||||
</div>
|
||||
<div id="fn7-procs-all">
|
||||
<div id="fn7">
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#fn7"><span class="Identifier">fn7</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#fn7"><span class="Identifier">fn7</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
comment
|
||||
@@ -435,7 +435,7 @@ Ref. <a class="reference internal nimdoc" title="proc `[]`[T](x: G[T]): T" href=
|
||||
</div>
|
||||
<div id="fn8-procs-all">
|
||||
<div id="fn8">
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#fn8"><span class="Identifier">fn8</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">auto</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#fn8"><span class="Identifier">fn8</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">auto</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
comment
|
||||
@@ -446,7 +446,7 @@ Ref. <a class="reference internal nimdoc" title="proc `[]`[T](x: G[T]): T" href=
|
||||
</div>
|
||||
<div id="fn9-procs-all">
|
||||
<div id="fn9,int">
|
||||
<dt><pre><span class="Keyword">func</span> <a href="#fn9%2Cint"><span class="Identifier">fn9</span></a><span class="Other">(</span><span class="Identifier">a</span><span class="Other">:</span> <span class="Identifier">int</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">int</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">func</span> <a href="#fn9%2Cint"><span class="Identifier">fn9</span></a><span class="Other">(</span><span class="Identifier">a</span><span class="Other">:</span> <span class="Identifier">int</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">int</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
comment
|
||||
@@ -457,7 +457,7 @@ Ref. <a class="reference internal nimdoc" title="proc `[]`[T](x: G[T]): T" href=
|
||||
</div>
|
||||
<div id="fn10-procs-all">
|
||||
<div id="fn10,int">
|
||||
<dt><pre><span class="Keyword">func</span> <a href="#fn10%2Cint"><span class="Identifier">fn10</span></a><span class="Other">(</span><span class="Identifier">a</span><span class="Other">:</span> <span class="Identifier">int</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">int</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">func</span> <a href="#fn10%2Cint"><span class="Identifier">fn10</span></a><span class="Other">(</span><span class="Identifier">a</span><span class="Other">:</span> <span class="Identifier">int</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">int</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
comment
|
||||
@@ -468,7 +468,7 @@ Ref. <a class="reference internal nimdoc" title="proc `[]`[T](x: G[T]): T" href=
|
||||
</div>
|
||||
<div id="fN11-procs-all">
|
||||
<div id="fN11">
|
||||
<dt><pre><span class="Keyword">func</span> <a href="#fN11"><span class="Identifier">fN11</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">func</span> <a href="#fN11"><span class="Identifier">fN11</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
|
||||
@@ -476,7 +476,7 @@ Ref. <a class="reference internal nimdoc" title="proc `[]`[T](x: G[T]): T" href=
|
||||
</dd>
|
||||
</div>
|
||||
<div id="fN11,int">
|
||||
<dt><pre><span class="Keyword">func</span> <a href="#fN11%2Cint"><span class="Identifier">fN11</span></a><span class="Other">(</span><span class="Identifier">x</span><span class="Other">:</span> <span class="Identifier">int</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">func</span> <a href="#fN11%2Cint"><span class="Identifier">fN11</span></a><span class="Other">(</span><span class="Identifier">x</span><span class="Other">:</span> <span class="Identifier">int</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
|
||||
@@ -498,7 +498,7 @@ Ref. <a class="reference internal nimdoc" title="proc `[]`[T](x: G[T]): T" href=
|
||||
</div>
|
||||
<div id="someType-procs-all">
|
||||
<div id="someType_2">
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#someType_2"><span class="Identifier">someType</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <a href="utils.html#SomeType"><span class="Identifier">SomeType</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#someType_2"><span class="Identifier">someType</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <a href="utils.html#SomeType"><span class="Identifier">SomeType</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
constructor.
|
||||
@@ -515,7 +515,7 @@ Ref. <a class="reference internal nimdoc" title="proc `[]`[T](x: G[T]): T" href=
|
||||
<dl class="item">
|
||||
<div id="fooBar-iterators-all">
|
||||
<div id="fooBar.i,seq[SomeType]">
|
||||
<dt><pre><span class="Keyword">iterator</span> <a href="#fooBar.i%2Cseq%5BSomeType%5D"><span class="Identifier">fooBar</span></a><span class="Other">(</span><span class="Identifier">a</span><span class="Other">:</span> <span class="Identifier">seq</span><span class="Other">[</span><a href="utils.html#SomeType"><span class="Identifier">SomeType</span></a><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">int</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">iterator</span> <a href="#fooBar.i%2Cseq%5BSomeType%5D"><span class="Identifier">fooBar</span></a><span class="Other">(</span><span class="Identifier">a</span><span class="Other">:</span> <span class="Identifier">seq</span><span class="Other">[</span><a href="utils.html#SomeType"><span class="Identifier">SomeType</span></a><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">int</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
|
||||
|
||||
@@ -471,7 +471,7 @@
|
||||
<dl class="item">
|
||||
<div id="addfBug14485-procs-all">
|
||||
<div id="addfBug14485">
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#addfBug14485"><span class="Identifier">addfBug14485</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#addfBug14485"><span class="Identifier">addfBug14485</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
Some proc
|
||||
@@ -494,7 +494,7 @@
|
||||
</div>
|
||||
<div id="anything-procs-all">
|
||||
<div id="anything">
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#anything"><span class="Identifier">anything</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#anything"><span class="Identifier">anything</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
There is no block quote after blank lines at the beginning.
|
||||
@@ -506,7 +506,7 @@
|
||||
<div id="asyncFun1-procs-all">
|
||||
<div id="asyncFun1">
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#asyncFun1"><span class="Identifier">asyncFun1</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">Future</span><span class="Other">[</span><span class="Identifier">int</span><span class="Other">]</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">Exception</span><span class="Other">,</span> <span class="Identifier">ValueError</span><span class="Other">]</span><span class="Other">,</span>
|
||||
<span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
ok1
|
||||
@@ -517,7 +517,8 @@
|
||||
</div>
|
||||
<div id="asyncFun2-procs-all">
|
||||
<div id="asyncFun2">
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#asyncFun2"><span class="Identifier">asyncFun2</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">owned</span><span class="Other">(</span><span class="Identifier">Future</span><span class="Other">[</span><span class="Identifier">void</span><span class="Other">]</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">Exception</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#asyncFun2"><span class="Identifier">asyncFun2</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">owned</span><span class="Other">(</span><span class="Identifier">Future</span><span class="Other">[</span><span class="Identifier">void</span><span class="Other">]</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">Exception</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span>
|
||||
</span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
|
||||
@@ -528,7 +529,8 @@
|
||||
</div>
|
||||
<div id="asyncFun3-procs-all">
|
||||
<div id="asyncFun3">
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#asyncFun3"><span class="Identifier">asyncFun3</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">owned</span><span class="Other">(</span><span class="Identifier">Future</span><span class="Other">[</span><span class="Identifier">void</span><span class="Other">]</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">Exception</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#asyncFun3"><span class="Identifier">asyncFun3</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">owned</span><span class="Other">(</span><span class="Identifier">Future</span><span class="Other">[</span><span class="Identifier">void</span><span class="Other">]</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">Exception</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span>
|
||||
</span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
|
||||
@@ -552,7 +554,7 @@
|
||||
</div>
|
||||
<div id="baz-procs-all">
|
||||
<div id="baz">
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#baz"><span class="Identifier">baz</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#baz"><span class="Identifier">baz</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
|
||||
@@ -589,7 +591,7 @@
|
||||
<div id="c_nonexistent-procs-all">
|
||||
<div id="c_nonexistent,cstring">
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#c_nonexistent%2Ccstring"><span class="Identifier">c_nonexistent</span></a><span class="Other">(</span><span class="Identifier">frmt</span><span class="Other">:</span> <span class="Identifier">cstring</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">cint</span> {.<span class="Identifier">importc</span><span class="Other">:</span> <span class="StringLit">"nonexistent"</span><span class="Other">,</span>
|
||||
<span class="Identifier">header</span><span class="Other">:</span> <span class="StringLit">"<stdio.h>"</span><span class="Other">,</span> <span class="Identifier">varargs</span><span class="Other">,</span> <span class="Identifier">discardable</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<span class="Identifier">header</span><span class="Other">:</span> <span class="StringLit">"<stdio.h>"</span><span class="Other">,</span> <span class="Identifier">varargs</span><span class="Other">,</span> <span class="Identifier">discardable</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
|
||||
@@ -601,7 +603,8 @@
|
||||
<div id="c_printf-procs-all">
|
||||
<div id="c_printf,cstring">
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#c_printf%2Ccstring"><span class="Identifier">c_printf</span></a><span class="Other">(</span><span class="Identifier">frmt</span><span class="Other">:</span> <span class="Identifier">cstring</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">cint</span> {.<span class="Identifier">importc</span><span class="Other">:</span> <span class="StringLit">"printf"</span><span class="Other">,</span> <span class="Identifier">header</span><span class="Other">:</span> <span class="StringLit">"<stdio.h>"</span><span class="Other">,</span>
|
||||
<span class="Identifier">varargs</span><span class="Other">,</span> <span class="Identifier">discardable</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<span class="Identifier">varargs</span><span class="Other">,</span> <span class="Identifier">discardable</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
|
||||
</span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
the c printf. etc.
|
||||
@@ -612,7 +615,7 @@
|
||||
</div>
|
||||
<div id="fromUtils3-procs-all">
|
||||
<div id="fromUtils3">
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#fromUtils3"><span class="Identifier">fromUtils3</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#fromUtils3"><span class="Identifier">fromUtils3</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
came form utils but should be shown where <tt class="docutils literal"><span class="pre"><span class="Identifier">fromUtilsGen</span></span></tt> is called
|
||||
@@ -638,7 +641,7 @@
|
||||
<div id="low-procs-all">
|
||||
<div id="low,T">
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#low%2CT"><span class="Identifier">low</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">:</span> <span class="Identifier">Ordinal</span> <span class="Operator">|</span> <span class="Keyword">enum</span> <span class="Operator">|</span> <span class="Identifier">range</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">x</span><span class="Other">:</span> <span class="Identifier">T</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">T</span> {.<span class="Identifier">magic</span><span class="Other">:</span> <span class="StringLit">"Low"</span><span class="Other">,</span> <span class="Identifier">noSideEffect</span><span class="Other">,</span>
|
||||
<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
<p>Returns the lowest possible value of an ordinal value <tt class="docutils literal"><span class="pre"><span class="Identifier">x</span></span></tt>. As a special semantic rule, <tt class="docutils literal"><span class="pre"><span class="Identifier">x</span></span></tt> may also be a type identifier.</p>
|
||||
@@ -654,7 +657,7 @@
|
||||
<div id="low2-procs-all">
|
||||
<div id="low2,T">
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#low2%2CT"><span class="Identifier">low2</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">:</span> <span class="Identifier">Ordinal</span> <span class="Operator">|</span> <span class="Keyword">enum</span> <span class="Operator">|</span> <span class="Identifier">range</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">x</span><span class="Other">:</span> <span class="Identifier">T</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">T</span> {.<span class="Identifier">magic</span><span class="Other">:</span> <span class="StringLit">"Low"</span><span class="Other">,</span> <span class="Identifier">noSideEffect</span><span class="Other">,</span>
|
||||
<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
<p>Returns the lowest possible value of an ordinal value <tt class="docutils literal"><span class="pre"><span class="Identifier">x</span></span></tt>. As a special semantic rule, <tt class="docutils literal"><span class="pre"><span class="Identifier">x</span></span></tt> may also be a type identifier.</p>
|
||||
@@ -671,7 +674,7 @@
|
||||
</div>
|
||||
<div id="p1-procs-all">
|
||||
<div id="p1">
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#p1"><span class="Identifier">p1</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#p1"><span class="Identifier">p1</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
cp1
|
||||
@@ -698,7 +701,7 @@ this is a nested doc comment
|
||||
</div>
|
||||
<div id="someFunc-procs-all">
|
||||
<div id="someFunc">
|
||||
<dt><pre><span class="Keyword">func</span> <a href="#someFunc"><span class="Identifier">someFunc</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">func</span> <a href="#someFunc"><span class="Identifier">someFunc</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
My someFunc. Stuff in <tt class="docutils literal"><span class="pre"><span class="Identifier">quotes</span></span></tt> here. <a class="reference external" href="https://nim-lang.org">Some link</a>
|
||||
@@ -709,7 +712,7 @@ this is a nested doc comment
|
||||
</div>
|
||||
<div id="tripleStrLitTest-procs-all">
|
||||
<div id="tripleStrLitTest">
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#tripleStrLitTest"><span class="Identifier">tripleStrLitTest</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#tripleStrLitTest"><span class="Identifier">tripleStrLitTest</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
|
||||
@@ -756,7 +759,7 @@ at indent 0
|
||||
</div>
|
||||
<div id="z1-procs-all">
|
||||
<div id="z1">
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#z1"><span class="Identifier">z1</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <a href="testproject.html#Foo"><span class="Identifier">Foo</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#z1"><span class="Identifier">z1</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <a href="testproject.html#Foo"><span class="Identifier">Foo</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
cz1
|
||||
@@ -767,7 +770,7 @@ at indent 0
|
||||
</div>
|
||||
<div id="z2-procs-all">
|
||||
<div id="z2">
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#z2"><span class="Identifier">z2</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#z2"><span class="Identifier">z2</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
cz2
|
||||
@@ -780,7 +783,7 @@ at indent 0
|
||||
</div>
|
||||
<div id="z3-procs-all">
|
||||
<div id="z3">
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#z3"><span class="Identifier">z3</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#z3"><span class="Identifier">z3</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
cz3
|
||||
@@ -791,7 +794,7 @@ at indent 0
|
||||
</div>
|
||||
<div id="z4-procs-all">
|
||||
<div id="z4">
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#z4"><span class="Identifier">z4</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#z4"><span class="Identifier">z4</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
cz4
|
||||
@@ -802,7 +805,7 @@ at indent 0
|
||||
</div>
|
||||
<div id="z5-procs-all">
|
||||
<div id="z5">
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#z5"><span class="Identifier">z5</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">int</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#z5"><span class="Identifier">z5</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">int</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
cz5
|
||||
@@ -813,7 +816,7 @@ at indent 0
|
||||
</div>
|
||||
<div id="z6-procs-all">
|
||||
<div id="z6">
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#z6"><span class="Identifier">z6</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">int</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#z6"><span class="Identifier">z6</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">int</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
cz6
|
||||
@@ -824,7 +827,7 @@ at indent 0
|
||||
</div>
|
||||
<div id="z7-procs-all">
|
||||
<div id="z7">
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#z7"><span class="Identifier">z7</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">int</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#z7"><span class="Identifier">z7</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">int</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
cz7
|
||||
@@ -835,7 +838,7 @@ at indent 0
|
||||
</div>
|
||||
<div id="z8-procs-all">
|
||||
<div id="z8">
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#z8"><span class="Identifier">z8</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">int</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#z8"><span class="Identifier">z8</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">int</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
cz8
|
||||
@@ -846,7 +849,7 @@ at indent 0
|
||||
</div>
|
||||
<div id="z9-procs-all">
|
||||
<div id="z9">
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#z9"><span class="Identifier">z9</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#z9"><span class="Identifier">z9</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
|
||||
@@ -859,7 +862,7 @@ at indent 0
|
||||
</div>
|
||||
<div id="z10-procs-all">
|
||||
<div id="z10">
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#z10"><span class="Identifier">z10</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#z10"><span class="Identifier">z10</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
|
||||
@@ -872,7 +875,7 @@ at indent 0
|
||||
</div>
|
||||
<div id="z11-procs-all">
|
||||
<div id="z11">
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#z11"><span class="Identifier">z11</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#z11"><span class="Identifier">z11</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
|
||||
@@ -885,7 +888,7 @@ at indent 0
|
||||
</div>
|
||||
<div id="z12-procs-all">
|
||||
<div id="z12">
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#z12"><span class="Identifier">z12</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">int</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#z12"><span class="Identifier">z12</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">int</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
|
||||
@@ -898,7 +901,7 @@ at indent 0
|
||||
</div>
|
||||
<div id="z13-procs-all">
|
||||
<div id="z13">
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#z13"><span class="Identifier">z13</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#z13"><span class="Identifier">z13</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
cz13
|
||||
@@ -911,7 +914,7 @@ at indent 0
|
||||
</div>
|
||||
<div id="z17-procs-all">
|
||||
<div id="z17">
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#z17"><span class="Identifier">z17</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#z17"><span class="Identifier">z17</span></a><span class="Other">(</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
cz17 rest
|
||||
@@ -930,7 +933,7 @@ at indent 0
|
||||
<dl class="item">
|
||||
<div id="method1-methods-all">
|
||||
<div id="method1.e,Moo">
|
||||
<dt><pre><span class="Keyword">method</span> <a href="#method1.e%2CMoo"><span class="Identifier">method1</span></a><span class="Other">(</span><span class="Identifier">self</span><span class="Other">:</span> <span class="Identifier">Moo</span><span class="Other">)</span> {.<span class="Identifier">base</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">method</span> <a href="#method1.e%2CMoo"><span class="Identifier">method1</span></a><span class="Other">(</span><span class="Identifier">self</span><span class="Other">:</span> <span class="Identifier">Moo</span><span class="Other">)</span> {.<span class="Identifier">base</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
foo1
|
||||
@@ -941,7 +944,7 @@ at indent 0
|
||||
</div>
|
||||
<div id="method2-methods-all">
|
||||
<div id="method2.e,Moo">
|
||||
<dt><pre><span class="Keyword">method</span> <a href="#method2.e%2CMoo"><span class="Identifier">method2</span></a><span class="Other">(</span><span class="Identifier">self</span><span class="Other">:</span> <span class="Identifier">Moo</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">int</span> {.<span class="Identifier">base</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">method</span> <a href="#method2.e%2CMoo"><span class="Identifier">method2</span></a><span class="Other">(</span><span class="Identifier">self</span><span class="Other">:</span> <span class="Identifier">Moo</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">int</span> {.<span class="Identifier">base</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
foo2
|
||||
@@ -952,7 +955,7 @@ at indent 0
|
||||
</div>
|
||||
<div id="method3-methods-all">
|
||||
<div id="method3.e,Moo">
|
||||
<dt><pre><span class="Keyword">method</span> <a href="#method3.e%2CMoo"><span class="Identifier">method3</span></a><span class="Other">(</span><span class="Identifier">self</span><span class="Other">:</span> <span class="Identifier">Moo</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">int</span> {.<span class="Identifier">base</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">method</span> <a href="#method3.e%2CMoo"><span class="Identifier">method3</span></a><span class="Other">(</span><span class="Identifier">self</span><span class="Other">:</span> <span class="Identifier">Moo</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">int</span> {.<span class="Identifier">base</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
foo3
|
||||
@@ -969,7 +972,7 @@ at indent 0
|
||||
<dl class="item">
|
||||
<div id="fromUtils1-iterators-all">
|
||||
<div id="fromUtils1.i">
|
||||
<dt><pre><span class="Keyword">iterator</span> <a href="#fromUtils1.i"><span class="Identifier">fromUtils1</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">int</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">iterator</span> <a href="#fromUtils1.i"><span class="Identifier">fromUtils1</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">int</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
|
||||
@@ -984,7 +987,7 @@ at indent 0
|
||||
</div>
|
||||
<div id="iter1-iterators-all">
|
||||
<div id="iter1.i,int">
|
||||
<dt><pre><span class="Keyword">iterator</span> <a href="#iter1.i%2Cint"><span class="Identifier">iter1</span></a><span class="Other">(</span><span class="Identifier">n</span><span class="Other">:</span> <span class="Identifier">int</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">int</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">iterator</span> <a href="#iter1.i%2Cint"><span class="Identifier">iter1</span></a><span class="Other">(</span><span class="Identifier">n</span><span class="Other">:</span> <span class="Identifier">int</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">int</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
foo1
|
||||
@@ -995,7 +998,7 @@ at indent 0
|
||||
</div>
|
||||
<div id="iter2-iterators-all">
|
||||
<div id="iter2.i,int">
|
||||
<dt><pre><span class="Keyword">iterator</span> <a href="#iter2.i%2Cint"><span class="Identifier">iter2</span></a><span class="Other">(</span><span class="Identifier">n</span><span class="Other">:</span> <span class="Identifier">int</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">int</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">iterator</span> <a href="#iter2.i%2Cint"><span class="Identifier">iter2</span></a><span class="Other">(</span><span class="Identifier">n</span><span class="Other">:</span> <span class="Identifier">int</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">int</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> </span><span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span>.}</pre></dt>
|
||||
<dd>
|
||||
|
||||
foo2
|
||||
|
||||
@@ -88,9 +88,9 @@ Next, run the appropriate build shell script for your platform:
|
||||
Finally, once you have finished the build steps (on Windows, Mac, or Linux) you
|
||||
should add the ``bin`` directory to your PATH.
|
||||
|
||||
See also [rebuilding the compiler](doc/intern.rst#rebuilding-the-compiler).
|
||||
See also [bootstrapping the compiler](https://nim-lang.github.io/Nim/intern.html#bootstrapping-the-compiler).
|
||||
|
||||
See also [reproducible builds](doc/intern.rst#reproducible-builds).
|
||||
See also [reproducible builds](https://nim-lang.github.io/Nim/intern.html#bootstrapping-the-compiler-reproducible-builds).
|
||||
|
||||
## Koch
|
||||
|
||||
@@ -104,7 +104,7 @@ can run a subset of tests by specifying a category (for example
|
||||
``./koch tests cat async``).
|
||||
|
||||
For more information on the ``koch`` build tool please see the documentation
|
||||
within the [doc/koch.rst](doc/koch.rst) file.
|
||||
within the [doc/koch.md](doc/koch.md) file.
|
||||
|
||||
## Nimble
|
||||
|
||||
|
||||
@@ -287,3 +287,14 @@ doAssert(foo2("Y", "a2") == 0)
|
||||
doAssert(foo2("Y", "2a") == 2)
|
||||
doAssert(foo2("N", "a3") == 3)
|
||||
doAssert(foo2("z", "2") == 0)
|
||||
|
||||
|
||||
# bug #20031
|
||||
proc main(a: uint64) =
|
||||
case a
|
||||
else:
|
||||
discard
|
||||
|
||||
static:
|
||||
main(10)
|
||||
main(10)
|
||||
|
||||
@@ -37,5 +37,6 @@ switch("define", "nimExperimentalLinenoiseExtra")
|
||||
|
||||
# preview APIs are expected to be the new default in upcoming versions
|
||||
switch("define", "nimPreviewFloatRoundtrip")
|
||||
switch("define", "nimPreviewDotLikeOps")
|
||||
switch("define", "nimPreviewJsonutilsHoleyEnum")
|
||||
switch("define", "nimPreviewHashRef")
|
||||
|
||||
21
tests/effects/teffects11.nim
Normal file
21
tests/effects/teffects11.nim
Normal file
@@ -0,0 +1,21 @@
|
||||
discard """
|
||||
action: compile
|
||||
errormsg: "type mismatch: got <proc (x: int){.gcsafe, locks: 0.}>"
|
||||
line: 21
|
||||
"""
|
||||
|
||||
type
|
||||
Effect1 = object
|
||||
Effect2 = object
|
||||
Effect3 = object
|
||||
|
||||
proc test(fnc: proc(x: int): void {.forbids: [Effect2].}) {.tags: [Effect1, Effect3, RootEffect].} =
|
||||
fnc(1)
|
||||
|
||||
proc t1(x: int): void = echo $x
|
||||
proc t2(x: int): void {.tags: [Effect2].} = echo $x
|
||||
proc t3(x: int): void {.tags: [Effect3].} = echo $x
|
||||
|
||||
test(t1)
|
||||
test(t3)
|
||||
test(t2)
|
||||
52
tests/effects/teffects12.nim
Normal file
52
tests/effects/teffects12.nim
Normal file
@@ -0,0 +1,52 @@
|
||||
discard """
|
||||
action: compile
|
||||
"""
|
||||
|
||||
import std/locks
|
||||
|
||||
type
|
||||
Test2Effect* = object
|
||||
Test2* = object
|
||||
value2*: int
|
||||
Test1Effect* = object
|
||||
Test1* = object
|
||||
value1*: int
|
||||
Main* = object
|
||||
test1Lock: Lock
|
||||
test1: Test1
|
||||
test2Lock: Lock
|
||||
test2: Test2
|
||||
|
||||
proc `=copy`(obj1: var Test2, obj2: Test2) {.error.}
|
||||
proc `=copy`(obj1: var Test1, obj2: Test1) {.error.}
|
||||
proc `=copy`(obj1: var Main, obj2: Main) {.error.}
|
||||
|
||||
proc withTest1(main: var Main,
|
||||
fn: proc(test1: var Test1) {.gcsafe, forbids: [Test1Effect].}) {.gcsafe, tags: [Test1Effect, RootEffect].} =
|
||||
withLock(main.test1Lock):
|
||||
fn(main.test1)
|
||||
|
||||
proc withTest2(main: var Main,
|
||||
fn: proc(test1: var Test2) {.gcsafe, forbids: [Test2Effect].}) {.gcsafe, tags: [Test2Effect, RootEffect].} =
|
||||
withLock(main.test2Lock):
|
||||
fn(main.test2)
|
||||
|
||||
proc newMain(): Main =
|
||||
var test1lock: Lock
|
||||
initLock(test1Lock)
|
||||
var test2lock: Lock
|
||||
initLock(test2Lock)
|
||||
var main = Main(test1Lock: move(test1Lock), test1: Test1(value1: 1),
|
||||
test2Lock: move(test2Lock), test2: Test2(value2: 2))
|
||||
main.withTest1(proc(test1: var Test1) = test1.value1 += 1)
|
||||
main.withTest2(proc(test2: var Test2) = test2.value2 += 1)
|
||||
move main
|
||||
|
||||
var main = newMain()
|
||||
main.withTest1(proc(test1: var Test1) =
|
||||
test1.value1 += 1
|
||||
main.withTest2(proc(test2: var Test2) = test2.value2 += 1)
|
||||
)
|
||||
|
||||
main.withTest1(proc(test1: var Test1) {.tags: [].} = echo $test1.value1)
|
||||
main.withTest2(proc(test2: var Test2) {.tags: [].} = echo $test2.value2)
|
||||
19
tests/effects/teffects13.nim
Normal file
19
tests/effects/teffects13.nim
Normal file
@@ -0,0 +1,19 @@
|
||||
discard """
|
||||
action: compile
|
||||
errormsg: "writeSomething() has an illegal effect: WriteIO"
|
||||
line: 19
|
||||
"""
|
||||
|
||||
type
|
||||
IO = object of RootEffect ## input/output effect
|
||||
ReadIO = object of IO ## input effect
|
||||
WriteIO = object of IO ## output effect
|
||||
|
||||
proc readSomething(): string {.tags: [ReadIO].} = ""
|
||||
proc writeSomething(): void {.tags: [WriteIO].} = echo "..."
|
||||
|
||||
proc noWritesPlease() {.forbids: [WriteIO].} =
|
||||
# this is OK:
|
||||
echo readSomething()
|
||||
# the compiler prevents this:
|
||||
writeSomething()
|
||||
15
tests/effects/teffects14.nim
Normal file
15
tests/effects/teffects14.nim
Normal file
@@ -0,0 +1,15 @@
|
||||
discard """
|
||||
action: compile
|
||||
errormsg: "func1() has an illegal effect: IO"
|
||||
line: 15
|
||||
"""
|
||||
|
||||
type IO = object ## input/output effect
|
||||
proc func1(): string {.tags: [IO].} = discard
|
||||
proc func2(): string = discard
|
||||
|
||||
proc no_IO_please() {.forbids: [IO].} =
|
||||
# this is OK because it didn't define any tag:
|
||||
discard func2()
|
||||
# the compiler prevents this:
|
||||
let y = func1()
|
||||
18
tests/effects/teffects15.nim
Normal file
18
tests/effects/teffects15.nim
Normal file
@@ -0,0 +1,18 @@
|
||||
discard """
|
||||
action: compile
|
||||
errormsg: "method1(c) has an illegal effect: IO"
|
||||
line: 18
|
||||
"""
|
||||
|
||||
type
|
||||
IO = object ## input/output effect
|
||||
CustomObject* = object of RootObj
|
||||
text: string
|
||||
|
||||
method method1(obj: var CustomObject): string {.tags: [IO].} = obj.text & "."
|
||||
method method2(obj: var CustomObject): string = obj.text & ":"
|
||||
|
||||
proc noIO() {.forbids: [IO].} =
|
||||
var c = CustomObject(text: "a")
|
||||
echo c.method2()
|
||||
echo c.method1()
|
||||
20
tests/effects/teffects16.nim
Normal file
20
tests/effects/teffects16.nim
Normal file
@@ -0,0 +1,20 @@
|
||||
discard """
|
||||
action: compile
|
||||
errormsg: "writeSomething(\"a\") can have an unlisted effect: WriteIO"
|
||||
line: 20
|
||||
"""
|
||||
|
||||
type
|
||||
IO = object of RootEffect ## input/output effect
|
||||
ReadIO = object of IO ## input effect
|
||||
WriteIO = object of IO ## output effect
|
||||
LogIO = object of IO ## another output effect
|
||||
|
||||
proc readSomething(): string {.tags: [ReadIO].} = ""
|
||||
proc writeSomething(msg: string): void {.tags: [WriteIO].} = echo msg
|
||||
proc logSomething(msg: string): void {.tags: [LogIo].} = echo msg
|
||||
|
||||
proc noWritesPlease() {.forbids: [WriteIO], tags: [LogIO, ReadIO].} =
|
||||
echo readSomething()
|
||||
logSomething("a")
|
||||
writeSomething("a")
|
||||
17
tests/effects/teffects17.nim
Normal file
17
tests/effects/teffects17.nim
Normal file
@@ -0,0 +1,17 @@
|
||||
discard """
|
||||
action: compile
|
||||
errormsg: "writeSomething(\"a\") has an illegal effect: WriteIO"
|
||||
line: 17
|
||||
"""
|
||||
|
||||
type
|
||||
IO = object of RootEffect ## input/output effect
|
||||
ReadIO = object of IO ## input effect
|
||||
WriteIO = object of IO ## output effect
|
||||
|
||||
proc readSomething(): string {.tags: [ReadIO].} = ""
|
||||
proc writeSomething(msg: string): void {.tags: [WriteIO].} = echo msg
|
||||
|
||||
proc illegalEffectNegation() {.forbids: [WriteIO], tags: [ReadIO, WriteIO].} =
|
||||
echo readSomething()
|
||||
writeSomething("a")
|
||||
19
tests/effects/teffects18.nim
Normal file
19
tests/effects/teffects18.nim
Normal file
@@ -0,0 +1,19 @@
|
||||
discard """
|
||||
action: compile
|
||||
errormsg: "type mismatch: got <ProcType2>"
|
||||
line: 19
|
||||
"""
|
||||
|
||||
type MyEffect = object
|
||||
type ProcType1 = proc (i: int): void {.forbids: [MyEffect].}
|
||||
type ProcType2 = proc (i: int): void
|
||||
|
||||
proc testFunc(p: ProcType1): void = p(1)
|
||||
|
||||
proc toBeCalled(i: int): void {.tags: [MyEffect].} = echo $i
|
||||
|
||||
let emptyTags = proc(i: int): void {.tags: [].} = echo $i
|
||||
let noTags: ProcType2 = proc(i: int): void = toBeCalled(i)
|
||||
|
||||
testFunc(emptyTags)
|
||||
testFunc(noTags)
|
||||
23
tests/effects/teffects19.nim
Normal file
23
tests/effects/teffects19.nim
Normal file
@@ -0,0 +1,23 @@
|
||||
discard """
|
||||
action: compile
|
||||
errormsg: "type mismatch: got <proc (i: int){.gcsafe, locks: 0.}>"
|
||||
line: 23
|
||||
"""
|
||||
|
||||
type MyEffect = object
|
||||
type ProcType1 = proc (i: int): void {.forbids: [MyEffect].}
|
||||
type ProcType2 = proc (i: int): void
|
||||
|
||||
proc caller1(p: ProcType1): void = p(1)
|
||||
proc caller2(p: ProcType2): void = p(1)
|
||||
|
||||
proc effectful(i: int): void {.tags: [MyEffect].} = echo $i
|
||||
proc effectless(i: int): void {.forbids: [MyEffect].} = echo $i
|
||||
|
||||
proc toBeCalled1(i: int): void = effectful(i)
|
||||
proc toBeCalled2(i: int): void = effectless(i)
|
||||
|
||||
caller1(toBeCalled2)
|
||||
caller2(toBeCalled1)
|
||||
caller2(toBeCalled2)
|
||||
caller1(toBeCalled1)
|
||||
@@ -9,7 +9,10 @@ type
|
||||
proc createCycle(leaf: string): Node =
|
||||
new result
|
||||
result.a = result
|
||||
shallowCopy result.leaf, leaf
|
||||
when defined(gcArc) or defined(gcOrc):
|
||||
result.leaf = leaf
|
||||
else:
|
||||
shallowCopy result.leaf, leaf
|
||||
|
||||
proc main =
|
||||
for i in 0 .. 100_000:
|
||||
|
||||
@@ -495,3 +495,11 @@ block: #17849 - yield in case subject
|
||||
yield 5
|
||||
|
||||
test(it, 1, 2, 13, 5)
|
||||
|
||||
block: # void iterator
|
||||
iterator it() {.closure.} =
|
||||
try:
|
||||
yield
|
||||
except:
|
||||
discard
|
||||
var a = it
|
||||
|
||||
11
tests/misc/mjsondoc.nim
Normal file
11
tests/misc/mjsondoc.nim
Normal file
@@ -0,0 +1,11 @@
|
||||
proc doSomething*(x, y: int): int =
|
||||
## do something
|
||||
x + y
|
||||
|
||||
const
|
||||
a* = 1 ## echo 1234
|
||||
b* = "test"
|
||||
|
||||
type
|
||||
MyEnum* = enum
|
||||
foo, bar
|
||||
@@ -216,6 +216,23 @@ sub/mmain.idx""", context
|
||||
let cmd = fmt"{nim} r --backend:{mode} --hints:off --nimcache:{nimcache} {file}"
|
||||
check execCmdEx(cmd) == ("ok3\n", 0)
|
||||
|
||||
block: # nim jsondoc # bug #20132
|
||||
let file = testsDir / "misc/mjsondoc.nim"
|
||||
let output = "nimcache_tjsondoc.json"
|
||||
defer: removeFile(output)
|
||||
let (msg, exitCode) = execCmdEx(fmt"{nim} jsondoc -o:{output} {file}")
|
||||
doAssert exitCode == 0, msg
|
||||
|
||||
let data = parseJson(readFile(output))["entries"]
|
||||
doAssert data.len == 4
|
||||
let doSomething = data[0]
|
||||
doAssert doSomething["name"].getStr == "doSomething"
|
||||
doAssert doSomething["type"].getStr == "skProc"
|
||||
doAssert doSomething["line"].getInt == 1
|
||||
doAssert doSomething["col"].getInt == 0
|
||||
doAssert doSomething["code"].getStr == "proc doSomething(x, y: int): int {.raises: [], tags: [], forbids: [].}"
|
||||
|
||||
|
||||
block: # further issues with `--backend`
|
||||
let file = testsDir / "misc/mbackend.nim"
|
||||
var cmd = fmt"{nim} doc -b:cpp --hints:off --nimcache:{nimcache} {file}"
|
||||
|
||||
4
tests/stdlib/tdb_mysql.nim
Normal file
4
tests/stdlib/tdb_mysql.nim
Normal file
@@ -0,0 +1,4 @@
|
||||
import std/db_mysql
|
||||
|
||||
doAssert dbQuote("SELECT * FROM foo WHERE col1 = 'bar_baz'") == "'SELECT * FROM foo WHERE col1 = \\'bar_baz\\''"
|
||||
doAssert dbQuote("SELECT * FROM foo WHERE col1 LIKE '%bar_baz%'") == "'SELECT * FROM foo WHERE col1 LIKE \\'%bar_baz%\\''"
|
||||
@@ -1 +0,0 @@
|
||||
doAssert defined(nimPreviewDotLikeOps)
|
||||
@@ -1,3 +1,7 @@
|
||||
discard """
|
||||
matrix: "--mm:orc; --mm:refc"
|
||||
"""
|
||||
|
||||
import std/marshal
|
||||
|
||||
# TODO: add static tests
|
||||
@@ -136,6 +140,16 @@ block:
|
||||
let test = to[LegacyEntry](str)
|
||||
doAssert $test == """(numeric: "")"""
|
||||
|
||||
block:
|
||||
let str = """{"numeric": null}"""
|
||||
|
||||
type
|
||||
LegacyEntry = object
|
||||
numeric: seq[int]
|
||||
|
||||
var test = to[LegacyEntry](str)
|
||||
doAssert $test == """(numeric: @[])"""
|
||||
|
||||
# bug #16022
|
||||
block:
|
||||
let p: proc (): string = proc (): string = "hello world"
|
||||
|
||||
@@ -471,21 +471,39 @@ suite "RST parsing":
|
||||
rnLeaf '.'
|
||||
""")
|
||||
|
||||
let expectCodeBlock = dedent"""
|
||||
rnCodeBlock
|
||||
[nil]
|
||||
rnFieldList
|
||||
rnField
|
||||
rnFieldName
|
||||
rnLeaf 'default-language'
|
||||
rnFieldBody
|
||||
rnLeaf 'Nim'
|
||||
rnLiteralBlock
|
||||
rnLeaf '
|
||||
let a = 1
|
||||
```'
|
||||
"""
|
||||
|
||||
test "Markdown code blocks with more > 3 backticks":
|
||||
check(dedent"""
|
||||
````
|
||||
let a = 1
|
||||
```
|
||||
````""".toAst ==
|
||||
dedent"""
|
||||
rnCodeBlock
|
||||
[nil]
|
||||
[nil]
|
||||
rnLiteralBlock
|
||||
rnLeaf '
|
||||
````""".toAst == expectCodeBlock)
|
||||
|
||||
test "Markdown code blocks with ~~~":
|
||||
check(dedent"""
|
||||
~~~
|
||||
let a = 1
|
||||
```'
|
||||
""")
|
||||
```
|
||||
~~~""".toAst == expectCodeBlock)
|
||||
check(dedent"""
|
||||
~~~~~
|
||||
let a = 1
|
||||
```
|
||||
~~~~~""".toAst == expectCodeBlock)
|
||||
|
||||
test "Markdown code blocks with Nim-specific arguments":
|
||||
check(dedent"""
|
||||
|
||||
@@ -552,7 +552,7 @@ context1
|
||||
|
||||
context2
|
||||
"""
|
||||
let output1 = input1.toHtml
|
||||
let output1 = input1.toHtml(preferRst)
|
||||
doAssert "<hr" in output1
|
||||
|
||||
let input2 = """
|
||||
@@ -582,9 +582,14 @@ Test literal block
|
||||
```
|
||||
let x = 1
|
||||
``` """
|
||||
let output1 = input1.toHtml
|
||||
let output1 = input1.toHtml({roSupportMarkdown, roPreferMarkdown})
|
||||
doAssert "<pre" in output1 and "class=\"Keyword\"" notin output1
|
||||
|
||||
# Check Nim highlighting by default in .nim files:
|
||||
let output1nim = input1.toHtml({roSupportMarkdown, roPreferMarkdown,
|
||||
roNimFile})
|
||||
doAssert "<pre" in output1nim and "class=\"Keyword\"" in output1nim
|
||||
|
||||
let input2 = """
|
||||
Parse the block with language specifier:
|
||||
```Nim
|
||||
@@ -1616,3 +1621,8 @@ suite "local file inclusion":
|
||||
discard ".. code-block:: nim\n :file: ./readme.md".toHtml(error=error)
|
||||
check(error[] == "input(2, 20) Error: disabled directive: 'file'")
|
||||
|
||||
test "code-block file directive is disabled - Markdown":
|
||||
var error = new string
|
||||
discard "```nim file = ./readme.md\n```".toHtml(error=error)
|
||||
check(error[] == "input(1, 23) Error: disabled directive: 'file'")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user