diff options
Diffstat (limited to 'compiler/cgen.nim')
-rw-r--r-- | compiler/cgen.nim | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 6e18c8389..db7070941 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -14,7 +14,7 @@ import nversion, nimsets, msgs, securehash, bitsets, idents, lists, types, ccgutils, os, ropes, math, passes, rodread, wordrecg, treetab, cgmeth, condsyms, rodutils, renderer, idgen, cgendata, ccgmerge, semfold, aliases, - lowerings, semparallel + lowerings, semparallel, tables from modulegraphs import ModuleGraph @@ -62,7 +62,7 @@ proc fillLoc(a: var TLoc, k: TLocKind, typ: PType, r: Rope, s: TStorageLoc) = proc isSimpleConst(typ: PType): bool = let t = skipTypes(typ, abstractVar) result = t.kind notin - {tyTuple, tyObject, tyArray, tyArrayConstr, tySet, tySequence} and not + {tyTuple, tyObject, tyArray, tySet, tySequence} and not (t.kind == tyProc and t.callConv == ccClosure) proc useStringh(m: BModule) = @@ -190,21 +190,24 @@ proc freshLineInfo(p: BProc; info: TLineInfo): bool = result = true proc genLineDir(p: BProc, t: PNode) = - var line = t.info.safeLineNm + let info = t.info + #if t.kind in nkCallKinds+{nkStmtListExpr} and t.len > 1: t[1].info + #else: t.info + var line = info.safeLineNm if optEmbedOrigSrc in gGlobalOptions: - add(p.s(cpsStmts), ~"//" & t.info.sourceLine & rnl) - genCLineDir(p.s(cpsStmts), t.info.toFullPath, line) + add(p.s(cpsStmts), ~"//" & info.sourceLine & rnl) + genCLineDir(p.s(cpsStmts), info.toFullPath, line) if ({optStackTrace, optEndb} * p.options == {optStackTrace, optEndb}) and (p.prc == nil or sfPure notin p.prc.flags): - if freshLineInfo(p, t.info): + if freshLineInfo(p, info): linefmt(p, cpsStmts, "#endb($1, $2);$n", - line.rope, makeCString(toFilename(t.info))) + line.rope, makeCString(toFilename(info))) elif ({optLineTrace, optStackTrace} * p.options == {optLineTrace, optStackTrace}) and - (p.prc == nil or sfPure notin p.prc.flags) and t.info.fileIndex >= 0: - if freshLineInfo(p, t.info): + (p.prc == nil or sfPure notin p.prc.flags) and info.fileIndex >= 0: + if freshLineInfo(p, info): linefmt(p, cpsStmts, "nimln($1, $2);$n", - line.rope, t.info.quotedFilename) + line.rope, info.quotedFilename) proc postStmtActions(p: BProc) {.inline.} = add(p.s(cpsStmts), p.module.injectStmt) @@ -263,7 +266,8 @@ type proc genRefAssign(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) proc isComplexValueType(t: PType): bool {.inline.} = - result = t.kind in {tyArray, tyArrayConstr, tySet, tyTuple, tyObject} or + let t = t.skipTypes(abstractInst) + result = t.kind in {tyArray, tySet, tyTuple, tyObject} or (t.kind == tyProc and t.callConv == ccClosure) proc resetLoc(p: BProc, loc: var TLoc) = @@ -296,7 +300,7 @@ proc resetLoc(p: BProc, loc: var TLoc) = genObjectInit(p, cpsStmts, loc.t, loc, true) proc constructLoc(p: BProc, loc: TLoc, isTemp = false) = - let typ = skipTypes(loc.t, abstractRange) + let typ = loc.t if not isComplexValueType(typ): linefmt(p, cpsStmts, "$1 = ($2)0;$n", rdLoc(loc), getTypeDesc(p.module, typ)) @@ -325,13 +329,9 @@ proc initLocalVar(p: BProc, v: PSym, immediateAsgn: bool) = proc getTemp(p: BProc, t: PType, result: var TLoc; needsInit=false) = inc(p.labels) result.r = "LOC" & rope(p.labels) - #addf(p.blocks[0].sections[cpsLocals], - # "$1 $2;$n", [getTypeDesc(p.module, t), result.r]) linefmt(p, cpsLocals, "$1 $2;$n", getTypeDesc(p.module, t), result.r) result.k = locTemp - #result.a = - 1 result.t = t - #result.t = getUniqueType(t) result.s = OnStack result.flags = {} constructLoc(p, result, not needsInit) @@ -359,9 +359,9 @@ proc localDebugInfo(p: BProc, s: PSym) = proc localVarDecl(p: BProc; s: PSym): Rope = if s.loc.k == locNone: - fillLoc(s.loc, locLocalVar, s.typ, mangleName(s), OnStack) + fillLoc(s.loc, locLocalVar, s.typ, mangleName(p.module, s), OnStack) if s.kind == skLet: incl(s.loc.flags, lfNoDeepCopy) - result = getTypeDesc(p.module, s.loc.t) + result = getTypeDesc(p.module, s.typ) if s.constraint.isNil: if sfRegister in s.flags: add(result, " register") #elif skipTypes(s.typ, abstractInst).kind in GcTypeKinds: @@ -387,7 +387,7 @@ proc mangleDynLibProc(sym: PSym): Rope proc assignGlobalVar(p: BProc, s: PSym) = if s.loc.k == locNone: - fillLoc(s.loc, locGlobalVar, s.typ, mangleName(s), OnHeap) + fillLoc(s.loc, locGlobalVar, s.typ, mangleName(p.module, s), OnHeap) if lfDynamicLib in s.loc.flags: var q = findPendingModule(p.module, s) @@ -426,9 +426,9 @@ proc assignParam(p: BProc, s: PSym) = assert(s.loc.r != nil) localDebugInfo(p, s) -proc fillProcLoc(sym: PSym) = +proc fillProcLoc(m: BModule; sym: PSym) = if sym.loc.k == locNone: - fillLoc(sym.loc, locProc, sym.typ, mangleName(sym), OnStack) + fillLoc(sym.loc, locProc, sym.typ, mangleName(m, sym), OnStack) proc getLabel(p: BProc): TLabel = inc(p.labels) @@ -729,7 +729,7 @@ proc genProcPrototype(m: BModule, sym: PSym) = add(m.s[cfsProcHeaders], rfmt(nil, "$1;$n", header)) proc genProcNoForward(m: BModule, prc: PSym) = - fillProcLoc(prc) + fillProcLoc(m, prc) useHeader(m, prc) if lfImportCompilerProc in prc.loc.flags: # dependency to a compilerproc: @@ -757,7 +757,7 @@ proc requestConstImpl(p: BProc, sym: PSym) = var m = p.module useHeader(m, sym) if sym.loc.k == locNone: - fillLoc(sym.loc, locData, sym.typ, mangleName(sym), OnStatic) + fillLoc(sym.loc, locData, sym.typ, mangleName(p.module, sym), OnStatic) if lfNoDecl in sym.loc.flags: return # declare implementation: var q = findPendingModule(m, sym) @@ -778,7 +778,7 @@ proc isActivated(prc: PSym): bool = prc.typ != nil proc genProc(m: BModule, prc: PSym) = if sfBorrow in prc.flags or not isActivated(prc): return - fillProcLoc(prc) + fillProcLoc(m, prc) if sfForward in prc.flags: addForwardedProc(m, prc) else: genProcNoForward(m, prc) @@ -792,7 +792,7 @@ proc genProc(m: BModule, prc: PSym) = proc genVarPrototypeAux(m: BModule, sym: PSym) = #assert(sfGlobal in sym.flags) useHeader(m, sym) - fillLoc(sym.loc, locGlobalVar, sym.typ, mangleName(sym), OnHeap) + fillLoc(sym.loc, locGlobalVar, sym.typ, mangleName(m, sym), OnHeap) if (lfNoDecl in sym.loc.flags) or containsOrIncl(m.declaredThings, sym.id): return if sym.owner.id != m.module.id: @@ -1094,10 +1094,10 @@ proc rawNewModule(module: PSym, filename: string): BModule = result.declaredProtos = initIntSet() result.cfilename = filename result.filename = filename - initIdTable(result.typeCache) - initIdTable(result.forwTypeCache) + result.typeCache = initTable[SigHash, Rope]() + result.forwTypeCache = initTable[SigHash, Rope]() result.module = module - result.typeInfoMarker = initIntSet() + result.typeInfoMarker = initTable[SigHash, Rope]() result.initProc = newProc(nil, result) result.initProc.options = initProcOptions(result) result.preInitProc = newPreInitProc(result) @@ -1123,7 +1123,7 @@ proc resetModule*(m: BModule) = # away all the data that was written to disk initLinkedList(m.headerFiles) m.declaredProtos = initIntSet() - initIdTable(m.forwTypeCache) + m.forwTypeCache = initTable[SigHash, Rope]() m.initProc = newProc(nil, m) m.initProc.options = initProcOptions(m) m.preInitProc = newPreInitProc(m) |