diff options
author | Aleksey Veresov <aleksey@veresov.pro> | 2021-02-15 19:31:12 +0300 |
---|---|---|
committer | Aleksey Veresov <aleksey@veresov.pro> | 2021-02-15 19:31:12 +0300 |
commit | 97bbb430e4f1460858b2f1baaffc2ef804c63086 (patch) | |
tree | 4cbf88a77e471c6c21ea7935d6a54f71c72728e3 /src/Utils.hs | |
parent | 0cdd25d921202030745069dbccd16ef856e16750 (diff) | |
download | suem-97bbb430e4f1460858b2f1baaffc2ef804c63086.tar suem-97bbb430e4f1460858b2f1baaffc2ef804c63086.tar.xz suem-97bbb430e4f1460858b2f1baaffc2ef804c63086.zip |
New style of command dispatcher! =)
Diffstat (limited to 'src/Utils.hs')
-rw-r--r-- | src/Utils.hs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/Utils.hs b/src/Utils.hs new file mode 100644 index 0000000..345b085 --- /dev/null +++ b/src/Utils.hs @@ -0,0 +1,32 @@ +module Utils where + +import Data.Word +import Data.Bits +import Machine + +boolToInt :: Bool -> Int +boolToInt True = 1 +boolToInt False = 0 + +toBits :: Word16 -> [Int] +toBits x = map (boolToInt . testBit x) [0..(finiteBitSize x-1)] + +fromBits :: [Int] -> Int +fromBits = foldl (\a b -> 2 * a + b) 0 . reverse + +args2 :: (Int -> Int -> Machine -> Machine) -> + [Int] -> [Int] -> Machine -> Machine +args2 f a b = f (fromBits a) (fromBits b) + +args3 :: (Int -> Int -> Int -> Machine -> Machine) -> + [Int] -> [Int] -> [Int] -> Machine -> Machine +args3 f a b c = f (fromBits a) (fromBits b) (fromBits c) + +args4 :: (Int -> Int -> Int -> Int -> Machine -> Machine) -> + [Int] -> [Int] -> [Int] -> [Int] -> Machine -> Machine +args4 f a b c d = f (fromBits a) (fromBits b) (fromBits c) (fromBits d) + +args5 :: (Int -> Int -> Int -> Int -> Int -> Machine -> Machine) -> + [Int] -> [Int] -> [Int] -> [Int] -> [Int] -> Machine -> Machine +args5 f a b c d e = f (fromBits a) (fromBits b) (fromBits c) + (fromBits d) (fromBits e) |