@@ -60,10 +60,15 @@ library
|
|||||||
Gyehoek.CPS.Syntax
|
Gyehoek.CPS.Syntax
|
||||||
Gyehoek.Driver
|
Gyehoek.Driver
|
||||||
Gyehoek.GenSym
|
Gyehoek.GenSym
|
||||||
|
Gyehoek.Language
|
||||||
Gyehoek.Options
|
Gyehoek.Options
|
||||||
Gyehoek.Prelude
|
Gyehoek.Prelude
|
||||||
Gyehoek.Scheme.Syntax
|
Gyehoek.Scheme.Syntax
|
||||||
Gyehoek.Sexp
|
Gyehoek.Sexp
|
||||||
|
Gyehoek.Sexp.Grammar
|
||||||
|
Gyehoek.Sexp.Print
|
||||||
|
Gyehoek.Sexp.Read
|
||||||
|
Gyehoek.Sexp.Syntax
|
||||||
Gyehoek.Stack.Syntax
|
Gyehoek.Stack.Syntax
|
||||||
Gyehoek.Stack.VM
|
Gyehoek.Stack.VM
|
||||||
Gyehoek.Wasm
|
Gyehoek.Wasm
|
||||||
@@ -90,6 +95,7 @@ library
|
|||||||
, prettyprinter
|
, prettyprinter
|
||||||
, process
|
, process
|
||||||
, recursion-schemes
|
, recursion-schemes
|
||||||
|
, scientific
|
||||||
, sexp-grammar
|
, sexp-grammar
|
||||||
, string-interpolate
|
, string-interpolate
|
||||||
, template-haskell
|
, template-haskell
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
{-# LANGUAGE TypeFamilies #-}
|
||||||
|
{-# LANGUAGE AllowAmbiguousTypes #-}
|
||||||
|
module Gyehoek.Language
|
||||||
|
( Language(..)
|
||||||
|
) where
|
||||||
|
|
||||||
|
import Data.Kind (Type)
|
||||||
|
import Gyehoek.Prelude
|
||||||
|
import Language.SexpGrammar (Position, Grammar, (:-), Sexp)
|
||||||
|
|
||||||
|
|
||||||
|
class Language l where
|
||||||
|
type Program l :: Type
|
||||||
|
languageName :: Text
|
||||||
|
programGrammar :: forall t. Grammar Position (List Sexp :- t) (Program l :- t)
|
||||||
|
|
||||||
|
readProgramFile
|
||||||
|
:: forall l es. Language l
|
||||||
|
=> FilePath -> Eff es (Program l)
|
||||||
|
readProgramFile fp = _
|
||||||
|
|
||||||
|
readProgramStringPos
|
||||||
|
:: forall l. Language l
|
||||||
|
=> Position -> Text -> Either Text (Program l)
|
||||||
|
readProgramStringPos pos s = _
|
||||||
+32
-3
@@ -2,8 +2,9 @@
|
|||||||
{-# LANGUAGE RecordWildCards #-}
|
{-# LANGUAGE RecordWildCards #-}
|
||||||
module Gyehoek.Options
|
module Gyehoek.Options
|
||||||
( Options(..)
|
( Options(..)
|
||||||
, Runtime(..)
|
|
||||||
, parser
|
, parser
|
||||||
|
, Runtime(..)
|
||||||
|
, Language(..)
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
|
|
||||||
@@ -13,7 +14,15 @@ import Gyehoek.Prelude hiding (argument)
|
|||||||
|
|
||||||
|
|
||||||
data Runtime = Stackify | Wasm | CPS
|
data Runtime = Stackify | Wasm | CPS
|
||||||
deriving (Show, Generic)
|
deriving (Show, Generic, Eq)
|
||||||
|
|
||||||
|
data Language
|
||||||
|
= LanguageScheme
|
||||||
|
| LanguageCPS
|
||||||
|
| LanguageClosed
|
||||||
|
| LanguageStackified
|
||||||
|
| LanguageWasm
|
||||||
|
deriving (Show, Generic, Eq)
|
||||||
|
|
||||||
data Options = MkOptions
|
data Options = MkOptions
|
||||||
{ dumpClosed :: Bool
|
{ dumpClosed :: Bool
|
||||||
@@ -24,9 +33,20 @@ data Options = MkOptions
|
|||||||
, inspectWasm :: Bool
|
, inspectWasm :: Bool
|
||||||
, output :: FilePath
|
, output :: FilePath
|
||||||
, sourceFile :: FilePath
|
, sourceFile :: FilePath
|
||||||
|
, sourceLanguage :: Language
|
||||||
}
|
}
|
||||||
deriving (Show, Generic)
|
deriving (Show, Generic)
|
||||||
|
|
||||||
|
languageValues = ["scheme","cps","closed","stackified","wasm"]
|
||||||
|
languageReader = maybeReader \case
|
||||||
|
"scheme" -> Just LanguageScheme
|
||||||
|
"cps" -> Just LanguageCPS
|
||||||
|
"closed" -> Just LanguageClosed
|
||||||
|
"stackified" -> Just LanguageStackified
|
||||||
|
"wasm" -> Just LanguageWasm
|
||||||
|
_ -> Nothing
|
||||||
|
|
||||||
|
runtimeValues = ["stackify","wasm","cps","none"]
|
||||||
runtimeReader = maybeReader \case
|
runtimeReader = maybeReader \case
|
||||||
"stackify" -> Just (Just Stackify)
|
"stackify" -> Just (Just Stackify)
|
||||||
"wasm" -> Just (Just Wasm)
|
"wasm" -> Just (Just Wasm)
|
||||||
@@ -45,8 +65,17 @@ parser = do
|
|||||||
[ long "runtime"
|
[ long "runtime"
|
||||||
, short 'R'
|
, short 'R'
|
||||||
, value (Just Stackify)
|
, value (Just Stackify)
|
||||||
, completeWith ["stackify","wasm","cps","none"]
|
, completeWith runtimeValues
|
||||||
, showDefaultWith $ const "stackify"
|
, showDefaultWith $ const "stackify"
|
||||||
|
, metavar "RUNTIME"
|
||||||
|
]
|
||||||
|
sourceLanguage <- option languageReader . fold $
|
||||||
|
[ long "source"
|
||||||
|
, short 'S'
|
||||||
|
, value LanguageScheme
|
||||||
|
, completeWith languageValues
|
||||||
|
, showDefaultWith $ const "scheme"
|
||||||
|
, metavar "LANGUAGE"
|
||||||
]
|
]
|
||||||
output <- strOption . fold $
|
output <- strOption . fold $
|
||||||
[ long "output"
|
[ long "output"
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ module Gyehoek.Prelude
|
|||||||
, IsList(fromList)
|
, IsList(fromList)
|
||||||
, HasCallStack
|
, HasCallStack
|
||||||
, Hashable
|
, Hashable
|
||||||
|
, NonEmpty((:|))
|
||||||
|
, Natural
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Lens
|
import Control.Lens
|
||||||
@@ -31,4 +33,6 @@ import Data.Generics.Labels ()
|
|||||||
import Data.String.Interpolate
|
import Data.String.Interpolate
|
||||||
import GHC.Stack (HasCallStack)
|
import GHC.Stack (HasCallStack)
|
||||||
import Data.Hashable (Hashable)
|
import Data.Hashable (Hashable)
|
||||||
|
import Data.List.NonEmpty (NonEmpty((:|)))
|
||||||
|
import Numeric.Natural (Natural)
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ module Gyehoek.Sexp
|
|||||||
, encodePrettyWith
|
, encodePrettyWith
|
||||||
, encodePretty
|
, encodePretty
|
||||||
, SpliceSexp(..)
|
, SpliceSexp(..)
|
||||||
|
, Position(..)
|
||||||
, parseSexpsWithPos
|
, parseSexpsWithPos
|
||||||
, parseSexpWithPos
|
, parseSexpWithPos
|
||||||
, parseSexp
|
, parseSexp
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
module Gyehoek.Sexp.Grammar
|
||||||
|
(
|
||||||
|
) where
|
||||||
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
module Gyehoek.Sexp.Print
|
||||||
|
(
|
||||||
|
) where
|
||||||
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
module Gyehoek.Sexp.Read
|
||||||
|
(
|
||||||
|
) where
|
||||||
|
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
{-# LANGUAGE DeriveAnyClass #-}
|
||||||
|
module Gyehoek.Sexp.Syntax
|
||||||
|
( DatumF(..)
|
||||||
|
, Simple(..)
|
||||||
|
, CompoundF(..)
|
||||||
|
, Prefix(..)
|
||||||
|
, Delimiter(..)
|
||||||
|
, Label(..)
|
||||||
|
) where
|
||||||
|
|
||||||
|
import Language.Haskell.TH.Syntax (Lift)
|
||||||
|
import Data.Scientific (Scientific)
|
||||||
|
import Data.ByteString (ByteString)
|
||||||
|
import Gyehoek.Prelude hiding (Simple)
|
||||||
|
|
||||||
|
|
||||||
|
data DatumF a
|
||||||
|
= SimpleF Simple
|
||||||
|
| CompoundF (CompoundF a)
|
||||||
|
| LabeledF Label a
|
||||||
|
| LabelRefF Label
|
||||||
|
deriving stock (Show, Eq, Data, Generic, Lift)
|
||||||
|
deriving anyclass (NFData)
|
||||||
|
|
||||||
|
data Simple
|
||||||
|
= SimpleBool Bool
|
||||||
|
| SimpleNumber Scientific
|
||||||
|
| SimpleChar
|
||||||
|
| SimpleString
|
||||||
|
| SimpleSymbol
|
||||||
|
| SimpleBytevector ByteString
|
||||||
|
deriving stock (Show, Eq, Data, Generic, Lift)
|
||||||
|
deriving anyclass (NFData)
|
||||||
|
|
||||||
|
data CompoundF a
|
||||||
|
= ListF (List a)
|
||||||
|
| DotListF (NonEmpty a) a
|
||||||
|
| VectorF (List a)
|
||||||
|
| AbbrevF Prefix a
|
||||||
|
deriving stock (Show, Eq, Data, Generic, Lift)
|
||||||
|
deriving anyclass (NFData)
|
||||||
|
|
||||||
|
data Prefix
|
||||||
|
= Quote | Backtick | Comma | CommaAt
|
||||||
|
deriving stock (Show, Eq, Data, Generic, Lift)
|
||||||
|
deriving anyclass (NFData)
|
||||||
|
|
||||||
|
data Delimiter
|
||||||
|
= Paren
|
||||||
|
| Square
|
||||||
|
| Curly
|
||||||
|
deriving stock (Show, Eq, Data, Generic, Lift)
|
||||||
|
deriving anyclass (NFData)
|
||||||
|
|
||||||
|
newtype Label = MkLabel Natural
|
||||||
|
deriving stock (Data, Generic, Lift)
|
||||||
|
deriving newtype (Eq, Ord, Show)
|
||||||
|
deriving anyclass (NFData)
|
||||||
Reference in New Issue
Block a user