From 1977b7ad1e86d2b922737eb04741607e9c9a991a Mon Sep 17 00:00:00 2001 From: Matthew Hall Date: Fri, 24 Feb 2023 23:03:33 +1300 Subject: Better printing functions --- DSL/Intrinsics.hs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'DSL/Intrinsics.hs') diff --git a/DSL/Intrinsics.hs b/DSL/Intrinsics.hs index 930a8a0..f3784a8 100644 --- a/DSL/Intrinsics.hs +++ b/DSL/Intrinsics.hs @@ -10,8 +10,9 @@ dump = StackModifier { smName="DUMP", smTypes=ts, smFunc=f } f (x:xs) = putStrLn x' >> return (Right $ xs) where x' = case x of - StackString s -> s - _ -> show x + StackString s -> "String:" ++ show s + StackInt i -> "Integer:" ++ show i + StackBool b -> "Boolean:" ++ show b f _ = unreachable drop' :: StackModifier @@ -119,3 +120,15 @@ greaterThan = StackModifier { smName="GREATERTHAN", smTypes=ts, smFunc=f } f (StackInt x:StackInt y:xs) = return $ Right $ StackBool(x > y):xs f _ = unreachable +put :: StackModifier +put = StackModifier { smName="PUT", smTypes=[tAny], smFunc=f } + where + f (x:xs) = putStr x' >> return (Right xs) + where + x' = case x of + StackBool True -> "true" + StackBool False -> "false" + StackInt i -> show i + StackString s -> s + f _ = unreachable + -- cgit v1.2.1