# HG changeset patch # User unc0rr # Date 1335296019 -14400 # Node ID d2405a6a86f59e4850f931be94d96b1380bfd952 # Parent 93bdd3d251fef95c0766d5b8bac2fc8ab491efb7 uCommands compiles diff -r 93bdd3d251fe -r d2405a6a86f5 hedgewars/pas2c.h --- a/hedgewars/pas2c.h Tue Apr 24 22:27:56 2012 +0400 +++ b/hedgewars/pas2c.h Tue Apr 24 23:33:39 2012 +0400 @@ -56,6 +56,7 @@ string255 _strconcat(string255 a, string255 b); string255 _strappend(string255 s, char c); string255 _strprepend(char c, string255 s); +bool _strcompare(string255 a, string255 b); char * _pchar(string255 s); int Length(string255 a); diff -r 93bdd3d251fe -r d2405a6a86f5 hedgewars/uCommands.pas --- a/hedgewars/uCommands.pas Tue Apr 24 22:27:56 2012 +0400 +++ b/hedgewars/uCommands.pas Tue Apr 24 23:33:39 2012 +0400 @@ -33,7 +33,7 @@ procedure StopMessages(Message: Longword); implementation -uses Types, uConsts, uVariables, uConsole, uUtils, uDebug; +uses uConsts, uVariables, uConsole, uUtils, uDebug; type PVariable = ^TVariable; TVariable = record diff -r 93bdd3d251fe -r d2405a6a86f5 tools/pas2c.hs --- a/tools/pas2c.hs Tue Apr 24 22:27:56 2012 +0400 +++ b/tools/pas2c.hs Tue Apr 24 23:33:39 2012 +0400 @@ -49,6 +49,8 @@ strs <- gets stringConsts let a = find ((==) str . snd) strs if isJust a then + do + modify (\s -> s{lastType = BTString}) return . text . fst . fromJust $ a else do @@ -463,7 +465,7 @@ return r where type2C' VoidType = return (text "void" <+>) - type2C' (String l) = return (text ("string" ++ show l) <+>) + type2C' (String l) = return (text "string255" <+>)--return (text ("string" ++ show l) <+>) type2C' (PointerTo (SimpleType i)) = liftM (\i a -> text "struct __" <> i <+> text "*" <+> a) $ id2C IODeferred i type2C' (PointerTo t) = liftM (\t a -> t (parens $ text "*" <> a)) $ type2C t type2C' (RecordType tvs union) = do @@ -510,10 +512,11 @@ ps <- mapM phrase2C p return $ text "{" $+$ (nest 4 . vcat $ ps) $+$ text "}" phrase2C (ProcCall f@(FunCall {}) []) = liftM (<> semi) $ ref2C f -phrase2C (ProcCall ref params) = do +phrase2C (ProcCall ref []) = liftM (<> semi) $ ref2CF ref +phrase2C (ProcCall ref params) = error $ "ProcCall"{-do r <- ref2C ref ps <- mapM expr2C params - return $ r <> parens (hsep . punctuate (char ',') $ ps) <> semi + return $ r <> parens (hsep . punctuate (char ',') $ ps) <> semi -} phrase2C (IfThenElse (expr) phrase1 mphrase2) = do e <- expr2C expr p1 <- (phrase2C . wrapPhrase) phrase1 @@ -524,10 +527,12 @@ elsePart | isNothing mphrase2 = return $ empty | otherwise = liftM (text "else" $$) $ (phrase2C . wrapPhrase) (fromJust mphrase2) phrase2C (Assignment ref expr) = do - r <- ref2C ref - e <- expr2C expr - return $ - r <> text " = " <> e <> semi + r <- ref2C ref + t <- gets lastType + e <- case (t, expr) of + (BTFunction _, (Reference r')) -> ref2C r' + _ -> expr2C expr + return $ r <+> text "=" <+> e <> semi phrase2C (WhileCycle expr phrase) = do e <- expr2C expr p <- phrase2C $ wrapPhrase phrase @@ -599,7 +604,12 @@ ("!=", BTString, _) -> expr2C $ BuiltInFunCall [expr1, expr2] (SimpleReference $ Identifier "_strncompare" (BTFunction BTBool)) ("&", BTBool, _) -> return $ parens e1 <+> text "&&" <+> parens e2 ("|", BTBool, _) -> return $ parens e1 <+> text "||" <+> parens e2 - (o, _, _) -> return $ parens e1 <+> text o <+> parens e2 + (o, _, _) | o `elem` boolOps -> do + modify(\s -> s{lastType = BTBool}) + return $ parens e1 <+> text o <+> parens e2 + | otherwise -> return $ parens e1 <+> text o <+> parens e2 + where + boolOps = ["==", "!=", "<", ">", "<=", ">="] expr2C (NumberLiteral s) = return $ text s expr2C (FloatLiteral s) = return $ text s expr2C (HexNumber s) = return $ text "0x" <> (text . map toLower $ s)