공통 타이프들 조금 정의
This commit is contained in:
1 parent
71a6dda189
commit
38b4047f5d
3 files changed
+77
-2
No files matched your search
@@ -0,0 +1,64 @@
|
||||
{-# LANGUAGE DeriveAnyClass #-}
|
||||
module Gyehoek.Language.Common
|
||||
(
|
||||
-- * Syntax
|
||||
Lib(..)
|
||||
, LibName(..)
|
||||
, Exports
|
||||
, Imports
|
||||
, ExternName(..)
|
||||
, Name(..)
|
||||
) where
|
||||
|
||||
import Gyehoek.Prelude
|
||||
import Data.String (IsString)
|
||||
import Gyehoek.GenSym (Gen)
|
||||
import qualified Gyehoek.Sexp as S
|
||||
|
||||
|
||||
-- | R⁷RS 라이프러리의 표현.
|
||||
data Lib name body = MkLib
|
||||
{ name :: LibName
|
||||
, exports :: Exports name
|
||||
, imports :: Imports name
|
||||
}
|
||||
deriving (Show)
|
||||
|
||||
newtype LibName = MkLibName { getLibName :: NonEmpty Text }
|
||||
deriving stock (Show, Generic, Data, Eq)
|
||||
deriving anyclass (NFData, Hashable)
|
||||
|
||||
-- | A map whose keys are names of library definitions and whose
|
||||
-- values are the names they are exported as. An @⟨identifier⟩@ @x@
|
||||
-- corresponds to an entry @(⟨identifier⟩, ⟨identifier⟩)@, while a
|
||||
-- @(rename ⟨identifier₁⟩ ⟨identifier₂⟩)@ form corresponds to an entry
|
||||
-- @(⟨identifier₁⟩, ⟨identifier₂⟩)@.
|
||||
type Exports name = HashMap name ExternName
|
||||
|
||||
-- | A map whose keys are symbols to be brought into the library's
|
||||
-- environment and whose values are pairs of the library in which the
|
||||
-- symbol is defined and the name the symbol is exported as.
|
||||
type Imports name = HashMap name (LibName, ExternName)
|
||||
|
||||
-- | Representation of an identifier at the library boundary. While
|
||||
-- 'Name's are used within a compilation unit and may be decorated
|
||||
-- with additional structure and metadata, they are exported as
|
||||
-- 'ExternName's, which are essentially just plain strings.
|
||||
newtype ExternName = MkExternName { getExternName :: Text }
|
||||
deriving newtype (Show)
|
||||
|
||||
newtype Name = MkName { inner :: Text }
|
||||
deriving newtype (Show, Eq, Ord, IsString, Gen, Hashable)
|
||||
deriving stock (Generic, Data)
|
||||
deriving anyclass (Wrapped, NFData)
|
||||
|
||||
instance Prefixed Name where
|
||||
prefixed (MkName s) = _Wrapped' . prefixed @Text s . from _Wrapped'
|
||||
|
||||
|
||||
--- DatumIsos
|
||||
|
||||
instance S.DatumIso Name where
|
||||
datumIso = S.decorate S.SynVariable
|
||||
>>> S.symbol
|
||||
>>> S.iso coerce coerce
|
||||
Reference in new issue
Block a user