exception tracking barely works; but disabled
This commit is contained in:
parent
2133fbfcce
commit
ce454fb835
4 changed files with 40 additions and 27 deletions
|
|
@ -41,7 +41,7 @@ proc getSysSym(name: string): PSym =
|
||||||
if result == nil: rawMessage(errSystemNeeds, name)
|
if result == nil: rawMessage(errSystemNeeds, name)
|
||||||
if result.kind == skStub: loadStub(result)
|
if result.kind == skStub: loadStub(result)
|
||||||
|
|
||||||
proc sysTypeFromName(name: string): PType =
|
proc sysTypeFromName*(name: string): PType =
|
||||||
result = getSysSym(name).typ
|
result = getSysSym(name).typ
|
||||||
|
|
||||||
proc getSysType(kind: TTypeKind): PType =
|
proc getSysType(kind: TTypeKind): PType =
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
import
|
import
|
||||||
ast, astalgo, msgs, semdata
|
ast, astalgo, msgs, renderer, magicsys, types, idents, trees, wordrecg
|
||||||
|
|
||||||
# Second semantic checking pass over the AST. Necessary because the old
|
# Second semantic checking pass over the AST. Necessary because the old
|
||||||
# way had some inherent problems. Performs:
|
# way had some inherent problems. Performs:
|
||||||
|
|
@ -44,13 +44,14 @@ import
|
||||||
# done: It essentially requires a built-in 'indexSplit' operation and dependent
|
# done: It essentially requires a built-in 'indexSplit' operation and dependent
|
||||||
# typing.
|
# typing.
|
||||||
|
|
||||||
proc sem2call(c: PContext, n: PNode): PNode =
|
when false:
|
||||||
assert n.kind in nkCallKinds
|
proc sem2call(c: PContext, n: PNode): PNode =
|
||||||
|
assert n.kind in nkCallKinds
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
proc sem2sym(c: PContext, n: PNode): PNode =
|
proc sem2sym(c: PContext, n: PNode): PNode =
|
||||||
assert n.kind == nkSym
|
assert n.kind == nkSym
|
||||||
|
|
||||||
|
|
||||||
# ------------------------ exception tracking -------------------------------
|
# ------------------------ exception tracking -------------------------------
|
||||||
|
|
@ -96,13 +97,16 @@ proc excType(n: PNode): PType =
|
||||||
else: n.sons[0].typ
|
else: n.sons[0].typ
|
||||||
result = skipTypes(t, skipPtrs)
|
result = skipTypes(t, skipPtrs)
|
||||||
|
|
||||||
proc mergeEffects(a: PEffects, b: PNode) =
|
proc addEffect(a: PEffects, e: PNode) =
|
||||||
|
assert e.kind == nkRaiseStmt
|
||||||
var aa = a.exc
|
var aa = a.exc
|
||||||
|
for i in a.bottom .. <aa.len:
|
||||||
|
if sameType(aa[i].excType, e.excType) and aa[i].info == e.info: return
|
||||||
|
throws(a, e)
|
||||||
|
|
||||||
|
proc mergeEffects(a: PEffects, b: PNode) =
|
||||||
for effect in items(b):
|
for effect in items(b):
|
||||||
block search
|
addEffect(a, effect)
|
||||||
for i in a.bottom .. <aa.len:
|
|
||||||
if sameType(aa[i].excType, b.excType): break search
|
|
||||||
throws(a, effect)
|
|
||||||
|
|
||||||
proc listEffects(a: PEffects) =
|
proc listEffects(a: PEffects) =
|
||||||
var aa = a.exc
|
var aa = a.exc
|
||||||
|
|
@ -111,7 +115,7 @@ proc listEffects(a: PEffects) =
|
||||||
|
|
||||||
proc catches(tracked: PEffects, e: PType) =
|
proc catches(tracked: PEffects, e: PType) =
|
||||||
let e = skipTypes(e, skipPtrs)
|
let e = skipTypes(e, skipPtrs)
|
||||||
let L = tracked.exc.len
|
var L = tracked.exc.len
|
||||||
var i = tracked.bottom
|
var i = tracked.bottom
|
||||||
while i < L:
|
while i < L:
|
||||||
# e supertype of r?
|
# e supertype of r?
|
||||||
|
|
@ -160,25 +164,29 @@ proc trackPragmaStmt(tracked: PEffects, n: PNode) =
|
||||||
proc track(tracked: PEffects, n: PNode) =
|
proc track(tracked: PEffects, n: PNode) =
|
||||||
case n.kind
|
case n.kind
|
||||||
of nkRaiseStmt: throws(tracked, n)
|
of nkRaiseStmt: throws(tracked, n)
|
||||||
of nkCallNode:
|
of nkCallKinds:
|
||||||
# p's effects are ours too:
|
# p's effects are ours too:
|
||||||
let op = n.sons[0].typ
|
let op = n.sons[0].typ
|
||||||
InternalAssert op.kind == tyProc and op.n.sons[0].kind == nkEffectList
|
if op != nil and op.kind == tyProc:
|
||||||
var effectList = op.n.sons[0]
|
InternalAssert op.kind == tyProc and op.n.sons[0].kind == nkEffectList
|
||||||
if effectList.len == 0:
|
var effectList = op.n.sons[0]
|
||||||
if isIndirectCall(n.sons[0]) or isForwardedProc(n.sons[0]):
|
if effectList.len == 0:
|
||||||
# assume the worst: raise of exception 'E_Base':
|
if isIndirectCall(n.sons[0]) or isForwardedProc(n.sons[0]):
|
||||||
var rs = newNodeI(nkRaiseStmt, n.info)
|
# assume the worst: raise of exception 'E_Base':
|
||||||
var re = newNodeIT(nkType, n.info, sysTypeFromName"E_Base")
|
var rs = newNodeI(nkRaiseStmt, n.info)
|
||||||
rs.add(re)
|
var re = newNodeIT(nkType, n.info, sysTypeFromName"E_Base")
|
||||||
effectList.add(rs)
|
rs.add(re)
|
||||||
mergeEffects(tracked, effectList)
|
addEffect(tracked, rs)
|
||||||
|
else:
|
||||||
|
effectList = effectList.sons[exceptionEffects]
|
||||||
|
mergeEffects(tracked, effectList)
|
||||||
of nkTryStmt:
|
of nkTryStmt:
|
||||||
trackTryStmt(tracked, n)
|
trackTryStmt(tracked, n)
|
||||||
return
|
return
|
||||||
of nkPragma:
|
of nkPragma:
|
||||||
trackPragmaStmt(tracked, n)
|
trackPragmaStmt(tracked, n)
|
||||||
return
|
return
|
||||||
|
of nkMacroDef, nkTemplateDef: return
|
||||||
else: nil
|
else: nil
|
||||||
for i in 0 .. <safeLen(n):
|
for i in 0 .. <safeLen(n):
|
||||||
track(tracked, n.sons[i])
|
track(tracked, n.sons[i])
|
||||||
|
|
@ -189,6 +197,7 @@ proc trackProc*(s: PSym, body: PNode) =
|
||||||
# effects already computed?
|
# effects already computed?
|
||||||
if effects.len == effectListLen: return
|
if effects.len == effectListLen: return
|
||||||
newSeq(effects.sons, effectListLen)
|
newSeq(effects.sons, effectListLen)
|
||||||
|
effects.sons[exceptionEffects] = newNodeI(nkArgList, body.info)
|
||||||
|
|
||||||
var t: TEffects
|
var t: TEffects
|
||||||
t.exc = effects.sons[exceptionEffects]
|
t.exc = effects.sons[exceptionEffects]
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
import
|
import
|
||||||
intsets, strutils, lists, options, ast, astalgo, trees, treetab, msgs, os,
|
intsets, strutils, lists, options, ast, astalgo, trees, treetab, msgs, os,
|
||||||
idents, renderer, types, passes, semfold, magicsys, cgmeth, rodread,
|
idents, renderer, types, passes, semfold, magicsys, cgmeth, rodread,
|
||||||
lambdalifting
|
lambdalifting, sempass2
|
||||||
|
|
||||||
const
|
const
|
||||||
genPrefix* = ":tmp" # prefix for generated names
|
genPrefix* = ":tmp" # prefix for generated names
|
||||||
|
|
@ -691,6 +691,7 @@ proc transformBody*(module: PSym, n: PNode, prc: PSym): PNode =
|
||||||
if nfTransf in n.flags or prc.kind in {skTemplate, skMacro}:
|
if nfTransf in n.flags or prc.kind in {skTemplate, skMacro}:
|
||||||
result = n
|
result = n
|
||||||
else:
|
else:
|
||||||
|
when false: trackProc(prc, n)
|
||||||
var c = openTransf(module, "")
|
var c = openTransf(module, "")
|
||||||
result = processTransf(c, n)
|
result = processTransf(c, n)
|
||||||
if prc.kind != skMacro:
|
if prc.kind != skMacro:
|
||||||
|
|
|
||||||
5
todo.txt
5
todo.txt
|
|
@ -1,6 +1,10 @@
|
||||||
version 0.9.2
|
version 0.9.2
|
||||||
=============
|
=============
|
||||||
|
|
||||||
|
- implement/generalize the effect system; checked exceptions
|
||||||
|
- overloading based on ASTs: 'constraint' should not be in PType but for the
|
||||||
|
parameter *symbol*
|
||||||
|
|
||||||
- document 'mixin' for generics and symbol lookup rules; special rule
|
- document 'mixin' for generics and symbol lookup rules; special rule
|
||||||
for ``[]=``
|
for ``[]=``
|
||||||
- implement the compiler as a service
|
- implement the compiler as a service
|
||||||
|
|
@ -135,7 +139,6 @@ Version 2 and beyond
|
||||||
troublesome, but maybe we can come up with a simple heuristic. (All procs
|
troublesome, but maybe we can come up with a simple heuristic. (All procs
|
||||||
that `new` shared memory are syncGC() candidates...)
|
that `new` shared memory are syncGC() candidates...)
|
||||||
|
|
||||||
- implement/generalize the effect system; checked exceptions
|
|
||||||
- const ptr/ref
|
- const ptr/ref
|
||||||
|
|
||||||
- language change: inheritance should only work with reference types, so that
|
- language change: inheritance should only work with reference types, so that
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue