Check if 'for' cycle body is executed at least once
authorunc0rr
Thu, 09 Aug 2012 19:35:52 +0400
changeset 7529 058fcb451b37
parent 7526 ff3a05e29ddd
child 7532 d8bdd4ec1c34
child 7536 e1b80da69991
Check if 'for' cycle body is executed at least once
gameServer/ServerCore.hs
tools/pas2c.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
--- 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