This commit is contained in:
@@ -120,13 +120,13 @@ driver opts = do
|
|||||||
hPutStrLn FS.stdout . view strict . pShowNoColor $ scm
|
hPutStrLn FS.stdout . view strict . pShowNoColor $ scm
|
||||||
cps <- convertProgram scm
|
cps <- convertProgram scm
|
||||||
when opts.dumpCPS do
|
when opts.dumpCPS do
|
||||||
hPutStrLn FS.stdout =<< S.encodeWith S.datumIso cps
|
S.writeDatum cps
|
||||||
closedCps <- closeProgram cps
|
closedCps <- closeProgram cps
|
||||||
when opts.dumpClosed do
|
when opts.dumpClosed do
|
||||||
hPutStrLn FS.stdout =<< S.encodeWith S.datumIso closedCps
|
S.writeData closedCps
|
||||||
hoistedCps <- hoistProgram closedCps
|
hoistedCps <- hoistProgram closedCps
|
||||||
when opts.dumpHoisted do
|
when opts.dumpHoisted do
|
||||||
hPutStrLn FS.stdout =<< S.encodeWith S.datumIso hoistedCps
|
S.writeData hoistedCps
|
||||||
-- contifiedCps <- contifyProgram hoistedCps
|
-- contifiedCps <- contifyProgram hoistedCps
|
||||||
-- when opts.dumpContified do
|
-- when opts.dumpContified do
|
||||||
-- hPutStrLn FS.stdout =<< S.encodeWith S.datumIso contifiedCps
|
-- hPutStrLn FS.stdout =<< S.encodeWith S.datumIso contifiedCps
|
||||||
@@ -139,8 +139,7 @@ driver opts = do
|
|||||||
>>> hPutStrLn FS.stdout)
|
>>> hPutStrLn FS.stdout)
|
||||||
when (rt_is #CPS) do
|
when (rt_is #CPS) do
|
||||||
CPS.evalProgram closedCps
|
CPS.evalProgram closedCps
|
||||||
>>= S.encodeDataWith S.dataIso
|
>>= S.writeData
|
||||||
>>= hPutStrLn FS.stdout
|
|
||||||
-- dumpOrRun opts.inspectWasm (rt_is #Wasm)
|
-- dumpOrRun opts.inspectWasm (rt_is #Wasm)
|
||||||
-- (lowerProgram cps)
|
-- (lowerProgram cps)
|
||||||
-- inspectWasm
|
-- inspectWasm
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ module Gyehoek.Sexp.Grammar
|
|||||||
, fromDatumUnsafe
|
, fromDatumUnsafe
|
||||||
, Control.Category.id
|
, Control.Category.id
|
||||||
, fromDataUnsafe
|
, fromDataUnsafe
|
||||||
|
, writeDatum
|
||||||
|
, writeData
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
|
|
||||||
@@ -45,6 +47,7 @@ import qualified Control.Category
|
|||||||
import qualified Data.Vector as V
|
import qualified Data.Vector as V
|
||||||
import Data.String (IsString (fromString))
|
import Data.String (IsString (fromString))
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
|
import System.Environment (lookupEnv)
|
||||||
|
|
||||||
|
|
||||||
toDatum :: Jalmot :> es => DatumGrammar a -> a -> Eff es Datum
|
toDatum :: Jalmot :> es => DatumGrammar a -> a -> Eff es Datum
|
||||||
@@ -126,6 +129,39 @@ encodeOrShow' g x = fromString $
|
|||||||
Left _ -> show x
|
Left _ -> show x
|
||||||
Right t -> T.unpack t
|
Right t -> T.unpack t
|
||||||
|
|
||||||
|
encodeOrShow :: (IsString s, Show a) => DatumGrammar a -> a -> s
|
||||||
|
encodeOrShow g x = fromString $
|
||||||
|
case runPureEff . runJalmot . encodeWith' g $ x of
|
||||||
|
Left _ -> show x
|
||||||
|
Right t -> T.unpack t
|
||||||
|
|
||||||
|
encodeOrShowData' :: (IsString s, Show a) => DataGrammar a -> a -> s
|
||||||
|
encodeOrShowData' g x = fromString $
|
||||||
|
case runPureEff . runJalmot . encodeDataWith' g $ x of
|
||||||
|
Left _ -> show x
|
||||||
|
Right t -> T.unpack t
|
||||||
|
|
||||||
|
encodeOrShowData :: (IsString s, Show a) => DataGrammar a -> a -> s
|
||||||
|
encodeOrShowData g x = fromString $
|
||||||
|
case runPureEff . runJalmot . encodeDataWith g $ x of
|
||||||
|
Left _ -> show x
|
||||||
|
Right t -> T.unpack t
|
||||||
|
|
||||||
|
useColour :: IO Bool
|
||||||
|
useColour = maybe True (const False) <$> lookupEnv "NO_COLOR"
|
||||||
|
|
||||||
|
writeDatum :: (Show a, DatumIso a, MonadIO m) => a -> m ()
|
||||||
|
writeDatum x = do
|
||||||
|
c <- liftIO useColour
|
||||||
|
let f = if c then encodeOrShow else encodeOrShow'
|
||||||
|
liftIO . TIO.putStrLn . f datumIso $ x
|
||||||
|
|
||||||
|
writeData :: (Show a, DataIso a, MonadIO m) => a -> m ()
|
||||||
|
writeData x = do
|
||||||
|
c <- liftIO useColour
|
||||||
|
let f = if c then encodeOrShowData else encodeOrShowData'
|
||||||
|
liftIO . TIO.putStrLn . f dataIso $ x
|
||||||
|
|
||||||
class DatumIso a where
|
class DatumIso a where
|
||||||
datumIso :: DatumGrammar a
|
datumIso :: DatumGrammar a
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user