3 | module Text.ILex.DStack
6 | import Text.ILex.Interfaces
7 | import Text.ILex.Parser
19 | data Stack : Bool -> (s : List Type -> Type) -> List Type -> Type where
20 | Nil : Stack False s []
21 | (:>) : (st : s ts) -> Stack b s ts -> Stack True s []
22 | (::) : (v : t) -> Stack b s ts -> Stack False s (t::ts)
24 | public export %inline
25 | push : {0 s : _} -> s [t] -> (v : t) -> Stack b s [] -> Stack True s []
26 | push st v stck = st :> v :: stck
33 | record DStack (s : List Type -> Type) (e : Type) (q : Type) where
38 | positions_ : Ref q (SnocList Position)
39 | strings_ : Ref q (SnocList String)
40 | stack_ : Ref q (Stack True s [])
41 | error_ : Ref q (Maybe $
BoundedErr e)
42 | bytes_ : Ref q ByteString
46 | init : Stack True s [] -> F1 q (DStack s e q)
55 | pure (S ln cl ps ss sk er bs)
58 | HasStack (DStack s e) (Stack True s []) where
62 | HasError (DStack s e) e where
66 | HasPosition (DStack s e) where
69 | positions = positions_
72 | HasBytes (DStack s e) where
76 | HasStringLits (DStack s e) where
80 | 0 StateAct : Type -> (s : List Type -> Type) -> Bits32 -> Type
88 | parameters {auto sk : DStack s e q}
91 | dact : StateAct q s r -> F1 q (Index r)
93 | let (st:>x) # t := read1 sk.stack_ t
97 | dput : s ts -> Cast (s ts) a => Stack b s ts -> F1 q a
98 | dput st x = writeAs sk.stack_ (st:>x) (cast st)
101 | dpush : s [t] -> Cast (s [t]) a => t -> F1 q a
103 | let stck # t := read1 sk.stack_ t
104 | in writeAs sk.stack_ (st:>v::stck) (cast st) t
107 | derr : s [] -> Cast (s []) a => s ts -> Stack b s ts -> F1 q a
108 | derr err st x = writeAs sk.stack_ (err:>st:>x) (cast err)