From f7607e47d681480c725ca6ddc6b3124616cef897 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Mon, 22 Jul 2019 13:14:44 -0400 Subject: [PATCH] Keep track of notes for a potential future guide --- docs/C-Interface-Notes.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 docs/C-Interface-Notes.md diff --git a/docs/C-Interface-Notes.md b/docs/C-Interface-Notes.md new file mode 100644 index 00000000..75084653 --- /dev/null +++ b/docs/C-Interface-Notes.md @@ -0,0 +1,14 @@ +This file is the attempted start of a best practices guide for the C interface... not much more than notes at this point, though. + +# Use built-in macros to create objects + +It is best for application code to avoid assigning to internal structures (such as hdr) if we can help it, just in case any of that were to change in the future. For example, hdr.immutable is a recent addition. Also, the C code is compiled with optimizations so most likely the generated assembly will avoid a double-assignment: + + alloca_pair(pl, ps, NULL); + // object pl = alloca(sizeof(pair_type)); + // ((list) pl)->hdr.mark = gc_color_red; + // ((list) pl)->hdr.grayed = 0; + // ((list) pl)->hdr.immutable = 0; + // ((list) pl)->tag = pair_tag; + // ((list) pl)->pair_car = ps; +