diff options
author | Araq <rumpf_a@web.de> | 2012-12-15 23:39:27 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2012-12-15 23:39:27 +0100 |
commit | cd006792891f2d8aafce73e7a3f29b6254410d59 (patch) | |
tree | f30ec4777fa259100dcf48d95bd56ee6536de228 /compiler | |
parent | a22c1f444fa76cc06fee1ae31c79986e9c3b459f (diff) | |
download | Nim-cd006792891f2d8aafce73e7a3f29b6254410d59.tar.gz |
some fixes for generic first class iterators
Diffstat (limited to 'compiler')
-rwxr-xr-x | compiler/sem.nim | 3 | ||||
-rwxr-xr-x | compiler/seminst.nim | 6 | ||||
-rwxr-xr-x | compiler/semstmts.nim | 12 |
3 files changed, 11 insertions, 10 deletions
diff --git a/compiler/sem.nim b/compiler/sem.nim index c8340a139..c70cbf61e 100755 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -39,8 +39,7 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType proc semStmt(c: PContext, n: PNode): PNode proc semParamList(c: PContext, n, genericParams: PNode, s: PSym) proc addParams(c: PContext, n: PNode, kind: TSymKind) -proc addResult(c: PContext, t: PType, info: TLineInfo, owner: TSymKind) -proc addResultNode(c: PContext, n: PNode) +proc maybeAddResult(c: PContext, s: PSym, n: PNode) proc instGenericContainer(c: PContext, n: PNode, header: PType): PType proc tryExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode proc fixImmediateParams(n: PNode): PNode diff --git a/compiler/seminst.nim b/compiler/seminst.nim index 8e164531a..0a1a17f72 100755 --- a/compiler/seminst.nim +++ b/compiler/seminst.nim @@ -93,9 +93,7 @@ proc instantiateBody(c: PContext, n: PNode, result: PSym) = # add it here, so that recursive generic procs are possible: addDecl(c, result) pushProcCon(c, result) - if result.kind in {skProc, skMethod, skConverter, skMacro}: - addResult(c, result.typ.sons[0], n.info, result.kind) - addResultNode(c, n) + maybeAddResult(c, result, n) var b = n.sons[bodyPos] var symMap: TIdTable InitIdTable symMap @@ -168,6 +166,8 @@ proc generateInstance(c: PContext, fn: PSym, pt: TIdTable, result.typ = newTypeS(tyProc, c) rawAddSon(result.typ, nil) result.typ.callConv = fn.typ.callConv + if result.kind == skIterator: result.typ.flags.incl(tfIterator) + var oldPrc = GenericCacheGet(c, entry) if oldPrc == nil: c.generics.generics.add(entry) diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 68d485f48..712a6d2af 100755 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -713,6 +713,12 @@ proc doDestructorStuff(c: PContext, s: PSym, n: PNode) = useSym(t.sons[i].destructor), 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, validPragmas: TSpecialWords): PNode = result = semProcAnnotation(c, n) @@ -794,17 +800,13 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind, if n.sons[genericParamsPos].kind == nkEmpty: ParamsTypeCheck(c, s.typ) pushProcCon(c, s) - if s.typ.sons[0] != nil and - (kind != skIterator or s.typ.callConv == ccClosure): - addResult(c, s.typ.sons[0], n.info, kind) - addResultNode(c, n) + maybeAddResult(c, s, n) if sfImportc notin s.flags: # no semantic checking for importc: let semBody = hloBody(c, semProcBody(c, n.sons[bodyPos])) # unfortunately we cannot skip this step when in 'system.compiles' # context as it may even be evaluated in 'system.compiles': n.sons[bodyPos] = transformBody(c.module, semBody, s) - #if s.typ.sons[0] != nil and kind != skIterator: addResultNode(c, n) popProcCon(c) else: if s.typ.sons[0] != nil and kind != skIterator: |