diff --git a/exec/src/arith/arith.c b/exec/src/arith/arith.c index 12e55744..bd28e28e 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/30 13:17:25 by rparodi ### ########.fr */ +/* Updated: 2024/07/30 14:07:29 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,21 +29,23 @@ t_error _binary_get_op(t_ast_arithmetic_operator op, t_arith_op_func *out) return (ERROR); } +// t_ast_node _postfix_op_decrement(t_ast_node ) + t_error _postfix_get_op(t_ast_arithmetic_operator op, t_arith_op_func *out) { if (op == ARITH_INCREMENT) - return (*out = _postfix_op_decrement, NO_ERROR); + return (*out = _postfix_op_inc, NO_ERROR); if (op == ARITH_DECREMENT) - return (*out = _postfix_op_decrement, NO_ERROR); + return (*out = _postfix_op_dec, NO_ERROR); return (ERROR); } t_error _unary_get_op(t_ast_arithmetic_operator op, t_arith_op_func *out) { if (op == ARITH_INCREMENT) - return (*out = _unary_op_increment, NO_ERROR); + return (*out = _unary_op_plus, NO_ERROR); if (op == ARITH_DECREMENT) - return (*out = _unary_op_decrement, NO_ERROR); + return (*out = _unary_op_minus, NO_ERROR); return (ERROR); } @@ -98,14 +100,16 @@ t_ast_node _arith_postfix_to_ast_node(t_ast_arithmetic_postfix *self) struct s_ast_node, data.arithmetic_postfix))); } -t_ast_node _arith_expansion_to_ast_node(t_ast_arithmetic_postfix *self) +/* +t_ast_node _arith_postfix_to_ast_node(t_ast_arithmetic_postfix *self) { t_u8 *ptr; ptr = (void *)(self); return ((void *)(ptr - offsetof(\ - struct s_ast_node, data.arithmetic_expansion))); + struct s_ast_node, data.arithmetic_postfix))); } +*/ // this is black magic don't worry t_ast_node _arith_literal_to_ast_node(t_ast_arithmetic_literal *self) @@ -144,6 +148,7 @@ t_error run_arithmetic_literal(t_ast_arithmetic_literal *arithmetic_literal, \ return (ERROR); } +/* t_error run_arithmetic_expansion( \ t_ast_arithmetic_expansion *arithmetic_expansion, t_state *state, t_i64 *out) { @@ -158,6 +163,7 @@ t_ast_arithmetic_expansion *arithmetic_expansion, t_state *state, t_i64 *out) *out = ret; return (NO_ERROR); } +*/ t_error run_arithmetic_binary(t_ast_arithmetic_binary *arithmetic_binary, \ t_state *state, t_i64 *out) @@ -184,11 +190,15 @@ t_error run_arithmetic_ternary(t_ast_arithmetic_ternary *arithmetic_ternary, \ 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); } @@ -214,7 +224,7 @@ t_ast_arithmetic_unary *arithmetic_unary, t_state *state, t_i64 *out) if (arithmetic_unary == NULL || state == NULL || out == NULL) return (ERROR); - if (_unary_get_op(arithmetic_unary->op, &func)) + if (_unary_get_op(arithmetic_unary->operator, &func)) return (ERROR); if (func(_arith_unary_to_ast_node(arithmetic_unary), state, out)) return (ERROR); @@ -228,7 +238,7 @@ t_ast_arithmetic_expansion *arithmetic_expansion, t_state *state, t_i64 *out) if (arithmetic_expansion == NULL || state == NULL || out == NULL) return (ERROR); - if (_get_node_number(arithmetic_expansion, start, out)) + if (_get_node_number(arithmetic_expansion->expr, state, out)) return (ERROR); return (NO_ERROR); } diff --git a/exec/src/arith/arith.h b/exec/src/arith/arith.h index ef5930cc..a75423cd 100644 --- a/exec/src/arith/arith.h +++ b/exec/src/arith/arith.h @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/27 21:13:15 by rparodi #+# #+# */ -/* Updated: 2024/07/30 11:59:09 by rparodi ### ########.fr */ +/* Updated: 2024/07/30 14:07:41 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -54,6 +54,10 @@ t_error _binary_op_sub(t_ast_node self, t_state *state, t_i64 *out); t_error _binary_op_mul(t_ast_node self, t_state *state, t_i64 *out); t_error _binary_op_div(t_ast_node self, t_state *state, t_i64 *out); t_error _binary_op_mod(t_ast_node self, t_state *state, t_i64 *out); +t_error _postfix_op_inc(t_ast_node self, t_state *state, t_i64 *out); +t_error _postfix_op_dec(t_ast_node self, t_state *state, t_i64 *out); +t_error _unary_op_plus(t_ast_node self, t_state *state, t_i64 *out); +t_error _unary_op_minus(t_ast_node self, t_state *state, t_i64 *out); t_ast_node _arith_binary_to_ast_node(t_ast_arithmetic_binary *self); #endif