[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2] pkl: Add exception_code to register user-defined exceptio
From: |
Jose E. Marchesi |
Subject: |
Re: [PATCH v2] pkl: Add exception_code to register user-defined exceptions |
Date: |
Mon, 25 Jan 2021 19:04:56 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
Hi Mohammad.
> 2021-01-25 Mohammad-Reza Nabipoor <m.nabipoor@yahoo.com>
>
> * libpoke/pkl-rt.pk (exception_code): New function.
> * doc/poke.texi (Exceptions): Add documentation for
> `exception_code`.
OK for master.
Thanks!
> ---
> ChangeLog | 5 +++++
> doc/poke.texi | 14 ++++++++++++++
> libpoke/pkl-rt.pk | 13 ++++++++++++-
> 3 files changed, 31 insertions(+), 1 deletion(-)
>
> diff --git a/ChangeLog b/ChangeLog
> index a92820ce..900a41d3 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,8 @@
> +2021-01-25 Mohammad-Reza Nabipoor <m.nabipoor@yahoo.com>
> +
> + * libpoke/pkl-rt.pk (exception_code): New function.
> + * doc/poke.texi (Exceptions): Add documentation for `exception_code`.
> +
> 2021-01-25 Mohammad-Reza Nabipoor <m.nabipoor@yahoo.com>
>
> * testsuite/Makefile.am (check-DEJAGNU): Fix `make distcheck`
> diff --git a/doc/poke.texi b/doc/poke.texi
> index 8aeb07cb..ad36fa2f 100644
> --- a/doc/poke.texi
> +++ b/doc/poke.texi
> @@ -10190,6 +10190,20 @@ example:
> raise Exception @{ code = 255; msg = "double upset event" @};
> @end example
>
> +User-defined exceptions should be resgistered using @code{exception_code}
> +function. For example:
> +
> +@example
> +var E_my_exception = Exception @{
> + code = exception_code,
> + msg = "double upset event",
> +@};
> +@end example
> +
> +@noindent
> +where the @code{E_my_exception.code} is a unique number greater than or
> +equal to @code{255}.
> +
> Exception codes in the range @code{0..254} are reserved for poke.
> These are used in predefined exceptions which are standard, and have
> specific meanings:
> diff --git a/libpoke/pkl-rt.pk b/libpoke/pkl-rt.pk
> index 9947d4d3..658ecd37 100644
> --- a/libpoke/pkl-rt.pk
> +++ b/libpoke/pkl-rt.pk
> @@ -77,7 +77,8 @@ type Exception =
> /* Standard exception codes.
> These codes should be in sync with PVM_E_* macros in pvm.h.
> Note that user-defined exceptions must have codes starting with
> - 255.
> + 255 (and should be registered using exception_code function defined
> + below).
> Note also that EC_generic _must_ be zero. */
>
> var EC_generic = 0;
> @@ -135,6 +136,16 @@ var E_exit
> var E_assert
> = Exception {code = EC_assert, msg = "assertion failure", exit_status = 1};
>
> +/* Registration of user-defined exceptions */
> +
> +type _ExceptionCodeGenerator = () int<32>;
> +var exception_code = lambda _ExceptionCodeGenerator:
> + {
> + var n = 255; /* First available code for user-defined exceptions */
> +
> + return lambda int<32>: { return n++; };
> + }();
> +
> /* Default exception handler.
>
> Note that the code in this function should NOT raise any exception,