Adding the modification to compile kissou

This commit is contained in:
Raphael (rparodi) 2024-07-30 14:13:21 +02:00
parent d9999a85d9
commit ed4015a8fe
2 changed files with 24 additions and 10 deletions

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */ /* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/26 15:14:50 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); 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) t_error _postfix_get_op(t_ast_arithmetic_operator op, t_arith_op_func *out)
{ {
if (op == ARITH_INCREMENT) if (op == ARITH_INCREMENT)
return (*out = _postfix_op_decrement, NO_ERROR); return (*out = _postfix_op_inc, NO_ERROR);
if (op == ARITH_DECREMENT) if (op == ARITH_DECREMENT)
return (*out = _postfix_op_decrement, NO_ERROR); return (*out = _postfix_op_dec, NO_ERROR);
return (ERROR); return (ERROR);
} }
t_error _unary_get_op(t_ast_arithmetic_operator op, t_arith_op_func *out) t_error _unary_get_op(t_ast_arithmetic_operator op, t_arith_op_func *out)
{ {
if (op == ARITH_INCREMENT) if (op == ARITH_INCREMENT)
return (*out = _unary_op_increment, NO_ERROR); return (*out = _unary_op_plus, NO_ERROR);
if (op == ARITH_DECREMENT) if (op == ARITH_DECREMENT)
return (*out = _unary_op_decrement, NO_ERROR); return (*out = _unary_op_minus, NO_ERROR);
return (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))); 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; t_u8 *ptr;
ptr = (void *)(self); ptr = (void *)(self);
return ((void *)(ptr - offsetof(\ 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 // this is black magic don't worry
t_ast_node _arith_literal_to_ast_node(t_ast_arithmetic_literal *self) 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); return (ERROR);
} }
/*
t_error run_arithmetic_expansion( \ t_error run_arithmetic_expansion( \
t_ast_arithmetic_expansion *arithmetic_expansion, t_state *state, t_i64 *out) 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; *out = ret;
return (NO_ERROR); return (NO_ERROR);
} }
*/
t_error run_arithmetic_binary(t_ast_arithmetic_binary *arithmetic_binary, \ t_error run_arithmetic_binary(t_ast_arithmetic_binary *arithmetic_binary, \
t_state *state, t_i64 *out) 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)) if (_get_node_number(arithmetic_ternary->condition, state, &cond))
return (ERROR); return (ERROR);
if (cond != 0) if (cond != 0)
{
if (_get_node_number(arithmetic_ternary->then, state, out)) if (_get_node_number(arithmetic_ternary->then, state, out))
return (ERROR); return (ERROR);
}
else else
{
if (_get_node_number(arithmetic_ternary->else_, state, out)) if (_get_node_number(arithmetic_ternary->else_, state, out))
return (ERROR); return (ERROR);
}
return (NO_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) if (arithmetic_unary == NULL || state == NULL || out == NULL)
return (ERROR); return (ERROR);
if (_unary_get_op(arithmetic_unary->op, &func)) if (_unary_get_op(arithmetic_unary->operator, &func))
return (ERROR); return (ERROR);
if (func(_arith_unary_to_ast_node(arithmetic_unary), state, out)) if (func(_arith_unary_to_ast_node(arithmetic_unary), state, out))
return (ERROR); 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) if (arithmetic_expansion == NULL || state == NULL || out == NULL)
return (ERROR); return (ERROR);
if (_get_node_number(arithmetic_expansion, start, out)) if (_get_node_number(arithmetic_expansion->expr, state, out))
return (ERROR); return (ERROR);
return (NO_ERROR); return (NO_ERROR);
} }

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */ /* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/27 21:13:15 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_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_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 _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); t_ast_node _arith_binary_to_ast_node(t_ast_arithmetic_binary *self);
#endif #endif