Markdown code blocks part 5 (#20236)
No logic was added, just a few more `*.md` files have been migrated.
This commit is contained in:
parent
60f6724b70
commit
1c31de361d
21 changed files with 486 additions and 413 deletions
|
|
@ -5083,10 +5083,7 @@ exception tracking.
|
|||
|
||||
There is also a way which can be used to forbid certain effects:
|
||||
|
||||
.. code-block:: nim
|
||||
:test: "nim c --warningAsError:Effect:on $1"
|
||||
:status: 1
|
||||
|
||||
```nim test = "nim c --warningAsError:Effect:on $1" status = 1
|
||||
type IO = object ## input/output effect
|
||||
proc readLine(): string {.tags: [IO].} = discard
|
||||
proc echoLine(): void = discard
|
||||
|
|
@ -5096,13 +5093,14 @@ There is also a way which can be used to forbid certain effects:
|
|||
echoLine()
|
||||
# the compiler prevents this:
|
||||
let y = readLine()
|
||||
```
|
||||
|
||||
The `forbids` pragma defines a list of illegal effects - if any statement
|
||||
invokes any of those effects, the compilation will fail.
|
||||
Procedure types with any disallowed effect are the subtypes of equal
|
||||
procedure types without such lists:
|
||||
|
||||
.. code-block:: nim
|
||||
```nim
|
||||
type MyEffect = object
|
||||
type ProcType1 = proc (i: int): void {.forbids: [MyEffect].}
|
||||
type ProcType2 = proc (i: int): void
|
||||
|
|
@ -5123,6 +5121,7 @@ procedure types without such lists:
|
|||
## these are OK because ProcType2 doesn't have any effect requirement:
|
||||
caller2(toBeCalled1)
|
||||
caller2(toBeCalled2)
|
||||
```
|
||||
|
||||
`ProcType2` is a subtype of `ProcType1`. Unlike with tags, the parent context - the function which calls other functions with forbidden effects - doesn't inherit the forbidden list of effects.
|
||||
|
||||
|
|
@ -8079,18 +8078,20 @@ from C. The optional argument is a string containing the C identifier. If
|
|||
the argument is missing, the C name is the Nim identifier *exactly as
|
||||
spelled*:
|
||||
|
||||
.. code-block::
|
||||
```nim
|
||||
proc printf(formatstr: cstring) {.header: "<stdio.h>", importc: "printf", varargs.}
|
||||
```
|
||||
|
||||
When `importc` is applied to a `let` statement it can omit its value which
|
||||
will then be expected to come from C. This can be used to import a C `const`:c:\:
|
||||
|
||||
.. code-block::
|
||||
```nim
|
||||
{.emit: "const int cconst = 42;".}
|
||||
|
||||
let cconst {.importc, nodecl.}: cint
|
||||
|
||||
assert cconst == 42
|
||||
```
|
||||
|
||||
Note that this pragma has been abused in the past to also work in the
|
||||
JS backend for JS objects and functions. Other backends do provide
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue