mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-17 22:41:14 +00:00
experiment: use quirky exceptions for the Nim compiler
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -48,6 +48,7 @@ define:useStdoutAsStdmsg
|
||||
@if nimUseStrictDefs:
|
||||
experimental:strictDefs
|
||||
warningAsError[Uninit]:on
|
||||
warningAsError[ProveInit]:on
|
||||
#warningAsError[ProveInit]:on
|
||||
@end
|
||||
|
||||
#--exceptions:quirky
|
||||
|
||||
@@ -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) =
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user