experiment: use quirky exceptions for the Nim compiler

This commit is contained in:
araq
2023-09-11 19:57:57 +02:00
parent 8f5b90f886
commit 7c7159f1f5
5 changed files with 21 additions and 10 deletions

View File

@@ -499,8 +499,8 @@ proc resetLoc(p: BProc, loc: var TLoc) =
# array passed as argument decayed into pointer, bug #7332
# so we use getTypeDesc here rather than rdLoc(loc)
let tyDesc = getTypeDesc(p.module, loc.t, descKindFromSymKind mapTypeChooser(loc))
if p.module.compileToCpp and isOrHasImportedCppType(typ):
if lfIndirect in loc.flags:
if p.module.compileToCpp and isOrHasImportedCppType(typ):
if lfIndirect in loc.flags:
#C++ cant be just zeroed. We need to call the ctors
var tmp = getTemp(p, loc.t)
linefmt(p, cpsStmts,"#nimCopyMem((void*)$1, (NIM_CONST void*)$2, sizeof($3));$n",
@@ -508,7 +508,7 @@ proc resetLoc(p: BProc, loc: var TLoc) =
else:
linefmt(p, cpsStmts, "#nimZeroMem((void*)$1, sizeof($2));$n",
[addrLoc(p.config, loc), tyDesc])
# XXX: We can be extra clever here and call memset only
# on the bytes following the m_type field?
genObjectInit(p, cpsStmts, loc.t, loc, constructObj)
@@ -1143,7 +1143,7 @@ proc genProcBody(p: BProc; procBody: PNode) =
p.blocks[0].sections[cpsInit].add(ropecg(p.module, "nimErr_ = #nimErrorFlag();$n", []))
proc isNoReturn(m: BModule; s: PSym): bool {.inline.} =
sfNoReturn in s.flags and m.config.exc != excGoto
sfNoReturn in s.flags and m.config.exc notin {excGoto, excQuirky}
proc genProcAux*(m: BModule, prc: PSym) =
var p = newProc(prc, m)
@@ -1191,7 +1191,7 @@ proc genProcAux*(m: BModule, prc: PSym) =
let ty = resNode.sym.typ[0] #generate nim's ctor
for i in 1..<resNode.sym.ast.len:
let field = resNode.sym.ast[i]
genFieldObjConstr(p, ty, useTemp = false, isRef = false,
genFieldObjConstr(p, ty, useTemp = false, isRef = false,
field[0], field[1], check = nil, resNode.sym.loc, "(*this)", tmpInfo)
else:
fillResult(p.config, resNode, prc.typ)

View File

@@ -48,6 +48,7 @@ define:useStdoutAsStdmsg
@if nimUseStrictDefs:
experimental:strictDefs
warningAsError[Uninit]:on
warningAsError[ProveInit]:on
#warningAsError[ProveInit]:on
@end
#--exceptions:quirky

View File

@@ -493,6 +493,7 @@ template handleJmpBack() {.dirty.} =
msgWriteln(c.config, "stack trace: (most recent call last)", {msgNoUnitSep})
stackTraceAux(c, tos, pc)
globalError(c.config, c.debug[pc], errTooManyIterations % $c.config.maxLoopIterationsVM)
return
dec(c.loopIterations)
proc recSetFlagIsRef(arg: PNode) =

View File

@@ -228,10 +228,16 @@ template dataLen(t): untyped = len(t.data)
include tableimpl
proc raiseKeyError[T](key: T) {.noinline, noreturn.} =
when compiles($key):
raise newException(KeyError, "key not found: " & $key)
when defined(nimQuirky):
when compiles($key):
quit "[KeyError] key not found: " & $key
else:
quit "[KeyError] key not found"
else:
raise newException(KeyError, "key not found")
when compiles($key):
raise newException(KeyError, "key not found: " & $key)
else:
raise newException(KeyError, "key not found")
template get(t, key): untyped =
## retrieves the value at `t[key]`. The value can be modified.

View File

@@ -31,7 +31,10 @@ proc `$`(info: InstantiationInfo): string =
proc raiseAssert*(msg: string) {.noinline, noreturn, nosinks.} =
## Raises an `AssertionDefect` with `msg`.
when defined(nimPreviewSlimSystem):
raise newException(AssertionDefect, msg)
when defined(nimQuirky):
quit "[AssertionError] " & msg
else:
raise newException(AssertionDefect, msg)
else:
sysFatal(AssertionDefect, msg)