summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rwxr-xr-xcompiler/ccgstmts.nim7
-rwxr-xr-xcompiler/ecmasgen.nim7
-rwxr-xr-xcompiler/msgs.nim6
-rwxr-xr-xcompiler/parser.nim2
-rw-r--r--compiler/patterns.nim3
-rwxr-xr-xcompiler/semstmts.nim13
-rwxr-xr-xcompiler/transf.nim23
-rwxr-xr-xcontributors.txt1
-rwxr-xr-xtodo.txt8
9 files changed, 34 insertions, 36 deletions
diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim
index 5a604ef98..7a2eaec9c 100755
--- a/compiler/ccgstmts.nim
+++ b/compiler/ccgstmts.nim
@@ -853,9 +853,10 @@ proc genStmts(p: BProc, t: PNode) =
     # transf is overly aggressive with 'nkFastAsgn', so we work around here.
     # See tests/run/tcnstseq3 for an example that would fail otherwise.
     genAsgn(p, t, fastAsgn=p.prc != nil)
-  of nkDiscardStmt: 
-    genLineDir(p, t)
-    initLocExpr(p, t.sons[0], a)
+  of nkDiscardStmt:
+    if t.sons[0].kind != nkEmpty:
+      genLineDir(p, t)
+      initLocExpr(p, t.sons[0], a)
   of nkAsmStmt: genAsmStmt(p, t)
   of nkTryStmt: 
     if gCmd == cmdCompileToCpp: genTryStmtCpp(p, t)
diff --git a/compiler/ecmasgen.nim b/compiler/ecmasgen.nim
index 0d4035e66..cff4cc1dd 100755
--- a/compiler/ecmasgen.nim
+++ b/compiler/ecmasgen.nim
@@ -1458,9 +1458,10 @@ proc genStmt(p: var TProc, n: PNode, r: var TCompRes) =
   of nkAsgn: genAsgn(p, n, r)
   of nkFastAsgn: genFastAsgn(p, n, r)
   of nkDiscardStmt: 
-    genLineDir(p, n, r)
-    gen(p, n.sons[0], r)
-    app(r.res, ';' & tnl)
+    if n.sons[0].kind != nkEmpty:
+      genLineDir(p, n, r)
+      gen(p, n.sons[0], r)
+      app(r.res, ';' & tnl)
   of nkAsmStmt: genAsmStmt(p, n, r)
   of nkTryStmt: genTryStmt(p, n, r)
   of nkRaiseStmt: genRaiseStmt(p, n, r)
diff --git a/compiler/msgs.nim b/compiler/msgs.nim
index d0ddf7721..74267c059 100755
--- a/compiler/msgs.nim
+++ b/compiler/msgs.nim
@@ -102,7 +102,7 @@ type
     warnDeprecated, warnConfigDeprecated,
     warnSmallLshouldNotBeUsed, warnUnknownMagic, warnRedefinitionOfLabel, 
     warnUnknownSubstitutionX, warnLanguageXNotSupported, warnCommentXIgnored, 
-    warnXisPassedToProcVar, warnAnalysisLoophole,
+    warnNilStatement, warnAnalysisLoophole,
     warnDifferentHeaps, warnWriteToForeignHeap, warnImplicitClosure,
     warnEachIdentIsTuple, warnUser,
     hintSuccess, hintSuccessX, 
@@ -345,7 +345,7 @@ const
     warnUnknownSubstitutionX: "unknown substitution \'$1\' [UnknownSubstitutionX]", 
     warnLanguageXNotSupported: "language \'$1\' not supported [LanguageXNotSupported]", 
     warnCommentXIgnored: "comment \'$1\' ignored [CommentXIgnored]", 
-    warnXisPassedToProcVar: "\'$1\' is passed to a procvar; deprecated [XisPassedToProcVar]", 
+    warnNilStatement: "'nil' statement is deprecated; use an empty 'discard' statement instead [NilStmt]", 
     warnAnalysisLoophole: "thread analysis incomplete due to unknown call '$1' [AnalysisLoophole]",
     warnDifferentHeaps: "possible inconsistency of thread local heaps [DifferentHeaps]",
     warnWriteToForeignHeap: "write to foreign heap [WriteToForeignHeap]",
@@ -375,7 +375,7 @@ const
     "Deprecated", "ConfigDeprecated",
     "SmallLshouldNotBeUsed", "UnknownMagic", 
     "RedefinitionOfLabel", "UnknownSubstitutionX", "LanguageXNotSupported", 
-    "CommentXIgnored", "XisPassedToProcVar",
+    "CommentXIgnored", "NilStmt",
     "AnalysisLoophole", "DifferentHeaps", "WriteToForeignHeap",
     "ImplicitClosure", "EachIdentIsTuple", "User"]
 
diff --git a/compiler/parser.nim b/compiler/parser.nim
index daa6f9b7f..b359c6e3d 100755
--- a/compiler/parser.nim
+++ b/compiler/parser.nim
@@ -1487,7 +1487,7 @@ proc simpleStmt(p: var TParser): PNode =
   of tkReturn: result = parseReturnOrRaise(p, nkReturnStmt)
   of tkRaise: result = parseReturnOrRaise(p, nkRaiseStmt)
   of tkYield: result = parseYieldOrDiscard(p, nkYieldStmt)
-  of tkDiscard: result = parseYieldOrDiscard(p, nkDiscardStmt)
+  of tkDiscard: result = parseReturnOrRaise(p, nkDiscardStmt)
   of tkBreak: result = parseBreakOrContinue(p, nkBreakStmt)
   of tkContinue: result = parseBreakOrContinue(p, nkContinueStmt)
   of tkCurlyDotLe: result = parseStmtPragma(p)
diff --git a/compiler/patterns.nim b/compiler/patterns.nim
index 7f3bf1556..d8c7e26d9 100644
--- a/compiler/patterns.nim
+++ b/compiler/patterns.nim
@@ -121,9 +121,6 @@ proc matchNested(c: PPatternContext, p, n: PNode, rpn: bool): bool =
       add(arglist, n)
     else:
       result = false
-      debug p.sons[2].sym.typ
-      debug n.typ
-      echo "type check failed!"
     
   if n.kind notin nkCallKinds: return false
   if matches(c, p.sons[1], n.sons[0]):
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim
index 4b79291e6..b62f77888 100755
--- a/compiler/semstmts.nim
+++ b/compiler/semstmts.nim
@@ -62,8 +62,9 @@ proc semIf(c: PContext, n: PNode): PNode =
 proc semDiscard(c: PContext, n: PNode): PNode = 
   result = n
   checkSonsLen(n, 1)
-  n.sons[0] = semExprWithType(c, n.sons[0])
-  if n.sons[0].typ == nil: localError(n.info, errInvalidDiscard)
+  if n.sons[0].kind != nkEmpty:
+    n.sons[0] = semExprWithType(c, n.sons[0])
+    if n.sons[0].typ == nil: localError(n.info, errInvalidDiscard)
   
 proc semBreakOrContinue(c: PContext, n: PNode): PNode =
   result = n
@@ -935,7 +936,8 @@ proc semStaticStmt(c: PContext, n: PNode): PNode =
   if result.isNil:
     LocalError(n.info, errCannotInterpretNodeX, renderTree(n))
   elif result.kind == nkEmpty:
-    result = newNodeI(nkNilLit, n.info)
+    result = newNodeI(nkDiscardStmt, n.info, 1)
+    result.sons[0] = emptyNode
 
 # special marker values that indicates that we are
 # 1) AnalyzingDestructor: currenlty analyzing the type for destructor 
@@ -1132,7 +1134,10 @@ proc SemStmt(c: PContext, n: PNode): PNode =
   of nkAsgn: result = semAsgn(c, n)
   of nkCall, nkInfix, nkPrefix, nkPostfix, nkCommand, nkMacroStmt, nkCallStrLit: 
     result = semCommand(c, n)
-  of nkEmpty, nkCommentStmt, nkNilLit: nil
+  of nkEmpty, nkCommentStmt: nil
+  of nkNilLit:
+    # XXX too much work and fixing would break bootstrapping:
+    #Message(n.info, warnNilStatement)
   of nkBlockStmt: result = semBlock(c, n)
   of nkStmtList: 
     var length = sonsLen(n)
diff --git a/compiler/transf.nim b/compiler/transf.nim
index fd356442f..d5ffbfd65 100755
--- a/compiler/transf.nim
+++ b/compiler/transf.nim
@@ -185,16 +185,6 @@ proc transformConstSection(c: PTransf, v: PNode): PTransNode =
       else:
         result[i] = PTransNode(it)
 
-proc trivialBody(s: PSym): PNode =
-  # a routine's body is trivially inlinable if marked as 'inline' and its
-  # body consists of only 1 statement. It is important that we perform this
-  # optimization here as 'distinct strings' may cause string copying otherwise:
-  # proc xml(s: string): TXmlString = return xmlstring(s)
-  # We have to generate a ``nkLineTracking`` node though to not lose
-  # debug information:
-  # XXX to implement
-  nil
-
 proc hasContinue(n: PNode): bool = 
   case n.kind
   of nkEmpty..nkNilLit, nkForStmt, nkParForStmt, nkWhileStmt: nil
@@ -627,11 +617,14 @@ proc transform(c: PTransf, n: PNode): PTransNode =
     result = transformAddrDeref(c, n, nkAddr, nkHiddenAddr)
   of nkHiddenStdConv, nkHiddenSubConv, nkConv: 
     result = transformConv(c, n)
-  of nkDiscardStmt: 
-    result = transformSons(c, n)
-    if isConstExpr(PNode(result).sons[0]): 
-      # ensure that e.g. discard "some comment" gets optimized away completely:
-      result = PTransNode(newNode(nkCommentStmt))
+  of nkDiscardStmt:
+    result = PTransNode(n)
+    if n.sons[0].kind != nkEmpty:
+      result = transformSons(c, n)
+      if isConstExpr(PNode(result).sons[0]):
+        # ensure that e.g. discard "some comment" gets optimized away
+        # completely:
+        result = PTransNode(newNode(nkCommentStmt))
   of nkCommentStmt, nkTemplateDef: 
     return n.ptransNode
   of nkConstSection:
diff --git a/contributors.txt b/contributors.txt
index e51914e26..23fcd14e0 100755
--- a/contributors.txt
+++ b/contributors.txt
@@ -1,5 +1,6 @@
 Comex
 Eric Doughty-Papassideris
+Simon Hafner
 Keita Haga
 Philippe Lhoste
 Zahary Karadjov
diff --git a/todo.txt b/todo.txt
index c640dd435..e5efa1f87 100755
--- a/todo.txt
+++ b/todo.txt
@@ -6,9 +6,6 @@ version 0.9.0
 
 - make 'bind' default for templates and introduce 'mixin'
 
-- implement "closure tuple consists of a single 'ref'" optimization
-- implement for loop transformation for first class iterators
-
 - implicit deref for parameter matching
 - optimize genericAssign in the code generator
 - the lookup rules for generics really are too permissive; global scope only
@@ -43,6 +40,8 @@ version 0.9.XX
     echo a
     echo b)
 
+- implement "closure tuple consists of a single 'ref'" optimization
+- implement for loop transformation for first class iterators
 - JS gen:
   - fix exception handling
 - object branch transitions can't work with the current 'reset'; add a 'reset'
@@ -60,7 +59,8 @@ version 0.9.XX
   a full blown statement; a ``try`` expression might be a good idea to make
   error handling more light-weight
 - ``=`` should be overloadable; requires specialization for ``=``
-- ``hoist`` pragma for loop hoisting
+- ``hoist`` pragma for loop hoisting: can be easily done with 
+  AST overloading + global
 - document destructors; don't work yet when used as expression
 - make use of ``tyIter`` to fix the implicit items/pairs issue
 - better support for macros that rewrite procs