summaryrefslogtreecommitdiffstats
path: root/HACKING
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-12-29 18:59:27 -0800
committerKaz Kylheku <kaz@kylheku.com>2021-12-29 23:42:14 -0800
commit5f67b95d218e1ef3473c39bca2f6491503aeeabe (patch)
tree095d53b02f0093911e06ab06221d0529f6f7da42 /HACKING
parent0b6c09e067981c232cef09f0d82fb9b4a9864553 (diff)
downloadtxr-5f67b95d218e1ef3473c39bca2f6491503aeeabe.tar.gz
txr-5f67b95d218e1ef3473c39bca2f6491503aeeabe.tar.bz2
txr-5f67b95d218e1ef3473c39bca2f6491503aeeabe.zip
Eliminate declaration-after-statement everywhere.
The use of -ansi doesn't by itself diagnose instances of some constructs we don't want in the project, like mixed declarations and statements. * configure (diag_flags): Add -Werror=declaration-after-statement. This is C only, so filter it out for C++. Also add -Werror=vla. * HACKING: Update inaccurate statements about what dialect we are using. TXR isn't pure C90: some GCC extensions are used. We even use long long if the configure script detects it as working, and some C99 library features. * buf.c (replace_buf, buf_list): Fix by reordering. * eval.c (op_dohash, op_load_time_lit): Fix by reordering. * ffi.c (ffi_simple_release): Fix by reordering. (align_sw_get): Fix empty macro to expand to dummy declaration so a semicolon after it isn't interpreted as a statement. On platforms with alignment, remove a semicolon from the macro so that it requires one. (ffi_i8_put, ffi_u8_put): Fix by reordering. * gc.c (gc_init): Fix with extra braces. * hash.c (hash_init): Fix by reordering. * lib.c (list_collect_revappend, sub_iter, replace_str, replace_vec, mapcar_listout, mappend, mapdo, window_map_list, subst): Fix by reordering. (gensym, find, rfind, pos, rpos, in, search_common): Fix by renaming optional argument and using declaration instead of assignment. * linenoise/linenoise.c (edit_in_editor): Fix by reordering. * parser.c (is_balanced_line): Fix by reordering. * regex.c (nfa_count_one, print_rec): Fix by reordering. * signal.c (sig_mask): Fix by reordering. * stream.c (get_string): Fix by renaming optional argument and using declaration instead of assignment. * struct.c (lookup_static_slot_desc): Fix by turning mutated variable into block local. (umethod_args_fun): Fix by reordering. (get_special_slot): Fix by new scope via braces. * sysif.c (usleep_wrap): Fix by new scope via braces. (setrlimit_wrap): Fix by new scope via braces. * time.c (time_string_meth, time_parse_meth): Fix by reordering. * tree.c (tr_do_delete_spec): Fix by new scope via braces. * unwind.h (uw_block_beg): New macro which doesn't define RESULTVAR but expects it to refers to an existing one. (uw_block_begin): Replace do while (0) with enum trick so that we have a declaration that requires a semicolon, rather than a statement, allowing declarations to follow. (uw_match_env_begin): Now opens a scope and features the same enum trick as in uw_block_begin. This fixes a declaration-follows-statement issue in the v_output function in match.c. (uw_match_env_end): Closes scope opened by uw_match_env_begin. * unwind.c (revive_cont): Fix by introducing variable, and using new uw_block_beg macro. * vm.c (vm_execute_closure): Fix using combination of local variable and reordering.
Diffstat (limited to 'HACKING')
-rw-r--r--HACKING96
1 files changed, 57 insertions, 39 deletions
diff --git a/HACKING b/HACKING
index 9544d114..caa7501c 100644
--- a/HACKING
+++ b/HACKING
@@ -8,40 +8,40 @@ SECTION LINE
0. Overview 47
1. Coding Practice 54
-1.2 Program File Structure 77
-1.3 Style 91
-1.3 Error Handling 153
-1.4 I/O 166
-1.5 Type Safety 176
-1.6 Regression 218
-
-2. Dynamic Types 227
-2.1 Two Kinds of Values 234
-2.1 Pointer Bitfield 245
-2.2 Heap Objects 268
-2.3 The COBJ type 288
-2.4 Strings 305
-2.4.1 Encapsulated C Strings 320
-2.4.2 Representation Hacks for 2-byte wchar_t 364
-
-3. Garbage Collection 423
-3.1 Root Pointers 441
-3.2 GC-safe Code 464
-3.2.1 Rule One: Full Initialization 490
-3.2.2 Rule Two: Make it Reachable 519
-3.3 Weak Reference Support 707
-3.4 Finalization 750
-3.5 Generational GC 774
-3.5.2 Representation of Generations 783
-3.5.3 Basic Algorithm 819
-3.5.4 Handling Backpointers 854
-3.5.5 Generational GC and Finalization 932
-
-4. Debugging 961
-4.2. Debugging the Yacc-generated Parser 1092
-4.3. Debugging GC Issues 1105
-4.4 Object Breakpoint 1128
-4.5 Valgrind: Your Friend 1147
+1.2 Program File Structure 95
+1.3 Style 109
+1.3 Error Handling 171
+1.4 I/O 184
+1.5 Type Safety 194
+1.6 Regression 236
+
+2. Dynamic Types 245
+2.1 Two Kinds of Values 252
+2.1 Pointer Bitfield 263
+2.2 Heap Objects 286
+2.3 The COBJ type 306
+2.4 Strings 323
+2.4.1 Encapsulated C Strings 338
+2.4.2 Representation Hacks for 2-byte wchar_t 382
+
+3. Garbage Collection 441
+3.1 Root Pointers 459
+3.2 GC-safe Code 482
+3.2.1 Rule One: Full Initialization 508
+3.2.2 Rule Two: Make it Reachable 537
+3.3 Weak Reference Support 725
+3.4 Finalization 768
+3.5 Generational GC 792
+3.5.2 Representation of Generations 801
+3.5.3 Basic Algorithm 837
+3.5.4 Handling Backpointers 872
+3.5.5 Generational GC and Finalization 950
+
+4. Debugging 979
+4.2. Debugging the Yacc-generated Parser 1110
+4.3. Debugging GC Issues 1123
+4.4 Object Breakpoint 1146
+4.5 Valgrind: Your Friend 1165
0. Overview
@@ -56,11 +56,29 @@ provide rationale and make coding recommendations.
1.1 Language
Txr is written in a language that consists of the common dialect between C90
-and C++98. The code can be built with either the GNU C compiler or the GNU C++
-compiler. Use is made of some Unix functions from before Unix95, which are
-requested by means of -D_XOPEN_SOURCE (POSIX.1, POSIX.2, X/Open Portability
-Guide 4). Also, the <wchar.h> header is used, which was introduced by a 1995
-addendum to the C language, so it may be said that the actual C dialect is C95.
+and C++98, with some GCC extensions, such as:
+
+- initializing structure members with values not computable at load-time
+- converting between object and function pointers
+- certain extensions detected by the configure script as working, such
+ as the long long type
+- bitfields of an enum type rather than int.
+
+The code can be built with either the GNU C compiler or the GNU C++
+compiler.
+
+Use is made of numerous library functions which are detected by the configure
+script without regard for dialect. For instance, some C99 mathematics functions
+are used, if available, as well as numerous POSIX functions. Effectively, these
+can be regarded as extensions to the C90 language, since they are revealed in
+the headers and library linkage.
+
+The <inttypes.h> header isn't used, though there is a reference to it in
+the Flex-generated scanner, active only if that is compiled in C99 mode.
+
+The <wchar.h> header is used, which was introduced by a 1995 addendum to the C
+language, so it may be said that the actual C dialect is C95 with some
+extensions.
In coding new features or fixing bugs, care must be taken to preserve this.
Code must continue to compile as C and C++, and not increase the portability