X-Git-Url: https://git.distorted.org.uk/~mdw/sod/blobdiff_plain/5f1bbd61fd7cdab58935ae74565e276d1c87505d..020b9e2b4364c61a668d47c4c5405295349817d8:/doc/runtime.tex diff --git a/doc/runtime.tex b/doc/runtime.tex index 0490763..75055e5 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(_) @\\ \\ \ind + _(int, x, 0) @\\ \\ _(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 @@ -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,33 +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 \{ @\\ \\ \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; \\ KW_TEST(f, somefunc(1, "two", 3, KWARGS_TEST("shiny", 68.7))); \\ /\=* \comment{now @|f| is nonzero if @|somefunc| accepts the - @|shiny| keyword} \+ \\ - {}* \comment{(which we hope wants a @|double| argument)} \\ + @|shiny| keyword} \+\\ + {}* \comment{(which we hope wants a @|double| argument)} \\ {}*/ \end{prog}