diff --git a/exec/src/arith/arith.c b/exec/src/arith/arith.c index 916c7822..5da48e62 100644 --- a/exec/src/arith/arith.c +++ b/exec/src/arith/arith.c @@ -6,13 +6,14 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/26 15:14:50 by maiboyer #+# #+# */ -/* Updated: 2024/07/27 21:24:11 by rparodi ### ########.fr */ +/* Updated: 2024/07/27 22:58:45 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include "./arith.h" -t_error _binary_get_op(t_ast_arithmetic_operator op, t_arith_op_func *out) +/// ADD OPERATOR STUFF +t_error _binary_get_op(t_ast_arithmetic_operator op, t_arith_op_func *out) { if (out == NULL) return (ERROR); @@ -26,46 +27,54 @@ t_error _binary_get_op(t_ast_arithmetic_operator op, t_arith_op_func *out) return (*out = _binary_op_div, NO_ERROR); if (op == ARITH_MOD) return (*out = _binary_op_mod, NO_ERROR); - /// add remaining; return (ERROR); } -t_error _get_node_number(t_ast_node self, t_state *state, t_i64 *out) +//NOT FINISH +t_error _get_node_number(t_ast_node self, t_state *state, t_i64 *out) { if (self == NULL || state == NULL || out == NULL) return (ERROR); if (self->kind == AST_ARITHMETIC_LITTERAL) - return (run_arithmetic_literal(&self->data.arithmetic_literal, state, out)); + return (run_arithmetic_literal(\ + &self->data.arithmetic_literal, state, out)); if (self->kind == AST_ARITHMETIC_BINARY) - return (run_arithmetic_binary(&self->data.arithmetic_binary, state, out)); - // ADD OTHER STUFF HERE + return (run_arithmetic_binary(\ + &self->data.arithmetic_binary, state, out)); return (ERROR); } // this is black magic don't worry -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) { - t_u8 *ptr; + t_u8 *ptr; ptr = (void *)(self); - return ((void *)(ptr - offsetof(struct s_ast_node, data.arithmetic_binary))); + return ((void *)(ptr - offsetof(\ + struct s_ast_node, data.arithmetic_binary))); } -t_error run_arithmetic_literal(t_ast_arithmetic_literal *arithmetic_literal, t_state *state, t_i64 *out) +/// AFTER 65 +/// the from node needs to change +/// if they find a raw_string, it is a variable expansion, +/// so create a AST_EXPANSION +/// AFTER 67 +/// probably an variable expansion i guess +t_error run_arithmetic_literal(t_ast_arithmetic_literal *arithmetic_literal, \ + t_state *state, t_i64 *out) { if (arithmetic_literal == NULL || state == NULL || out == NULL) return (ERROR); - /// the from node needs to change - /// if they find a raw_string, it is a variable expansion, so create a AST_EXPANSION if (arithmetic_literal->value->kind == AST_RAW_STRING) - return (str_to_i64(arithmetic_literal->value->data.raw_string.str, 10, out)); - // probably an variable expansion i guess + return (str_to_i64(\ + arithmetic_literal->value->data.raw_string.str, 10, out)); return (ERROR); } -t_error run_arithmetic_binary(t_ast_arithmetic_binary *arithmetic_binary, t_state *state, t_i64 *out) +t_error run_arithmetic_binary(t_ast_arithmetic_binary *arithmetic_binary, \ + t_state *state, t_i64 *out) { - t_arith_op_func func; + t_arith_op_func func; if (arithmetic_binary == NULL || state == NULL || out == NULL) return (ERROR); diff --git a/exec/src/arith/arith.h b/exec/src/arith/arith.h index d8217400..9261054e 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/27 21:21:17 by rparodi ### ########.fr */ +/* Updated: 2024/07/27 22:51:50 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,26 +33,26 @@ typedef t_error (*t_arith_op_func)(t_ast_node self, t_state *state, t_i64 *out); -t_error run_arithmetic_binary(t_ast_arithmetic_binary *arithmetic_binary, \ - t_state *state, t_i64 *out); -t_error run_arithmetic_literal(t_ast_arithmetic_literal *arithmetic_literal, \ - t_state *state, t_i64 *out); -t_error run_arithmetic_postfix(t_ast_arithmetic_postfix *arithmetic_postfix, \ - t_state *state, t_i64 *out); -t_error run_arithmetic_ternary(t_ast_arithmetic_ternary *arithmetic_ternary, \ - t_state *state, t_i64 *out); -t_error run_arithmetic_unary(t_ast_arithmetic_unary *arithmetic_unary, \ - t_state *state, t_i64 *out); -t_error run_arithmetic_expansion( \ - t_ast_arithmetic_expansion *arithmetic_expansion, \ - t_state *state, t_i64 *out); +t_error run_arithmetic_binary( \ +t_ast_arithmetic_binary *arithmetic_binary, t_state *state, t_i64 *out); +t_error run_arithmetic_literal( \ +t_ast_arithmetic_literal *arithmetic_literal, t_state *state, t_i64 *out); +t_error run_arithmetic_postfix( \ +t_ast_arithmetic_postfix *arithmetic_postfix, t_state *state, t_i64 *out); +t_error run_arithmetic_ternary( \ +t_ast_arithmetic_ternary *arithmetic_ternary, t_state *state, t_i64 *out); +t_error run_arithmetic_unary( \ +t_ast_arithmetic_unary *arithmetic_unary, t_state *state, t_i64 *out); +t_error run_arithmetic_expansion( \ +t_ast_arithmetic_expansion *arithmetic_expansion, t_state *state, t_i64 *out); -t_error _get_node_number(t_ast_node self, t_state *state, t_i64 *out); +t_error _get_node_number(t_ast_node self, t_state *state, t_i64 *out); -t_error _binary_op_add(t_ast_node self, t_state *state, t_i64 *out); -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 _binary_op_add(t_ast_node self, t_state *state, t_i64 *out); +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_ast_node _arith_binary_to_ast_node(t_ast_arithmetic_binary *self); #endif diff --git a/exec/src/arith/arith_operation.c b/exec/src/arith/arith_operation.c index ee13ed01..43a94a9c 100644 --- a/exec/src/arith/arith_operation.c +++ b/exec/src/arith/arith_operation.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/27 21:23:07 by rparodi #+# #+# */ -/* Updated: 2024/07/27 21:24:04 by rparodi ### ########.fr */ +/* Updated: 2024/07/27 22:54:43 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,8 @@ t_error _binary_op_add(t_ast_node self, t_state *state, t_i64 *out) t_i64 lhs; t_i64 rhs; - if (self == NULL || state == NULL || out == NULL || self->kind == AST_ARITHMETIC_BINARY) + if (self == NULL || state == NULL || out == NULL || \ + self->kind == AST_ARITHMETIC_BINARY) return (ERROR); if (_get_node_number(self->data.arithmetic_binary.lhs, state, &lhs)) return (ERROR); @@ -29,12 +30,13 @@ t_error _binary_op_add(t_ast_node self, t_state *state, t_i64 *out) return (NO_ERROR); } -t_error _binary_op_sub(t_ast_node self, t_state *state, t_i64 *out) +t_error _binary_op_sub(t_ast_node self, t_state *state, t_i64 *out) { - t_i64 lhs; - t_i64 rhs; + t_i64 lhs; + t_i64 rhs; - if (self == NULL || state == NULL || out == NULL || self->kind == AST_ARITHMETIC_BINARY) + if (self == NULL || state == NULL || out == NULL || \ + self->kind == AST_ARITHMETIC_BINARY) return (ERROR); if (_get_node_number(self->data.arithmetic_binary.lhs, state, &lhs)) return (ERROR); @@ -51,7 +53,8 @@ t_error _binary_op_mul(t_ast_node self, t_state *state, t_i64 *out) t_i64 lhs; t_i64 rhs; - if (self == NULL || state == NULL || out == NULL || self->kind == AST_ARITHMETIC_BINARY) + if (self == NULL || state == NULL || out == NULL || \ + self->kind == AST_ARITHMETIC_BINARY) return (ERROR); if (_get_node_number(self->data.arithmetic_binary.lhs, state, &lhs)) return (ERROR); @@ -63,12 +66,13 @@ t_error _binary_op_mul(t_ast_node self, t_state *state, t_i64 *out) return (NO_ERROR); } -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_i64 lhs; t_i64 rhs; - if (self == NULL || state == NULL || out == NULL || self->kind == AST_ARITHMETIC_BINARY) + if (self == NULL || state == NULL || out == NULL || \ + self->kind == AST_ARITHMETIC_BINARY) return (ERROR); if (_get_node_number(self->data.arithmetic_binary.lhs, state, &lhs)) return (ERROR); @@ -80,12 +84,13 @@ t_error _binary_op_div(t_ast_node self, t_state *state, t_i64 *out) return (NO_ERROR); } -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_i64 lhs; t_i64 rhs; - if (self == NULL || state == NULL || out == NULL || self->kind == AST_ARITHMETIC_BINARY) + if (self == NULL || state == NULL || out == NULL || \ + self->kind == AST_ARITHMETIC_BINARY) return (ERROR); if (_get_node_number(self->data.arithmetic_binary.lhs, state, &lhs)) return (ERROR);