on master help sign in
Export intermediate representation as JSON
commit80225af11b6736fbbc6a0f3ed31abc319c9f7e95 authorNiklas Larsson <niklas@mm.st> dateSat 14 May 2016, 23:27 (10 years ago) parent536372f
8 files changed+322−14
idris.cabal+3−1 src/IRTS/Compiler.hs+14−5 src/IRTS/Portable.hs+277 src/Idris/AbsSyntax.hs+14−3 src/Idris/AbsSyntaxTree.hs+4−1 src/Idris/CmdOptions.hs+1 src/Idris/DeepSeq.hs+3−1 src/Idris/REPL.hs+6−3
idris.cabal+3−1
@@ -606,7 +606,7 @@ Extra-source-files:
606606 test/interactive013/input
607607 test/interactive013/run
608608 test/interactive013/*.idr
609−
609+
610610 test/interfaces001/*.idr
611611 test/interfaces001/run
612612 test/interfaces001/expected
@@ -1031,6 +1031,7 @@ Library
10311031 , IRTS.Inliner
10321032 , IRTS.Lang
10331033 , IRTS.LangOpts
1034+ , IRTS.Portable
10341035 , IRTS.Simplified
10351036 , IRTS.System
10361037
@@ -1051,6 +1052,7 @@ Library
10511052 , Tools_idris
10521053
10531054 Build-depends: base >=4 && <5
1055+ , aeson >= 0.11 && < 0.12
10541056 , annotated-wl-pprint >= 0.7 && < 0.8
10551057 , ansi-terminal < 0.7
10561058 , ansi-wl-pprint < 0.7
src/IRTS/Compiler.hs+14−5
@@ -12,6 +12,7 @@ import IRTS.DumpBC
1212import IRTS.CodegenJavaScript
1313import IRTS.Inliner
1414import IRTS.Exports
15+import IRTS.Portable
1516
1617import Idris.AbsSyntax
1718import Idris.AbsSyntaxTree
@@ -121,14 +122,22 @@ compile codegen f mtm
121122 [] -> return ()
122123 ((fc, msg):fs) -> ierror . At fc . Msg $ "Cannot compile:\n " ++ msg
123124
124−generate :: Codegen -> FilePath -> CodegenInfo -> IO ()
125−generate codegen mainmod ir
125+generate :: Codegen -> FilePath -> Bool -> CodegenInfo -> IO ()
126+generate codegen mainmod port ir
126127 = case codegen of
127128 -- Built-in code generators (FIXME: lift these out!)
128129 Via "c" -> codegenC ir
129130 -- Any external code generator
130− Via cg -> do let cmd = "idris-codegen-" ++ cg
131− args = [mainmod, "-o", outputFile ir] ++ compilerFlags ir
131+ Via cg -> do input <- if port
132+ then do
133+ tempdir <- getTemporaryDirectory
134+ (fn, h) <- openTempFile tempdir "idris-cg.json"
135+ writePortable h ir
136+ hClose h
137+ return fn
138+ else return mainmod
139+ let cmd = "idris-codegen-" ++ cg
140+ args = [input, "-o", outputFile ir] ++ compilerFlags ir
132141 exit <- rawSystem cmd args
133142 when (exit /= ExitSuccess) $
134143 putStrLn ("FAILURE: " ++ show cmd ++ " " ++ show args)
@@ -350,7 +359,7 @@ irTerm vs env tm@(App _ f a) = do
350359
351360 -- overapplied
352361 GT -> ifail ("overapplied data constructor: " ++ show tm ++
353− "\nDEBUG INFO:\n" ++
362+ "\nDEBUG INFO:\n" ++
354363 "Arity: " ++ show arity ++ "\n" ++
355364 "Arguments: " ++ show args ++ "\n" ++
356365 "Pruned arguments: " ++ show argsPruned)
src/IRTS/Portable.hsnew file+277
@@ -0,0 +1,277 @@
1+{-# LANGUAGE OverloadedStrings #-}
2+
3+module IRTS.Portable (writePortable) where
4+
5+import Data.Aeson
6+import qualified Data.ByteString.Lazy as B
7+import qualified Data.Text as T
8+
9+import Idris.Core.CaseTree
10+import Idris.Core.TT
11+
12+import IRTS.Bytecode
13+import IRTS.CodegenCommon
14+import IRTS.Defunctionalise
15+import IRTS.Lang
16+import IRTS.Simplified
17+
18+import System.IO
19+
20+data CodegenFile = CGFile {
21+ fileType :: String,
22+ version :: Int,
23+ cgInfo :: CodegenInfo
24+}
25+
26+-- Update the version when the format changes
27+formatVersion :: Int
28+formatVersion = 1
29+
30+writePortable :: Handle -> CodegenInfo -> IO ()
31+writePortable file ci = do
32+ let json = encode $ CGFile "idris-codegen" formatVersion ci
33+ B.hPut file json
34+
35+instance ToJSON CodegenFile where
36+ toJSON (CGFile ft v ci) = object ["file-type" .= ft,
37+ "version" .= v,
38+ "codegen-info" .= toJSON ci]
39+
40+instance ToJSON CodegenInfo where
41+ toJSON ci = object ["output-file" .= (outputFile ci),
42+ "includes" .= (includes ci),
43+ "import-dirs" .= (importDirs ci),
44+ "compile-objs" .= (compileObjs ci),
45+ "compile-libs" .= (compileLibs ci),
46+ "compiler-flags" .= (compilerFlags ci),
47+ "interfaces" .= (interfaces ci),
48+ "exports" .= (exportDecls ci),
49+ "lift-decls" .= (liftDecls ci),
50+ "defun-decls" .= (defunDecls ci),
51+ "simple-decls" .= (simpleDecls ci),
52+ "bytecode" .= (map toBC (simpleDecls ci))]
53+
54+instance ToJSON Name where
55+ toJSON n = toJSON $ showCG n
56+
57+instance ToJSON ExportIFace where
58+ toJSON (Export n f xs) = object ["ffi-desc" .= n,
59+ "interface-file" .= f,
60+ "exports" .= xs]
61+
62+instance ToJSON FDesc where
63+ toJSON (FCon n) = object ["FCon" .= n]
64+ toJSON (FStr s) = object ["FStr" .= s]
65+ toJSON (FUnknown) = object ["FUnknown" .= Null]
66+ toJSON (FIO fd) = object ["FIO" .= fd]
67+ toJSON (FApp n xs) = object ["FApp" .= (n, xs)]
68+
69+instance ToJSON Export where
70+ toJSON (ExportData fd) = object ["ExportData" .= fd]
71+ toJSON (ExportFun n dsc ret args) = object ["ExportFun" .= (n, dsc, ret, args)]
72+
73+instance ToJSON LDecl where
74+ toJSON (LFun opts name args def) = object ["LFun" .= (opts, name, args, def)]
75+ toJSON (LConstructor name tag ar) = object ["LConstructor" .= (name, tag, ar)]
76+
77+instance ToJSON LOpt where
78+ toJSON Inline = String "Inline"
79+ toJSON NoInline = String "NoInline"
80+
81+instance ToJSON LExp where
82+ toJSON (LV lv) = object ["LV" .= lv]
83+ toJSON (LApp tail exp args) = object ["LApp" .= (tail, exp, args)]
84+ toJSON (LLazyApp name exps) = object ["LLazyApp" .= (name, exps)]
85+ toJSON (LLazyExp exp) = object ["LLazyExp" .= exp]
86+ toJSON (LForce exp) = object ["LForce" .= exp]
87+ toJSON (LLet name a b) = object ["LLet" .= (name, a, b)]
88+ toJSON (LLam args exp) = object ["LLam" .= (args, exp)]
89+ toJSON (LProj exp i) = object ["LProj" .= (exp, i)]
90+ toJSON (LCon lv i n exps) = object ["LCon" .= (lv, i, n, exps)]
91+ toJSON (LCase ct exp alts) = object ["LCase" .= (ct, exp, alts)]
92+ toJSON (LConst c) = object ["LConst" .= c]
93+ toJSON (LForeign fd ret exps) = object ["LForeign" .= (fd, ret, exps)]
94+ toJSON (LOp prim exps) = object ["LOp" .= (prim, exps)]
95+ toJSON LNothing = object ["LNothing" .= Null]
96+ toJSON (LError s) = object ["LError" .= s]
97+
98+instance ToJSON LVar where
99+ toJSON (Loc i) = object ["Loc" .= i]
100+ toJSON (Glob n) = object ["Glob" .= n]
101+
102+instance ToJSON CaseType where
103+ toJSON Updatable = String "Updatable"
104+ toJSON Shared = String "Shared"
105+
106+instance ToJSON LAlt where
107+ toJSON (LConCase i n ns exp) = object ["LConCase" .= (i, n, ns, exp)]
108+ toJSON (LConstCase c exp) = object ["LConstCase" .= (c, exp)]
109+ toJSON (LDefaultCase exp) = object ["LDefaultCase" .= exp]
110+
111+instance ToJSON Const where
112+ toJSON (I i) = object ["int" .= i]
113+ toJSON (BI i) = object ["bigint" .= (show i)]
114+ toJSON (Fl d) = object ["double" .= d]
115+ toJSON (Ch c) = object ["char" .= (show c)]
116+ toJSON (Str s) = object ["string" .= s]
117+ toJSON (B8 b) = object ["bits8" .= b]
118+ toJSON (B16 b) = object ["bits16" .= b]
119+ toJSON (B32 b) = object ["bits32" .= b]
120+ toJSON (B64 b) = object ["bits64" .= b]
121+ toJSON (AType at) = object ["atype" .= at]
122+ toJSON StrType = object ["strtype" .= Null]
123+ toJSON WorldType = object ["worldtype" .= Null]
124+ toJSON TheWorld = object ["theworld" .= Null]
125+ toJSON VoidType = object ["voidtype" .= Null]
126+ toJSON Forgot = object ["forgot" .= Null]
127+
128+instance ToJSON ArithTy where
129+ toJSON (ATInt it) = object ["ATInt" .= it]
130+ toJSON ATFloat = object ["ATFloat" .= Null]
131+
132+instance ToJSON IntTy where
133+ toJSON it = toJSON $ intTyName it
134+
135+instance ToJSON PrimFn where
136+ toJSON (LPlus aty) = object ["LPlus" .= aty]
137+ toJSON (LMinus aty) = object ["LMinus" .= aty]
138+ toJSON (LTimes aty) = object ["LTimes" .= aty]
139+ toJSON (LUDiv aty) = object ["LUDiv" .= aty]
140+ toJSON (LSDiv aty) = object ["LSDiv" .= aty]
141+ toJSON (LAnd ity) = object ["LAnd" .= ity]
142+ toJSON (LOr ity) = object ["LOr" .= ity]
143+ toJSON (LXOr ity) = object ["LXOr" .= ity]
144+ toJSON (LCompl ity) = object ["LCompl" .= ity]
145+ toJSON (LSHL ity) = object ["LSHL" .= ity]
146+ toJSON (LLSHR ity) = object ["LLSHR" .= ity]
147+ toJSON (LASHR ity) = object ["LASHR" .= ity]
148+ toJSON (LEq aty) = object ["LEq" .= aty]
149+ toJSON (LLt ity) = object ["LLt" .= ity]
150+ toJSON (LLe ity) = object ["LLe" .= ity]
151+ toJSON (LGt ity) = object ["LGt" .= ity]
152+ toJSON (LGe ity) = object ["LGe" .= ity]
153+ toJSON (LSLt aty) = object ["LSLt" .= aty]
154+ toJSON (LSLe aty) = object ["LSLe" .= aty]
155+ toJSON (LSGt aty) = object ["LSGt" .= aty]
156+ toJSON (LSGe aty) = object ["LSGe" .= aty]
157+ toJSON (LZExt from to) = object ["LZExt" .= (from, to)]
158+ toJSON (LSExt from to) = object ["LSExt" .= (from, to)]
159+ toJSON (LTrunc from to) = object ["LTrunc" .= (from, to)]
160+ toJSON LStrConcat = object ["LStrConcat" .= Null]
161+ toJSON LStrLt = object ["LStrLt" .= Null]
162+ toJSON LStrEq = object ["LStrEq" .= Null]
163+ toJSON LStrLen = object ["LStrLen" .= Null]
164+ toJSON (LIntFloat ity) = object ["LIntFloat" .= ity]
165+ toJSON (LFloatInt ity) = object ["LFloatInt" .= ity]
166+ toJSON (LIntStr ity) = object ["LIntStr" .= ity]
167+ toJSON (LStrInt ity) = object ["LStrInt" .= ity]
168+ toJSON (LIntCh ity) = object ["LIntCh" .= ity]
169+ toJSON (LChInt ity) = object ["LChInt" .= ity]
170+ toJSON LFloatStr = object ["LFloatStr" .= Null]
171+ toJSON LStrFloat = object ["LStrFloat" .= Null]
172+ toJSON (LBitCast from to) = object ["LBitCast" .= (from, to)]
173+ toJSON LFExp = object ["LFExp" .= Null]
174+ toJSON LFLog = object ["LFLog" .= Null]
175+ toJSON LFSin = object ["LFSin" .= Null]
176+ toJSON LFCos = object ["LFCos" .= Null]
177+ toJSON LFTan = object ["LFTan" .= Null]
178+ toJSON LFASin = object ["LFASin" .= Null]
179+ toJSON LFACos = object ["LFACos" .= Null]
180+ toJSON LFATan = object ["LFATan" .= Null]
181+ toJSON LFSqrt = object ["LFSqrt" .= Null]
182+ toJSON LFFloor = object ["LFFloor" .= Null]
183+ toJSON LFCeil = object ["LFCeil" .= Null]
184+ toJSON LFNegate = object ["LFNegate" .= Null]
185+ toJSON LStrHead = object ["LStrHead" .= Null]
186+ toJSON LStrTail = object ["LStrTail" .= Null]
187+ toJSON LStrCons = object ["LStrCons" .= Null]
188+ toJSON LStrIndex = object ["LStrIndex" .= Null]
189+ toJSON LStrRev = object ["LStrRev" .= Null]
190+ toJSON LStrSubstr = object ["LStrSubstr" .= Null]
191+ toJSON LReadStr = object ["LReadStr" .= Null]
192+ toJSON LWriteStr = object ["LWriteStr" .= Null]
193+ toJSON LSystemInfo = object ["LSystemInfo" .= Null]
194+ toJSON LFork = object ["LFork" .= Null]
195+ toJSON LPar = object ["LPar" .= Null]
196+ toJSON (LExternal name) = object ["LExternal" .= name]
197+ toJSON LNoOp = object ["LNoOp" .= Null]
198+
199+
200+
201+
202+
203+instance ToJSON DDecl where
204+ toJSON (DFun name args exp) = object ["DFun" .= (name, args, exp)]
205+ toJSON (DConstructor name tag arity) = object ["DConstructor" .= (name, tag, arity)]
206+
207+instance ToJSON DExp where
208+ toJSON (DV lv) = object ["DV" .= lv]
209+ toJSON (DApp tail name exps) = object ["DApp" .= (tail, name, exps)]
210+ toJSON (DLet name a b) = object ["DLet" .= (name, a, b)]
211+ toJSON (DUpdate name exp) = object ["DUpdate" .= (name,exp)]
212+ toJSON (DProj exp i) = object ["DProj" .= (exp, i)]
213+ toJSON (DC lv i name exp) = object ["DC" .= (lv, i, name, exp)]
214+ toJSON (DCase ct exp alts) = object ["DCase" .= (ct, exp, alts)]
215+ toJSON (DChkCase exp alts) = object ["DChkCase" .= (exp, alts)]
216+ toJSON (DConst c) = object ["DConst" .= c]
217+ toJSON (DForeign fd ret exps) = object ["DForeign" .= (fd, ret, exps)]
218+ toJSON (DOp prim exps) = object ["DOp" .= (prim, exps)]
219+ toJSON DNothing = object ["DNothing" .= Null]
220+ toJSON (DError s) = object ["DError" .= s]
221+
222+instance ToJSON DAlt where
223+ toJSON (DConCase i n ns exp) = object ["DConCase" .= (i, n, ns, exp)]
224+ toJSON (DConstCase c exp) = object ["DConstCase" .= (c, exp)]
225+ toJSON (DDefaultCase exp) = object ["DDefaultCase" .= exp]
226+
227+instance ToJSON SDecl where
228+ toJSON (SFun name args i exp) = object ["SFun" .= (name, args, i, exp)]
229+
230+instance ToJSON SExp where
231+ toJSON (SV lv) = object ["SV" .= lv]
232+ toJSON (SApp tail name exps) = object ["SApp" .= (tail, name, exps)]
233+ toJSON (SLet lv a b) = object ["SLet" .= (lv, a, b)]
234+ toJSON (SUpdate lv exp) = object ["SUpdate" .= (lv, exp)]
235+ toJSON (SProj lv i) = object ["DProj" .= (lv, i)]
236+ toJSON (SCon lv i name vars) = object ["SCon" .= (lv, i, name, vars)]
237+ toJSON (SCase ct lv alts) = object ["SCase" .= (ct, lv, alts)]
238+ toJSON (SChkCase lv alts) = object ["DChkCase" .= (lv, alts)]
239+ toJSON (SConst c) = object ["SConst" .= c]
240+ toJSON (SForeign fd ret exps) = object ["SForeign" .= (fd, ret, exps)]
241+ toJSON (SOp prim vars) = object ["DOp" .= (prim, vars)]
242+ toJSON SNothing = object ["SNothing" .= Null]
243+ toJSON (SError s) = object ["SError" .= s]
244+
245+instance ToJSON SAlt where
246+ toJSON (SConCase i j n ns exp) = object ["SConCase" .= (i, j, n, ns, exp)]
247+ toJSON (SConstCase c exp) = object ["SConstCase" .= (c, exp)]
248+ toJSON (SDefaultCase exp) = object ["SDefaultCase" .= exp]
249+
250+instance ToJSON BC where
251+ toJSON (ASSIGN r1 r2) = object ["ASSIGN" .= (r1, r2)]
252+ toJSON (ASSIGNCONST r c) = object ["ASSIGNCONST" .= (r, c)]
253+ toJSON (UPDATE r1 r2) = object ["UPDATE" .= (r1, r2)]
254+ toJSON (MKCON con mr i regs) = object ["MKCON" .= (con, mr, i, regs)]
255+ toJSON (CASE b r alts def) = object ["CASE" .= (b, r, alts, def)]
256+ toJSON (PROJECT r loc arity) = object ["PROJECT" .= (r, loc, arity)]
257+ toJSON (PROJECTINTO r1 r2 loc) = object ["PROJECTINTO" .= (r1, r2, loc)]
258+ toJSON (CONSTCASE r alts def) = object ["CONSTCASE" .= (r, alts, def)]
259+ toJSON (CALL name) = object ["CALL" .= name]
260+ toJSON (TAILCALL name) = object ["TAILCALL" .= name]
261+ toJSON (FOREIGNCALL r fd ret exps) = object ["FOREIGNCALL" .= (r, fd, ret, exps)]
262+ toJSON (SLIDE i) = object ["SLIDE" .= i]
263+ toJSON (RESERVE i) = object ["RESERVE" .= i]
264+ toJSON (ADDTOP i) = object ["ADDTOP" .= i]
265+ toJSON (TOPBASE i) = object ["TOPBASE" .= i]
266+ toJSON (BASETOP i) = object ["BASETOP" .= i]
267+ toJSON REBASE = object ["REBASE" .= Null]
268+ toJSON STOREOLD = object ["STOREOLD" .= Null]
269+ toJSON (OP r prim args) = object ["OP" .= (r, prim, args)]
270+ toJSON (NULL r) = object ["NULL" .= r]
271+ toJSON (ERROR s) = object ["ERROR" .= s]
272+
273+instance ToJSON Reg where
274+ toJSON RVal = object ["RVal" .= Null]
275+ toJSON (T i) = object ["T" .= i]
276+ toJSON (L i) = object ["L" .= i]
277+ toJSON Tmp = object ["Tmp" .= Null]
src/Idris/AbsSyntax.hs+14−3
@@ -459,13 +459,13 @@ addInstance int res n i
459459-- Returns the old list, so we can revert easily at the end of a block
460460
461461addOpenImpl :: [Name] -> Idris [Name]
462−addOpenImpl ns = do ist <- getIState
462+addOpenImpl ns = do ist <- getIState
463463 ns' <- mapM (checkValid ist) ns
464464 let open = idris_openimpls ist
465465 putIState $ ist { idris_openimpls = nub (ns' ++ open) }
466466 return open
467467 where
468− checkValid ist n
468+ checkValid ist n
469469 = case lookupCtxtName n (idris_implicits ist) of
470470 [(n', _)] -> return n'
471471 [] -> throwError (NoSuchVariable n)
@@ -946,6 +946,17 @@ codegen :: Idris Codegen
946946codegen = do i <- getIState
947947 return (opt_codegen (idris_options i))
948948
949+setPortableCodegen :: Bool -> Idris ()
950+setPortableCodegen p = do i <- getIState
951+ let opts = idris_options i
952+ let opt' = opts { opt_portableCG = p }
953+ putIState $ i { idris_options = opt' }
954+
955+getPortableCodegen :: Idris Bool
956+getPortableCodegen = do i <- getIState
957+ let opts = idris_options i
958+ return (opt_portableCG opts)
959+
949960setOutputTy :: OutputType -> Idris ()
950961setOutputTy t = do i <- getIState
951962 let opts = idris_options i
@@ -2329,7 +2340,7 @@ shadow n n' t = sm 0 t where
23292340 sm 0 (PTyped x y) = PTyped (sm 0 x) (sm 0 y)
23302341 sm 0 (PPair f hls p x y) = PPair f hls p (sm 0 x) (sm 0 y)
23312342 sm 0 (PDPair f hls p x t y) = PDPair f hls p (sm 0 x) (sm 0 t) (sm 0 y)
2332− sm 0 (PAlternative ms a as)
2343+ sm 0 (PAlternative ms a as)
23332344 = PAlternative (map shadowAlt ms) a (map (sm 0) as)
23342345 sm 0 (PTactics ts) = PTactics (map (fmap (sm 0)) ts)
23352346 sm 0 (PProof ts) = PProof (map (fmap (sm 0)) ts)
src/Idris/AbsSyntaxTree.hs+4−1
@@ -85,6 +85,7 @@ data IOption = IOption {
8585 , opt_nobanner :: Bool
8686 , opt_quiet :: Bool
8787 , opt_codegen :: Codegen
88+ , opt_portableCG :: Bool
8889 , opt_outputTy :: OutputType
8990 , opt_ibcsubdir :: FilePath
9091 , opt_importdirs :: [FilePath]
@@ -113,6 +114,7 @@ defaultOpts = IOption { opt_logLevel = 0
113114 , opt_nobanner = False
114115 , opt_quiet = False
115116 , opt_codegen = Via "c"
117+ , opt_portableCG = False
116118 , opt_outputTy = Executable
117119 , opt_ibcsubdir = ""
118120 , opt_importdirs = []
@@ -186,7 +188,7 @@ data DefaultTotality = DefaultCheckingTotal -- ^ Total
186188 | DefaultCheckingPartial -- ^ Partial
187189 | DefaultCheckingCovering -- ^Total coverage, but may diverge
188190 deriving (Show, Eq)
189−
191+
190192-- | The global state used in the Idris monad
191193data IState = IState {
192194 tt_ctxt :: Context, -- ^ All the currently defined names and their terms
@@ -558,6 +560,7 @@ data Opt = Filename String
558560 | DumpDefun String
559561 | DumpCases String
560562 | UseCodegen Codegen
563+ | PortableCodegen
561564 | CodegenArgs String
562565 | OutputTy OutputType
563566 | Extension LanguageExt
src/Idris/CmdOptions.hs+1
@@ -149,6 +149,7 @@ parseFlags = many $
149149 <|> ((\s -> UseCodegen $ parseCodegen s) <$> strOption (long "codegen"
150150 <> metavar "TARGET"
151151 <> help "Select code generator: C, Javascript, Node and bytecode are bundled with Idris"))
152+ <|> flag' PortableCodegen (long "portable" <> help "Call codegen with json-formatted codegen info")
152153 <|> (CodegenArgs <$> strOption (long "cg-opt"
153154 <> metavar "ARG"
154155 <> help "Arguments to pass to code generator"))
src/Idris/DeepSeq.hs+3−1
@@ -149,6 +149,7 @@ instance NFData Opt where
149149 rnf (DumpDefun str) = rnf str `seq` ()
150150 rnf (DumpCases str) = rnf str `seq` ()
151151 rnf (UseCodegen cg) = rnf cg `seq` ()
152+ rnf (PortableCodegen) = ()
152153 rnf (CodegenArgs str) = rnf str `seq` ()
153154 rnf (OutputTy ot) = rnf ot `seq` ()
154155 rnf (Extension le) = rnf le `seq` ()
@@ -187,6 +188,7 @@ instance NFData IOption where
187188 opt_nobanner
188189 opt_quiet
189190 opt_codegen
191+ opt_portableCG
190192 opt_outputTy
191193 opt_ibcsubdir
192194 opt_importdirs
@@ -700,7 +702,7 @@ instance NFData DefaultTotality where
700702 rnf DefaultCheckingTotal = ()
701703 rnf DefaultCheckingPartial = ()
702704 rnf DefaultCheckingCovering = ()
703−
705+
704706instance NFData IState where
705707 rnf (IState x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20
706708 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40
src/Idris/REPL.hs+6−3
@@ -1228,7 +1228,8 @@ process fn (Execute tm)
12281228 -- gcc adds .exe when it builds windows programs
12291229 progName <- return $ if isWindows then tmpn ++ ".exe" else tmpn
12301230 ir <- compile t tmpn (Just m)
1231− runIO $ generate t (fst (head (idris_imported ist))) ir
1231+ port <- getPortableCodegen
1232+ runIO $ generate t (fst (head (idris_imported ist))) port ir
12321233 case idris_outputmode ist of
12331234 RawOutput h -> do runIO $ rawSystem progName []
12341235 return ()
@@ -1249,9 +1250,9 @@ process fn (Compile codegen f)
12491250 [pexp $ PRef fc [] mainname])
12501251 return (Just m')
12511252 ir <- compile codegen f m
1252−
1253+ port <- getPortableCodegen
12531254 i <- getIState
1254− runIO $ generate codegen (fst (head (idris_imported i))) ir
1255+ runIO $ generate codegen (fst (head (idris_imported i))) port ir
12551256 where fc = fileFC "main"
12561257process fn (LogLvl i) = setLogLevel i
12571258process fn (LogCategory cs) = setLogCats cs
@@ -1690,6 +1691,7 @@ idrisMain opts =
16901691 let cgn = case opt getCodegen opts of
16911692 [] -> Via "c"
16921693 xs -> last xs
1694+ let portable = PortableCodegen `elem` opts
16931695 let cgFlags = opt getCodegenArgs opts
16941696
16951697 -- Now set/unset specifically chosen optimisations
@@ -1717,6 +1719,7 @@ idrisMain opts =
17171719 setOutputTy outty
17181720 setNoBanner nobanner
17191721 setCodegen cgn
1722+ setPortableCodegen portable
17201723 mapM_ (addFlag cgn) cgFlags
17211724 mapM_ makeOption opts
17221725 -- if we have the --bytecode flag, drop into the bytecode assembler