added system.finished for first class iterators
This commit is contained in:
parent
7a2c11d3cf
commit
7f6633a06f
8 changed files with 55 additions and 12 deletions
|
|
@ -344,7 +344,7 @@ type
|
|||
nfSem # node has been checked for semantics
|
||||
|
||||
TNodeFlags* = set[TNodeFlag]
|
||||
TTypeFlag* = enum # keep below 15 for efficiency reasons (now: 14)
|
||||
TTypeFlag* = enum # keep below 17 for efficiency reasons (now: 16)
|
||||
tfVarargs, # procedure has C styled varargs
|
||||
tfNoSideEffect, # procedure type does not allow side effects
|
||||
tfFinal, # is the object final?
|
||||
|
|
|
|||
|
|
@ -692,13 +692,6 @@ proc liftIterator*(iter: PSym, body: PNode): PNode =
|
|||
stateAsgnStmt.add(newIntTypeNode(nkIntLit, -1, getSysType(tyInt)))
|
||||
result.add(stateAsgnStmt)
|
||||
|
||||
# TODO:
|
||||
# - nested iterators
|
||||
# - arglist as a type
|
||||
# - tyIterator everywhere
|
||||
# - 'finished' builtin
|
||||
# - 'start' builtin (XXX copy Lua's terminology?)
|
||||
|
||||
proc liftIterSym*(n: PNode): PNode =
|
||||
# transforms (iter) to (let env = newClosure[iter](); (iter, env))
|
||||
result = newNodeIT(nkStmtListExpr, n.info, n.typ)
|
||||
|
|
|
|||
|
|
@ -1473,7 +1473,7 @@ proc simpleStmt(p: var TParser): PNode =
|
|||
case p.tok.tokType
|
||||
of tkReturn: result = parseReturnOrRaise(p, nkReturnStmt)
|
||||
of tkRaise: result = parseReturnOrRaise(p, nkRaiseStmt)
|
||||
of tkYield: result = parseYieldOrDiscard(p, nkYieldStmt)
|
||||
of tkYield: result = parseReturnOrRaise(p, nkYieldStmt)
|
||||
of tkDiscard: result = parseReturnOrRaise(p, nkDiscardStmt)
|
||||
of tkBreak: result = parseBreakOrContinue(p, nkBreakStmt)
|
||||
of tkContinue: result = parseBreakOrContinue(p, nkContinueStmt)
|
||||
|
|
|
|||
|
|
@ -1173,6 +1173,8 @@ proc SemYield(c: PContext, n: PNode): PNode =
|
|||
SemYieldVarResult(c, n, restype)
|
||||
else:
|
||||
localError(n.info, errCannotReturnExpr)
|
||||
elif c.p.owner.typ.sons[0] != nil:
|
||||
localError(n.info, errGenerated, "yield statement must yield a value")
|
||||
|
||||
proc lookUpForDefined(c: PContext, i: PIdent, onlyCurrentScope: bool): PSym =
|
||||
if onlyCurrentScope:
|
||||
|
|
|
|||
|
|
@ -818,7 +818,7 @@ proc semIterator(c: PContext, n: PNode): PNode =
|
|||
result = semProcAux(c, n, skIterator, iteratorPragmas)
|
||||
var s = result.sons[namePos].sym
|
||||
var t = s.typ
|
||||
if t.sons[0] == nil:
|
||||
if t.sons[0] == nil and s.typ.callConv != ccClosure:
|
||||
LocalError(n.info, errXNeedsReturnType, "iterator")
|
||||
# iterators are either 'inline' or 'closure'; for backwards compatibility,
|
||||
# we require first class iterators to be marked with 'closure' explicitly
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue