fix catching of exceptions in tests

This commit is contained in:
2026-08-18 23:50:13 -06:00
parent eb51f4fff7
commit ca1b53f3d1
11 changed files with 61 additions and 22 deletions
+1
View File
@@ -34,6 +34,7 @@ import Gyehoek.Stack.VM (eval, writeObj, Obj)
import qualified Data.Text as T
import Data.List (List)
import Gyehoek.Stack.Syntax (encodeProgram)
import Effectful.Exception
main :: IO ()
+16 -8
View File
@@ -57,12 +57,13 @@ import Effectful.FileSystem (runFileSystem)
import qualified Effectful.FileSystem.IO as FS
import qualified Data.Text.Encoding as T
import qualified Effectful.FileSystem.IO.ByteString as FB
import Control.DeepSeq (NFData)
newtype Name = MkName { inner :: Text }
deriving newtype (Show, Eq, Ord, IsString, Gen, Hashable)
deriving stock (Generic, Data)
deriving anyclass (Wrapped)
deriving anyclass (Wrapped, NFData)
instance Prefixed Name where
prefixed (MkName s) = _Wrapped' . prefixed @Text s . from _Wrapped'
@@ -87,7 +88,8 @@ data Prim e
| PrimMakeClosure { code :: e, env :: List e }
| PrimEnvRef e Int
| PrimCallCC e
deriving (Show, Generic, Functor, Foldable, Traversable, Data, Eq)
deriving stock (Show, Generic, Functor, Foldable, Traversable, Data, Eq)
deriving anyclass (NFData)
instance Each (Prim e) (Prim e') e e'
@@ -97,7 +99,8 @@ data Lit
| LitBool Bool
| LitString Text
| LitQuote Sexp
deriving (Show, Generic, Data, Eq)
deriving stock (Show, Generic, Data, Eq)
deriving anyclass (NFData)
pattern Void :: Lit
pattern Void = LitNil
@@ -105,7 +108,8 @@ pattern Void = LitNil
data Def
= DefConstant Name Exp
| DefProcedure Name (List Name) (List Exp)
deriving (Show, Generic, Data)
deriving stock (Show, Generic, Data)
deriving anyclass (NFData)
data Exp
= ExpLet (NonEmpty (Name, Exp)) Exp
@@ -117,24 +121,28 @@ data Exp
| ExpLambda (List Name) Exp
| ExpVar Name
| ExpApply Exp (List Exp)
deriving (Show, Generic, Data)
deriving stock (Show, Generic, Data)
deriving anyclass (NFData)
data Sexp
= SexpCons Sexp Sexp
| SexpSymbol Text
| SexpLit Lit
deriving (Show, Generic, Data, Eq)
deriving stock (Show, Generic, Data, Eq)
deriving anyclass (NFData)
data CommandOrDef
= Command Exp
| Definition Def
| Begin (List CommandOrDef)
deriving (Show, Generic, Data)
deriving stock (Show, Generic, Data)
deriving anyclass (NFData)
data Program = MkProgram
{ commandsAndDefs :: List CommandOrDef
}
deriving (Show, Generic, Data)
deriving stock (Show, Generic, Data)
deriving anyclass (NFData)
instance Each Program Program (Either Exp Def) (Either Exp Def) where
each = #commandsAndDefs . each . go
+9 -1
View File
@@ -1,6 +1,7 @@
{-# LANGUAGE TemplateHaskellQuotes #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE DeriveAnyClass #-}
module Gyehoek.Stack.Syntax
( Program(..)
, Block(..)
@@ -32,6 +33,7 @@ import Effectful
import Gyehoek.Scheme.Syntax (Name(..), Lit(..), Prim(..))
import GHC.Exts (IsList(..))
import Data.List (intersperse)
import Control.DeepSeq (NFData)
newtype Program = MkProgram
@@ -39,6 +41,7 @@ newtype Program = MkProgram
}
deriving stock (Show, Generic, Data)
deriving newtype (Semigroup, Monoid)
deriving anyclass (NFData)
instance IsList Program where
type Item Program = Block
@@ -51,6 +54,7 @@ data Block = MkBlock
, code :: List Instr
}
deriving stock (Show, Generic, Data)
deriving anyclass (NFData)
instance Each Block Block Instr Instr where
each = #code . each
@@ -64,11 +68,13 @@ data Instr
| Call Val (List Val)
| If Val (List Instr) (List Instr)
deriving stock (Show, Generic, Data)
deriving anyclass (NFData)
data Val
= ValReg Name
| ValImm Imm
deriving stock (Show, Generic, Data, Eq)
deriving anyclass (NFData)
pattern ValLabel :: Name -> Val
pattern ValLabel x = ValImm (ImmLabel x)
@@ -78,10 +84,12 @@ data Imm
| ImmBool Bool
| ImmLabel Name
deriving stock (Show, Generic, Data, Eq)
deriving anyclass (NFData)
data Obj
= ObjImm Imm
deriving (Show, Generic, Data, Eq)
deriving stock (Show, Generic, Data, Eq)
deriving anyclass (NFData)
--- sexp work