mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-30 10:27:11 +03:00
53 lines
1.3 KiB
Haskell
53 lines
1.3 KiB
Haskell
{-|
|
|
Test jam/cue on pills.
|
|
-}
|
|
module Urbit.King.TryJamPill where
|
|
|
|
import ClassyPrelude
|
|
import Control.Lens
|
|
import Urbit.Noun
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
main :: IO ()
|
|
main = do
|
|
print "cue brass" -- void getLine
|
|
tryCueJamPill Brass
|
|
|
|
print "cue ivory" -- void getLine
|
|
tryCueJamPill Ivory
|
|
|
|
print "cue solid" -- void getLine
|
|
tryCueJamPill Solid
|
|
|
|
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"
|