@@ -1,6 +1,6 @@
1{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}
1{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}
3−module Nock (tar, hax, fas, cell, atom, Annotation (..), Noun, RawNoun (..), pretty) where
3+module Nock (tar, hax, fas, cell, atom, Annotation (..), Noun, RawNoun (..)) where
5import Control.DeepSeq (NFData, force)
5import Control.DeepSeq (NFData, force)
6import Data.Bits
6import Data.Bits
@@ -13,24 +13,8 @@ import GHC.Base
13import GHC.Conc (par)
13import GHC.Conc (par)
14import GHC.Generics (Generic)
14import GHC.Generics (Generic)
15import GHC.Num
15import GHC.Num
17−newtype Annotation = Annotation
17+import Nock.Types
20− deriving stock (Show, Generic)
21− deriving anyclass (NFData)
23−atom :: Natural -> Noun
24−atom nat = Atom nat Annotation {hash = hash nat}
26−cell :: Noun -> Noun -> Noun
32− { hash = hash ((annotation lhs).hash, (annotation rhs).hash)
35sig :: Noun
19sig :: Noun
36sig = atom 0
20sig = atom 0
@@ -53,37 +37,6 @@ twoThree = cell two three
53sigOne :: Noun
37sigOne :: Noun
54sigOne = cell sig one
38sigOne = cell sig one
56−annotation :: RawNoun ann -> ann
57−annotation (Atom _ ann) = ann
58−annotation (Cell _ _ ann) = ann
62− | Cell (RawNoun ann) (RawNoun ann) ann
63− deriving stock (Generic)
64− deriving anyclass (NFData)
66−instance Show (RawNoun ann) where
67− show = TL.unpack . pretty
69−instance Eq (RawNoun ann) where
70− (Atom lhs _) == (Atom rhs _) = lhs == rhs
71− (Cell lhslhs lhsrhs _) == (Cell rhslhs rhsrhs _) =
72− let rhsRes = lhsrhs == rhsrhs
73− in (force rhsRes `par` lhslhs == rhslhs) && rhsRes
76−hashEq :: Noun -> Noun -> Bool
77−hashEq (Atom lhsNat lhsAnn) (Atom rhsNat rhsAnn) =
78− let normalEq = lhsNat == rhsNat
79− in (force normalEq `par` lhsAnn.hash == rhsAnn.hash) && normalEq
80−hashEq (Cell lhslhs lhsrhs lhsAnn) (Cell rhslhs rhsrhs rhsAnn) =
81− let normalEq = hashEq lhslhs rhslhs && hashEq lhsrhs rhsrhs
82− in (force normalEq `par` lhsAnn.hash == rhsAnn.hash) && normalEq
85−type Noun = RawNoun Annotation
87wut :: Noun -> Noun
40wut :: Noun -> Noun
88wut Cell {} = sig
41wut Cell {} = sig
89wut Atom {} = one
42wut Atom {} = one
@@ -149,9 +102,14 @@ tar' b c subject = case b of
149 4## -> case c of
102 4## -> case c of
150 ~(Cell l k _) -> lus $ tar' l k subject
103 ~(Cell l k _) -> lus $ tar' l k subject
151 _ -> case c of
104 _ -> case c of
152− ~(Cell x ~formula@(Cell h j _) _) -> case n of
105+ ~(Cell x ~(Cell h j _) _) -> case n of
153− 2## -> case (tar' h j subject, x) of
106+ 2## -> case x of
154− ~(~(Cell u v _), ~(Cell l k _)) -> tar' u v (tar' l k subject)
107+ ~(Cell l k _) -> case tar' l k subject of
108+ ~(formula@(Cell battery ~(Cell sample _ _) _)) ->
109+ if battery == Nock.Jets.dec
110+ then error "Found it!"
111+ else case (tar' h j subject) of
112+ ~(Cell u v _) -> tar' u v formula
155 5## -> case x of
113 5## -> case x of
156 ~(Cell l k _) -> tis (tar' h j subject) (tar' l k subject)
114 ~(Cell l k _) -> tis (tar' h j subject) (tar' l k subject)
157 7## -> case x of
115 7## -> case x of
@@ -164,14 +122,6 @@ tar' b c subject = case b of
164 10## -> case x of
122 10## -> case x of
165 ~(Cell ~(Atom b' _) ~(Cell u v _) _) -> hax b' (tar' u v subject) (tar' h j subject)
123 ~(Cell ~(Atom b' _) ~(Cell u v _) _) -> hax b' (tar' u v subject) (tar' h j subject)
166 11## -> case x of
124 11## -> case x of
167− Cell _ ~(Cell u v _) _ -> traceShow (formula, subject) $ tar' h j subject
125+ Cell _ ~(Cell u v _) _ -> tar' h j subject
168 Atom _ _ -> tar' h j subject
126 Atom _ _ -> tar' h j subject
169 _ -> undefined
127 _ -> undefined
171−pretty :: RawNoun ann -> TL.Text
172−pretty noun = TLB.toLazyText $ pretty' noun False
174−pretty' :: RawNoun ann -> Bool -> TLB.Builder
175−pretty' (Atom a _) _ = TLB.decimal a
176−pretty' (Cell lhs rhs _) True = pretty' lhs False <> " " <> pretty' rhs True
177−pretty' (Cell lhs rhs _) False = "[" <> pretty' lhs False <> " " <> pretty' rhs True <> "]"