diff options
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/astalgo.nim | 16 | ||||
-rw-r--r-- | compiler/cgen.nim | 10 | ||||
-rw-r--r-- | compiler/filter_tmpl.nim | 24 | ||||
-rw-r--r-- | compiler/nimconf.nim | 25 | ||||
-rw-r--r-- | compiler/options.nim | 17 | ||||
-rw-r--r-- | compiler/renderer.nim | 2 | ||||
-rw-r--r-- | compiler/sem.nim | 5 | ||||
-rw-r--r-- | compiler/semcall.nim | 1 | ||||
-rw-r--r-- | compiler/types.nim | 6 | ||||
-rw-r--r-- | compiler/vm.nim | 2 | ||||
-rw-r--r-- | compiler/vmgen.nim | 3 |
11 files changed, 57 insertions, 54 deletions
diff --git a/compiler/astalgo.nim b/compiler/astalgo.nim index d98a42b34..15072e175 100644 --- a/compiler/astalgo.nim +++ b/compiler/astalgo.nim @@ -69,22 +69,22 @@ proc debug*(n: PNode) {.deprecated.} template mdbg*: bool {.dirty.} = when compiles(c.module): - c.module.fileIdx.int32 == gProjectMainIdx + c.module.fileIdx.int32 == c.config.projectMainIdx elif compiles(c.c.module): - c.c.module.fileIdx.int32 == gProjectMainIdx + c.c.module.fileIdx.int32 == c.c.config.projectMainIdx elif compiles(m.c.module): - m.c.module.fileIdx.int32 == gProjectMainIdx + m.c.module.fileIdx.int32 == m.c.config.projectMainIdx elif compiles(cl.c.module): - cl.c.module.fileIdx.int32 == gProjectMainIdx + cl.c.module.fileIdx.int32 == cl.c.config.projectMainIdx elif compiles(p): when compiles(p.lex): - p.lex.fileIdx.int32 == gProjectMainIdx + p.lex.fileIdx.int32 == p.lex.config.projectMainIdx else: - p.module.module.fileIdx.int32 == gProjectMainIdx + p.module.module.fileIdx.int32 == p.config.projectMainIdx elif compiles(m.module.fileIdx): - m.module.fileIdx.int32 == gProjectMainIdx + m.module.fileIdx.int32 == m.config.projectMainIdx elif compiles(L.fileIdx): - L.fileIdx.int32 == gProjectMainIdx + L.fileIdx.int32 == L.config.projectMainIdx else: error() diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 133e86cea..6a16474c0 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -1099,7 +1099,7 @@ proc getSomeInitName(m: PSym, suffix: string): Rope = if {sfSystemModule, sfMainModule} * m.flags == {}: result = m.owner.name.s.mangle.rope result.add "_" - result.add m.name.s + result.add m.name.s.mangle result.add suffix proc getInitName(m: PSym): Rope = @@ -1115,8 +1115,8 @@ proc registerModuleToMain(g: BModuleList; m: PSym) = var init = m.getInitName datInit = m.getDatInitName - addf(g.mainModProcs, "NIM_EXTERNC N_NOINLINE(void, $1)(void);$N", [init]) - addf(g.mainModProcs, "NIM_EXTERNC N_NOINLINE(void, $1)(void);$N", [datInit]) + addf(g.mainModProcs, "N_LIB_PRIVATE N_NIMCALL(void, $1)(void);$N", [init]) + addf(g.mainModProcs, "N_LIB_PRIVATE N_NIMCALL(void, $1)(void);$N", [datInit]) if sfSystemModule notin m.flags: addf(g.mainDatInit, "\t$1();$N", [datInit]) let initCall = "\t$1();$N" % [init] @@ -1127,7 +1127,7 @@ proc registerModuleToMain(g: BModuleList; m: PSym) = proc genInitCode(m: BModule) = var initname = getInitName(m.module) - var prc = "NIM_EXTERNC N_NOINLINE(void, $1)(void) {$N" % [initname] + var prc = "N_LIB_PRIVATE N_NIMCALL(void, $1)(void) {$N" % [initname] if m.typeNodes > 0: appcg(m, m.s[cfsTypeInit1], "static #TNimNode $1[$2];$n", [m.typeNodesName, rope(m.typeNodes)]) @@ -1169,7 +1169,7 @@ proc genInitCode(m: BModule) = add(prc, deinitGCFrame(m.initProc)) addf(prc, "}$N$N", []) - prc.addf("NIM_EXTERNC N_NOINLINE(void, $1)(void) {$N", + prc.addf("N_LIB_PRIVATE N_NIMCALL(void, $1)(void) {$N", [getDatInitName(m.module)]) for i in cfsTypeInit1..cfsDynLibInit: diff --git a/compiler/filter_tmpl.nim b/compiler/filter_tmpl.nim index f93355e6b..6c16a0b4e 100644 --- a/compiler/filter_tmpl.nim +++ b/compiler/filter_tmpl.nim @@ -42,8 +42,7 @@ proc newLine(p: var TTmplParser) = proc scanPar(p: var TTmplParser, d: int) = var i = d - let hi = p.x.len - 1 - while i <= hi: + while i < p.x.len: case p.x[i] of '(': inc(p.par) of ')': dec(p.par) @@ -63,22 +62,19 @@ const proc parseLine(p: var TTmplParser) = var j = 0 - let hi = p.x.len - 1 + let len = p.x.len - if hi == 0: - return + while j < len and p.x[j] == ' ': inc(j) - while j <= hi and p.x[j] == ' ': inc(j) - - if p.x.len >= 2 and p.x[0] == p.nimDirective and p.x[1] == '?': + if len >= 2 and p.x[0] == p.nimDirective and p.x[1] == '?': newLine(p) - elif j < p.x.len and p.x[j] == p.nimDirective: + elif j < len and p.x[j] == p.nimDirective: newLine(p) inc(j) - while j <= hi and p.x[j] == ' ': inc(j) + while j < len and p.x[j] == ' ': inc(j) let d = j var keyw = "" - while j <= hi and p.x[j] in PatternChars: + while j < len and p.x[j] in PatternChars: add(keyw, p.x[j]) inc(j) @@ -132,7 +128,7 @@ proc parseLine(p: var TTmplParser) = llStreamWrite(p.outp, "(\"") inc(p.emitPar) p.state = psTempl - while j <= hi: + while j < len: case p.x[j] of '\x01'..'\x1F', '\x80'..'\xFF': llStreamWrite(p.outp, "\\x") @@ -160,7 +156,7 @@ proc parseLine(p: var TTmplParser) = llStreamWrite(p.outp, '(') inc(j) var curly = 0 - while j <= hi: + while j < len: case p.x[j] of '{': inc(j) @@ -185,7 +181,7 @@ proc parseLine(p: var TTmplParser) = llStreamWrite(p.outp, p.conc) llStreamWrite(p.outp, p.toStr) llStreamWrite(p.outp, '(') - while j <= hi and p.x[j] in PatternChars: + while j < len and p.x[j] in PatternChars: llStreamWrite(p.outp, p.x[j]) inc(j) llStreamWrite(p.outp, ')') diff --git a/compiler/nimconf.nim b/compiler/nimconf.nim index 6cb5bab0f..a455b4a44 100644 --- a/compiler/nimconf.nim +++ b/compiler/nimconf.nim @@ -201,7 +201,8 @@ proc parseAssignment(L: var TLexer, tok: var TToken; else: processSwitch(s, val, passPP, info, config) -proc readConfigFile(filename: string; cache: IdentCache; config: ConfigRef) = +proc readConfigFile( + filename: string; cache: IdentCache; config: ConfigRef): bool = var L: TLexer tok: TToken @@ -216,7 +217,7 @@ proc readConfigFile(filename: string; cache: IdentCache; config: ConfigRef) = while tok.tokType != tkEof: parseAssignment(L, tok, config, condStack) if len(condStack) > 0: lexMessage(L, errGenerated, "expected @end") closeLexer(L) - rawMessage(config, hintConf, filename) + return true proc getUserConfigPath(filename: string): string = result = joinPath(getConfigDir(), filename) @@ -232,27 +233,37 @@ proc getSystemConfigPath(conf: ConfigRef; filename: string): string = proc loadConfigs*(cfg: string; cache: IdentCache; conf: ConfigRef) = setDefaultLibpath(conf) + + var configFiles = newSeq[string]() + + template readConfigFile(path: string) = + let configPath = path + if readConfigFile(configPath, cache, conf): + add(configFiles, configPath) if optSkipConfigFile notin conf.globalOptions: - readConfigFile(getSystemConfigPath(conf, cfg), cache, conf) + readConfigFile(getSystemConfigPath(conf, cfg)) if optSkipUserConfigFile notin conf.globalOptions: - readConfigFile(getUserConfigPath(cfg), cache, conf) + readConfigFile(getUserConfigPath(cfg)) let pd = if conf.projectPath.len > 0: conf.projectPath else: getCurrentDir() if optSkipParentConfigFiles notin conf.globalOptions: for dir in parentDirs(pd, fromRoot=true, inclusive=false): - readConfigFile(dir / cfg, cache, conf) + readConfigFile(dir / cfg) if optSkipProjConfigFile notin conf.globalOptions: - readConfigFile(pd / cfg, cache, conf) + readConfigFile(pd / cfg) if conf.projectName.len != 0: # new project wide config file: var projectConfig = changeFileExt(conf.projectFull, "nimcfg") if not fileExists(projectConfig): projectConfig = changeFileExt(conf.projectFull, "nim.cfg") - readConfigFile(projectConfig, cache, conf) + readConfigFile(projectConfig) + + for filename in configFiles: + rawMessage(conf, hintConf, filename) proc loadConfigs*(cfg: string; conf: ConfigRef) = # for backwards compatibility only. diff --git a/compiler/options.nim b/compiler/options.nim index 8fe3cf054..150e67a18 100644 --- a/compiler/options.nim +++ b/compiler/options.nim @@ -222,7 +222,8 @@ proc newConfigRef*(): ConfigRef = keepComments: true, # whether the parser needs to keep comments implicitImports: @[], # modules that are to be implicitly imported implicitIncludes: @[], # modules that are to be implicitly included - docSeeSrcUrl: "" + docSeeSrcUrl: "", + arguments: "" ) # enable colors by default on terminals if terminal.isatty(stderr): @@ -520,20 +521,6 @@ proc isDynlibOverride*(conf: ConfigRef; lib: string): bool = result = optDynlibOverrideAll in conf.globalOptions or conf.dllOverrides.hasKey(lib.canonDynlibName) -proc binaryStrSearch*(x: openArray[string], y: string): int = - var a = 0 - var b = len(x) - 1 - while a <= b: - var mid = (a + b) div 2 - var c = cmpIgnoreCase(x[mid], y) - if c < 0: - a = mid + 1 - elif c > 0: - b = mid - 1 - else: - return mid - result = - 1 - proc parseIdeCmd*(s: string): IdeCmd = case s: of "sug": ideSug diff --git a/compiler/renderer.nim b/compiler/renderer.nim index 259d0211f..6ac6e797e 100644 --- a/compiler/renderer.nim +++ b/compiler/renderer.nim @@ -189,7 +189,7 @@ proc putComment(g: var TSrcGen, s: string) = put(g, tkComment, com) com = "## " inc(i) - if s[i] == '\x0A': inc(i) + if i < s.len and s[i] == '\x0A': inc(i) optNL(g, ind) of '\x0A': put(g, tkComment, com) diff --git a/compiler/sem.nim b/compiler/sem.nim index c5c3dd99b..d56355f14 100644 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -38,6 +38,7 @@ proc changeType(c: PContext; n: PNode, newType: PType, check: bool) proc semLambda(c: PContext, n: PNode, flags: TExprFlags): PNode proc semTypeNode(c: PContext, n: PNode, prev: PType): PType proc semStmt(c: PContext, n: PNode): PNode +proc semOpAux(c: PContext, n: PNode) proc semParamList(c: PContext, n, genericParams: PNode, s: PSym) proc addParams(c: PContext, n: PNode, kind: TSymKind) proc maybeAddResult(c: PContext, s: PSym, n: PNode) @@ -161,7 +162,9 @@ proc commonType*(x, y: PType): PType = # this will trigger an error later: if result.isNil or result == a: return x if result == b: return y - if k != tyNone: + # bug #7906, tyRef/tyPtr + tyGenericInst of ref/ptr object -> + # ill-formed AST, no need for additional tyRef/tyPtr + if k != tyNone and x.kind != tyGenericInst: let r = result result = newType(k, r.owner) result.addSonSkipIntLit(r) diff --git a/compiler/semcall.nim b/compiler/semcall.nim index e9a31d3d6..df99d6c24 100644 --- a/compiler/semcall.nim +++ b/compiler/semcall.nim @@ -254,6 +254,7 @@ proc resolveOverloads(c: PContext, n, orig: PNode, var f = n.sons[0] if f.kind == nkBracketExpr: # fill in the bindings: + semOpAux(c, f) initialBinding = f f = f.sons[0] else: diff --git a/compiler/types.nim b/compiler/types.nim index b5f4fbf54..1fab842cc 100644 --- a/compiler/types.nim +++ b/compiler/types.nim @@ -1059,8 +1059,12 @@ proc commonSuperclass*(a, b: PType): PType = x = x.sons[0] var y = b while y != nil: + var t = y # bug #7818, save type before skip y = skipTypes(y, skipPtrs) - if ancestors.contains(y.id): return y + if ancestors.contains(y.id): + # bug #7818, defer the previous skipTypes + if t.kind != tyGenericInst: t = y + return t y = y.sons[0] type diff --git a/compiler/vm.nim b/compiler/vm.nim index dcb4cefd7..cbd304caa 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -441,7 +441,7 @@ proc setLenSeq(c: PCtx; node: PNode; newLen: int; info: TLineInfo) = node.sons[i] = newNodeI(typeKind, info) const - errIndexOutOfBounds = "index ouf of bounds" + errIndexOutOfBounds = "index out of bounds" errNilAccess = "attempt to access a nil address" errOverOrUnderflow = "over- or underflow" errConstantDivisionByZero = "division by zero" diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim index 7ac3b5cf7..8a3c7e2e6 100644 --- a/compiler/vmgen.nim +++ b/compiler/vmgen.nim @@ -844,7 +844,8 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest; m: TMagic) = of mNewStringOfCap: # we ignore the 'cap' argument and translate it as 'newString(0)'. # eval n.sons[1] for possible side effects: - var tmp = c.genx(n.sons[1]) + c.freeTemp(c.genx(n.sons[1])) + var tmp = c.getTemp(n.sons[1].typ) c.gABx(n, opcLdImmInt, tmp, 0) if dest < 0: dest = c.getTemp(n.typ) c.gABC(n, opcNewStr, dest, tmp) |