# HG changeset patch
# User unc0rr
# Date 1344526552 -14400
# Node ID 058fcb451b37340f7670d05ef679b651d6944239
# Parent  ff3a05e29ddd1eccf3220e7df905bc8fc0fd4cce
Check if 'for' cycle body is executed at least once

diff -r ff3a05e29ddd -r 058fcb451b37 gameServer/ServerCore.hs
--- a/gameServer/ServerCore.hs	Thu Aug 09 15:32:49 2012 +0400
+++ b/gameServer/ServerCore.hs	Thu Aug 09 19:35:52 2012 +0400
@@ -43,7 +43,7 @@
 
         ClientMessage (ci, cmd) -> do
             liftIO $ debugM "Clients" $ show ci ++ ": " ++ show cmd
-            
+
             removed <- gets removedClients
             unless (ci `Set.member` removed) $ do
                 modify (\s -> s{clientIndex = Just ci})
@@ -75,8 +75,6 @@
             (fromJust $ serverSocket si)
             (coreChan si)
 
-    return ()
-
     _ <- forkIO $ timerLoop 0 $ coreChan si
 
     startDBConnection si
diff -r ff3a05e29ddd -r 058fcb451b37 tools/pas2c.hs
--- a/tools/pas2c.hs	Thu Aug 09 15:32:49 2012 +0400
+++ b/tools/pas2c.hs	Thu Aug 09 19:35:52 2012 +0400
@@ -809,14 +809,15 @@
     e2 <- expr2C e2'
     let inc = if up then "inc" else "dec"
     let add = if up then "+ 1" else "- 1"
+    let iEnd = i <> text "__end__"
     ph <- phrase2C . appendPhrase (BuiltInFunctionCall [Reference $ SimpleReference i'] (SimpleReference (Identifier inc BTUnknown))) $ wrapPhrase p
     return . braces $
         i <+> text "=" <+> e1 <> semi
         $$
-        iType <+> i <> text "__end__" <+> text "=" <+> e2 <+> text add <> semi
+        iType <+> iEnd <+> text "=" <+> e2 <> semi
         $$ 
-        text "do" <+> ph <+>
-        text "while" <> parens (i <+> text "!=" <+> i <> text "__end__") <> semi
+        text "if" <+> (parens $ i <+> text "<=" <+> iEnd) <+> text "do" <+> ph <+>
+        text "while" <> parens (i <+> text "!=" <+> iEnd <+> text add) <> semi
     where
         appendPhrase p (Phrases ps) = Phrases $ ps ++ [p]
 phrase2C (RepeatCycle e' p') = do