diff --git a/HACKING b/HACKING index 44f59912c50edd2bf76f01dbe19652926abc41e6..56a818ad43040b0f5b26eea535b3f6955f96166d 100644 --- a/HACKING +++ b/HACKING @@ -6,12 +6,13 @@ internal anaphoric macros use. Chances are that if you use these names for other things, you're gonna have a bad time. In particular, these names, and the macros that use them, are: -- state: - Used by a_new and company. Should be an HParseState* -- mm__: - Used by h_new and h_free. Should be an HAllocator* -- stk__: - Used in desugaring. Should be an HCFStack* + +- `state`: + Used by `a_new` and company. Should be an `HParseState*`. +- `mm__`: + Used by `h_new` and `h_free`. Should be an `HAllocator*`. +- `stk__`: + Used in desugaring. Should be an `HCFStack*`. Function suffixes ================= @@ -21,9 +22,9 @@ parameters or parameters in multiple different forms. For example, often, you have a global memory manager that is used for an entire program. In this case, you can leave off the memory manager arguments off, letting them be implicit instead. Further, it is often convenient -to pass an array or va_list to a function instead of listing the -arguments inline (eg, for wrapping a function, generating the -arguments programattically, or writing bindings for another language. +to pass an array or `va_list` to a function instead of listing the +arguments inline (e.g., for wrapping a function, generating the +arguments programatically, or writing bindings for another language.) Because we have found that most variants fall into a fairly small set of forms, and to minimize the amount of API calls that users need to @@ -32,21 +33,22 @@ variants: the function name is followed by two underscores and a set of single-character "flags" indicating what optional features that particular variant has (in alphabetical order, of course): - __a: takes variadic arguments as a void*[] (not implemented yet, but will be soon. - __m: takes a memory manager as the first argument, to override the system memory manager. - __v: Takes the variadic argument list as a va_list - +- `__a`: takes variadic arguments as a `void*[]` (not implemented yet, + but will be soon.) +- `__m`: takes a memory manager as the first argument, to override the + system memory manager. +- `__v`: Takes the variadic argument list as a `va_list`. Memory managers =============== -If the __m function variants are used or system_allocator is +If the `__m` function variants are used or `system_allocator` is overridden, there come some difficult questions to answer, particularly regarding the behavior when multiple memory managers are combined. As a general rule of thumb (exceptions will be explicitly documented), assume that - If you have a function f, which is passed a memory manager m and +> If you have a function f, which is passed a memory manager m and returns a value r, any function that uses r as a parameter must also be told to use m as a memory manager. @@ -57,7 +59,7 @@ Language-independent test suite There is a language-independent representation of the Hammer test suite in `lib/test-suite`. This is intended to be used with the -tsparser.pl prolog library, along with a language-specific frontend. +tsparser.pl Prolog library, along with a language-specific frontend. Only the C# frontend exists so far; to regenerate the test suites using it, run diff --git a/docs/hammerman.3 b/docs/hammerman.3 index cf1654b9943dd6e5160b3e5b519faa7c76210554..f3cf7e12b12d439a5026d3b23d5ff3bfea499e35 100644 --- a/docs/hammerman.3 +++ b/docs/hammerman.3 @@ -77,11 +77,13 @@ Benchmarking for parsing backends -- determine empirically which backend will be 11 12 HParseResult *result = h_parse(hello_parser, input, inputsize); 13 if(result) { -14 printf("yay!\n"); +14 printf("yay!\\n"); 15 } else { -16 printf("boo!\n"); +16 printf("boo!\\n"); 17 } -18 } +18 h_parse_result_free(result); +19 return 0 == result; +20 } .fi .SH "AUTHOR" .sp diff --git a/examples/base64.c b/examples/base64.c index 4b7dd9f1629f5a55693adbf95a61ad371c4acc81..7fe3cffb7cc125542a949f01b0d63b5616497de0 100644 --- a/examples/base64.c +++ b/examples/base64.c @@ -70,6 +70,8 @@ void assert_parse(int expected, char *data) { h_pprint(stdout, result->ast, 0, 0); } #endif + + h_parse_result_free(result); } void test() { @@ -107,6 +109,7 @@ int main(int argc, char **argv) if(result) { fprintf(stderr, "parsed=%" PRId64 " bytes\n", result->bit_length/8); h_pprint(stdout, result->ast, 0, 0); + h_parse_result_free(result); return 0; } else { return 1; diff --git a/examples/base64_sem1.c b/examples/base64_sem1.c index afbbef841cc0ef0593e68a1ca7101eacc976f474..7127d1eb4738c450fba5d3a9b8ab1fa3ac32496a 100644 --- a/examples/base64_sem1.c +++ b/examples/base64_sem1.c @@ -149,12 +149,13 @@ HParser *init_parser(void) #include <stdio.h> +const HParser *parser; // Allocated statically to suppress leak warnings + int main(int argc, char **argv) { uint8_t input[102400]; size_t inputsize; - const HParser *parser; - const HParseResult *result; + HParseResult *result; parser = init_parser(); @@ -166,6 +167,7 @@ int main(int argc, char **argv) if(result) { fprintf(stderr, "parsed=%" PRId64 " bytes\n", result->bit_length/8); h_pprint(stdout, result->ast, 0, 0); + h_parse_result_free(result); return 0; } else { return 1; diff --git a/examples/base64_sem2.c b/examples/base64_sem2.c index b8f7b4a20312dcf39695ba52cdcf9573376d6c69..dac7e7ab0021198b76849da2bfe86af8864a9e9d 100644 --- a/examples/base64_sem2.c +++ b/examples/base64_sem2.c @@ -153,12 +153,13 @@ const HParser *init_parser(void) #include <stdio.h> +const HParser *parser; // Allocated statically to suppress leak warnings + int main(int argc, char **argv) { uint8_t input[102400]; size_t inputsize; - const HParser *parser; - const HParseResult *result; + HParseResult *result; parser = init_parser(); @@ -170,6 +171,7 @@ int main(int argc, char **argv) if(result) { fprintf(stderr, "parsed=%" PRId64 " bytes\n", result->bit_length/8); h_pprint(stdout, result->ast, 0, 0); + h_parse_result_free(result); return 0; } else { return 1;