77 lines
2.1 KiB
Haskell
77 lines
2.1 KiB
Haskell
{- HLINT ignore "Use newtype instead of data" -}
|
|
{-# LANGUAGE TypeFamilies #-}
|
|
{-# LANGUAGE DeepSubsumption #-}
|
|
{-# LANGUAGE NoFieldSelectors #-}
|
|
{-# LANGUAGE OverloadedRecordDot #-}
|
|
{-# LANGUAGE RecordPuns #-}
|
|
{-# LANGUAGE DuplicateRecordFields #-}
|
|
{-# LANGUAGE QuasiQuotes #-}
|
|
{-# LANGUAGE OverloadedLabels #-}
|
|
{-# LANGUAGE OverloadedLists #-}
|
|
{-# LANGUAGE ImpredicativeTypes #-}
|
|
{-# LANGUAGE DerivingVia #-}
|
|
module Gyehoek.Wasm
|
|
( Module
|
|
)
|
|
where
|
|
|
|
import Language.SexpGrammar
|
|
( SexpIso(..), list, el, (>>>), rest, sym, symbol, (:-) )
|
|
import Language.SexpGrammar qualified as Sexp
|
|
import Language.SexpGrammar.Generic
|
|
import Data.List (List)
|
|
import GHC.Generics (Generic, Generically(..))
|
|
import Data.Text (Text)
|
|
import Data.String (IsString (fromString))
|
|
import Text.Printf
|
|
import Effectful
|
|
import Numeric.Natural (Natural)
|
|
import Effectful.Dispatch.Dynamic
|
|
import Effectful.State.Dynamic
|
|
import Control.Lens
|
|
import Data.Generics.Labels
|
|
import Data.Vector (Vector)
|
|
import Data.String.Interpolate
|
|
import qualified Data.Vector as V
|
|
import qualified Data.Text as T
|
|
import Effectful.Writer.Dynamic
|
|
import Control.Applicative (Alternative((<|>)))
|
|
import Control.Category qualified as Cat
|
|
import Data.Vector.Lens
|
|
import Data.Either (fromLeft, fromRight)
|
|
import Language.Sexp.Located
|
|
import qualified Gyehoek.Sexp
|
|
import GHC.IsList (IsList(..))
|
|
import Data.Coerce (coerce)
|
|
import qualified Control.Category
|
|
import Data.Functor (void)
|
|
|
|
|
|
newtype Module = MkModule { inner :: Vector Sexp }
|
|
deriving (Show, Generic)
|
|
deriving newtype (Semigroup, Monoid)
|
|
|
|
newtype Expr = MkExpr { inner :: Vector Sexp }
|
|
deriving (Show, Generic)
|
|
deriving newtype (Semigroup, Monoid)
|
|
|
|
newtype Idx = MkIdx { inner :: Natural }
|
|
deriving (Generic)
|
|
deriving newtype (Show)
|
|
|
|
|
|
-- GenMod
|
|
|
|
-- | 'GenModState' is a 'Module' paired with the numbers of functions,
|
|
-- types, globals, etc. defined in the module.
|
|
data GenModState = MkGenModState
|
|
{ mod :: Module
|
|
, funcs :: Natural
|
|
, types :: Natural
|
|
}
|
|
deriving (Show, Generic)
|
|
|
|
data GenMod :: Effect where
|
|
DefineFunction :: Sexp -> GenMod m Idx
|
|
DefineType :: Sexp -> GenMod m Idx
|