From 0ad800ea0632459c2eceb0aa9a819497922ea484 Mon Sep 17 00:00:00 2001 From: Lassi Kortela Date: Wed, 28 Aug 2019 12:47:01 +0300 Subject: [PATCH] Add C file forgotten from last commit --- c/util.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 c/util.c diff --git a/c/util.c b/c/util.c new file mode 100644 index 0000000..53bc169 --- /dev/null +++ b/c/util.c @@ -0,0 +1,38 @@ +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "scheme.h" + +void accum_elt(struct accum *accum, value_t elt) +{ + value_t newtail; + + newtail = fl_cons(elt, FL_NIL); + if (accum->tail != FL_NIL) { + cdr_(accum->tail) = newtail; + } else { + accum->list = newtail; + } + accum->tail = newtail; +} + +void accum_pair(struct accum *accum, value_t a, value_t d) +{ + accum_elt(accum, fl_cons(a, d)); +} + +void accum_name_value(struct accum *accum, const char *name, value_t value) +{ + accum_pair(accum, string_from_cstr(name), value); +}