This commit is contained in:
Andreas Rumpf
2016-07-12 20:38:31 +02:00
parent 8dd27a6699
commit f47165af11
5 changed files with 47 additions and 1 deletions

View File

@@ -150,6 +150,9 @@ proc mapType(typ: PType): TCTypeKind =
of tyCString: result = ctCString
of tyInt..tyUInt64:
result = TCTypeKind(ord(typ.kind) - ord(tyInt) + ord(ctInt))
of tyStatic:
if typ.n != nil: result = mapType(lastSon typ)
else: internalError("mapType")
else: internalError("mapType")
proc mapReturnType(typ: PType): TCTypeKind =
@@ -256,6 +259,11 @@ proc getSimpleTypeDesc(m: BModule, typ: PType): Rope =
of tyInt..tyUInt64:
result = typeNameOrLiteral(typ, NumericalTypeToStr[typ.kind])
of tyDistinct, tyRange, tyOrdinal: result = getSimpleTypeDesc(m, typ.sons[0])
of tyStatic:
if typ.n != nil: result = getSimpleTypeDesc(m, lastSon typ)
else: internalError("tyStatic for getSimpleTypeDesc")
of tyGenericInst:
result = getSimpleTypeDesc(m, lastSon typ)
else: result = nil
proc pushType(m: BModule, typ: PType) =
@@ -1025,6 +1033,9 @@ proc genTypeInfo(m: BModule, t: PType): Rope =
of tyEmpty, tyVoid: result = rope"0"
of tyPointer, tyBool, tyChar, tyCString, tyString, tyInt..tyUInt64, tyVar:
genTypeInfoAuxBase(m, t, t, result, rope"0")
of tyStatic:
if t.n != nil: result = genTypeInfo(m, lastSon t)
else: internalError("genTypeInfo(" & $t.kind & ')')
of tyProc:
if t.callConv != ccClosure:
genTypeInfoAuxBase(m, t, t, result, rope"0")

View File

@@ -164,8 +164,11 @@ proc mapType(typ: PType): TJSTypeKind =
of tyNil: result = etyNull
of tyGenericInst, tyGenericParam, tyGenericBody, tyGenericInvocation,
tyNone, tyFromExpr, tyForward, tyEmpty, tyFieldAccessor,
tyExpr, tyStmt, tyStatic, tyTypeDesc, tyTypeClasses, tyVoid:
tyExpr, tyStmt, tyTypeDesc, tyTypeClasses, tyVoid:
result = etyNone
of tyStatic:
if t.n != nil: result = mapType(lastSon t)
else: result = etyNone
of tyProc: result = etyProc
of tyCString: result = etyString
@@ -1427,6 +1430,12 @@ proc createVar(p: PProc, typ: PType, indirect: bool): Rope =
result = putToSeq("null", indirect)
of tySequence, tyString, tyCString, tyPointer, tyProc:
result = putToSeq("null", indirect)
of tyStatic:
if t.n != nil:
result = createVar(p, lastSon t, indirect)
else:
internalError("createVar: " & $t.kind)
result = nil
else:
internalError("createVar: " & $t.kind)
result = nil

View File

@@ -165,4 +165,7 @@ proc genTypeInfo(p: PProc, typ: PType): Rope =
of tyEnum: genEnumInfo(p, t, result)
of tyObject: genObjectInfo(p, t, result)
of tyTuple: genTupleInfo(p, t, result)
of tyStatic:
if t.n != nil: result = genTypeInfo(p, lastSon t)
else: internalError("genTypeInfo(" & $t.kind & ')')
else: internalError("genTypeInfo(" & $t.kind & ')')

View File

@@ -1317,6 +1317,9 @@ proc computeSizeAux(typ: PType, a: var BiggestInt): BiggestInt =
of tyTypeDesc:
result = computeSizeAux(typ.base, a)
of tyForward: return szIllegalRecursion
of tyStatic:
if typ.n != nil: result = computeSizeAux(lastSon(typ), a)
else: result = szUnknownSize
else:
#internalError("computeSizeAux()")
result = szUnknownSize

View File

@@ -0,0 +1,20 @@
discard """
output: '''1 mod 7'''
"""
# bug #3706
type Modulo[M: static[int]] = distinct int
proc modulo(a: int, M: static[int]): Modulo[M] = Modulo[M](a %% M)
proc `+`[M: static[int]](a, b: Modulo[M]): Modulo[M] = (a.int + b.int).modulo(M)
proc `$`*[M: static[int]](a: Modulo[M]): string = $(a.int) & " mod " & $(M)
when isMainModule:
let
a = 3.modulo(7)
b = 5.modulo(7)
echo a + b