-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy patht90_exprs1.nim
149 lines (123 loc) Β· 2.88 KB
/
t90_exprs1.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
include preamble
suite "expression flattening":
test "flatten expression list in var/let":
var k = newKiller(3)
proc foo() {.cps: Cont.} =
let
x = (noop(); step 1; 42)
y = (noop(); step 2; x)
check x == y
var (a, b) = (noop(); step 3; (10, y))
check a == 10
check b == y
foo()
check k
test "flatten block expression":
var k = newKiller(3)
proc foo() {.cps: Cont.} =
step 1
let x = block:
noop()
step 2
42
step 3
check x == 42
foo()
check k
test "flatten if expression":
var k = newKiller(5)
proc foo() {.cps: Cont.} =
step 1
let x =
if true:
noop()
step 2
42
elif true:
fail "this branch should not run"
0 # needed because the compiler doesn't recognize fail as noreturn
else:
fail "this branch should not run"
-1 # needed because the compiler doesn't recognize fail as noreturn
step 3
check x == 42
let y =
if false:
fail "this branch should not run"
-1
elif false:
fail "this branch should not run"
0
else:
noop()
step 4
30
step 5
check y == 30
foo()
check k
test "flatten case expression":
var k = newKiller(3)
proc foo() {.cps: Cont.} =
step 1
let x =
case "true"
of "truer", "truest", "very true":
fail "this branch should not run"
0
of "false":
fail "this branch should not run"
-1
of "true":
noop()
step 2
42
elif true:
fail "this branch should not run"
-3
else:
fail "this branch should not run"
-2
step 3
check x == 42
foo()
check k
test "flatten try statement":
var k = newKiller(4)
proc foo() {.cps: Cont.} =
step 1
let x =
try:
raise newException(ValueError, "something")
0
except ValueError, IOError:
noop()
let e = getCurrentException()
check e of ValueError
check e.msg == "something"
step 2
42
except CatchableError:
fail "this branch should not run"
-1
finally:
step 3
step 4
check x == 42
foo()
check k
test "flatten if condition":
var k = newKiller(5)
proc foo() {.cps: Cont.} =
step 1
if (noop(); step 2; false):
fail "This branch should not be run"
elif (noop(); step 3; true):
step 4
elif (noop(); fail"This expression should not be evaluated"; false):
fail "This branch should not be run"
else:
fail "This branch should not be run"
step 5
foo()
check k