type constraints; tuple lifting

This commit is contained in:
Araq
2011-04-01 00:26:07 +02:00
parent dc669155e3
commit 4d91c9d887
17 changed files with 527 additions and 139 deletions

View File

@@ -0,0 +1,15 @@
proc myGenericProc[T: object|tuple|int|ptr|ref|distinct](x: T): string =
result = $x
type
TMyObj = tuple[x, y: int]
var
x: TMyObj
assert myGenericProc(232) == "232"
assert myGenericProc(x) == "(x: 0, y: 0)"

View File

@@ -0,0 +1,19 @@
type
TMatcherKind = enum
mkTerminal, mkSequence, mkAlternation, mkRepeat
TMatcher[T] = object
case kind: TMatcherKind
of mkTerminal:
value: T
of mkSequence, mkAlternation:
matchers: seq[TMatcher[T]]
of mkRepeat:
matcher: PMatcher[T]
min, max: int
PMatcher[T] = ref TMatcher[T]
var
m: PMatcher[int]

View File

@@ -0,0 +1,24 @@
# Compiles:
type
TA[T] = object
PA[T] = ref TA[T]
var a: PA[string]
# Compiles unless you use var a: PA[string]
type
PA = ref TA
TA[T] = object
# Cannot instanciate:
type
TA[T] = object
a: PA[T]
PA[T] = ref TA[T]
type
PA[T] = ref TA[T]
TA[T] = object