minor refactorings
This commit is contained in:
parent
649bf326bf
commit
1917ebf082
5 changed files with 34 additions and 22 deletions
|
|
@ -1832,3 +1832,21 @@ proc addParam*(procType: PType; param: PSym) =
|
|||
template destructor*(t: PType): PSym = t.attachedOps[attachedDestructor]
|
||||
template assignment*(t: PType): PSym = t.attachedOps[attachedAsgn]
|
||||
template asink*(t: PType): PSym = t.attachedOps[attachedSink]
|
||||
|
||||
const magicsThatCanRaise = {
|
||||
mNone, mSlurp, mStaticExec, mParseExprToAst, mParseStmtToAst}
|
||||
|
||||
proc canRaiseConservative*(fn: PNode): bool =
|
||||
if fn.kind == nkSym and fn.sym.magic notin magicsThatCanRaise:
|
||||
result = false
|
||||
else:
|
||||
result = true
|
||||
|
||||
proc canRaise*(fn: PNode): bool =
|
||||
if fn.kind == nkSym and (fn.sym.magic notin magicsThatCanRaise or
|
||||
{sfImportc, sfInfixCall} * fn.sym.flags == {sfImportc}):
|
||||
result = false
|
||||
else:
|
||||
result = fn.typ != nil and ((fn.typ.n[0].len < effectListLen) or
|
||||
(fn.typ.n[0][exceptionEffects] != nil and
|
||||
fn.typ.n[0][exceptionEffects].safeLen > 0))
|
||||
|
|
|
|||
|
|
@ -104,17 +104,17 @@ proc getModuleDllPath(m: BModule, s: PSym): Rope =
|
|||
|
||||
import macros
|
||||
|
||||
proc cgFormatValue(result: var string; value: Rope): void =
|
||||
proc cgFormatValue(result: var string; value: Rope) =
|
||||
for str in leaves(value):
|
||||
result.add str
|
||||
|
||||
proc cgFormatValue(result: var string; value: string): void =
|
||||
proc cgFormatValue(result: var string; value: string) =
|
||||
result.add value
|
||||
|
||||
proc cgFormatValue(result: var string; value: BiggestInt): void =
|
||||
proc cgFormatValue(result: var string; value: BiggestInt) =
|
||||
result.addInt value
|
||||
|
||||
proc cgFormatValue(result: var string; value: Int128): void =
|
||||
proc cgFormatValue(result: var string; value: Int128) =
|
||||
result.addInt128 value
|
||||
|
||||
# TODO: please document
|
||||
|
|
|
|||
|
|
@ -693,14 +693,6 @@ proc genDef(c: var Con; n: PNode) =
|
|||
elif isAnalysableFieldAccess(n, c.owner):
|
||||
c.code.add Instr(n: n, kind: def, sym: nil)
|
||||
|
||||
proc canRaise(fn: PNode): bool =
|
||||
const magicsThatCanRaise = {
|
||||
mNone, mSlurp, mStaticExec, mParseExprToAst, mParseStmtToAst}
|
||||
if fn.kind == nkSym and fn.sym.magic notin magicsThatCanRaise:
|
||||
result = false
|
||||
else:
|
||||
result = true
|
||||
|
||||
proc genCall(c: var Con; n: PNode) =
|
||||
gen(c, n[0])
|
||||
var t = n[0].typ
|
||||
|
|
@ -715,7 +707,7 @@ proc genCall(c: var Con; n: PNode) =
|
|||
# optimizer.
|
||||
genDef(c, n[i])
|
||||
# every call can potentially raise:
|
||||
if c.inTryStmt > 0 and canRaise(n[0]):
|
||||
if c.inTryStmt > 0 and canRaiseConservative(n[0]):
|
||||
# we generate the instruction sequence:
|
||||
# fork lab1
|
||||
# goto exceptionHandler (except or finally)
|
||||
|
|
|
|||
|
|
@ -708,6 +708,8 @@ proc track(tracked: PEffects, n: PNode) =
|
|||
of nkCallKinds:
|
||||
# p's effects are ours too:
|
||||
var a = n[0]
|
||||
#if canRaise(a):
|
||||
# echo "this can raise ", tracked.config $ n.info
|
||||
let op = a.typ
|
||||
if n.typ != nil:
|
||||
if tracked.owner.kind != skMacro and n.typ.skipTypes(abstractVar).kind != tyOpenArray:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue