summary refs log tree commit diff stats
path: root/tests/pragmas/treorder.nim
blob: 72e8808b3d148aa30617ad1c1cb2e21574ee15c9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
discard """
matrix: "--experimental:codeReordering"
output:'''0
1
2
3'''
"""

import macros
# {.reorder: on .}
{.experimental: "codeReordering".}

echo foo(-1)
echo callWithFoo(0)
echo(CA+CD)
echo useTypes(TA(x:TB(x:1)), 2)
second(0)

template callWithFoo(arg: untyped): untyped =
  foo(arg)

proc first(i: int): void

proc second(i: int): void =
  make(first)
  first(i)

proc useTypes(a: TA, d: TD): int =
  result = a.x.x+d

type
  TDoubleCyclic = ref object
    x: TCyclicA
    y: TCyclicB

type
  TCyclicA = ref object
    x: TDoubleCyclic

type
  TCyclicB = ref object
    x: TDoubleCyclic

const
  CA = 1
  CB = CC

type
  TA = object
    x: TB
  TC = type(CC)
  TD = type(CA)

const
  CC = 1
  CD = CB

type
  TB = object
    x: TC

proc foo(x: int): int =
  result = bar(x)

proc bar(x: int): int =
  result = x+1

macro make(arg: untyped): untyped =
  ss &= arg.repr
  ss &= " "
  discard

proc first(i: int): void =
  make(second)

var ss {.compileTime.}: string = ""