3Description : Serialise Idris' IR to JSON.
6Maintainer : The Idris Community.
8{-# LANGUAGE OverloadedStrings #-}
9module IRTS.Portable (writePortable) where
12import qualified Data.ByteString.Lazy as B
13import qualified Data.Text as T
15import Idris.Core.CaseTree
19import IRTS.CodegenCommon
20import IRTS.Defunctionalise
26data CodegenFile = CGFile {
32-- Update the version when the format changes
36writePortable :: Handle -> CodegenInfo -> IO ()
37writePortable file ci = do
38 let json = encode $ CGFile "idris-codegen" formatVersion ci
41instance ToJSON CodegenFile where
42 toJSON (CGFile ft v ci) = object ["file-type" .= ft,
44 "codegen-info" .= toJSON ci]
46instance ToJSON CodegenInfo where
47 toJSON ci = object ["output-file" .= (outputFile ci),
48 "includes" .= (includes ci),
49 "import-dirs" .= (importDirs ci),
50 "compile-objs" .= (compileObjs ci),
51 "compile-libs" .= (compileLibs ci),
52 "compiler-flags" .= (compilerFlags ci),
53 "interfaces" .= (interfaces ci),
54 "exports" .= (exportDecls ci),
55 "lift-decls" .= (liftDecls ci),
56 "defun-decls" .= (defunDecls ci),
57 "simple-decls" .= (simpleDecls ci),
58 "bytecode" .= (map toBC (simpleDecls ci))]
60instance ToJSON Name where
61 toJSON n = toJSON $ showCG n
63instance ToJSON ExportIFace where
64 toJSON (Export n f xs) = object ["ffi-desc" .= n,
65 "interface-file" .= f,
68instance ToJSON FDesc where
69 toJSON (FCon n) = object ["FCon" .= n]
70 toJSON (FStr s) = object ["FStr" .= s]
71 toJSON (FUnknown) = object ["FUnknown" .= Null]
72 toJSON (FIO fd) = object ["FIO" .= fd]
73 toJSON (FApp n xs) = object ["FApp" .= (n, xs)]
75instance ToJSON Export where
76 toJSON (ExportData fd) = object ["ExportData" .= fd]
77 toJSON (ExportFun n dsc ret args) = object ["ExportFun" .= (n, dsc, ret, args)]
79instance ToJSON LDecl where
80 toJSON (LFun opts name args def) = object ["LFun" .= (opts, name, args, def)]
81 toJSON (LConstructor name tag ar) = object ["LConstructor" .= (name, tag, ar)]
83instance ToJSON LOpt where
84 toJSON Inline = String "Inline"
85 toJSON NoInline = String "NoInline"
87instance ToJSON LExp where
88 toJSON (LV lv) = object ["LV" .= lv]
89 toJSON (LApp tail exp args) = object ["LApp" .= (tail, exp, args)]
90 toJSON (LLazyApp name exps) = object ["LLazyApp" .= (name, exps)]
91 toJSON (LLazyExp exp) = object ["LLazyExp" .= exp]
92 toJSON (LForce exp) = object ["LForce" .= exp]
93 toJSON (LLet name a b) = object ["LLet" .= (name, a, b)]
94 toJSON (LLam args exp) = object ["LLam" .= (args, exp)]
95 toJSON (LProj exp i) = object ["LProj" .= (exp, i)]
96 toJSON (LCon lv i n exps) = object ["LCon" .= (lv, i, n, exps)]
97 toJSON (LCase ct exp alts) = object ["LCase" .= (ct, exp, alts)]
98 toJSON (LConst c) = object ["LConst" .= c]
99 toJSON (LForeign fd ret exps) = object ["LForeign" .= (fd, ret, exps)]
100 toJSON (LOp prim exps) = object ["LOp" .= (prim, exps)]
101 toJSON LNothing = object ["LNothing" .= Null]
102 toJSON (LError s) = object ["LError" .= s]
104instance ToJSON LVar where
105 toJSON (Loc i) = object ["Loc" .= i]
106 toJSON (Glob n) = object ["Glob" .= n]
108instance ToJSON CaseType where
109 toJSON Updatable = String "Updatable"
110 toJSON Shared = String "Shared"
112instance ToJSON LAlt where
113 toJSON (LConCase i n ns exp) = object ["LConCase" .= (i, n, ns, exp)]
114 toJSON (LConstCase c exp) = object ["LConstCase" .= (c, exp)]
115 toJSON (LDefaultCase exp) = object ["LDefaultCase" .= exp]
117instance ToJSON Const where
118 toJSON (I i) = object ["int" .= i]
119 toJSON (BI i) = object ["bigint" .= (show i)]
120 toJSON (Fl d) = object ["double" .= d]
121 toJSON (Ch c) = object ["char" .= (show c)]
122 toJSON (Str s) = object ["string" .= s]
123 toJSON (B8 b) = object ["bits8" .= b]
124 toJSON (B16 b) = object ["bits16" .= b]
125 toJSON (B32 b) = object ["bits32" .= b]
126 toJSON (B64 b) = object ["bits64" .= b]
127 toJSON (AType at) = object ["atype" .= at]
128 toJSON StrType = object ["strtype" .= Null]
129 toJSON WorldType = object ["worldtype" .= Null]
130 toJSON TheWorld = object ["theworld" .= Null]
131 toJSON VoidType = object ["voidtype" .= Null]
132 toJSON Forgot = object ["forgot" .= Null]
134instance ToJSON ArithTy where
135 toJSON (ATInt it) = object ["ATInt" .= it]
136 toJSON ATFloat = object ["ATFloat" .= Null]
138instance ToJSON IntTy where
139 toJSON it = toJSON $ intTyName it
141instance ToJSON PrimFn where
142 toJSON (LPlus aty) = object ["LPlus" .= aty]
143 toJSON (LMinus aty) = object ["LMinus" .= aty]
144 toJSON (LTimes aty) = object ["LTimes" .= aty]
145 toJSON (LUDiv aty) = object ["LUDiv" .= aty]
146 toJSON (LSDiv aty) = object ["LSDiv" .= aty]
147 toJSON (LAnd ity) = object ["LAnd" .= ity]
148 toJSON (LOr ity) = object ["LOr" .= ity]
149 toJSON (LXOr ity) = object ["LXOr" .= ity]
150 toJSON (LCompl ity) = object ["LCompl" .= ity]
151 toJSON (LSHL ity) = object ["LSHL" .= ity]
152 toJSON (LLSHR ity) = object ["LLSHR" .= ity]
153 toJSON (LASHR ity) = object ["LASHR" .= ity]
154 toJSON (LEq aty) = object ["LEq" .= aty]
155 toJSON (LLt ity) = object ["LLt" .= ity]
156 toJSON (LLe ity) = object ["LLe" .= ity]
157 toJSON (LGt ity) = object ["LGt" .= ity]
158 toJSON (LGe ity) = object ["LGe" .= ity]
159 toJSON (LSLt aty) = object ["LSLt" .= aty]
160 toJSON (LSLe aty) = object ["LSLe" .= aty]
161 toJSON (LSGt aty) = object ["LSGt" .= aty]
162 toJSON (LSGe aty) = object ["LSGe" .= aty]
163 toJSON (LZExt from to) = object ["LZExt" .= (from, to)]
164 toJSON (LSExt from to) = object ["LSExt" .= (from, to)]
165 toJSON (LTrunc from to) = object ["LTrunc" .= (from, to)]
166 toJSON LStrConcat = object ["LStrConcat" .= Null]
167 toJSON LStrLt = object ["LStrLt" .= Null]
168 toJSON LStrEq = object ["LStrEq" .= Null]
169 toJSON LStrLen = object ["LStrLen" .= Null]
170 toJSON (LIntFloat ity) = object ["LIntFloat" .= ity]
171 toJSON (LFloatInt ity) = object ["LFloatInt" .= ity]
172 toJSON (LIntStr ity) = object ["LIntStr" .= ity]
173 toJSON (LStrInt ity) = object ["LStrInt" .= ity]
174 toJSON (LIntCh ity) = object ["LIntCh" .= ity]
175 toJSON (LChInt ity) = object ["LChInt" .= ity]
176 toJSON LFloatStr = object ["LFloatStr" .= Null]
177 toJSON LStrFloat = object ["LStrFloat" .= Null]
178 toJSON (LBitCast from to) = object ["LBitCast" .= (from, to)]
179 toJSON LFExp = object ["LFExp" .= Null]
180 toJSON LFLog = object ["LFLog" .= Null]
181 toJSON LFSin = object ["LFSin" .= Null]
182 toJSON LFCos = object ["LFCos" .= Null]
183 toJSON LFTan = object ["LFTan" .= Null]
184 toJSON LFASin = object ["LFASin" .= Null]
185 toJSON LFACos = object ["LFACos" .= Null]
186 toJSON LFATan = object ["LFATan" .= Null]
187 toJSON LFSqrt = object ["LFSqrt" .= Null]
188 toJSON LFFloor = object ["LFFloor" .= Null]
189 toJSON LFCeil = object ["LFCeil" .= Null]
190 toJSON LFNegate = object ["LFNegate" .= Null]
191 toJSON LStrHead = object ["LStrHead" .= Null]
192 toJSON LStrTail = object ["LStrTail" .= Null]
193 toJSON LStrCons = object ["LStrCons" .= Null]
194 toJSON LStrIndex = object ["LStrIndex" .= Null]
195 toJSON LStrRev = object ["LStrRev" .= Null]
196 toJSON LStrSubstr = object ["LStrSubstr" .= Null]
197 toJSON LReadStr = object ["LReadStr" .= Null]
198 toJSON LWriteStr = object ["LWriteStr" .= Null]
199 toJSON LSystemInfo = object ["LSystemInfo" .= Null]
200 toJSON LFork = object ["LFork" .= Null]
201 toJSON LPar = object ["LPar" .= Null]
202 toJSON (LExternal name) = object ["LExternal" .= name]
203 toJSON LNoOp = object ["LNoOp" .= Null]
209instance ToJSON DDecl where
210 toJSON (DFun name args exp) = object ["DFun" .= (name, args, exp)]
211 toJSON (DConstructor name tag arity) = object ["DConstructor" .= (name, tag, arity)]
213instance ToJSON DExp where
214 toJSON (DV lv) = object ["DV" .= lv]
215 toJSON (DApp tail name exps) = object ["DApp" .= (tail, name, exps)]
216 toJSON (DLet name a b) = object ["DLet" .= (name, a, b)]
217 toJSON (DUpdate name exp) = object ["DUpdate" .= (name,exp)]
218 toJSON (DProj exp i) = object ["DProj" .= (exp, i)]
219 toJSON (DC lv i name exp) = object ["DC" .= (lv, i, name, exp)]
220 toJSON (DCase ct exp alts) = object ["DCase" .= (ct, exp, alts)]
221 toJSON (DChkCase exp alts) = object ["DChkCase" .= (exp, alts)]
222 toJSON (DConst c) = object ["DConst" .= c]
223 toJSON (DForeign fd ret exps) = object ["DForeign" .= (fd, ret, exps)]
224 toJSON (DOp prim exps) = object ["DOp" .= (prim, exps)]
225 toJSON DNothing = object ["DNothing" .= Null]
226 toJSON (DError s) = object ["DError" .= s]
228instance ToJSON DAlt where
229 toJSON (DConCase i n ns exp) = object ["DConCase" .= (i, n, ns, exp)]
230 toJSON (DConstCase c exp) = object ["DConstCase" .= (c, exp)]
231 toJSON (DDefaultCase exp) = object ["DDefaultCase" .= exp]
233instance ToJSON SDecl where
234 toJSON (SFun name args i exp) = object ["SFun" .= (name, args, i, exp)]
236instance ToJSON SExp where
237 toJSON (SV lv) = object ["SV" .= lv]
238 toJSON (SApp tail name exps) = object ["SApp" .= (tail, name, exps)]
239 toJSON (SLet lv a b) = object ["SLet" .= (lv, a, b)]
240 toJSON (SUpdate lv exp) = object ["SUpdate" .= (lv, exp)]
241 toJSON (SProj lv i) = object ["DProj" .= (lv, i)]
242 toJSON (SCon lv i name vars) = object ["SCon" .= (lv, i, name, vars)]
243 toJSON (SCase ct lv alts) = object ["SCase" .= (ct, lv, alts)]
244 toJSON (SChkCase lv alts) = object ["DChkCase" .= (lv, alts)]
245 toJSON (SConst c) = object ["SConst" .= c]
246 toJSON (SForeign fd ret exps) = object ["SForeign" .= (fd, ret, exps)]
247 toJSON (SOp prim vars) = object ["DOp" .= (prim, vars)]
248 toJSON SNothing = object ["SNothing" .= Null]
249 toJSON (SError s) = object ["SError" .= s]
251instance ToJSON SAlt where
252 toJSON (SConCase i j n ns exp) = object ["SConCase" .= (i, j, n, ns, exp)]
253 toJSON (SConstCase c exp) = object ["SConstCase" .= (c, exp)]
254 toJSON (SDefaultCase exp) = object ["SDefaultCase" .= exp]
256instance ToJSON BC where
257 toJSON (ASSIGN r1 r2) = object ["ASSIGN" .= (r1, r2)]
258 toJSON (ASSIGNCONST r c) = object ["ASSIGNCONST" .= (r, c)]
259 toJSON (UPDATE r1 r2) = object ["UPDATE" .= (r1, r2)]
260 toJSON (MKCON con mr i regs) = object ["MKCON" .= (con, mr, i, regs)]
261 toJSON (CASE b r alts def) = object ["CASE" .= (b, r, alts, def)]
262 toJSON (PROJECT r loc arity) = object ["PROJECT" .= (r, loc, arity)]
263 toJSON (PROJECTINTO r1 r2 loc) = object ["PROJECTINTO" .= (r1, r2, loc)]
264 toJSON (CONSTCASE r alts def) = object ["CONSTCASE" .= (r, alts, def)]
265 toJSON (CALL name) = object ["CALL" .= name]
266 toJSON (TAILCALL name) = object ["TAILCALL" .= name]
267 toJSON (FOREIGNCALL r fd ret exps) = object ["FOREIGNCALL" .= (r, fd, ret, exps)]
268 toJSON (SLIDE i) = object ["SLIDE" .= i]
269 toJSON (RESERVE i) = object ["RESERVE" .= i]
270 toJSON (ADDTOP i) = object ["ADDTOP" .= i]
271 toJSON (TOPBASE i) = object ["TOPBASE" .= i]
272 toJSON (BASETOP i) = object ["BASETOP" .= i]
273 toJSON REBASE = object ["REBASE" .= Null]
274 toJSON STOREOLD = object ["STOREOLD" .= Null]
275 toJSON (OP r prim args) = object ["OP" .= (r, prim, args)]
276 toJSON (NULL r) = object ["NULL" .= r]
277 toJSON (ERROR s) = object ["ERROR" .= s]
279instance ToJSON Reg where
280 toJSON RVal = object ["RVal" .= Null]
281 toJSON (T i) = object ["T" .= i]
282 toJSON (L i) = object ["L" .= i]
283 toJSON Tmp = object ["Tmp" .= Null]
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list