From fe6d5e0ac088e6b648a5029b101402c017fd04de Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Thu, 2 Mar 2006 20:41:09 +0000 Subject: [PATCH] introduced pushAndPop in the typechecker too --- Typecheck.hs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/Typecheck.hs b/Typecheck.hs index a78f8f0..cdba298 100644 --- a/Typecheck.hs +++ b/Typecheck.hs @@ -56,27 +56,25 @@ findVariable :: (MonadState Types m) => Ident -> Types -> m Type findVariable i [] = fail $ "Variable "++show i++" not found in any scope." findVariable i (m:ms) = if member i m then lookup i m else findVariable i ms +pushAndPop :: (MonadState Types m) => m a -> m () +pushAndPop s = do + modify (empty:) + s + modify tail + typeCheckStm :: (MonadState Types m) => Stm -> m () typeCheckStm SNoop = return () typeCheckStm (SExp e) = do typeCheckExp e return () -typeCheckStm (SBlock ss) = do - modify (empty:) - mapM typeCheckStm ss - modify tail +typeCheckStm (SBlock ss) = pushAndPop $ mapM typeCheckStm ss typeCheckStm (SIf e s s') = do TBool <- typeCheckExp e - modify (empty:) - typeCheckStm s - modify (\s -> empty:tail s) - typeCheckStm s' - modify tail + pushAndPop $ typeCheckStm s + pushAndPop $ typeCheckStm s' typeCheckStm (SWhile e s) = do TBool <- typeCheckExp e - modify (empty:) - typeCheckStm s - modify tail + pushAndPop $ typeCheckStm s typeCheckStm (SDecl t i e) = do t2 <- typeCheckExp e assert (t == t2) $ "Illegal to assign an expression of type "++show t2++" to variable "++show i++" of type "++show t -- 2.39.2