diff options
-rw-r--r-- | compiler/cgen.nim | 2 | ||||
-rw-r--r-- | compiler/options.nim | 2 | ||||
-rw-r--r-- | compiler/semexprs.nim | 3 | ||||
-rw-r--r-- | compiler/suggest.nim | 17 | ||||
-rw-r--r-- | lib/system/excpt.nim | 6 | ||||
-rw-r--r-- | tests/compile/tvarious.nim | 8 | ||||
-rw-r--r-- | todo.txt | 1 |
7 files changed, 22 insertions, 17 deletions
diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 92216d278..7e782fc12 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -346,6 +346,8 @@ proc resetLoc(p: BProc, loc: var TLoc) = else: linefmt(p, cpsStmts, "$1 = 0;$n", rdLoc(loc)) else: + if optNilCheck in p.options: + linefmt(p, cpsStmts, "#chckNil((void*)$1);$n", addrLoc(loc)) if loc.s != OnStack: linefmt(p, cpsStmts, "#genericReset((void*)$1, $2);$n", addrLoc(loc), genTypeInfo(p.module, loc.t)) diff --git a/compiler/options.nim b/compiler/options.nim index f67ded163..6d93048fe 100644 --- a/compiler/options.nim +++ b/compiler/options.nim @@ -92,7 +92,7 @@ var gOptions*: TOptions = {optObjCheck, optFieldCheck, optRangeCheck, optBoundsCheck, optOverflowCheck, optAssert, optWarns, optHints, optStackTrace, optLineTrace, - optPatterns} + optPatterns, optNilCheck} gGlobalOptions*: TGlobalOptions = {optThreadAnalysis} gExitcode*: int8 gCmd*: TCommands = cmdNone # the command diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index e07821d1f..03730f30c 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -920,7 +920,7 @@ proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode = result = check elif ty.kind == tyTuple and ty.n != nil: f = getSymFromList(ty.n, i) - if f != nil: + if f != nil: n.sons[0] = makeDeref(n.sons[0]) n.sons[1] = newSymNode(f) n.typ = f.typ @@ -1582,6 +1582,7 @@ proc semTupleFieldsConstr(c: PContext, n: PNode, flags: TExprFlags): PNode = flags*{efAllowDestructor}) var f = newSymS(skField, n.sons[i].sons[0], c) f.typ = skipIntLit(n.sons[i].sons[1].typ) + f.position = i rawAddSon(typ, f.typ) addSon(typ.n, newSymNode(f)) n.sons[i].sons[0] = newSymNode(f) diff --git a/compiler/suggest.nim b/compiler/suggest.nim index 1f0cbe639..b86a2c365 100644 --- a/compiler/suggest.nim +++ b/compiler/suggest.nim @@ -27,17 +27,14 @@ proc SymToStr(s: PSym, isLocal: bool, section: string, li: TLineInfo): string = result.add(sep) result.add($s.kind) result.add(sep) - if not isLocal: - var a: array [0..4, PSym] - var L = 0 - var ow = s - while ow.kind != skModule and ow.owner != nil and L < len(a): - a[L] = ow - inc L - ow = ow.owner - for i in countdown(L-1, 0): - result.add(a[i].name.s) + if not isLocal and s.kind != skModule: + let ow = s.owner + if ow.kind != skModule and ow.owner != nil: + let ow2 = ow.owner + result.add(ow2.name.s) result.add('.') + result.add(ow.name.s) + result.add('.') result.add(s.name.s) result.add(sep) if s.typ != nil: diff --git a/lib/system/excpt.nim b/lib/system/excpt.nim index faaefe083..bf0fe4b72 100644 --- a/lib/system/excpt.nim +++ b/lib/system/excpt.nim @@ -32,7 +32,7 @@ proc registerSignalHandler() proc chckIndx(i, a, b: int): int {.inline, compilerproc.} proc chckRange(i, a, b: int): int {.inline, compilerproc.} proc chckRangeF(x, a, b: float): float {.inline, compilerproc.} -proc chckNil(p: pointer) {.inline, compilerproc.} +proc chckNil(p: pointer) {.noinline, compilerproc.} var framePtr {.rtlThreadVar.}: PFrame @@ -359,7 +359,9 @@ proc chckRangeF(x, a, b: float): float = raise newException(EOutOfRange, "value " & $x & " out of range") proc chckNil(p: pointer) = - if p == nil: c_raise(SIGSEGV) + if p == nil: + raise newException(EInvalidValue, "attempt to write to a nil address") + #c_raise(SIGSEGV) proc chckObj(obj, subclass: PNimType) {.compilerproc.} = # checks if obj is of type subclass: diff --git a/tests/compile/tvarious.nim b/tests/compile/tvarious.nim index 52dd46184..087233226 100644 --- a/tests/compile/tvarious.nim +++ b/tests/compile/tvarious.nim @@ -1,5 +1,8 @@ # Test various aspects +var x = (x: 42, y: (a: 8, z: 10)) +echo x.y + import mvarious @@ -31,7 +34,7 @@ var r.b.a.x = 0 global = global + 1 exportme() -write(stdout, "Hallo wie heißt du? ") +write(stdout, "Hallo wie heißt du? ") write(stdout, getPA().x) s = readLine(stdin) i = 0 @@ -39,5 +42,4 @@ while i < s.len: if s[i] == 'c': write(stdout, "'c' in deinem Namen gefunden\n") i = i + 1 -write(stdout, "Du heißt " & s) - +write(stdout, "Du heißt " & s) diff --git a/todo.txt b/todo.txt index 5214245ae..b59f7502e 100644 --- a/todo.txt +++ b/todo.txt @@ -9,6 +9,7 @@ version 0.9.4 - overloading of ``.``? Special case ``.=``? - built-in 'getImpl' - macros.gensym still missing? +- optimize 'genericReset'; 'newException' leads to code bloat Bugs |