some fixes for generic first class iterators
This commit is contained in:
parent
a22c1f444f
commit
cd00679289
4 changed files with 12 additions and 11 deletions
|
|
@ -39,8 +39,7 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType
|
||||||
proc semStmt(c: PContext, n: PNode): PNode
|
proc semStmt(c: PContext, n: PNode): PNode
|
||||||
proc semParamList(c: PContext, n, genericParams: PNode, s: PSym)
|
proc semParamList(c: PContext, n, genericParams: PNode, s: PSym)
|
||||||
proc addParams(c: PContext, n: PNode, kind: TSymKind)
|
proc addParams(c: PContext, n: PNode, kind: TSymKind)
|
||||||
proc addResult(c: PContext, t: PType, info: TLineInfo, owner: TSymKind)
|
proc maybeAddResult(c: PContext, s: PSym, n: PNode)
|
||||||
proc addResultNode(c: PContext, n: PNode)
|
|
||||||
proc instGenericContainer(c: PContext, n: PNode, header: PType): PType
|
proc instGenericContainer(c: PContext, n: PNode, header: PType): PType
|
||||||
proc tryExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode
|
proc tryExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode
|
||||||
proc fixImmediateParams(n: PNode): PNode
|
proc fixImmediateParams(n: PNode): PNode
|
||||||
|
|
|
||||||
|
|
@ -93,9 +93,7 @@ proc instantiateBody(c: PContext, n: PNode, result: PSym) =
|
||||||
# add it here, so that recursive generic procs are possible:
|
# add it here, so that recursive generic procs are possible:
|
||||||
addDecl(c, result)
|
addDecl(c, result)
|
||||||
pushProcCon(c, result)
|
pushProcCon(c, result)
|
||||||
if result.kind in {skProc, skMethod, skConverter, skMacro}:
|
maybeAddResult(c, result, n)
|
||||||
addResult(c, result.typ.sons[0], n.info, result.kind)
|
|
||||||
addResultNode(c, n)
|
|
||||||
var b = n.sons[bodyPos]
|
var b = n.sons[bodyPos]
|
||||||
var symMap: TIdTable
|
var symMap: TIdTable
|
||||||
InitIdTable symMap
|
InitIdTable symMap
|
||||||
|
|
@ -168,6 +166,8 @@ proc generateInstance(c: PContext, fn: PSym, pt: TIdTable,
|
||||||
result.typ = newTypeS(tyProc, c)
|
result.typ = newTypeS(tyProc, c)
|
||||||
rawAddSon(result.typ, nil)
|
rawAddSon(result.typ, nil)
|
||||||
result.typ.callConv = fn.typ.callConv
|
result.typ.callConv = fn.typ.callConv
|
||||||
|
if result.kind == skIterator: result.typ.flags.incl(tfIterator)
|
||||||
|
|
||||||
var oldPrc = GenericCacheGet(c, entry)
|
var oldPrc = GenericCacheGet(c, entry)
|
||||||
if oldPrc == nil:
|
if oldPrc == nil:
|
||||||
c.generics.generics.add(entry)
|
c.generics.generics.add(entry)
|
||||||
|
|
|
||||||
|
|
@ -713,6 +713,12 @@ proc doDestructorStuff(c: PContext, s: PSym, n: PNode) =
|
||||||
useSym(t.sons[i].destructor),
|
useSym(t.sons[i].destructor),
|
||||||
n.sons[paramsPos][1][0]]))
|
n.sons[paramsPos][1][0]]))
|
||||||
|
|
||||||
|
proc maybeAddResult(c: PContext, s: PSym, n: PNode) =
|
||||||
|
if s.typ.sons[0] != nil and
|
||||||
|
(s.kind != skIterator or s.typ.callConv == ccClosure):
|
||||||
|
addResult(c, s.typ.sons[0], n.info, s.kind)
|
||||||
|
addResultNode(c, n)
|
||||||
|
|
||||||
proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
|
proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
|
||||||
validPragmas: TSpecialWords): PNode =
|
validPragmas: TSpecialWords): PNode =
|
||||||
result = semProcAnnotation(c, n)
|
result = semProcAnnotation(c, n)
|
||||||
|
|
@ -794,17 +800,13 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
|
||||||
if n.sons[genericParamsPos].kind == nkEmpty:
|
if n.sons[genericParamsPos].kind == nkEmpty:
|
||||||
ParamsTypeCheck(c, s.typ)
|
ParamsTypeCheck(c, s.typ)
|
||||||
pushProcCon(c, s)
|
pushProcCon(c, s)
|
||||||
if s.typ.sons[0] != nil and
|
maybeAddResult(c, s, n)
|
||||||
(kind != skIterator or s.typ.callConv == ccClosure):
|
|
||||||
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)
|
|
||||||
popProcCon(c)
|
popProcCon(c)
|
||||||
else:
|
else:
|
||||||
if s.typ.sons[0] != nil and kind != skIterator:
|
if s.typ.sons[0] != nil and kind != skIterator:
|
||||||
|
|
|
||||||
2
todo.txt
2
todo.txt
|
|
@ -3,7 +3,7 @@ version 0.9.2
|
||||||
|
|
||||||
- test&finish first class iterators:
|
- test&finish first class iterators:
|
||||||
* nested iterators
|
* nested iterators
|
||||||
* test generic iterators
|
* document them
|
||||||
- fix closure bug finally
|
- fix closure bug finally
|
||||||
- fix marshal bug
|
- fix marshal bug
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue