From 80cbe61c6c9935acfb2934c348fbfbbe96de0600 Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 5 Dec 2016 16:27:37 +0100 Subject: [PATCH] made more tests green --- compiler/ccgtypes.nim | 16 ++++++++++++++-- compiler/cgendata.nim | 4 +++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index 6a40d40705..d4e0485d24 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -107,8 +107,10 @@ proc mangleName(m: BModule; s: PSym): Rope = s.loc.r = result proc typeName(typ: PType): Rope = - result = if typ.sym != nil: typ.sym.name.s.mangle.rope - else: ~"TY" + result = if typ.sym != nil and typ.kind in {tyObject, tyEnum}: + typ.sym.name.s.mangle.rope + else: + ~"TY" proc getTypeName(m: BModule; typ: PType; sig: SigHash): Rope = let typ = if typ.kind == tyAlias: typ.lastSon else: typ @@ -1078,6 +1080,14 @@ proc genTypeInfo(m: BModule, t: PType): Rope = if result != nil: return "(&".rope & result & ")".rope + result = m.g.typeInfoMarker.getOrDefault(sig) + if result != nil: + discard cgsym(m, "TNimType") + discard cgsym(m, "TNimNode") + addf(m.s[cfsVars], "extern TNimType $1; /* $2 */$n", + [result, rope(typeToString(t))]) + return "(&".rope & result & ")".rope + result = "NTI$1" % [rope($sig)] m.typeInfoMarker[sig] = result @@ -1091,6 +1101,8 @@ proc genTypeInfo(m: BModule, t: PType): Rope = addf(m.s[cfsVars], "extern TNimType $1; /* $2 */$n", [result, rope(typeToString(t))]) return "(&".rope & result & ")".rope + + m.g.typeInfoMarker[sig] = result case t.kind of tyEmpty, tyVoid: result = rope"0" of tyPointer, tyBool, tyChar, tyCString, tyString, tyInt..tyUInt64, tyVar: diff --git a/compiler/cgendata.nim b/compiler/cgendata.nim index b10d18e675..94d34c5cf1 100644 --- a/compiler/cgendata.nim +++ b/compiler/cgendata.nim @@ -114,6 +114,7 @@ type generatedHeader*: BModule breakPointId*: int breakpoints*: Rope # later the breakpoints are inserted into the main proc + typeInfoMarker*: TypeCache TCGen = object of TPassContext # represents a C source file s*: TCFileSections # sections of the C file @@ -162,7 +163,8 @@ proc newProc*(prc: PSym, module: BModule): BProc = result.nestedTryStmts = @[] result.finallySafePoints = @[] -proc newModuleList*(): BModuleList = BModuleList(modules: @[]) +proc newModuleList*(): BModuleList = + BModuleList(modules: @[], typeInfoMarker: initTable[SigHash, Rope]()) iterator cgenModules*(g: BModuleList): BModule = for i in 0..high(g.modules):