bugfix: typeinfo generation
This commit is contained in:
parent
034686d4c0
commit
32aa46a881
4 changed files with 24 additions and 26 deletions
|
|
@ -677,17 +677,18 @@ proc getNimNode(m: BModule): PRope =
|
||||||
result = ropef("$1[$2]", [m.typeNodesName, toRope(m.typeNodes)])
|
result = ropef("$1[$2]", [m.typeNodesName, toRope(m.typeNodes)])
|
||||||
inc(m.typeNodes)
|
inc(m.typeNodes)
|
||||||
|
|
||||||
proc getNimType(m: BModule): PRope =
|
when false:
|
||||||
result = ropef("$1[$2]", [m.nimTypesName, toRope(m.nimTypes)])
|
proc getNimType(m: BModule): PRope =
|
||||||
inc(m.nimTypes)
|
result = ropef("$1[$2]", [m.nimTypesName, toRope(m.nimTypes)])
|
||||||
|
inc(m.nimTypes)
|
||||||
|
|
||||||
proc allocMemTI(m: BModule, typ: PType, name: PRope) =
|
proc allocMemTI(m: BModule, typ: PType, name: PRope) =
|
||||||
var tmp = getNimType(m)
|
var tmp = getNimType(m)
|
||||||
appf(m.s[cfsTypeInit2], "$2 = &$1;$n", [tmp, name])
|
appf(m.s[cfsTypeInit2], "$2 = &$1;$n", [tmp, name])
|
||||||
|
|
||||||
proc genTypeInfoAuxBase(m: BModule, typ: PType, name, base: PRope) =
|
proc genTypeInfoAuxBase(m: BModule, typ: PType, name, base: PRope) =
|
||||||
var nimtypeKind: int
|
var nimtypeKind: int
|
||||||
allocMemTI(m, typ, name)
|
#allocMemTI(m, typ, name)
|
||||||
if (typ.kind == tyObject) and (tfFinal in typ.flags) and
|
if (typ.kind == tyObject) and (tfFinal in typ.flags) and
|
||||||
(typ.sons[0] == nil):
|
(typ.sons[0] == nil):
|
||||||
nimtypeKind = ord(tyPureObject)
|
nimtypeKind = ord(tyPureObject)
|
||||||
|
|
@ -698,7 +699,7 @@ proc genTypeInfoAuxBase(m: BModule, typ: PType, name, base: PRope) =
|
||||||
if tfIncompleteStruct in typ.flags: size = toRope"void*"
|
if tfIncompleteStruct in typ.flags: size = toRope"void*"
|
||||||
else: size = getTypeDesc(m, typ)
|
else: size = getTypeDesc(m, typ)
|
||||||
appf(m.s[cfsTypeInit3],
|
appf(m.s[cfsTypeInit3],
|
||||||
"$1->size = sizeof($2);$n" & "$1->kind = $3;$n" & "$1->base = $4;$n",
|
"$1.size = sizeof($2);$n" & "$1.kind = $3;$n" & "$1.base = $4;$n",
|
||||||
[name, size, toRope(nimtypeKind), base])
|
[name, size, toRope(nimtypeKind), base])
|
||||||
# compute type flags for GC optimization
|
# compute type flags for GC optimization
|
||||||
var flags = 0
|
var flags = 0
|
||||||
|
|
@ -706,8 +707,9 @@ proc genTypeInfoAuxBase(m: BModule, typ: PType, name, base: PRope) =
|
||||||
if not canFormAcycle(typ): flags = flags or 2
|
if not canFormAcycle(typ): flags = flags or 2
|
||||||
#else MessageOut("can contain a cycle: " & typeToString(typ))
|
#else MessageOut("can contain a cycle: " & typeToString(typ))
|
||||||
if flags != 0:
|
if flags != 0:
|
||||||
appf(m.s[cfsTypeInit3], "$1->flags = $2;$n", [name, toRope(flags)])
|
appf(m.s[cfsTypeInit3], "$1.flags = $2;$n", [name, toRope(flags)])
|
||||||
appf(m.s[cfsVars], "TNimType* $1; /* $2 */$n",
|
discard cgsym(m, "TNimType")
|
||||||
|
appf(m.s[cfsVars], "TNimType $1; /* $2 */$n",
|
||||||
[name, toRope(typeToString(typ))])
|
[name, toRope(typeToString(typ))])
|
||||||
|
|
||||||
proc genTypeInfoAux(m: BModule, typ: PType, name: PRope) =
|
proc genTypeInfoAux(m: BModule, typ: PType, name: PRope) =
|
||||||
|
|
@ -795,7 +797,7 @@ proc genObjectInfo(m: BModule, typ: PType, name: PRope) =
|
||||||
else: genTypeInfoAuxBase(m, typ, name, toRope("0"))
|
else: genTypeInfoAuxBase(m, typ, name, toRope("0"))
|
||||||
var tmp = getNimNode(m)
|
var tmp = getNimNode(m)
|
||||||
genObjectFields(m, typ, typ.n, tmp)
|
genObjectFields(m, typ, typ.n, tmp)
|
||||||
appf(m.s[cfsTypeInit3], "$1->node = &$2;$n", [name, tmp])
|
appf(m.s[cfsTypeInit3], "$1.node = &$2;$n", [name, tmp])
|
||||||
|
|
||||||
proc genTupleInfo(m: BModule, typ: PType, name: PRope) =
|
proc genTupleInfo(m: BModule, typ: PType, name: PRope) =
|
||||||
genTypeInfoAuxBase(m, typ, name, toRope("0"))
|
genTypeInfoAuxBase(m, typ, name, toRope("0"))
|
||||||
|
|
@ -818,7 +820,7 @@ proc genTupleInfo(m: BModule, typ: PType, name: PRope) =
|
||||||
else:
|
else:
|
||||||
appf(m.s[cfsTypeInit3], "$1.len = $2; $1.kind = 2;$n",
|
appf(m.s[cfsTypeInit3], "$1.len = $2; $1.kind = 2;$n",
|
||||||
[expr, toRope(length)])
|
[expr, toRope(length)])
|
||||||
appf(m.s[cfsTypeInit3], "$1->node = &$2;$n", [name, expr])
|
appf(m.s[cfsTypeInit3], "$1.node = &$2;$n", [name, expr])
|
||||||
|
|
||||||
proc genEnumInfo(m: BModule, typ: PType, name: PRope) =
|
proc genEnumInfo(m: BModule, typ: PType, name: PRope) =
|
||||||
# Type information for enumerations is quite heavy, so we do some
|
# Type information for enumerations is quite heavy, so we do some
|
||||||
|
|
@ -857,17 +859,17 @@ proc genEnumInfo(m: BModule, typ: PType, name: PRope) =
|
||||||
toRope(length), m.typeNodesName, toRope(firstNimNode), enumArray, nodePtrs])
|
toRope(length), m.typeNodesName, toRope(firstNimNode), enumArray, nodePtrs])
|
||||||
app(m.s[cfsTypeInit3], specialCases)
|
app(m.s[cfsTypeInit3], specialCases)
|
||||||
appf(m.s[cfsTypeInit3],
|
appf(m.s[cfsTypeInit3],
|
||||||
"$1.len = $2; $1.kind = 2; $1.sons = &$3[0];$n$4->node = &$1;$n",
|
"$1.len = $2; $1.kind = 2; $1.sons = &$3[0];$n$4.node = &$1;$n",
|
||||||
[getNimNode(m), toRope(length), nodePtrs, name])
|
[getNimNode(m), toRope(length), nodePtrs, name])
|
||||||
if hasHoles:
|
if hasHoles:
|
||||||
# 1 << 2 is {ntfEnumHole}
|
# 1 << 2 is {ntfEnumHole}
|
||||||
appf(m.s[cfsTypeInit3], "$1->flags = 1<<2;$n", [name])
|
appf(m.s[cfsTypeInit3], "$1.flags = 1<<2;$n", [name])
|
||||||
|
|
||||||
proc genSetInfo(m: BModule, typ: PType, name: PRope) =
|
proc genSetInfo(m: BModule, typ: PType, name: PRope) =
|
||||||
assert(typ.sons[0] != nil)
|
assert(typ.sons[0] != nil)
|
||||||
genTypeInfoAux(m, typ, name)
|
genTypeInfoAux(m, typ, name)
|
||||||
var tmp = getNimNode(m)
|
var tmp = getNimNode(m)
|
||||||
appf(m.s[cfsTypeInit3], "$1.len = $2; $1.kind = 0;$n" & "$3->node = &$1;$n",
|
appf(m.s[cfsTypeInit3], "$1.len = $2; $1.kind = 0;$n" & "$3.node = &$1;$n",
|
||||||
[tmp, toRope(firstOrd(typ)), name])
|
[tmp, toRope(firstOrd(typ)), name])
|
||||||
|
|
||||||
proc genArrayInfo(m: BModule, typ: PType, name: PRope) =
|
proc genArrayInfo(m: BModule, typ: PType, name: PRope) =
|
||||||
|
|
@ -900,10 +902,10 @@ proc genTypeInfo(m: BModule, typ: PType): PRope =
|
||||||
# refenrece the type info as extern here
|
# refenrece the type info as extern here
|
||||||
discard cgsym(m, "TNimType")
|
discard cgsym(m, "TNimType")
|
||||||
discard cgsym(m, "TNimNode")
|
discard cgsym(m, "TNimNode")
|
||||||
appf(m.s[cfsVars], "extern TNimType* $1; /* $2 */$n",
|
appf(m.s[cfsVars], "extern TNimType $1; /* $2 */$n",
|
||||||
[result, toRope(typeToString(t))])
|
[result, toRope(typeToString(t))])
|
||||||
return
|
return con("&", result)
|
||||||
if ContainsOrIncl(m.typeInfoMarker, t.id): return
|
if ContainsOrIncl(m.typeInfoMarker, t.id): return con("&", result)
|
||||||
case t.kind
|
case t.kind
|
||||||
of tyEmpty: result = toRope"0"
|
of tyEmpty: result = toRope"0"
|
||||||
of tyPointer, tyBool, tyChar, tyCString, tyString, tyInt..tyUInt64, tyVar:
|
of tyPointer, tyBool, tyChar, tyCString, tyString, tyInt..tyUInt64, tyVar:
|
||||||
|
|
@ -917,7 +919,7 @@ proc genTypeInfo(m: BModule, typ: PType): PRope =
|
||||||
genTypeInfoAux(m, t, result)
|
genTypeInfoAux(m, t, result)
|
||||||
if optRefcGC in gGlobalOptions:
|
if optRefcGC in gGlobalOptions:
|
||||||
let markerProc = genTraverseProc(m, t, tiNew)
|
let markerProc = genTraverseProc(m, t, tiNew)
|
||||||
appf(m.s[cfsTypeInit3], "$1->marker = $2;$n", [result, markerProc])
|
appf(m.s[cfsTypeInit3], "$1.marker = $2;$n", [result, markerProc])
|
||||||
of tyPtr, tyRange: genTypeInfoAux(m, t, result)
|
of tyPtr, tyRange: genTypeInfoAux(m, t, result)
|
||||||
of tyArrayConstr, tyArray: genArrayInfo(m, t, result)
|
of tyArrayConstr, tyArray: genArrayInfo(m, t, result)
|
||||||
of tySet: genSetInfo(m, t, result)
|
of tySet: genSetInfo(m, t, result)
|
||||||
|
|
@ -930,6 +932,7 @@ proc genTypeInfo(m: BModule, typ: PType): PRope =
|
||||||
# results are not deterministic!
|
# results are not deterministic!
|
||||||
genTupleInfo(m, t, result)
|
genTupleInfo(m, t, result)
|
||||||
else: InternalError("genTypeInfo(" & $t.kind & ')')
|
else: InternalError("genTypeInfo(" & $t.kind & ')')
|
||||||
|
result = con("&", result)
|
||||||
|
|
||||||
proc genTypeSection(m: BModule, n: PNode) =
|
proc genTypeSection(m: BModule, n: PNode) =
|
||||||
nil
|
nil
|
||||||
|
|
|
||||||
|
|
@ -904,11 +904,6 @@ proc registerModuleToMain(m: PSym) =
|
||||||
appff(mainDatInit, "\t$1();$n", "call void ()* $1$n", [datInit])
|
appff(mainDatInit, "\t$1();$n", "call void ()* $1$n", [datInit])
|
||||||
|
|
||||||
proc genInitCode(m: BModule) =
|
proc genInitCode(m: BModule) =
|
||||||
if optProfiler in m.initProc.options:
|
|
||||||
# This does not really belong here, but there is no good place for this
|
|
||||||
# code. I don't want to put this to the proc generation as the
|
|
||||||
# ``IncludeStr`` call is quite slow.
|
|
||||||
discard lists.IncludeStr(m.headerFiles, "<cycle.h>")
|
|
||||||
var initname = getInitName(m.module)
|
var initname = getInitName(m.module)
|
||||||
var prc = ropeff("N_NOINLINE(void, $1)(void) {$n",
|
var prc = ropeff("N_NOINLINE(void, $1)(void) {$n",
|
||||||
"define void $1() noinline {$n", [initname])
|
"define void $1() noinline {$n", [initname])
|
||||||
|
|
|
||||||
|
|
@ -136,6 +136,7 @@ proc runThreadTests(r: var TResults, options: string) =
|
||||||
runSingleTest(r, "tests/threads" / filename, options & " --tlsEmulation:on")
|
runSingleTest(r, "tests/threads" / filename, options & " --tlsEmulation:on")
|
||||||
|
|
||||||
test "tactors"
|
test "tactors"
|
||||||
|
test "tactors2"
|
||||||
test "threadex"
|
test "threadex"
|
||||||
# deactivated because output capturing still causes problems sometimes:
|
# deactivated because output capturing still causes problems sometimes:
|
||||||
#test "trecursive_actor"
|
#test "trecursive_actor"
|
||||||
|
|
|
||||||
1
todo.txt
1
todo.txt
|
|
@ -99,7 +99,6 @@ Low priority
|
||||||
- ``with proc `+`(x, y: T): T`` for generic code
|
- ``with proc `+`(x, y: T): T`` for generic code
|
||||||
- new feature: ``distinct T with operations``
|
- new feature: ``distinct T with operations``
|
||||||
- implement the "easy" constructors idea
|
- implement the "easy" constructors idea
|
||||||
- code generated for type information is wasteful
|
|
||||||
- resizing of strings/sequences could take into account the memory that
|
- resizing of strings/sequences could take into account the memory that
|
||||||
is allocated
|
is allocated
|
||||||
- timeout for locks
|
- timeout for locks
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue