diff --git a/allocator/Filelist.aq.mk b/allocator/Filelist.aq.mk index ead60e1c..63698d77 100644 --- a/allocator/Filelist.aq.mk +++ b/allocator/Filelist.aq.mk @@ -9,11 +9,11 @@ me_alloc/merge_blocks \ me_alloc/pages \ me_alloc/realloc \ vg/dummy_block \ -vg/dummy_mem_status \ vg/dummy_mempool \ vg/dummy_mempool_bis \ +vg/dummy_mem_status \ vg/valgrind_block \ -vg/valgrind_mem_status \ vg/valgrind_mempool \ vg/valgrind_mempool_bis \ +vg/valgrind_mem_status \ diff --git a/exec/Filelist.exec.mk b/exec/Filelist.exec.mk index ab6061cf..829d15e7 100644 --- a/exec/Filelist.exec.mk +++ b/exec/Filelist.exec.mk @@ -1,4 +1,4 @@ SRC_FILES = \ -arith \ +arith/arith \ run_ast \ diff --git a/exec/src/arith.c b/exec/src/arith/arith.c similarity index 56% rename from exec/src/arith.c rename to exec/src/arith/arith.c index 94a9e043..916c7822 100644 --- a/exec/src/arith.c +++ b/exec/src/arith/arith.c @@ -6,63 +6,11 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/26 15:14:50 by maiboyer #+# #+# */ -/* Updated: 2024/07/27 14:43:31 by maiboyer ### ########.fr */ +/* Updated: 2024/07/27 21:24:11 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ -#include "app/state.h" -#include "ast/ast.h" -#include "exec/run.h" -#include "me/convert/numbers_to_str.h" -#include "me/convert/str_to_numbers.h" -#include "me/hashmap/hashmap_env.h" -#include "me/mem/mem.h" -#include "me/os/pipe.h" -#include "me/os/process.h" -#include "me/str/str.h" -#include "me/string/string.h" -#include "me/types.h" -#include "me/vec/vec_estr.h" -#include "me/vec/vec_str.h" - -#include -#include - -#pragma clang diagnostic ignored "-Wunused-parameter" -#pragma clang diagnostic ignored "-Wunused-variable" - -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 _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_i64 lhs; - t_i64 rhs; - - 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); - if (_get_node_number(self->data.arithmetic_binary.rhs, state, &rhs)) - return (ERROR); - // do check for invalid values here (like rhs == 0 for div/mod) - *out = lhs + rhs; - return (NO_ERROR); -} +#include "./arith.h" t_error _binary_get_op(t_ast_arithmetic_operator op, t_arith_op_func *out) { @@ -105,7 +53,6 @@ t_ast_node _arith_binary_to_ast_node(t_ast_arithmetic_binary *self) 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 diff --git a/exec/src/arith/arith.h b/exec/src/arith/arith.h new file mode 100644 index 00000000..d8217400 --- /dev/null +++ b/exec/src/arith/arith.h @@ -0,0 +1,58 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* arith.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/07/27 21:13:15 by rparodi #+# #+# */ +/* Updated: 2024/07/27 21:21:17 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef ARITH_H +# define ARITH_H + +# include +# include + +# include "app/state.h" +# include "ast/ast.h" +# include "exec/run.h" +# include "me/convert/numbers_to_str.h" +# include "me/convert/str_to_numbers.h" +# include "me/hashmap/hashmap_env.h" +# include "me/mem/mem.h" +# include "me/os/pipe.h" +# include "me/os/process.h" +# include "me/str/str.h" +# include "me/string/string.h" +# include "me/types.h" +# include "me/vec/vec_estr.h" +# include "me/vec/vec_str.h" + +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 _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); + +#endif diff --git a/exec/src/arith/arith_operation.c b/exec/src/arith/arith_operation.c new file mode 100644 index 00000000..ee13ed01 --- /dev/null +++ b/exec/src/arith/arith_operation.c @@ -0,0 +1,98 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* arith_operation.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/07/27 21:23:07 by rparodi #+# #+# */ +/* Updated: 2024/07/27 21:24:04 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "./arith.h" + +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) + return (ERROR); + if (_get_node_number(self->data.arithmetic_binary.lhs, state, &lhs)) + return (ERROR); + if (_get_node_number(self->data.arithmetic_binary.rhs, state, &rhs)) + return (ERROR); + *out = lhs + rhs; + if (*out - lhs != rhs || *out - rhs != lhs) + return (ERROR); + return (NO_ERROR); +} + +t_error _binary_op_sub(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) + return (ERROR); + if (_get_node_number(self->data.arithmetic_binary.lhs, state, &lhs)) + return (ERROR); + if (_get_node_number(self->data.arithmetic_binary.rhs, state, &rhs)) + return (ERROR); + *out = lhs - rhs; + if (*out + lhs != rhs || *out + rhs != lhs) + return (ERROR); + return (NO_ERROR); +} + +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) + return (ERROR); + if (_get_node_number(self->data.arithmetic_binary.lhs, state, &lhs)) + return (ERROR); + if (_get_node_number(self->data.arithmetic_binary.rhs, state, &rhs)) + return (ERROR); + *out = lhs * rhs; + if (*out / lhs != rhs || *out / rhs != lhs) + return (ERROR); + return (NO_ERROR); +} + +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) + return (ERROR); + if (_get_node_number(self->data.arithmetic_binary.lhs, state, &lhs)) + return (ERROR); + if (_get_node_number(self->data.arithmetic_binary.rhs, state, &rhs)) + return (ERROR); + *out = lhs / rhs; + if (*out * rhs != lhs) + return (ERROR); + return (NO_ERROR); +} + +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) + return (ERROR); + if (_get_node_number(self->data.arithmetic_binary.lhs, state, &lhs)) + return (ERROR); + if (_get_node_number(self->data.arithmetic_binary.rhs, state, &rhs)) + return (ERROR); + *out = lhs % rhs; + if (*out > rhs) + return (ERROR); + return (NO_ERROR); +} diff --git a/line/Filelist.line.mk b/line/Filelist.line.mk index 020b59ee..b1a79d04 100644 --- a/line/Filelist.line.mk +++ b/line/Filelist.line.mk @@ -2,9 +2,9 @@ SRC_FILES = \ line \ line_edit_actions \ line_edit_actions2 \ -line_edit_mode \ line_editing \ line_editing2 \ +line_edit_mode \ line_globals \ line_history \ line_internals \ diff --git a/parser/Filelist.gmr.mk b/parser/Filelist.gmr.mk index 2b8b91b5..09b9dc53 100644 --- a/parser/Filelist.gmr.mk +++ b/parser/Filelist.gmr.mk @@ -114,6 +114,28 @@ primary_state_ids/primary_state_ids_18 \ primary_state_ids/primary_state_ids_19 \ primary_state_ids/primary_state_ids_20 \ primary_state_ids/primary_state_ids_21 \ +small_parse_table_map/small_parse_table_map_0 \ +small_parse_table_map/small_parse_table_map_1 \ +small_parse_table_map/small_parse_table_map_2 \ +small_parse_table_map/small_parse_table_map_3 \ +small_parse_table_map/small_parse_table_map_4 \ +small_parse_table_map/small_parse_table_map_5 \ +small_parse_table_map/small_parse_table_map_6 \ +small_parse_table_map/small_parse_table_map_7 \ +small_parse_table_map/small_parse_table_map_8 \ +small_parse_table_map/small_parse_table_map_9 \ +small_parse_table_map/small_parse_table_map_10 \ +small_parse_table_map/small_parse_table_map_11 \ +small_parse_table_map/small_parse_table_map_12 \ +small_parse_table_map/small_parse_table_map_13 \ +small_parse_table_map/small_parse_table_map_14 \ +small_parse_table_map/small_parse_table_map_15 \ +small_parse_table_map/small_parse_table_map_16 \ +small_parse_table_map/small_parse_table_map_17 \ +small_parse_table_map/small_parse_table_map_18 \ +small_parse_table_map/small_parse_table_map_19 \ +small_parse_table_map/small_parse_table_map_20 \ +small_parse_table_map/small_parse_table_map_21 \ small_parse_table/small_parse_table_0 \ small_parse_table/small_parse_table_1 \ small_parse_table/small_parse_table_2 \ @@ -946,28 +968,6 @@ small_parse_table/small_parse_table_828 \ small_parse_table/small_parse_table_829 \ small_parse_table/small_parse_table_830 \ small_parse_table/small_parse_table_831 \ -small_parse_table_map/small_parse_table_map_0 \ -small_parse_table_map/small_parse_table_map_1 \ -small_parse_table_map/small_parse_table_map_2 \ -small_parse_table_map/small_parse_table_map_3 \ -small_parse_table_map/small_parse_table_map_4 \ -small_parse_table_map/small_parse_table_map_5 \ -small_parse_table_map/small_parse_table_map_6 \ -small_parse_table_map/small_parse_table_map_7 \ -small_parse_table_map/small_parse_table_map_8 \ -small_parse_table_map/small_parse_table_map_9 \ -small_parse_table_map/small_parse_table_map_10 \ -small_parse_table_map/small_parse_table_map_11 \ -small_parse_table_map/small_parse_table_map_12 \ -small_parse_table_map/small_parse_table_map_13 \ -small_parse_table_map/small_parse_table_map_14 \ -small_parse_table_map/small_parse_table_map_15 \ -small_parse_table_map/small_parse_table_map_16 \ -small_parse_table_map/small_parse_table_map_17 \ -small_parse_table_map/small_parse_table_map_18 \ -small_parse_table_map/small_parse_table_map_19 \ -small_parse_table_map/small_parse_table_map_20 \ -small_parse_table_map/small_parse_table_map_21 \ symbols_metadata/symbols_metadata_0 \ symbols_metadata/symbols_metadata_1 \ symbols_names/symbols_names_0 \ diff --git a/stdme/Filelist.me.mk b/stdme/Filelist.me.mk index e96d23e9..38f2a870 100644 --- a/stdme/Filelist.me.mk +++ b/stdme/Filelist.me.mk @@ -38,10 +38,10 @@ fs/read \ fs/read_to_vec \ fs/write \ gnl/get_next_line \ +hash/hasher \ hash/hash_signed \ hash/hash_str \ hash/hash_unsigned \ -hash/hasher \ hash/sip/sip13 \ hash/sip/sip_utils \ hash/sip/sip_utils2 \ @@ -89,6 +89,10 @@ printf/printf \ printf/printf_fd \ printf/printf_str \ printf/vprintf \ +string/mod \ +string/string_insert \ +string/string_remove \ +string/string_reserve \ str/str_clone \ str/str_compare \ str/str_find_chr \ @@ -105,10 +109,6 @@ str/str_n_find_str \ str/str_split \ str/str_substring \ str/str_trim \ -string/mod \ -string/string_insert \ -string/string_remove \ -string/string_reserve \ GEN_FILES = \ convert/i16_to_str \