-
Notifications
You must be signed in to change notification settings - Fork 0
/
crashes.nim
67 lines (60 loc) · 1.93 KB
/
crashes.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
block:
import macros
proc toDistinct(x:static NimNode):auto =
when x.kind == nnkStmtList: x.StmtList
elif x.kind == nnkCall: x.Call
else: x
discard toDistinct(nnkStmtList.newNimNode())
block:
import macros
type
SafeNimNodeObj = object
case kind: NimNodeKind
of nnkNone, nnkEmpty, nnkNilLit:
discard # node contains no additional fields
of nnkCharLit..nnkUInt64Lit:
intVal: BiggestInt # the int literal
of nnkFloatLit..nnkFloat64Lit:
floatVal: BiggestFloat # the float literal
of nnkStrLit..nnkTripleStrLit, nnkCommentStmt, nnkIdent, nnkSym:
strVal: string # the string literal
else:
sons: seq[SafeNimNode] # the node's sons (or children)
SafeNimNode = ref SafeNimNodeObj
converter toSafeNimNode(x:NimNode):SafeNimNode =
result = SafeNimNode(kind: x.kind)
case x.kind:
of nnkNone, nnkEmpty, nnkNilLit:
discard
of nnkCharLit..nnkUInt64Lit:
result.intVal = x.intVal
of nnkFloatLit..nnkFloat64Lit:
result.floatVal = x.floatVal
of nnkStrLit..nnkTripleStrLit, nnkCommentStmt, nnkIdent, nnkSym:
result.strVal = x.strVal
else:
for s in x:
result.sons.add toSafeNimNode(s)
proc toDistinct(x:static SafeNimNode):auto =
when x.kind == nnkStmtList: 1#x.StmtList
elif x.kind == nnkCall: 2#x.Call
else: 3
echo toDistinct(nnkStmtList.newNimNode()) # toDistinct(nnkStmtList.newNimNode().toSafeNimNode) doesn't crash
block:
import std/setutils
type FooKind = enum
a,b,c
template bar(s: static set[FooKind] = FooKind.fullSet):untyped = discard
block:
template typ[T](t:typedesc[T]):type =
static: echo "typ"
#type t = T
int
#type X[T] = typ[T]
static: echo "1"
var x: typ(int)
static: echo "2"
#not a crash,but from a nims
block:
import strformat
exec &"echo {nimCacheDir()}/{projectName()}.json}"