From 94938d648e021d2ace0f3b7bf383d256449d619f Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Fri, 13 Sep 2024 23:07:04 +0200 Subject: WIP better zero/plus, fixing Accum (...) The accumulator implementation was wrong because it forgot (in accumAdd) to take into account that values may be variably-sized. Furthermore, it was also complexity-inefficient because it did not build up a sparse value. Thus let's go for the Haskell-interpreter-equivalent of what a real, fast, compiled implementation would do: just a tree with mutable variables. In practice one can decide to indeed flatten parts of that tree, i.e. using a tree representation for nested pairs is bad, but that should have been done _before_ execution and for _all_ occurrences of that type fragment, not live at runtime by the accumulator implementation. --- src/AST/Pretty.hs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/AST/Pretty.hs') diff --git a/src/AST/Pretty.hs b/src/AST/Pretty.hs index 2ce883b..f5e681a 100644 --- a/src/AST/Pretty.hs +++ b/src/AST/Pretty.hs @@ -181,6 +181,13 @@ ppExpr' d val = \case return $ showParen (d > 10) $ showString ("accum " ++ show (unSNat i) ++ " ") . e1' . showString " " . e2' . showString " " . e3' + EZero _ -> return $ showString "zero" + + EPlus _ a b -> do + a' <- ppExpr' 11 val a + b' <- ppExpr' 11 val b + return $ showParen (d > 10) $ showString "plus " . a' . showString " " . b' + EError _ s -> return $ showParen (d > 10) $ showString ("error " ++ show s) ppExprLet :: Int -> SVal env -> Expr x env t -> M ShowS -- cgit v1.2.3-70-g09d2