summary refs log tree commit diff stats
path: root/tests/trmacros/tcse.nim
blob: 315570d8f9599fca19f111824a2f2473c540fab2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
discard """
  output: "4"
"""

template cse{f(a, a, x)}(a: typed{(nkDotExpr|call|nkBracketExpr)&noSideEffect},
                         f: typed, x: varargs[typed]): untyped =
  let aa = a
  f(aa, aa, x)+4

var
  a: array[0..10, int]
  i = 3
echo a[i] + a[i]