From 102b41d1705922e043864b8f8835021ccd624fda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl?= Date: Sat, 27 Jul 2024 14:27:54 +0200 Subject: [PATCH] adding the start of arit --- ast/src/from_node.c | 2 +- exec/src/arith.c | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/ast/src/from_node.c b/ast/src/from_node.c index 968987b7..f046b36e 100644 --- a/ast/src/from_node.c +++ b/ast/src/from_node.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/26 10:55:52 by rparodi #+# #+# */ -/* Updated: 2024/07/26 11:27:49 by rparodi ### ########.fr */ +/* Updated: 2024/07/27 12:30:19 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/exec/src/arith.c b/exec/src/arith.c index b96ad470..2f48d6ea 100644 --- a/exec/src/arith.c +++ b/exec/src/arith.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/26 15:14:50 by maiboyer #+# #+# */ -/* Updated: 2024/07/26 15:20:41 by maiboyer ### ########.fr */ +/* Updated: 2024/07/27 12:44:46 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,6 +23,7 @@ #include "me/types.h" #include "me/vec/vec_estr.h" #include "me/vec/vec_str.h" +#include "me/convert/str_to_numbers.h" #include @@ -35,3 +36,25 @@ t_error run_arithmetic_postfix(t_ast_arithmetic_postfix *arithmetic_postfix, t_s t_error run_arithmetic_ternary(t_ast_arithmetic_ternary *arithmetic_ternary, t_state *state, void *out); t_error run_arithmetic_unary(t_ast_arithmetic_unary *arithmetic_unary, t_state *state, void *out); t_error run_arithmetic_expansion(t_ast_arithmetic_expansion *arithmetic_expansion, t_state *state, void *out); + +t_error run_arithmetic_binary(t_ast_arithmetic_binary *arithmetic_binary, t_state *state, void *out) +{ + t_i64 ret; + t_i64 left; + t_i64 right; + + if (str_to_i64(arithmetic_binary->lhs->data, 10, &left)) + return (ERROR); + if (str_to_i64(arithmetic_binary->rhs->data, 10, &right)) + return (ERROR); + if (arithmetic_binary->op == ARITH_PLUS) + ret = arithmetic_binary->lhs->data + arithmetic_binary->rhs->data; + if (arithmetic_binary->op == ARITH_MINUS) + ret = arithmetic_binary->lhs->data - arithmetic_binary->rhs->data; + if (arithmetic_binary->op == ARITH_MULT) + ret = arithmetic_binary->lhs->data * arithmetic_binary->rhs->data; + if (arithmetic_binary->op == ARITH_MOD) + ret = arithmetic_binary->lhs->data % arithmetic_binary->rhs->data; + if (arithmetic_binary->op == ARITH_DIVIDE) + ret = arithmetic_binary->lhs->data / arithmetic_binary->rhs->data; +}