on master help sign in
Second hax optimization
0983c2ciko
src/Nock.hs+5−8
@@ -46,9 +46,6 @@ twoThree = cell two three
46sigOne :: Noun
46sigOne :: Noun
47sigOne = cell sig one
47sigOne = cell sig one
48
48
49−sigThree :: Noun
50−sigThree = cell sig three
51−
52annotation :: RawNoun ann -> ann
49annotation :: RawNoun ann -> ann
53annotation (Atom _ ann) = ann
50annotation (Atom _ ann) = ann
54annotation (Cell _ _ ann) = ann
51annotation (Cell _ _ ann) = ann
@@ -99,13 +96,13 @@ fas lhs rhs =
99 else fas 3 (fas d rhs)
96 else fas 3 (fas d rhs)
100 _ -> undefined
97 _ -> undefined
101
98
102−hax :: Natural -> Noun -> Noun
99+hax :: Natural -> Noun -> Noun -> Noun
103−hax n ~(Cell b c _) =
100+hax n b c =
104 let (a, m) = divMod n 2
101 let (a, m) = divMod n 2
105 in case n of
102 in case n of
106 1 -> b
103 1 -> b
107− _ | m == 0 -> hax a (cell (cell b (fas (a + a + 1) c)) c)
104+ _ | m == 0 -> hax a (cell b (fas (a + a + 1) c)) c
108− _ -> hax a (cell (cell (fas (a + a) c) b) c)
105+ _ -> hax a (cell (fas (a + a) c) b) c
109
106
110tar :: Noun -> Noun
107tar :: Noun -> Noun
111tar ~(Cell subject ~(Cell a b _) _) = tar' a b subject
108tar ~(Cell subject ~(Cell a b _) _) = tar' a b subject
@@ -136,7 +133,7 @@ tar' b c subject = case b of
136 6 -> case tar' sig (tar' sig (tar' four (cell four x) subject) twoThree) (cell h j) of
133 6 -> case tar' sig (tar' sig (tar' four (cell four x) subject) twoThree) (cell h j) of
137 ~(Cell u v _) -> tar' u v subject
134 ~(Cell u v _) -> tar' u v subject
138 10 -> case x of
135 10 -> case x of
139− ~(Cell ~(Atom b' _) ~(Cell u v _) _) -> hax b' $ cell (tar' u v subject) $ tar' h j subject
136+ ~(Cell ~(Atom b' _) ~(Cell u v _) _) -> hax b' (tar' u v subject) (tar' h j subject)
140 11 -> case x of
137 11 -> case x of
141 Cell _ ~(Cell u v _) _ -> tar' sig three (cell (tar' u v subject) (tar' h j subject))
138 Cell _ ~(Cell u v _) _ -> tar' sig three (cell (tar' u v subject) (tar' h j subject))
142 Atom _ _ -> tar' h j subject
139 Atom _ _ -> tar' h j subject