forked from nim-lang/Nim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trepr.nim
89 lines (63 loc) · 1.37 KB
/
trepr.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
discard """
cmd: "nim c --gc:arc $file"
nimout: '''(a: true, n: doAssert)
Table[system.string, trepr.MyType](data: @[], counter: 0)
nil
'''
output: '''
nil
2
Obj(member: ref @["hello"])
ref (member: ref @["hello"])
'''
"""
# xxx consider merging with `tests/stdlib/trepr.nim` to increase overall test coverage
import tables
type
NimSym = distinct NimNode
MyType = tuple
a: bool
n: NimSym
proc myproc(t: MyType) =
echo repr(t)
proc myproc2(t: MyType) =
var x = Table[string, t]()
echo repr(x)
proc myproc3(t: MyType) =
var x: TableRef[string, t]
echo repr(x)
macro dumpSym(a: typed) =
myproc((a: true, n: NimSym(a)))
myproc2((a: true, n: NimSym(a)))
myproc3((a: true, n: NimSym(a)))
dumpSym(doAssert)
# bug 13731
import os
var a: File
echo repr a
# bug 13872
echo repr(2'u16)
# bug 14270
type
Obj = ref object
member: ref seq[string]
var c = Obj(member: new seq[string])
c.member[] = @["hello"]
echo c.repr
var c2 = new tuple[member: ref seq[string]]
c2.member = new seq[string]
c2.member[] = @["hello"]
echo c2.repr
proc p2 =
echo "hey"
discard repr p2
#####################################################################
# bug #15043
import macros
macro extract(): untyped =
result = newStmtList()
var x: seq[tuple[node: NimNode]]
proc test(n: NimNode) {.closure.} =
x.add (node: n)
test(parseExpr("discard"))
extract()