summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2012-11-17 01:25:32 +0100
committerAraq <rumpf_a@web.de>2012-11-17 01:25:32 +0100
commit7f6633a06feeac8d6bd1eb1e6d8e841591326618 (patch)
tree8476159a24003dfae000de06cecb66b35c32412e /compiler
parent7a2c11d3cfef74eaf55ab27adbb1748a04d7904f (diff)
downloadNim-7f6633a06feeac8d6bd1eb1e6d8e841591326618.tar.gz
added system.finished for first class iterators
Diffstat (limited to 'compiler')
-rwxr-xr-xcompiler/ast.nim2
-rw-r--r--compiler/lambdalifting.nim7
-rwxr-xr-xcompiler/parser.nim2
-rwxr-xr-xcompiler/semexprs.nim2
-rwxr-xr-xcompiler/semstmts.nim2
5 files changed, 5 insertions, 10 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim
index 46cb792b5..cdca68c20 100755
--- a/compiler/ast.nim
+++ b/compiler/ast.nim
@@ -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?
diff --git a/compiler/lambdalifting.nim b/compiler/lambdalifting.nim
index dc51d2d22..c0098fb17 100644
--- a/compiler/lambdalifting.nim
+++ b/compiler/lambdalifting.nim
@@ -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)
diff --git a/compiler/parser.nim b/compiler/parser.nim
index 347c12b13..680279bcf 100755
--- a/compiler/parser.nim
+++ b/compiler/parser.nim
@@ -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)
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index a047fed20..910100e92 100755
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -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: 
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim
index 18588fb49..b0cef2df7 100755
--- a/compiler/semstmts.nim
+++ b/compiler/semstmts.nim
@@ -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