bugfix: typeinfo generation

This commit is contained in:
Araq
2012-09-21 16:28:57 +02:00
parent 034686d4c0
commit 32aa46a881
4 changed files with 24 additions and 26 deletions

View File

@@ -677,17 +677,18 @@ proc getNimNode(m: BModule): PRope =
result = ropef("$1[$2]", [m.typeNodesName, toRope(m.typeNodes)])
inc(m.typeNodes)
proc getNimType(m: BModule): PRope =
result = ropef("$1[$2]", [m.nimTypesName, toRope(m.nimTypes)])
inc(m.nimTypes)
when false:
proc getNimType(m: BModule): PRope =
result = ropef("$1[$2]", [m.nimTypesName, toRope(m.nimTypes)])
inc(m.nimTypes)
proc allocMemTI(m: BModule, typ: PType, name: PRope) =
var tmp = getNimType(m)
appf(m.s[cfsTypeInit2], "$2 = &$1;$n", [tmp, name])
proc allocMemTI(m: BModule, typ: PType, name: PRope) =
var tmp = getNimType(m)
appf(m.s[cfsTypeInit2], "$2 = &$1;$n", [tmp, name])
proc genTypeInfoAuxBase(m: BModule, typ: PType, name, base: PRope) =
var nimtypeKind: int
allocMemTI(m, typ, name)
#allocMemTI(m, typ, name)
if (typ.kind == tyObject) and (tfFinal in typ.flags) and
(typ.sons[0] == nil):
nimtypeKind = ord(tyPureObject)
@@ -698,16 +699,17 @@ proc genTypeInfoAuxBase(m: BModule, typ: PType, name, base: PRope) =
if tfIncompleteStruct in typ.flags: size = toRope"void*"
else: size = getTypeDesc(m, typ)
appf(m.s[cfsTypeInit3],
"$1->size = sizeof($2);$n" & "$1->kind = $3;$n" & "$1->base = $4;$n",
[name, size, toRope(nimtypeKind), base])
"$1.size = sizeof($2);$n" & "$1.kind = $3;$n" & "$1.base = $4;$n",
[name, size, toRope(nimtypeKind), base])
# compute type flags for GC optimization
var flags = 0
if not containsGarbageCollectedRef(typ): flags = flags or 1
if not canFormAcycle(typ): flags = flags or 2
#else MessageOut("can contain a cycle: " & typeToString(typ))
if flags != 0:
appf(m.s[cfsTypeInit3], "$1->flags = $2;$n", [name, toRope(flags)])
appf(m.s[cfsVars], "TNimType* $1; /* $2 */$n",
appf(m.s[cfsTypeInit3], "$1.flags = $2;$n", [name, toRope(flags)])
discard cgsym(m, "TNimType")
appf(m.s[cfsVars], "TNimType $1; /* $2 */$n",
[name, toRope(typeToString(typ))])
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"))
var tmp = getNimNode(m)
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) =
genTypeInfoAuxBase(m, typ, name, toRope("0"))
@@ -818,7 +820,7 @@ proc genTupleInfo(m: BModule, typ: PType, name: PRope) =
else:
appf(m.s[cfsTypeInit3], "$1.len = $2; $1.kind = 2;$n",
[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) =
# 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])
app(m.s[cfsTypeInit3], specialCases)
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])
if hasHoles:
# 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) =
assert(typ.sons[0] != nil)
genTypeInfoAux(m, typ, name)
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])
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
discard cgsym(m, "TNimType")
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))])
return
if ContainsOrIncl(m.typeInfoMarker, t.id): return
return con("&", result)
if ContainsOrIncl(m.typeInfoMarker, t.id): return con("&", result)
case t.kind
of tyEmpty: result = toRope"0"
of tyPointer, tyBool, tyChar, tyCString, tyString, tyInt..tyUInt64, tyVar:
@@ -917,7 +919,7 @@ proc genTypeInfo(m: BModule, typ: PType): PRope =
genTypeInfoAux(m, t, result)
if optRefcGC in gGlobalOptions:
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 tyArrayConstr, tyArray: genArrayInfo(m, t, result)
of tySet: genSetInfo(m, t, result)
@@ -930,6 +932,7 @@ proc genTypeInfo(m: BModule, typ: PType): PRope =
# results are not deterministic!
genTupleInfo(m, t, result)
else: InternalError("genTypeInfo(" & $t.kind & ')')
result = con("&", result)
proc genTypeSection(m: BModule, n: PNode) =
nil

View File

@@ -904,11 +904,6 @@ proc registerModuleToMain(m: PSym) =
appff(mainDatInit, "\t$1();$n", "call void ()* $1$n", [datInit])
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 prc = ropeff("N_NOINLINE(void, $1)(void) {$n",
"define void $1() noinline {$n", [initname])

View File

@@ -136,6 +136,7 @@ proc runThreadTests(r: var TResults, options: string) =
runSingleTest(r, "tests/threads" / filename, options & " --tlsEmulation:on")
test "tactors"
test "tactors2"
test "threadex"
# deactivated because output capturing still causes problems sometimes:
#test "trecursive_actor"

View File

@@ -99,7 +99,6 @@ Low priority
- ``with proc `+`(x, y: T): T`` for generic code
- new feature: ``distinct T with operations``
- implement the "easy" constructors idea
- code generated for type information is wasteful
- resizing of strings/sequences could take into account the memory that
is allocated
- timeout for locks