diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2015-09-05 10:03:35 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2015-09-05 10:03:35 +0200 |
commit | 63a6bfce7114bd1a0cf488b0a401f043212d6216 (patch) | |
tree | 83b38df915652f9c1dc7b8d0538b4e175bc06583 /doc | |
parent | cd9d126a2f5054092f494674a4fa33a21a416891 (diff) | |
parent | c0fa4b7d9c0fce48116102c5fa57dc722665fbe0 (diff) | |
download | Nim-63a6bfce7114bd1a0cf488b0a401f043212d6216.tar.gz |
Merge pull request #3286 from yglukhov/when-nimvm
when nimvm stmt
Diffstat (limited to 'doc')
-rw-r--r-- | doc/manual/stmts.txt | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/doc/manual/stmts.txt b/doc/manual/stmts.txt index cecf37b64..3fc950b4b 100644 --- a/doc/manual/stmts.txt +++ b/doc/manual/stmts.txt @@ -329,6 +329,35 @@ The ``when`` statement enables conditional compilation techniques. As a special syntactic extension, the ``when`` construct is also available within ``object`` definitions. +When nimvm statement +--------------------- +``nimvm`` is a special symbol, that may be used as expression of ``when nimvm`` +statement to differentiate execution path between runtime and compile time. + +Example: + +.. code-block:: nim + proc someProcThatMayRunInCompileTime(): bool = + when nimvm: + # This code runs in compile time + result = true + else: + # This code runs in runtime + result = false + const ctValue = someProcThatMayRunInCompileTime() + let rtValue = someProcThatMayRunInCompileTime() + assert(ctValue == true) + assert(rtValue == false) + +``when nimvm`` statement must meet the following requirements: + +* Its expression must always be ``nimvm``. More complex expressions are not + allowed. +* It must not contain ``elif`` branches. +* It must contain ``else`` branch. +* Code in branches must not affect semantics of the code that follows the + ``when nimvm`` statement. E.g. it must not define symbols that are used in + the following code. Return statement ---------------- |