@@ -0,0 +1,34 @@
1+module IRTS.CodegenC where
2+
3+import IRTS.Bytecode
4+import IRTS.Lang
5+import Core.TT
6+import Paths_idris
7+
8+import Data.Char
9+
10+cname :: Name -> String
11+cname n = "_idris_" ++ concatMap cchar (show n)
12+ where cchar x | isAlpha x || isDigit x = [x]
13+ | otherwise = "_" ++ show (fromEnum x) ++ "_"
14+
15+indent i = take (i * 4) (repeat ' ')
16+
17+creg RVal = "RVAL"
18+creg (L i) = "LOC(" ++ show i ++ ")"
19+creg (T i) = "TOP(" ++ show i ++ ")"
20+
21+toDecl :: Name -> String
22+toDecl f = "void " ++ cname f ++ "(VM*, VAL*);\n"
23+
24+toC :: Name -> [BC] -> String
25+toC f code
26+ = -- "/* " ++ show code ++ "*/\n\n" ++
27+ "void " ++ cname f ++ "(VM* vm, VAL* oldbase) {" ++
28+ concatMap (bcc 1) code ++ "}\n\n"
29+
30+bcc :: Int -> BC -> String
31+bcc i (ASSIGN l r) = indent i ++ creg l ++ " = " ++ creg r ++ ";\n"
32+
33+bcc i _ = indent i ++ "// not done yet\n"
34+