exception tracking barely works; but disabled

This commit is contained in:
Araq 2012-10-31 02:31:03 +01:00
commit ce454fb835
4 changed files with 40 additions and 27 deletions

View file

@ -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 =

View file

@ -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,12 +44,13 @@ 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:
proc sem2call(c: PContext, n: PNode): PNode =
assert n.kind in nkCallKinds 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
@ -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 effect in items(b):
block search
for i in a.bottom .. <aa.len: for i in a.bottom .. <aa.len:
if sameType(aa[i].excType, b.excType): break search if sameType(aa[i].excType, e.excType) and aa[i].info == e.info: return
throws(a, effect) throws(a, e)
proc mergeEffects(a: PEffects, b: PNode) =
for effect in items(b):
addEffect(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,9 +164,10 @@ 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
if op != nil and op.kind == tyProc:
InternalAssert op.kind == tyProc and op.n.sons[0].kind == nkEffectList InternalAssert op.kind == tyProc and op.n.sons[0].kind == nkEffectList
var effectList = op.n.sons[0] var effectList = op.n.sons[0]
if effectList.len == 0: if effectList.len == 0:
@ -171,7 +176,9 @@ proc track(tracked: PEffects, n: PNode) =
var rs = newNodeI(nkRaiseStmt, n.info) var rs = newNodeI(nkRaiseStmt, n.info)
var re = newNodeIT(nkType, n.info, sysTypeFromName"E_Base") var re = newNodeIT(nkType, n.info, sysTypeFromName"E_Base")
rs.add(re) rs.add(re)
effectList.add(rs) addEffect(tracked, rs)
else:
effectList = effectList.sons[exceptionEffects]
mergeEffects(tracked, effectList) mergeEffects(tracked, effectList)
of nkTryStmt: of nkTryStmt:
trackTryStmt(tracked, n) trackTryStmt(tracked, n)
@ -179,6 +186,7 @@ proc track(tracked: PEffects, n: PNode) =
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]

View file

@ -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:

View file

@ -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