3 | module Text.ILex.DStack
6 | import Text.ILex.Interfaces
7 | import Text.ILex.Parser
19 | data Stack : Bool -> (s : SnocList Type -> Type) -> SnocList Type -> Type where
20 | Lin : Stack False s [<]
21 | (:>) : Stack b s ts -> (st : s ts) -> Stack True s [<]
22 | (:<) : Stack b s ts -> (v : t) -> Stack False s (ts:<t)
24 | public export %inline
25 | push : {0 s : _} -> Stack b s [<] -> (v : t) -> s [<t] -> Stack True s [<]
26 | push stck v st = stck :< v :> st
33 | record DStack (s : SnocList Type -> Type) (e : Type) (q : Type) where
39 | cur_ : IBuffer bufSize_
42 | from_ : Ref q (LTENat bufSize_)
43 | till_ : Ref q (LTENat bufSize_)
44 | positions_ : Ref q (SnocList BytePos)
46 | strings_ : Ref q (SnocList String)
47 | stack_ : Ref q (Stack True s [<])
48 | error_ : Ref q (Maybe $
BBErr e)
52 | init : Stack True s [<] -> (n : Nat) -> IBuffer n -> F1 q (DStack s e q)
53 | init st n buf = T1.do
54 | rf <- ref1 (first n)
55 | rt <- ref1 (first n)
60 | pure (S n empty buf 0 0 rf rt ps ss sk er)
63 | HasBytes (DStack s e) where
67 | prevOffset = prevOffset_
68 | curOffset = curOffset_
71 | positions = positions_
72 | copy s o bs buf rf rt sk =
77 | , curOffset_ := o + bs.size
83 | HasStack (DStack s e) (Stack True s [<]) where
87 | HasBBErr (DStack s e) e where
91 | HasStringLits (DStack s e) where
95 | 0 StateAct : Type -> (s : SnocList Type -> Type) -> Bits32 -> Type
103 | parameters {auto sk : DStack s e q}
106 | dact : StateAct q s r -> F1 q (Index r)
108 | let (x:>st) # t := read1 sk.stack_ t
112 | dput : s ts -> Cast (s ts) a => Stack b s ts -> F1 q a
113 | dput st x = writeAs sk.stack_ (x:>st) (cast st)
116 | dpush0 : s [<] -> Cast (s [<]) a => F1 q a
118 | let stck # t := read1 sk.stack_ t
119 | in writeAs sk.stack_ (stck:>st) (cast st) t
122 | dpush : s [<t] -> Cast (s [<t]) a => t -> F1 q a
124 | let stck # t := read1 sk.stack_ t
125 | in writeAs sk.stack_ (stck:<v:>st) (cast st) t
128 | derr : s [<] -> Cast (s [<]) a => Stack b s ts -> s ts -> F1 q a
129 | derr err st x = writeAs sk.stack_ (st:>x:>err) (cast err)