1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
/************************************************************************/
/* */
/* Applied Type System */
/* */
/* Hongwei Xi */
/* */
/************************************************************************/
/*
** ATS - Unleashing the Power of Types!
**
** Copyright (C) 2002-2008 Hongwei Xi.
**
** ATS is free software; you can redistribute it and/or modify it under
** the terms of the GNU LESSER GENERAL PUBLIC LICENSE as published by the
** Free Software Foundation; either version 2.1, or (at your option) any
** later version.
**
** ATS is distributed in the hope that it will be useful, but WITHOUT ANY
** WARRANTY; without even the implied warranty of MERCHANTABILITY or
** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
** for more details.
**
** You should have received a copy of the GNU General Public License
** along with ATS; see the file COPYING. If not, please write to the
** Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
** 02110-1301, USA.
**
*/
/*
**
** Authors:
** Likai Liu (liulk AT cs DOT bu DOT edu) // Summer 2005
** Rick Lavoie (coldfury AT cs DOT bu DOT edu) // Fall 2006
** Hongwei Xi (hwxi AT cs DOT bu DOT edu) // Summer 2007
**
*/
#ifndef ATS_EXCEPTION_H
#define ATS_EXCEPTION_H // the file should only be loaded once
/* ****** ****** */
/*
** always loaded after the following two files:
*/
#include "ats_types.h"
#include "ats_basics.h"
/* ****** ****** */
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE // for [sigsetjmp] in gcc-4.5
#endif // end of [_XOPEN_SOURCE]
#include <alloca.h>
#include <setjmp.h>
/* ****** ****** */
/*
** function for handling uncaught exceptions
*/
extern
ats_void_type
ats_uncaught_exception_handle(const ats_exn_ptr_type exn) ;
/* ****** ****** */
/* exception implementation */
typedef
struct ats_exception_frame_struct {
ats_exn_ptr_type exn ;
struct ats_exception_frame_struct *prev ;
sigjmp_buf env ;
} ats_exception_frame_type ;
/* ****** ****** */
#ifdef _ATS_MULTITHREAD
extern ATSthreadlocalstorage()
ats_exception_frame_type *the_ats_exception_stack ;
#else /* single thread */
extern
ats_exception_frame_type *the_ats_exception_stack ;
#endif // end of [_ATS_MULTITHREAD]
/* ****** ****** */
#define ATS_CURRENT_FRAME (the_ats_exception_stack)
#define ATS_ENTER_EXCEPTION_FRAME() \
do { \
ats_exception_frame_type *frame = \
(ats_exception_frame_type*) alloca(sizeof(ats_exception_frame_type)); \
frame->prev = ATS_CURRENT_FRAME ; \
ATS_CURRENT_FRAME = frame ; \
} while(0)
#define ATS_LEAVE_EXCEPTION_FRAME() \
do { ATS_CURRENT_FRAME = ATS_CURRENT_FRAME->prev; } while(0)
#define ATS_RAISE(exn) \
do { \
if (ATS_CURRENT_FRAME == 0 /*null*/) ats_uncaught_exception_handle(exn) ; \
ATS_CURRENT_FRAME->exn = exn ; \
siglongjmp(ATS_CURRENT_FRAME->env, 0) ; \
} while(0)
/* ****** ****** */
/*
** WARNING: DO NOT USE THE FOLLOWING MACROS:
*/
#define ATS_TRYWITH_TRY(tmp_exn) \
do { \
ATS_ENTER_EXCEPTION_FRAME() ; \
tmp_exn = (ats_exn_ptr_type)(intptr_t)sigsetjmp(ATS_CURRENT_FRAME->env, 0) ; \
if ((intptr_t)tmp_exn == 0) { /* ... */
#define ATS_TRYWITH_WITH(tmp_exn) \
ATS_LEAVE_EXCEPTION_FRAME() ; \
} else { \
tmp_exn = ATS_CURRENT_FRAME->exn ; \
ATS_LEAVE_EXCEPTION_FRAME() ; /* exception handling */
#define ATS_TRYWITH_END() \
} \
} while(0)
/* end of WARNING */
/* ****** ****** */
static inline
ats_void_type ats_raise_exn // raising an exception
(const ats_exn_ptr_type exn) { ATS_RAISE(exn) ; return ; }
/* end of [ats_raise_exn] */
/* ****** ****** */
/*
**
** function for generating new exception constructor tag
**
*/
extern int ats_exception_con_tag ;
static inline
int ats_exception_con_tag_new () {
ats_exception_con_tag += 1 ; return (ats_exception_con_tag) ;
} /* end of [ats_exception_con_tag_new] */
/* functions for handling match failures */
extern
ats_void_type ats_caseof_failure(void) ;
extern
ats_void_type ats_funarg_match_failure(void) ;
/* ****** ****** */
#endif /* ATS_EXCEPTION_H */
/* end of [ats_exception.h] */
|