-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy patht90_exprs3.nim
114 lines (91 loc) · 2.06 KB
/
t90_exprs3.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
include preamble
suite "expression flattening":
test "flatten unpacking assignments":
type
O = object
x: int
y: int
var k = newKiller(3)
proc foo() {.cps: Cont.} =
step 1
var o = O()
(o.x, o.y) =
if true:
noop()
step 2
(42, 10)
else:
fail "this branch should not be run"
return
step 3
check o.x == 42
check o.y == 10
foo()
check k
test "flatten upcasting assignments":
when not defined(release) and not defined(isNimSkull):
skip"compiler crashes on debug"
else:
type
O = ref object of RootObj
x: int
y: int
I = ref object of O
var k = newKiller(3)
proc foo() {.cps: Cont.} =
step 1
var o = O()
o =
if true:
noop()
step 2
I(x: 42, y: 10)
else:
fail "this branch should not be run"
I(x: 42, y: 20)
step 3
check o of I
check o.x == 42
check o.y == 10
foo()
check k
test "flatten implicitly converted assignments":
var k = newKiller(3)
proc foo() {.cps: Cont.} =
step 1
let o: int =
if true:
noop()
step 2
Natural(42)
else:
fail "this branch should not be run"
return
step 3
check o == 42
foo()
check k
test "flatten explicitly converted assignments":
var k = newKiller(3)
proc foo() {.cps: Cont.} =
step 1
let i = int(block: (noop(); step 2; 42.Natural))
step 3
check i == 42
foo()
check k
test "flatten discard statements":
var k = newKiller(3)
proc foo() {.cps: Cont.} =
step 1
discard (block: (noop(); step 2; 42.Natural))
step 3
foo()
check k
test "flatten return statements":
var k = newKiller(2)
proc foo(): int {.cps: Cont.} =
step 1
return (block: (noop(); step 2; 42.Natural))
check foo() == 42
check k