module EnvCont(Env, empty_env, lookup_variable, maybe_lookup_variable, bind_variable, variable_table, merge_declarations, get_return_cont, get_break_cont, get_continue_cont, set_return_cont, set_break_cont, set_continue_cont) where import qualified Table type Symbol = String data Env val c = Env (Table.T Symbol val) (c -> (String, String)) (c -> (String, String)) (c -> (String, String)) instance Eq val => Eq(Env val c) where (Env t1 _ _ _) == (Env t2 _ _ _) = t1 == t2 empty_env :: Env val c empty_env = Env Table.empty (\ _ -> error "return out-side of function") (\ _ -> error "break out-side of loop") (\ _ -> error "continue out-side of loop") lookup_variable :: Env val c -> Symbol -> val lookup_variable (Env t _ _ _) name = Table.lookup t name maybe_lookup_variable :: Env val c -> Symbol -> Maybe val maybe_lookup_variable (Env t _ _ _) name = Table.maybe_lookup t name bind_variable :: Env val c -> Symbol -> val -> Env val c bind_variable (Env t rc bc cc) name loc = Env (Table.bind t name loc) rc bc cc variable_table :: Env val c -> Table.T Symbol val variable_table (Env t _ _ _) = t merge_declarations :: Env val c -> Table.T Symbol val -> Env val c merge_declarations (Env t rc bc cc) decls = Env (Table.merge t decls) rc bc cc get_return_cont (Env _ rc _ _) = rc get_break_cont (Env _ _ bc _) = bc get_continue_cont (Env _ _ _ cc) = cc set_return_cont (Env t _ bc cc) rc = Env t rc bc cc set_break_cont (Env t rc _ cc) bc = Env t rc bc cc set_continue_cont (Env t rc bc _ ) cc = Env t rc bc cc