tools/pas2c/Pas2C.hs
changeset 10688 9459c45b5190
parent 10497 c7c50f165946
child 10747 07ade56c3b4a
equal deleted inserted replaced
10687:2e921409b5b1 10688:9459c45b5190
   907 phrase2C (ForCycle i' e1' e2' p up) = do
   907 phrase2C (ForCycle i' e1' e2' p up) = do
   908     i <- id2C IOLookup i'
   908     i <- id2C IOLookup i'
   909     iType <- gets lastIdTypeDecl
   909     iType <- gets lastIdTypeDecl
   910     e1 <- expr2C e1'
   910     e1 <- expr2C e1'
   911     e2 <- expr2C e2'
   911     e2 <- expr2C e2'
   912     let inc = if up then "inc" else "dec"
       
   913     let add = if up then "+ 1" else "- 1"
       
   914     let iEnd = i <> text "__end__"
   912     let iEnd = i <> text "__end__"
   915     ph <- phrase2C . appendPhrase (BuiltInFunctionCall [Reference $ SimpleReference i'] (SimpleReference (Identifier inc BTUnknown))) $ wrapPhrase p
   913     ph <- phrase2C $ wrapPhrase p
   916     return . braces $
   914     return . braces $
   917         i <+> text "=" <+> e1 <> semi
   915         i <+> text "=" <+> e1 <> semi
   918         $$
   916         $$
   919         iType <+> iEnd <+> text "=" <+> e2 <> semi
   917         iType <+> iEnd <+> text "=" <+> e2 <> semi
   920         $$
   918         $$
   921         text "if" <+> (parens $ i <+> text (if up then "<=" else ">=") <+> iEnd) <+> text "do" <+> ph <+>
   919         text "if" <+> (parens $ i <+> text (if up then "<=" else ">=") <+> iEnd) <+> text "do" <+> ph <+>
   922         text "while" <> parens (i <+> text "!=" <+> iEnd <+> text add) <> semi
   920         text "while" <> parens (i <> text (if up then "++" else "--") <+> text "!=" <+> iEnd) <> semi
   923     where
   921     where
   924         appendPhrase p (Phrases ps) = Phrases $ ps ++ [p]
   922         appendPhrase p (Phrases ps) = Phrases $ ps ++ [p]
   925         appendPhrase _ _ = error "illegal appendPhrase call"
   923         appendPhrase _ _ = error "illegal appendPhrase call"
   926 phrase2C (RepeatCycle e' p') = do
   924 phrase2C (RepeatCycle e' p') = do
   927     e <- expr2C e'
   925     e <- expr2C e'