-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy patht90_exprs2.nim
129 lines (103 loc) · 2.2 KB
/
t90_exprs2.nim
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
include preamble
suite "expression flattening":
test "flatten case matching expression":
var k = newKiller(4)
proc foo() {.cps: Cont.} =
step 1
case (noop(); step 2; "string")
of "str":
fail "This branch should not be run"
of "string":
step 3
else:
fail "This branch should not be run"
step 4
foo()
check k
test "flatten case elif branches":
var k = newKiller(4)
proc foo() {.cps: Cont.} =
step 1
case "string"
of "str":
fail "This branch should not be run"
of "String":
fail "This branch should not be run"
elif (noop(); step 2; true):
step 3
else:
fail "This branch should not be run"
step 4
foo()
check k
test "flatten while condition":
var k = newKiller(4)
proc foo() {.cps: Cont.} =
step 1
var x = 2
while (noop(); step x; inc x; x < 4):
discard
step 4
foo()
check k
test "flatten assignments with LHS being a symbol":
var k = newKiller(3)
proc foo() {.cps: Cont.} =
step 1
var x: int
x =
if true:
noop()
step 2
42
else:
fail "this branch should not be run"
-1
step 3
check x == 42
foo()
check k
test "flatten assignments with LHS being an object access":
type
A = object
i: int
O = object
a: A
var k = newKiller(3)
proc foo() {.cps: Cont.} =
step 1
var o: O
o.a.i =
if true:
noop()
step 2
42
else:
fail "this branch should not be run"
-1
step 3
check o.a.i == 42
foo()
check k
test "flatten assignments with LHS being a ref access from immutable location":
type
A = object
i: int
O = ref object
a: A
var k = newKiller(3)
proc foo() {.cps: Cont.} =
step 1
let o = O()
o.a.i =
if true:
noop()
step 2
42
else:
fail "this branch should not be run"
return
step 3
check o.a.i == 42
foo()
check k