Skip to content

Commit 29cb8c4

Browse files
committed
Extend usage of 'CompileMode' to also accomodate 'Interactive Mode'
1 parent 8369414 commit 29cb8c4

File tree

10 files changed

+34
-34
lines changed

10 files changed

+34
-34
lines changed

compiler/app/Main.hs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ process :: [Flag] -> Maybe String -> String -> IO ExitCode
7171
process flags fname input = do
7272
let ast = parseProg input
7373

74-
let compileMode =
75-
if elem LibMode flags then Export
76-
else Normal
74+
let compileMode = if LibMode `elem` flags then Library else Normal
7775

7876
let verbose = Verbose `elem` flags
7977
noRawOpt = NoRawOpt `elem` flags
@@ -91,18 +89,15 @@ process flags fname input = do
9189

9290
------------------------------------------------------
9391
-- TROUPE (FRONTEND) ---------------------------------
94-
let prog_without_dependencies =
95-
case compileMode of
96-
Normal -> addAmbientMethods prog_parsed
97-
Export -> prog_parsed
92+
let prog_without_dependencies = case compileMode of Normal -> addAmbientMethods prog_parsed
93+
_ -> prog_parsed
9894

9995
prog <- (processImports) prog_without_dependencies
10096

101-
exports <- case compileMode of
102-
Normal -> return Nothing
103-
Export -> case runExcept (extractExports prog) of
104-
Right es -> return (Just (es))
105-
Left s -> die s
97+
exports <- case compileMode of Library -> case runExcept (extractExports prog) of
98+
Right es -> return (Just (es))
99+
Left s -> die s
100+
_ -> return Nothing
106101

107102
when verbose $ do printSep "SYNTAX"
108103
writeFileD "out/out.syntax" (showIndent 2 prog)
@@ -167,9 +162,9 @@ process flags fname input = do
167162
(Stack.ProgramStackUnit stack)
168163
writeFile outPath stackjs
169164

170-
case exports of
171-
Nothing -> return ()
172-
Just es -> writeExports outPath es
165+
-- case compileMode of Library -> ...
166+
case exports of Nothing -> return ()
167+
Just es -> writeExports outPath es
173168

174169
----- EPILOGUE --------------------------------------
175170
when verbose printHr

compiler/src/CaseElimination.hs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ import Data.List (nub, (\\))
2121
type Trans = Except String
2222

2323
trans :: CompileMode -> S.Prog -> Trans T.Prog
24-
trans mode (S.Prog imports atms tm) = do
25-
let tm' = case mode of
26-
Normal ->
27-
S.Let [ S.ValDecl (S.VarPattern "authority") (S.Var "$$authorityarg") _srcRT ]
28-
tm
29-
Export -> tm
24+
trans compileMode (S.Prog imports atms tm) = do
25+
let tm' = case compileMode of
26+
CompileMode.Library -> tm
27+
_ ->
28+
S.Let [ S.ValDecl (S.VarPattern "authority") (S.Var "$$authorityarg") _srcRT ]
29+
tm
3030
atms' <- transAtoms atms
3131
tm'' <- transTerm tm'
3232
return (T.Prog imports atms' tm'')
@@ -302,4 +302,4 @@ transFields = mapM $ \case
302302
(f, Nothing) -> return (f, T.Var f)
303303
(f, Just t) -> do
304304
t' <- transTerm t
305-
return (f, t')
305+
return (f, t')

compiler/src/ClosureConv.hs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,10 @@ cpsToIR (CPS.Halt v) = do
224224
(compileMode,_ , _ , _, _ ) <- ask
225225
let constructor =
226226
case compileMode of
227-
Normal -> CCIR.Ret
228227
-- Compiling library, then generate export instruction
229-
Export -> CCIR.LibExport
228+
CompileMode.Library -> CCIR.LibExport
229+
-- Otherwise, keep it as a simple return
230+
_ -> CCIR.Ret
230231

231232
return $ CCIR.BB [] $ constructor v'
232233

@@ -275,8 +276,11 @@ closureConvert compileMode (CPS.Prog (C.Atoms atms) t) =
275276
(bb, (fdefs, _, consts_wo_levs)) = evalRWS (cpsToIR t) initEnv initState
276277
(argumentName, toplevel) =
277278
case compileMode of
278-
Normal -> ("$$authorityarg", "main") -- passing authority through the argument to main
279-
Export -> ("$$dummy", "export")
279+
-- Top level function of a library is named 'export'
280+
CompileMode.Library -> ("$$dummy", "export")
281+
-- Passing authority through the argument to main
282+
_ -> ("$$authorityarg", "main")
283+
280284

281285
-- obs that our 'main' may have two names depending on the compilation mode; 2018-07-02; AA
282286
consts = (fst.unzip) consts_wo_levs

compiler/src/CompileMode.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
module CompileMode
22
where
33

4-
data CompileMode = Normal | Export
4+
-- | Different modes of compilation.
5+
data CompileMode = -- | Compilation of a single file for a Troupe program
6+
Normal
7+
-- | Compiling a libary (deprecated)
8+
| Library
9+
-- | Interactive deserialization of IR
10+
| Interactive

compiler/src/IR.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import Data.Serialize (Serialize)
2828
import qualified Data.Serialize as Serialize
2929
import GHC.Generics (Generic)
3030

31-
import CompileMode
3231
import Text.PrettyPrint.HughesPJ (hsep, nest, text, vcat, ($$), (<+>))
3332
import qualified Text.PrettyPrint.HughesPJ as PP
3433
import TroupePositionInfo

compiler/src/Raw.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import Control.Monad.Writer
3030
import Data.List
3131
import qualified Data.ByteString as BS
3232

33-
import CompileMode
3433
import Text.PrettyPrint.HughesPJ (hsep, nest, text, vcat, ($$), (<+>))
3534
import qualified Text.PrettyPrint.HughesPJ as PP
3635
import TroupePositionInfo

compiler/src/Raw2Stack.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import qualified Data.Text as T
3434
import Data.Text.Encoding
3535
import Data.ByteString.Lazy (ByteString)
3636
import Data.ByteString.Base64 (encode,decode)
37-
import CompileMode
3837
import TroupePositionInfo
3938
import qualified Data.Aeson as Aeson
4039
import GHC.Generics (Generic)

compiler/src/RawDefUse.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ import qualified Data.Text as T
3939
import Data.Text.Encoding
4040
import Data.ByteString.Lazy (ByteString)
4141
import Data.ByteString.Base64 (encode,decode)
42-
import CompileMode
4342
import TroupePositionInfo
4443
import qualified Data.Aeson as Aeson
4544
import GHC.Generics (Generic)

compiler/src/Stack.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import Control.Monad.Writer
3030
import Data.List
3131
import qualified Data.ByteString as BS
3232

33-
import CompileMode
3433
import Text.PrettyPrint.HughesPJ (hsep, nest, text, vcat, ($$), (<+>))
3534
import qualified Text.PrettyPrint.HughesPJ as PP
3635
import TroupePositionInfo

compiler/src/Stack2JS.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ stack2PPDoc compileMode debugMode (ProgramStackUnit sp) =
154154
$$ PP.rbrace
155155
$$ PP.text "module.exports = Top"
156156

157-
ppDoc = case compileMode of CompileMode.Export -> inner
158-
CompileMode.Normal -> outer
157+
ppDoc = case compileMode of CompileMode.Library -> inner
158+
_ -> outer
159159
in (ppDoc, w)
160160

161161
stack2PPDoc _ debugMode su =

0 commit comments

Comments
 (0)