Parse and store javadoc-style docstrings at toplevel
[kaos.git] / src / Kaos / Emit.hs
blobbd52b71aba67637e6799c766336647f27a9e96f1
1 {-
2 Kaos - A compiler for creatures scripts
3 Copyright (C) 2005-2008 Bryan Donlan
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 module Kaos.Emit (emitCaos, emitConst) where
20 import Kaos.CAOS
21 import Kaos.AST
22 import Data.Char
24 --- XXX unflattenable
25 emitCaos :: [CAOSLine CAOSRegister] -> String
26 emitCaos c = unlines $ map emitLine c
28 emitLine :: CAOSLine CAOSRegister -> String
29 emitLine (CAOSLine l) = unwords $ map emitToken l
30 emitLine (CAOSLoop l) = unlines $ map emitLine l
32 emitToken :: CAOSToken CAOSRegister -> String
33 emitToken (CAOSLiteral s) = map toUpper s
34 emitToken r@(CAOSRegister (CAOSReg i)) =
35 case show i of
36 s@[_] -> "VA0" ++ s
37 s@[_,_] -> "VA" ++ s
38 _ -> error $ "ICE: Register out of range (bug bd_): " ++ show r
39 emitToken (CAOSConst cv) = emitConst cv
41 emitConst :: ConstValue -> String
42 emitConst (CInteger i) = show i
43 emitConst (CString s) = s
44 emitConst (CFloat f) = show f