Skip to content

Commit f29f96d

Browse files
committed
Extend usage of 'CompileMode' to also accomodate 'Interactive Mode'
1 parent 3ecdd7f commit f29f96d

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
@@ -70,9 +70,7 @@ process :: [Flag] -> Maybe String -> String -> IO ExitCode
7070
process flags fname input = do
7171
let ast = parseProg input
7272

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

7775
let verbose = Verbose `elem` flags
7876
noRawOpt = NoRawOpt `elem` flags
@@ -90,18 +88,15 @@ process flags fname input = do
9088

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

9894
prog <- (processImports) prog_without_dependencies
9995

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

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

169-
case exports of
170-
Nothing -> return ()
171-
Just es -> writeExports outPath es
164+
-- case compileMode of Library -> ...
165+
case exports of Nothing -> return ()
166+
Just es -> writeExports outPath es
172167

173168
----- EPILOGUE --------------------------------------
174169
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
@@ -153,8 +153,8 @@ stack2PPDoc compileMode debugMode (ProgramStackUnit sp) =
153153
$$ PP.rbrace
154154
$$ PP.text "module.exports = Top"
155155

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

160160
stack2PPDoc _ debugMode su =

0 commit comments

Comments
 (0)