From 073105080457218e67d999d6d70610914c9effe7 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Thu, 30 Dec 2021 17:01:50 +0100 Subject: Ensure new procedures are compiled only once --- src/parser.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'src/parser.c') diff --git a/src/parser.c b/src/parser.c index 29a0444..bd52c49 100644 --- a/src/parser.c +++ b/src/parser.c @@ -852,7 +852,44 @@ object_equal(Object *a, Object *b) { return sv_equal(&a->text, &b->text); } break; case OBJ_TYPE_BUILTIN: { - return a->builtin = b->builtin; + return a->builtin == b->builtin; + } break; + case OBJ_TYPE_PAIR: { + Object *a_head = a->head; + Object *b_head = b->head; + if (!object_equal(a_head, b_head)) { + return false; + } + Object *a_tail = a->tail; + Object *b_tail = b->tail; + while (a_tail != NULL && b_tail != NULL) { + if (!object_equal(a_head, b_head)) { + return false; + } + a_head = a_tail->head; + b_head = b_tail->head; + a_tail = a_tail->tail; + b_tail = b_tail->tail; + } + if (a_tail == b_tail && object_equal(a_head, b_head)) { + return true; + } + return false; + } break; + case OBJ_TYPE_LAMBDA: { + size_t n_params_a = array_size(a->params); + size_t n_params_b = array_size(b->params); + size_t n_expr_a = array_size(a->body); + size_t n_expr_b = array_size(b->body); + if (n_params_a != n_params_b || n_expr_a != n_expr_b) { + return false; + } + for (size_t i = 0; i < array_size(a->body); ++i) { + if (!object_equal(a->body[i], b->body[i])) { + return false; + } + } + return true; } break; default: break; } -- cgit v1.2.1