-
Notifications
You must be signed in to change notification settings - Fork 4
/
sets.nim
24 lines (20 loc) · 858 Bytes
/
sets.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import macros
from typesinfo import TypeChunk, Context
proc genSet*(context: Context, declaration: NimNode): TypeChunk {.compileTime.}
from strutils import `%`
from tables import contains, `[]`
from typesinfo import isBasic, estimateBasicSize
from basics import genBasic
proc genSet(context: Context, declaration: NimNode): TypeChunk =
declaration.expectMinLen(2)
let undertype = $declaration[1]
if undertype.isBasic():
let size = estimateBasicSize(undertype)
result = context.genBasic(1 shl (size * 8 - 3))
elif undertype in context.declared:
let enumtype = context.declared[undertype]
if enumtype.nodekind != nnkEnumTy:
error("The type '$1' neither of enum or basic type!" % undertype)
result = context.genBasic(int(enumtype.maxcount div 8) + 1)
else:
error("Impossible type under the set: " & declaration.repr)