From b6d4175a780c7b3dae8c035d814b06ef86429881 Mon Sep 17 00:00:00 2001 From: Simon Forman Date: Sun, 12 Feb 2023 16:01:19 -0800 Subject: [PATCH] Bring behaviour inline with joytest. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pop has it's own error message. Div should be "floor" division > fdiv rounds q down towards -infinity, and r will have the same sign as > d. The f stands for “floor”. https://gmplib.org/manual/Integer-Division --- implementations/C/joy.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/implementations/C/joy.c b/implementations/C/joy.c index 494b4fc..34d5abc 100644 --- a/implementations/C/joy.c +++ b/implementations/C/joy.c @@ -558,8 +558,8 @@ name(JoyListPtr stack, __attribute__((unused)) JoyListPtr expression) \ BINARY_MATH_OP(add) BINARY_MATH_OP(sub) BINARY_MATH_OP(mul) -BINARY_MATH_OP(tdiv_q) -BINARY_MATH_OP(tdiv_r) +BINARY_MATH_OP(fdiv_q) +BINARY_MATH_OP(fdiv_r) /* @@ -639,6 +639,10 @@ cons(JoyListPtr stack, __attribute__((unused)) JoyListPtr expression) void pop(JoyListPtr stack, __attribute__((unused)) JoyListPtr expression) { + if (!(*stack)) { + printf("Cannot pop empty stack.\n"); + longjmp(jbuf, 1); + } pop_any(stack); }