{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE UndecidableInstances #-}
module Bytezap.Struct.Generic where
import Bytezap.Struct
import GHC.Generics
import GHC.Exts
type family UnwrapGenericS1 a where
UnwrapGenericS1 (S1 c (Rec0 a)) = a
class GPokeBase idx where
type GPokeBaseSt idx
type GPokeBaseC idx a :: Constraint
gPokeBase :: GPokeBaseC idx a => a -> Poke# (GPokeBaseSt idx)
type KnownSizeOf' idx a :: Constraint
sizeOf' :: forall a. KnownSizeOf' idx a => Proxy# a -> Int#
class GPoke idx f where gPoke :: f p -> Poke# (GPokeBaseSt idx)
instance GPoke idx f => GPoke idx (D1 c f) where gPoke :: forall (p :: k). D1 c f p -> Poke# (GPokeBaseSt idx)
gPoke = forall (idx :: k) (f :: k -> Type) (p :: k).
GPoke idx f =>
f p -> Poke# (GPokeBaseSt idx)
forall {k} {k} (idx :: k) (f :: k -> Type) (p :: k).
GPoke idx f =>
f p -> Poke# (GPokeBaseSt idx)
gPoke @idx (f p -> Poke# (GPokeBaseSt idx))
-> (D1 c f p -> f p) -> D1 c f p -> Poke# (GPokeBaseSt idx)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. D1 c f p -> f p
forall k i (c :: Meta) (f :: k -> Type) (p :: k). M1 i c f p -> f p
unM1
instance GPoke idx f => GPoke idx (C1 c f) where gPoke :: forall (p :: k). C1 c f p -> Poke# (GPokeBaseSt idx)
gPoke = forall (idx :: k) (f :: k -> Type) (p :: k).
GPoke idx f =>
f p -> Poke# (GPokeBaseSt idx)
forall {k} {k} (idx :: k) (f :: k -> Type) (p :: k).
GPoke idx f =>
f p -> Poke# (GPokeBaseSt idx)
gPoke @idx (f p -> Poke# (GPokeBaseSt idx))
-> (C1 c f p -> f p) -> C1 c f p -> Poke# (GPokeBaseSt idx)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. C1 c f p -> f p
forall k i (c :: Meta) (f :: k -> Type) (p :: k). M1 i c f p -> f p
unM1
instance (GPoke idx l, GPoke idx r, GPokeBase idx, KnownSizeOf' idx (UnwrapGenericS1 l))
=> GPoke idx (l :*: r) where
gPoke :: forall (p :: k). (:*:) l r p -> Poke# (GPokeBaseSt idx)
gPoke (l p
l :*: r p
r) Addr#
base# = \Int#
os# State# (GPokeBaseSt idx)
s0 ->
case forall (idx :: k) (f :: k -> Type) (p :: k).
GPoke idx f =>
f p -> Poke# (GPokeBaseSt idx)
forall {k} {k} (idx :: k) (f :: k -> Type) (p :: k).
GPoke idx f =>
f p -> Poke# (GPokeBaseSt idx)
gPoke @idx l p
l Addr#
base# Int#
os# State# (GPokeBaseSt idx)
s0 of
State# (GPokeBaseSt idx)
s1 -> forall (idx :: k) (f :: k -> Type) (p :: k).
GPoke idx f =>
f p -> Poke# (GPokeBaseSt idx)
forall {k} {k} (idx :: k) (f :: k -> Type) (p :: k).
GPoke idx f =>
f p -> Poke# (GPokeBaseSt idx)
gPoke @idx r p
r Addr#
base# (Int#
os# Int# -> Int# -> Int#
+# forall (idx :: k) a.
(GPokeBase idx, KnownSizeOf' idx a) =>
Proxy# a -> Int#
forall {k} (idx :: k) a.
(GPokeBase idx, KnownSizeOf' idx a) =>
Proxy# a -> Int#
sizeOf' @idx @(UnwrapGenericS1 l) Proxy# (UnwrapGenericS1 l)
forall {k} (a :: k). Proxy# a
proxy#) State# (GPokeBaseSt idx)
s1
instance (GPokeBase idx, GPokeBaseC idx a) => GPoke idx (S1 c (Rec0 a)) where
gPoke :: forall (p :: k). S1 c (Rec0 a) p -> Poke# (GPokeBaseSt idx)
gPoke = forall (idx :: k) a.
(GPokeBase idx, GPokeBaseC idx a) =>
a -> Poke# (GPokeBaseSt idx)
forall {k} (idx :: k) a.
(GPokeBase idx, GPokeBaseC idx a) =>
a -> Poke# (GPokeBaseSt idx)
gPokeBase @idx (a -> Poke# (GPokeBaseSt idx))
-> (S1 c (Rec0 a) p -> a)
-> S1 c (Rec0 a) p
-> Poke# (GPokeBaseSt idx)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. K1 R a p -> a
forall k i c (p :: k). K1 i c p -> c
unK1 (K1 R a p -> a)
-> (S1 c (Rec0 a) p -> K1 R a p) -> S1 c (Rec0 a) p -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. S1 c (Rec0 a) p -> K1 R a p
forall k i (c :: Meta) (f :: k -> Type) (p :: k). M1 i c f p -> f p
unM1
instance GPoke idx U1 where gPoke :: forall (p :: k). U1 p -> Poke# (GPokeBaseSt idx)
gPoke U1 p
U1 Addr#
_base# = \Int#
_os# State# (GPokeBaseSt idx)
s0 -> State# (GPokeBaseSt idx)
s0