forked from nim-lang/Nim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tdo.nim
79 lines (69 loc) · 1.51 KB
/
tdo.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
discard """
output: '''true
true
true
true inner B'''
"""
template withValue(a, b, c, d, e: untyped) =
if c:
d
else:
e
template withValue(a, b, c, d: untyped) =
if c:
d
const
EVENT_READ = 1
EVENT_WRITE = 2
FLAG_HANDLE = 3
EVENT_MASK = 3
var s: string
proc main =
var value = false
var fd = 8888
var event = 0
s.withValue(fd, value) do:
if value:
var oe = (EVENT_MASK)
if (oe xor event) != 0:
if (oe and EVENT_READ) != 0 and (event and EVENT_READ) == 0:
discard
if (oe and EVENT_WRITE) != 0 and (event and EVENT_WRITE) == 0:
discard
if (oe and EVENT_READ) == 0 and (event and EVENT_READ) != 0:
discard
if (oe and EVENT_WRITE) == 0 and (event and EVENT_WRITE) != 0:
discard
else:
raise newException(ValueError, "error")
do:
raise newException(ValueError, "Descriptor is not registered in queue")
proc main2 =
var unused = 8
# test 'then' branch:
s.withValue(unused, true) do:
echo "true"
do:
echo "false"
# test overloading:
s.withValue(unused, false) do:
echo "cannot come here"
# test 'else' branch:
s.withValue(unused, false) do:
echo "false"
do:
echo "true"
# test proper nesting:
s.withValue(unused, false) do:
echo "false"
s.withValue(unused, false) do:
echo "false inner A"
do:
echo "true inner A"
do:
echo "true"
s.withValue(unused, false) do:
echo "false inner B"
do:
echo "true inner B"
main2()