From 799e3d970dd8498d5c940e3231e877f8bd61db4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl?= Date: Sun, 28 Jul 2024 20:13:24 +0200 Subject: [PATCH] Adding the correcting arith --- exec/src/arith/arith.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/exec/src/arith/arith.c b/exec/src/arith/arith.c index 90a6447f..c97790f8 100644 --- a/exec/src/arith/arith.c +++ b/exec/src/arith/arith.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/26 15:14:50 by maiboyer #+# #+# */ -/* Updated: 2024/07/28 14:44:24 by rparodi ### ########.fr */ +/* Updated: 2024/07/28 19:26:01 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,8 +26,6 @@ t_error _binary_get_op(t_ast_arithmetic_operator op, t_arith_op_func *out) return (*out = _binary_op_mul, NO_ERROR); if (op == ARITH_DIVIDE) return (*out = _binary_op_div, NO_ERROR); - if (op == ARITH_MOD) - return (*out = _binary_op_mod, NO_ERROR); return (ERROR); } @@ -119,3 +117,27 @@ t_error run_arithmetic_binary(t_ast_arithmetic_binary *arithmetic_binary, \ return (ERROR); return (NO_ERROR); } + +t_error run_arithmetic_ternary(t_ast_arithmetic_ternary *arithmetic_ternary, \ + t_state *state, t_i64 *out) +{ + t_arith_op_func func; + t_i64 cond; + + if (arithmetic_ternary == NULL || state == NULL || out == NULL) + return (ERROR); + + if (_get_node_number(arithmetic_ternary->condition, state, &cond)) + return (ERROR); + if (cond != 0) + { + if (_get_node_number(arithmetic_ternary->then, state, out)) + return (ERROR); + } + else + { + if (_get_node_number(arithmetic_ternary->else_, state, out)) + return (ERROR); + } + return (NO_ERROR); +}