urbit/pkg/hs/urbit-king/lib/Ur/King/TryJamPill.hs

53 lines
1.3 KiB
Haskell
Raw Normal View History

2020-01-23 07:16:09 +03:00
{-|
Test jam/cue on pills.
-}
module Ur.King.TryJamPill where
2019-04-26 00:02:19 +03:00
import ClassyPrelude
import Control.Lens
2020-01-23 05:58:22 +03:00
import Ur.Noun
2019-04-26 00:02:19 +03:00
--------------------------------------------------------------------------------
main :: IO ()
main = do
2019-07-03 08:14:39 +03:00
print "cue brass" -- void getLine
tryCueJamPill Brass
2019-07-03 08:14:39 +03:00
print "cue ivory" -- void getLine
tryCueJamPill Ivory
2019-07-03 08:14:39 +03:00
print "cue solid" -- void getLine
tryCueJamPill Solid
2019-07-12 04:16:40 +03:00
loadNoun :: FilePath -> IO (Maybe Noun)
loadNoun = fmap (preview _Cue) . readFile
dumpJam :: FilePath -> Noun -> IO ()
dumpJam fp = writeFile fp . view (re _Cue)
tryCuePill :: PillFile -> IO ()
tryCuePill pill =
loadNoun (show pill) >>= \case Nothing -> print "nil"
Just (Atom _) -> print "atom"
Just (Cell _ _) -> print "cell"
tryCueJamPill :: PillFile -> IO ()
tryCueJamPill pill = do
n <- loadNoun (show pill) >>= \case
Nothing -> print "failure" >> pure (Atom 0)
Just n@(Atom _) -> print "atom" >> pure n
Just n@(Cell _ _) -> print "cell" >> pure n
bs <- evaluate (force (jamBS n))
print ("jam size: " <> show (length bs))
data PillFile = Brass | Ivory | Solid
instance Show PillFile where
show = \case
Brass -> "./bin/brass.pill"
Solid -> "./bin/solid.pill"
Ivory -> "./bin/ivory.pill"