diff options
author | Araq <rumpf_a@web.de> | 2012-09-21 16:28:57 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2012-09-21 16:28:57 +0200 |
commit | 32aa46a8813ebfde12cf3593362e0809e81d415f (patch) | |
tree | bd0f9cd7b2345a8f6d37706ba95d333c0fe0bcd3 /compiler | |
parent | 034686d4c0d3e4ce76c495b9753da04b6ba45f41 (diff) | |
download | Nim-32aa46a8813ebfde12cf3593362e0809e81d415f.tar.gz |
bugfix: typeinfo generation
Diffstat (limited to 'compiler')
-rwxr-xr-x | compiler/ccgtypes.nim | 43 | ||||
-rwxr-xr-x | compiler/cgen.nim | 5 |
2 files changed, 23 insertions, 25 deletions
diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index c2dfb5d63..d99740ed4 100755 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -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 diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 07ab15b33..78616ef30 100755 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -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]) |