From 8647f40895c6ed4ea5384b088a8cbc5f90f9baed Mon Sep 17 00:00:00 2001 From: Simon Forman Date: Fri, 3 Feb 2023 09:18:32 -0800 Subject: [PATCH] newJoyList --- implementations/C/joy.c | 13 ++++--------- implementations/C/joy.h | 2 ++ 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/implementations/C/joy.c b/implementations/C/joy.c index 0912b2b..2282c4f 100644 --- a/implementations/C/joy.c +++ b/implementations/C/joy.c @@ -64,8 +64,7 @@ my_callback(GC_PTR void_obj, __attribute__((unused)) GC_PTR void_environment) { JoyList push_integer_from_str(char *str, JoyList tail) { - JoyList el; - el = GC_malloc(sizeof(struct list_node)); + JoyList el = newJoyList; el->head.kind = joyInt; mpz_init_set_str(el->head.value.i, str, 10); GC_register_finalizer(el->head.value.i, my_callback, NULL, NULL, NULL); @@ -130,11 +129,9 @@ trim_leading_blanks(char *str) JoyList make_non_list_node(char *text, size_t size) { - struct list_node *node; char *sym; const struct dict_entry *interned; - - node = GC_malloc(sizeof(struct list_node)); + JoyList node = newJoyList; interned = in_word_set(text, size); if (interned) { @@ -169,13 +166,11 @@ make_non_list_node(char *text, size_t size) return node; } - /* Create a new list_node with a joyList head. */ JoyList -make_list_node(struct list_node *el) +make_list_node(JoyList el) { - struct list_node *node; - node = GC_malloc(sizeof(struct list_node)); + JoyList node = newJoyList; node->head.kind = joyList; node->head.value.el = el; return node; diff --git a/implementations/C/joy.h b/implementations/C/joy.h index c05ada1..9bc41e6 100644 --- a/implementations/C/joy.h +++ b/implementations/C/joy.h @@ -49,6 +49,8 @@ struct list_node { #define EMPTY_LIST (JoyList)NULL +#define newJoyList GC_malloc(sizeof(struct list_node)) + typedef void (*JoyFunc)(struct list_node**, struct list_node**);