-----------------------------------------------------------------------------
-- |
  Module       :  . Annotate
  Copyright    : ( c ) 2009 - 2012  
-- License     : BSD-style
-- Maintainer  : 
-- Stability   : experimental
  Portability : ghc
--
  Add stack annotations to top - level functions in  programs .
-----------------------------------------------------------------------------
module Ministg.Annotate where

import Ministg.AST

class Annotate t where
   annotate :: t -> t

instance Annotate a => Annotate [a] where
   annotate = map annotate

instance Annotate Program where
   annotate (Program decls) = Program $ annotate decls

instance Annotate Decl where
   -- don't annotate functions which are already annotated (by the user)
   annotate decl@(Decl _ (Fun _ (Stack {}))) = decl
   annotate (Decl var (Fun args body))
      = Decl var (Fun args (Stack var body))
   -- don't annotate thunks which are already annotated (by the user)
   annotate decl@(Decl _ (Thunk (Stack {}) _)) = decl
   annotate decl@(Decl var (Thunk body callStack)) 
      = Decl var (Thunk (Stack var body) callStack) 
   annotate other = other

---------------------------------------------------------------------------
 |
 License     : BSD-style
 Maintainer  : 
 Stability   : experimental

---------------------------------------------------------------------------
 don't annotate functions which are already annotated (by the user)
 don't annotate thunks which are already annotated (by the user)
  Module       :  . Annotate
  Copyright    : ( c ) 2009 - 2012  
  Portability : ghc
  Add stack annotations to top - level functions in  programs .
module Ministg.Annotate where

import Ministg.AST

class Annotate t where
   annotate :: t -> t

instance Annotate a => Annotate [a] where
   annotate = map annotate

instance Annotate Program where
   annotate (Program decls) = Program $ annotate decls

instance Annotate Decl where
   annotate decl@(Decl _ (Fun _ (Stack {}))) = decl
   annotate (Decl var (Fun args body))
      = Decl var (Fun args (Stack var body))
   annotate decl@(Decl _ (Thunk (Stack {}) _)) = decl
   annotate decl@(Decl var (Thunk body callStack)) 
      = Decl var (Thunk (Stack var body) callStack) 
   annotate other = other
