fixed and documented computedGoto pragma
This commit is contained in:
parent
50403afb5c
commit
6f1fc1b5ba
8 changed files with 94 additions and 35 deletions
|
|
@ -4561,6 +4561,51 @@ tested against via linear scanning. If put into the last branch of the
|
|||
whole ``case`` statement, the whole ``case`` statement uses linear scanning.
|
||||
|
||||
|
||||
computedGoto pragma
|
||||
-------------------
|
||||
The `computedGoto`:idx: pragma can be used to tell the compiler how to
|
||||
compile a Nimrod `case`:idx: in a ``while true`` statement.
|
||||
Syntactically it has to be used as a statement inside the loop:
|
||||
|
||||
.. code-block:: nimrod
|
||||
|
||||
type
|
||||
MyEnum = enum
|
||||
enumA, enumB, enumC, enumD, enumE
|
||||
|
||||
proc vm() =
|
||||
var instructions: array [0..100, MyEnum]
|
||||
instructions[2] = enumC
|
||||
instructions[3] = enumD
|
||||
instructions[4] = enumA
|
||||
instructions[5] = enumD
|
||||
instructions[6] = enumC
|
||||
instructions[7] = enumA
|
||||
instructions[8] = enumB
|
||||
|
||||
instructions[12] = enumE
|
||||
var pc = 0
|
||||
while true:
|
||||
{.computedGoto.}
|
||||
let instr = instructions[pc]
|
||||
case instr
|
||||
of enumA:
|
||||
echo "yeah A"
|
||||
of enumC, enumD:
|
||||
echo "yeah CD"
|
||||
of enumB:
|
||||
echo "yeah B"
|
||||
of enumE:
|
||||
break
|
||||
inc(pc)
|
||||
|
||||
vm()
|
||||
|
||||
As the example shows ``computedGoto`` is mostly useful for interpreters. If
|
||||
the underlying backend (C compiler) does not support the computed goto
|
||||
extension the pragma is simply ignored.
|
||||
|
||||
|
||||
unroll pragma
|
||||
-------------
|
||||
The `unroll`:idx: pragma can be used to tell the compiler that it should unroll
|
||||
|
|
|
|||
|
|
@ -488,7 +488,7 @@ in C/C++).
|
|||
|
||||
|
||||
Nimrod idetools integration
|
||||
=======================
|
||||
===========================
|
||||
|
||||
Nimrod provides language integration with external IDEs through the
|
||||
idetools command. See the documentation of `idetools <idetools.html>`_
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue