X-Git-Url: https://git.distorted.org.uk/~mdw/sod/blobdiff_plain/5b0c3a982e3d53b9a2b0a823eeeb511b5bdaf0fd..02840f3dba856d042fe27a0adfb0367346447cda:/doc/runtime.tex diff --git a/doc/runtime.tex b/doc/runtime.tex index b357f75..a4a15ed 100644 --- a/doc/runtime.tex +++ b/doc/runtime.tex @@ -43,9 +43,9 @@ The header file defines two simple structure types, and a function type which will be described later. \begin{describe}[struct kwval]{type} - {struct kwval \{ \\ \ind - const char *kw; \\ - const void *val; \- \\ + {struct kwval \{ \\ \ind + const char *kw; \\ + const void *val; \-\\ \};} The @|kwval| structure describes a keyword argument name/value pair. The @@ -56,9 +56,9 @@ will be described later. \end{describe} \begin{describe}[struct kwtab]{type} - {struct kwtab \{ \\ \ind - const struct kwval *v; \\ - size_t n; \- \\ + {struct kwtab \{ \\ \ind + const struct kwval *v; \\ + size_t n; \-\\ \};} The @|kwtab| structure describes a list of keyword arguments, represented @@ -203,8 +203,8 @@ list items of the form \end{prog} with no separation between them. For example: \begin{prog} - \#define example_KWSET(_) @\\ \\ \ind - _(int, x, 0) @\\ \\ + \#define example_KWSET(_) \macsl \\ \ind + _(int, x, 0) \macsl \\ _(const char *, y, NULL) \end{prog} @@ -285,9 +285,10 @@ keyword arguments. The macro @|KWSET_PARSEFN| defines a keyword argument \emph{parser function} \begin{prog} - void @{}_kwparse(\=struct @{}_kwargs *@, - const char *@, va_list *@, \+ \\ - const struct kwval *@, size_t @); + void @{}_kwparse% + (\=struct @{}_kwargs *@, + const char *@, va_list *@, \+\\ + const struct kwval *@, size_t @); \end{prog} The macro call can (and usually will) be preceded by storage class specifiers such as @|static|, for example to adjust the linkage of the @@ -327,7 +328,7 @@ keyword arguments. which expects keyword arguments, but don't supply any and forget the null pointer which terminates the (empty) list.} % If @ is a null pointer, then @ need not be a valid pointer; - otherwise, the cursor object @|* @| will be modified as the function + otherwise, the cursor object @|*@| will be modified as the function extracts successive arguments from the tail. The keyword vector is read from the vector of @|kwval| structures starting @@ -417,9 +418,10 @@ allow keyword arguments. \end{describe} \begin{describe}[kw_parseempty]{fun} - {void kw_parseempty(\=const char *@, - const char *@, va_list *@, \+ \\ - const struct kwval *@, size_t @);} + {void kw_parseempty% + (\=const char *@, + const char *@, va_list *@, \+\\ + const struct kwval *@, size_t @);} This function checks an keyword argument list to make sure that contains no keyword arguments (other than the special ones described in \xref{sec:runtime.keywords.calling}). @@ -551,32 +553,33 @@ particular keyword argument. \begin{prog} \#define KWARGS_TEST(k, val) KWARGS(K(k, val) K(kw.unknown, 0)) - \\+ + \\+ static jmp_buf kw_test_jmp; - \\+ - static void kw_test_unknown(const char *set, const char *kw) \\ - \{ \\ \ind - if (strcmp(kw, "kw.unknown")) longjmp(kw_test_jmp, 1); \\ - else longjmp(kw_test_jmp, 2); \- \\ - \} - \\+ - \#define KW_TEST(flag, set, call) do \{ @\\ \\ \ind - kw_unkhookfn *oldunk = kw_unkhook; @\\ \\ - kw_unkhook = kw_test_unknown; @\\ \\ - switch (setjmp(kw_test_jmp)) \{ @\\ \\ \ind - case 0: call; abort(); @\\ \\ - case 1: flag = 1; break; @\\ \\ - case 2: flag = 0; break; @\\ \\ - default: abort(); \- @\\ \\ - \} @\\ \\ - kw_unkhook = oldunk; \- @\\ \\ - \} while (0) - \\+ - /* Example of use */ \\ - int f; \\ + \\+ + static void kw_test_unknown(const char *set, const char *kw) \\ + \{ \\ \ind + if (strcmp(kw, "kw.unknown")) longjmp(kw_test_jmp, 1); \\ + else longjmp(kw_test_jmp, 2); \-\\ + \} \\+ + + \#define KW_TEST(flag, set, call) do \{ \macsl \\ \ind + kw_unkhookfn *oldunk = kw_unkhook; \macsl \\ + kw_unkhook = kw_test_unknown; \macsl \\ + switch (setjmp(kw_test_jmp)) \{ \macsl \\ \ind + case 0: call; abort(); \macsl \\ + case 1: flag = 1; break; \macsl \\ + case 2: flag = 0; break; \macsl \\ + default: abort(); \macsl\-\\ + \} \macsl \\ + kw_unkhook = oldunk; \macsl\-\\ + \} while (0) \\+ + + @/* Example of use */ \\ + int f; \\ KW_TEST(f, somefunc(1, "two", 3, KWARGS_TEST("shiny", 68.7))); \\ - /\=* now f is nonzero if `somefunc' accepts the `shiny' keyword \+ \\ - {}* (which we hope wants a double argument) \\ + /\=* \comment{now @|f| is nonzero if @|somefunc| accepts the + @|shiny| keyword} \+\\ + {}* \comment{(which we hope wants a @|double| argument)} \\ {}*/ \end{prog}