-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy patht90_exprs5.nim
96 lines (71 loc) · 1.74 KB
/
t90_exprs5.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
include preamble
suite "expression flattening":
test "flatten pragma block expression":
var k = newKiller(3)
proc foo() {.cps: Cont.} =
step 1
let x =
block:
{.cast(gcsafe).}:
noop()
step 2
10
step 3
check x == 10
foo()
check k
test "flatten result expressions":
var k = newKiller(1)
proc foo(): int {.cps: Cont.} =
noop()
step 1
42.Natural
check foo() == 42
check k
test "flatten bracket expressions (array access)":
var k = newKiller(2)
proc foo() {.cps: Cont.} =
check (noop(); step 1; [42])[(noop(); step 2; 0)] == 42
foo()
check k
test "flatten dot expressions":
type
P = object
val: int
var k = newKiller(1)
proc foo() {.cps: Cont.} =
check (noop(); step 1; P(val: 42)).val == 42
foo()
check k
test "flatten dereference expressions":
type
P = ref object
val: int
var k = newKiller(1)
proc foo() {.cps: Cont.} =
check (noop(); step 1; P(val: 42))[].val == 42
foo()
check k
test "flatten hidden dereference expressions":
type
P = ref object
val: int
var k = newKiller(1)
proc foo() {.cps: Cont.} =
check (noop(); step 1; P(val: 42)).val == 42
foo()
check k
test "flatten magic calls with mutable variables":
var k = newKiller(3)
proc foo() {.cps: Cont.} =
var x: string
# add(var string, string) is a magic
x.add (noop(); step 1; "test")
check x == "test"
var y: seq[string]
# add(var seq[T], T) is a magic with generics
y.add (noop(); step 2; "test")
check y == @["test"]
step 3
foo()
check k