summary refs log tree commit diff stats
path: root/doc/manual.txt
diff options
context:
space:
mode:
Diffstat (limited to 'doc/manual.txt')
-rw-r--r--doc/manual.txt45
1 files changed, 45 insertions, 0 deletions
diff --git a/doc/manual.txt b/doc/manual.txt
index 5fdc5a884..d2fc7e5c9 100644
--- a/doc/manual.txt
+++ b/doc/manual.txt
@@ -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