on 79e6bf7 help sign in
Idris-dev/src/IRTS/CodegenC.hs
34 lines 845 B history raw
1module IRTS.CodegenC where
3import IRTS.Bytecode
4import IRTS.Lang
5import Core.TT
6import Paths_idris
8import Data.Char
10cname :: Name -> String
11cname n = "_idris_" ++ concatMap cchar (show n)
12 where cchar x | isAlpha x || isDigit x = [x]
13 | otherwise = "_" ++ show (fromEnum x) ++ "_"
15indent i = take (i * 4) (repeat ' ')
17creg RVal = "RVAL"
18creg (L i) = "LOC(" ++ show i ++ ")"
19creg (T i) = "TOP(" ++ show i ++ ")"
21toDecl :: Name -> String
22toDecl f = "void " ++ cname f ++ "(VM*, VAL*);\n"
24toC :: Name -> [BC] -> String
25toC f code
26 = -- "/* " ++ show code ++ "*/\n\n" ++
27 "void " ++ cname f ++ "(VM* vm, VAL* oldbase) {" ++
28 concatMap (bcc 1) code ++ "}\n\n"
30bcc :: Int -> BC -> String
31bcc i (ASSIGN l r) = indent i ++ creg l ++ " = " ++ creg r ++ ";\n"
33bcc i _ = indent i ++ "// not done yet\n"