When nimvm statement
nimvm is a special symbol that may be used as the expression of a when nimvm statement to differentiate the execution path between compile-time and the executable.
Example:
proc someProcThatMayRunInCompileTime(): bool =
when nimvm:
# This branch is taken at compile time.
result = true
else:
# This branch is taken in the executable.
result = false
const ctValue = someProcThatMayRunInCompileTime()
let rtValue = someProcThatMayRunInCompileTime()
assert(ctValue == true)
assert(rtValue == false)
A 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 an 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.
当前内容版权归 nim-lang.org 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 nim-lang.org .