@@ -1,9 +1,11 @@
1−module Urbit exposing (..)
1+module Urbit exposing (Noun(..), mat, rub)
3import BitParser as BP exposing (BitParser)
3import BitParser as BP exposing (BitParser)
4+import BitWriter as BW exposing (BitWriter)
4import Bytes exposing (Bytes)
6import Bytes exposing (Bytes)
5−import Bytes.Decode as BD
7+import Bytes.Extra as Bytes
6−import Bytes.Encode as BE
8+import List.Extra as List
@@ -11,13 +13,39 @@ type Noun
11 | Atom Bytes
13 | Atom Bytes
18+ Bytes.toByteValues bytes |> List.all (\x -> x == 0)
21+mat : Bytes -> BitWriter -> BitWriter
29+ bytesToBits bytes |> List.dropWhileRight (\x -> x == 0)
32+ bits |> List.length |> intToBits |> List.reverse |> List.drop 1 |> List.reverse
36+ |> BW.bits (List.repeat (List.length lengthBits) 0)
38+ |> BW.bits lengthBits
14rub : BitParser Bytes
42rub : BitParser Bytes
17 |> BP.andThen
45 |> BP.andThen
18 (\zeroBit ->
46 (\zeroBit ->
19 if zeroBit == 1 then
47 if zeroBit == 1 then
20− BP.succeed (BE.unsignedInt8 0 |> BE.encode)
48+ BP.succeed Bytes.empty
@@ -40,7 +68,7 @@ rub =
40 (\preLengthRawBits ->
68 (\preLengthRawBits ->
43− BP.bitsToInt (1 :: preLengthRawBits)
71+ BP.bitsToInt (preLengthRawBits ++ [ 1 ])
45 BP.bits length
73 BP.bits length
@@ -48,7 +76,22 @@ rub =
79+bytesToBits : Bytes -> List Int
82+ BP.run (BP.rawBits (Bytes.width bytes * 8)) bytes
91+intToBits : Int -> List Int
52−-- met : BitParser Bytes
96+ else
53−-- met =
97+ Bitwise.and 1 n :: intToBits (Bitwise.shiftRightBy 1 n)