diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2019-09-05 08:21:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-05 08:21:01 +0200 |
commit | 58bcf6cd46fe9108f2dced59c612153d2951aee2 (patch) | |
tree | e485be2b109f7a75295f20faa779676ccf4f188d /tests/template/tparams_gensymed.nim | |
parent | c2ba0ee144adfaea6f2e1cc93a20d022149f6ccf (diff) | |
download | Nim-58bcf6cd46fe9108f2dced59c612153d2951aee2.tar.gz |
fixes #12121 (#12126)
Diffstat (limited to 'tests/template/tparams_gensymed.nim')
-rw-r--r-- | tests/template/tparams_gensymed.nim | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/template/tparams_gensymed.nim b/tests/template/tparams_gensymed.nim index fe5608add..a35d878d5 100644 --- a/tests/template/tparams_gensymed.nim +++ b/tests/template/tparams_gensymed.nim @@ -14,6 +14,7 @@ wth 1 0 (total: 6) +S1 ''' """ # bug #1915 @@ -164,3 +165,33 @@ template baz(): untyped = echo (total: bar2(3)) baz() + +# bug #12121 +macro state_machine_enum(states: varargs[untyped]) = + result = nnkTypeSection.newTree( + nnkTypeDef.newTree( + nnkPragmaExpr.newTree(ident("State"), nnkPragma.newTree(ident("pure"))), + newEmptyNode(), + nnkEnumTy.newTree(newEmptyNode()) + ) + ) + + for s in states: + expectKind(s, nnkIdent) + result[0][2].add s + +template mystate_machine(body: untyped) = + state_machine_enum(S1, S2, S3) + var state_stack: seq[State] + template state_current(): State {.inject, used.} = + state_stack[^1] + template state_push(state_name) {.inject, used.} = + state_stack.add State.state_name + template state_pop(n = 1) {.inject, used.} = + state_stack.setLen(state_stack.len - n) + body + +mystate_machine: + state_push(S1) + echo state_current() + state_pop() |