bugfix: 'result' cannot be captured in a closure
This commit is contained in:
parent
ea4435544e
commit
603dc36008
4 changed files with 18 additions and 20 deletions
|
|
@ -538,9 +538,6 @@ proc liftLambdas*(fn: PSym, body: PNode): PNode =
|
||||||
if body.kind == nkEmpty or gCmd == cmdCompileToEcmaScript:
|
if body.kind == nkEmpty or gCmd == cmdCompileToEcmaScript:
|
||||||
# ignore forward declaration:
|
# ignore forward declaration:
|
||||||
result = body
|
result = body
|
||||||
elif not containsNode(body, procDefs) and false:
|
|
||||||
# fast path: no inner procs, so no closure needed:
|
|
||||||
result = body
|
|
||||||
else:
|
else:
|
||||||
var o = newOuterContext(fn)
|
var o = newOuterContext(fn)
|
||||||
let ex = closureCreationPoint(body)
|
let ex = closureCreationPoint(body)
|
||||||
|
|
@ -552,6 +549,10 @@ proc liftLambdas*(fn: PSym, body: PNode): PNode =
|
||||||
InternalError(params.info, "liftLambdas: strange params")
|
InternalError(params.info, "liftLambdas: strange params")
|
||||||
let param = params.sons[i].sym
|
let param = params.sons[i].sym
|
||||||
IdTablePut(o.localsToEnv, param, o.currentEnv)
|
IdTablePut(o.localsToEnv, param, o.currentEnv)
|
||||||
|
# put the 'result' into the environment so it can be captured:
|
||||||
|
let ast = fn.ast
|
||||||
|
if resultPos < sonsLen(ast) and ast.sons[resultPos].kind == nkSym:
|
||||||
|
IdTablePut(o.localsToEnv, ast.sons[resultPos].sym, o.currentEnv)
|
||||||
searchForInnerProcs(o, body)
|
searchForInnerProcs(o, body)
|
||||||
discard transformOuterProc(o, body)
|
discard transformOuterProc(o, body)
|
||||||
result = ex
|
result = ex
|
||||||
|
|
|
||||||
|
|
@ -661,7 +661,7 @@ proc semLambda(c: PContext, n: PNode): PNode =
|
||||||
LocalError(n.sons[bodyPos].info, errImplOfXNotAllowed, s.name.s)
|
LocalError(n.sons[bodyPos].info, errImplOfXNotAllowed, s.name.s)
|
||||||
pushProcCon(c, s)
|
pushProcCon(c, s)
|
||||||
addResult(c, s.typ.sons[0], n.info, skProc)
|
addResult(c, s.typ.sons[0], n.info, skProc)
|
||||||
let semBody = hloBody(c, semStmtScope(c, n.sons[bodyPos]))
|
let semBody = hloBody(c, semProcBody(c, n.sons[bodyPos]))
|
||||||
n.sons[bodyPos] = transformBody(c.module, semBody, s)
|
n.sons[bodyPos] = transformBody(c.module, semBody, s)
|
||||||
addResultNode(c, n)
|
addResultNode(c, n)
|
||||||
popProcCon(c)
|
popProcCon(c)
|
||||||
|
|
@ -765,13 +765,14 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
|
||||||
pushProcCon(c, s)
|
pushProcCon(c, s)
|
||||||
if s.typ.sons[0] != nil and kind != skIterator:
|
if s.typ.sons[0] != nil and kind != skIterator:
|
||||||
addResult(c, s.typ.sons[0], n.info, kind)
|
addResult(c, s.typ.sons[0], n.info, kind)
|
||||||
|
addResultNode(c, n)
|
||||||
if sfImportc notin s.flags:
|
if sfImportc notin s.flags:
|
||||||
# no semantic checking for importc:
|
# no semantic checking for importc:
|
||||||
let semBody = hloBody(c, semProcBody(c, n.sons[bodyPos]))
|
let semBody = hloBody(c, semProcBody(c, n.sons[bodyPos]))
|
||||||
# unfortunately we cannot skip this step when in 'system.compiles'
|
# unfortunately we cannot skip this step when in 'system.compiles'
|
||||||
# context as it may even be evaluated in 'system.compiles':
|
# context as it may even be evaluated in 'system.compiles':
|
||||||
n.sons[bodyPos] = transformBody(c.module, semBody, s)
|
n.sons[bodyPos] = transformBody(c.module, semBody, s)
|
||||||
if s.typ.sons[0] != nil and kind != skIterator: addResultNode(c, n)
|
#if s.typ.sons[0] != nil and kind != skIterator: addResultNode(c, n)
|
||||||
popProcCon(c)
|
popProcCon(c)
|
||||||
else:
|
else:
|
||||||
if s.typ.sons[0] != nil and kind != skIterator:
|
if s.typ.sons[0] != nil and kind != skIterator:
|
||||||
|
|
|
||||||
|
|
@ -426,21 +426,23 @@ proc handleIrc(irc: var TAsyncIRC, event: TIRCEvent, state: PState) =
|
||||||
nil # TODO: ?
|
nil # TODO: ?
|
||||||
|
|
||||||
proc open(port: TPort = TPort(5123)): PState =
|
proc open(port: TPort = TPort(5123)): PState =
|
||||||
new(result)
|
var res: PState
|
||||||
result.dispatcher = newDispatcher()
|
new(res)
|
||||||
|
res.dispatcher = newDispatcher()
|
||||||
|
|
||||||
result.hubPort = port
|
res.hubPort = port
|
||||||
result.hubConnect()
|
res.hubConnect()
|
||||||
let hirc =
|
let hirc =
|
||||||
proc (a: var TAsyncIRC, ev: TIRCEvent) =
|
proc (a: var TAsyncIRC, ev: TIRCEvent) =
|
||||||
handleIrc(a, ev, result)
|
handleIrc(a, ev, res)
|
||||||
# Connect to the irc server.
|
# Connect to the irc server.
|
||||||
result.ircClient = AsyncIrc(ircServer, nick = botNickname, user = botNickname,
|
res.ircClient = AsyncIrc(ircServer, nick = botNickname, user = botNickname,
|
||||||
joinChans = joinChans, ircEvent = hirc)
|
joinChans = joinChans, ircEvent = hirc)
|
||||||
result.ircClient.connect()
|
res.ircClient.connect()
|
||||||
result.dispatcher.register(result.ircClient)
|
res.dispatcher.register(res.ircClient)
|
||||||
|
|
||||||
result.dbConnected = false
|
res.dbConnected = false
|
||||||
|
result = res
|
||||||
|
|
||||||
var state = tircbot.open() # Connect to the website and the IRC server.
|
var state = tircbot.open() # Connect to the website and the IRC server.
|
||||||
|
|
||||||
|
|
|
||||||
6
todo.txt
6
todo.txt
|
|
@ -1,9 +1,3 @@
|
||||||
version 0.9.0
|
|
||||||
=============
|
|
||||||
|
|
||||||
- fix tirc capture of 'result'
|
|
||||||
|
|
||||||
|
|
||||||
version 0.9.2
|
version 0.9.2
|
||||||
=============
|
=============
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue