From 81eebc5b9bf6e2b79ede36a108ad0369a4ec32cd Mon Sep 17 00:00:00 2001 From: Simon Forman Date: Sat, 4 Feb 2023 10:25:14 -0800 Subject: [PATCH] Boolean singleton values. --- implementations/C/joy.c | 12 +++++++++--- implementations/C/joy.h | 1 - 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/implementations/C/joy.c b/implementations/C/joy.c index c62a3cb..444e39c 100644 --- a/implementations/C/joy.c +++ b/implementations/C/joy.c @@ -32,6 +32,9 @@ const char *BLANKS = " \t"; const char *FALSE = "false"; const char *TRUE = "true"; +JoyTypePtr JoyTrue; +JoyTypePtr JoyFalse; + void* reallocate_function (void *ptr, __attribute__((unused)) size_t old_size, size_t new_size) { @@ -139,11 +142,9 @@ make_non_list_node(char *text, size_t size) if (!strncmp(sym, FALSE, 6)) { /* I know it's wrong to hardcode the length here. Sorry. */ /* If head was a pointer we could reuse Boolean singletons... */ node->head->kind = joyFalse; - node->head->value.boolean = 0; } else if (!strncmp(sym, TRUE, 5)) { /* I know it's wrong to hardcode the length here. Sorry. */ node->head->kind = joyTrue; - node->head->value.boolean = 1; } else if (mpz_init_set_str(node->head->value.i, sym, 10)) { /* Non-zero (-1) return value means the string is not an int. */ @@ -389,7 +390,7 @@ void joy(JoyListPtr stack, JoyListPtr expression) { char *sym; - JoyType *term; + JoyTypePtr term; const struct dict_entry *interned; while (*expression) { @@ -423,6 +424,11 @@ main(void) JoyList stack = EMPTY_LIST; JoyList expression = EMPTY_LIST; + JoyTrue = newJoyType; + JoyTrue->kind = joyTrue; + JoyFalse= newJoyType; + JoyFalse->kind = joyFalse; + mp_set_memory_functions( &GC_malloc, &reallocate_function, diff --git a/implementations/C/joy.h b/implementations/C/joy.h index cc47449..b0fbf21 100644 --- a/implementations/C/joy.h +++ b/implementations/C/joy.h @@ -34,7 +34,6 @@ typedef JoyList* JoyListPtr; typedef struct { enum JoyTypeType kind; union { - int boolean; /* TODO: Remoce this field, we don't use it. */ mpz_t i; JoyList el; char *symbol;