summaryrefslogtreecommitdiff
path: root/src/Interpreter/Rep.hs
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2024-10-26 00:04:14 +0200
committerTom Smeding <tom@tomsmeding.com>2024-10-26 00:04:14 +0200
commitaf51ad3cdce90ac6afe4727c8713426624ebaecd (patch)
treef9cf215d8737c2fda66f94dd46f195a809865433 /src/Interpreter/Rep.hs
parent6a0381f9c6cfc56ac805801bf4cefda8305ff055 (diff)
Debugging
Diffstat (limited to 'src/Interpreter/Rep.hs')
-rw-r--r--src/Interpreter/Rep.hs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/Interpreter/Rep.hs b/src/Interpreter/Rep.hs
index 5c20183..baf38fc 100644
--- a/src/Interpreter/Rep.hs
+++ b/src/Interpreter/Rep.hs
@@ -3,6 +3,8 @@
{-# LANGUAGE UndecidableInstances #-}
module Interpreter.Rep where
+import Data.List (intersperse)
+import Data.Foldable (toList)
import Data.IORef
import GHC.TypeError
@@ -53,3 +55,23 @@ vPair = liftV2 (,)
vUnpair :: Value (TPair a b) -> (Value a, Value b)
vUnpair (Value (x, y)) = (Value x, Value y)
+
+showValue :: Int -> STy t -> Rep t -> ShowS
+showValue _ STNil () = showString "()"
+showValue _ (STPair a b) (x, y) = showString "(" . showValue 0 a x . showString "," . showValue 0 b y . showString ")"
+showValue d (STEither a _) (Left x) = showParen (d > 10) $ showString "Left " . showValue 11 a x
+showValue d (STEither _ b) (Right y) = showParen (d > 10) $ showString "Right " . showValue 11 b y
+showValue _ (STMaybe _) Nothing = showString "Nothing"
+showValue d (STMaybe t) (Just x) = showParen (d > 10) $ showString "Just " . showValue 11 t x
+showValue d (STArr _ t) arr = showParen (d > 10) $
+ showString "arrayFromList " . showsPrec 11 (arrayShape arr)
+ . showString " ["
+ . foldr (.) id (intersperse (showString ",") $ map (showValue 0 t) (toList arr))
+ . showString "]"
+showValue _ (STScal sty) x = case sty of
+ STF32 -> shows x
+ STF64 -> shows x
+ STI32 -> shows x
+ STI64 -> shows x
+ STBool -> shows x
+showValue _ STAccum{} _ = error "Cannot show accumulators"