diff --git a/ast/Filelist.ast.mk b/ast/Filelist.ast.mk index c28e3edd..159bcdcd 100644 --- a/ast/Filelist.ast.mk +++ b/ast/Filelist.ast.mk @@ -1,5 +1,4 @@ SRC_FILES = \ -from_node \ from_node/ast_free \ from_node/ast_free_scripting \ from_node/from_node \ diff --git a/exec/Makefile b/exec/Makefile index 41f5ecc1..35fde4dd 100644 --- a/exec/Makefile +++ b/exec/Makefile @@ -6,7 +6,7 @@ # By: maiboyer +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/11/03 13:20:01 by maiboyer #+# #+# # -# Updated: 2024/07/23 21:52:40 by maiboyer ### ########.fr # +# Updated: 2024/07/30 16:02:19 by maiboyer ### ########.fr # # # # **************************************************************************** # @@ -23,7 +23,7 @@ LIB_NAME ?= TARGET = $(BUILD_DIR)/$(NAME) CC ?= clang CFLAGS = -Wno-unused-command-line-argument -Wall -Werror -Wextra -g3 -L$(BUILD_DIR) -MMD -rdynamic -DBASE_PATH='"$(BASE_PATH)/"' -CFLAGS = $(CFLAGS_ADDITIONAL) +CFLAGS += $(CFLAGS_ADDITIONAL) -include Filelist.$(ANAME).mk diff --git a/exec/src/arith/arith.h b/exec/include/exec/arith.h similarity index 84% rename from exec/src/arith/arith.h rename to exec/include/exec/arith.h index a75423cd..08b20c93 100644 --- a/exec/src/arith/arith.h +++ b/exec/include/exec/arith.h @@ -6,31 +6,17 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/27 21:13:15 by rparodi #+# #+# */ -/* Updated: 2024/07/30 14:07:41 by rparodi ### ########.fr */ +/* Updated: 2024/07/30 15:58:54 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef ARITH_H # define ARITH_H -# include -# 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" +# include typedef t_error (*t_arith_op_func)(t_ast_node self, t_state *state, t_i64 *out); diff --git a/exec/include/exec/spawn_cmd/process.h b/exec/include/exec/spawn_cmd/process.h index f9ddf651..d2308d61 100644 --- a/exec/include/exec/spawn_cmd/process.h +++ b/exec/include/exec/spawn_cmd/process.h @@ -6,13 +6,14 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/03 15:43:08 by maiboyer #+# #+# */ -/* Updated: 2024/07/30 13:23:00 by maiboyer ### ########.fr */ +/* Updated: 2024/07/30 16:28:05 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef PROCESS_H #define PROCESS_H +#include "me/fs/fs.h" #include "me/types.h" #include "me/vec/vec_str.h" #include "me/vec/vec_u8.h" @@ -30,7 +31,7 @@ enum e_redirection union u_redirection { struct s_fd_redirection { - int value; + t_fd *value; } fd; struct s_piped_redirection { @@ -41,7 +42,7 @@ union u_redirection { }; /// @brief Redirection for spawning a process -typedef struct s_redirection +typedef struct s_process_redirection { enum e_redirection tag; union u_redirection vals; @@ -70,7 +71,7 @@ static inline t_redirection inherited(void) /// @brief Create a file descriptor redirection /// @param fd file descriptor to redirect /// @return the redirection -static inline t_redirection fd(int fd) +static inline t_redirection fd(t_fd *fd) { return ((t_redirection){.tag = R_FD, .vals = (union u_redirection){ @@ -78,59 +79,8 @@ static inline t_redirection fd(int fd) }}); } -/// @brief Wrapped file descriptor tag -enum e_wrapped_fd_tag -{ - READ_ONLY, - WRITE_ONLY, - READ_WRITE, - INVALID, -}; - -/// @brief Wrapped file descriptor -union u_wrapped_fd { - struct s_read_only - { - int fd; - } ro; - struct s_write_only - { - int fd; - } wo; - struct s_read_write - { - int fd; - } rw; -}; - -/// @brief Wrapped file descriptor -typedef struct s_wrapped_fd -{ - enum e_wrapped_fd_tag tag; - union u_wrapped_fd vals; -} t_wrapped_fd; - -/// @brief Create a Read only wrapped file descriptor -/// @param fd file descriptor to wrap -/// @return the wrapped file descriptor -static inline t_wrapped_fd ro(int fd) -{ - return ((t_wrapped_fd){.tag = READ_ONLY, - .vals = (union u_wrapped_fd){ - .ro = {.fd = fd}, - }}); -} - -/// @brief Create a Write only wrapped file descriptor -/// @param fd file descriptor to wrap -/// @return the wrapped file descriptor -static inline t_wrapped_fd wo(int fd) -{ - return ((t_wrapped_fd){.tag = WRITE_ONLY, .vals = (union u_wrapped_fd){.wo = {.fd = fd}}}); -} - /// @brief Spawn information -typedef struct s_spawn_info +typedef struct s_exec_spawn_info { t_redirection stdin; t_redirection stdout; @@ -140,30 +90,18 @@ typedef struct s_spawn_info t_str binary_path; void (*forked_free)(void *); void *forked_free_args; -} t_spawn_info; +} t_exec_spawn_info; /// @brief Process information typedef struct s_process { - t_wrapped_fd stdin; - t_wrapped_fd stdout; - t_wrapped_fd stderr; t_pid pid; -} t_process; -/// @struct Process output -/// @brief Process output information -typedef struct s_process_output -{ - t_pid pid; - t_vec_u8 stdout; - t_vec_u8 stderr; - t_exit_code exit_code; -} t_process_output; +} t_exec_process; /// @brief Spawn a new process with the given information /// @param info the information to spawn the process /// @param process data returned by the function /// @return true if an error occured, false otherwise -t_error spawn_process(t_spawn_info info, t_process *process); +t_error spawn_process(t_exec_spawn_info info, t_exec_process *process); #endif /* PROCESS_H */ diff --git a/exec/src/arith/arith.c b/exec/src/arith/arith.c index bd28e28e..0a4caac2 100644 --- a/exec/src/arith/arith.c +++ b/exec/src/arith/arith.c @@ -6,12 +6,13 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/26 15:14:50 by maiboyer #+# #+# */ -/* Updated: 2024/07/30 14:07:29 by rparodi ### ########.fr */ +/* Updated: 2024/07/30 16:31:20 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ -#include "./arith.h" +#include "exec/arith.h" #include "me/types.h" +#include "me/convert/str_to_numbers.h" /// ADD OPERATOR STUFF t_error _binary_get_op(t_ast_arithmetic_operator op, t_arith_op_func *out) @@ -100,17 +101,6 @@ t_ast_node _arith_postfix_to_ast_node(t_ast_arithmetic_postfix *self) struct s_ast_node, data.arithmetic_postfix))); } -/* -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_postfix))); -} -*/ - // this is black magic don't worry t_ast_node _arith_literal_to_ast_node(t_ast_arithmetic_literal *self) { @@ -182,7 +172,6 @@ t_error run_arithmetic_binary(t_ast_arithmetic_binary *arithmetic_binary, \ t_error run_arithmetic_ternary(t_ast_arithmetic_ternary *arithmetic_ternary, \ t_state *state, t_i64 *out) { - t_arith_op_func func; t_i64 cond; if (arithmetic_ternary == NULL || state == NULL || out == NULL) @@ -234,11 +223,7 @@ 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_arith_op_func func; - if (arithmetic_expansion == NULL || state == NULL || out == NULL) return (ERROR); - if (_get_node_number(arithmetic_expansion->expr, state, out)) - return (ERROR); - return (NO_ERROR); + return (_get_node_number(arithmetic_expansion->expr, state, out)); } diff --git a/exec/src/arith/arith_operation.c b/exec/src/arith/arith_operation.c index 2afcea9f..bf353c90 100644 --- a/exec/src/arith/arith_operation.c +++ b/exec/src/arith/arith_operation.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "./arith.h" +#include "exec/arith.h" t_error _binary_op_add(t_ast_node self, t_state *state, t_i64 *out) { diff --git a/exec/src/spawn_cmd/handle_redirection.c b/exec/src/spawn_cmd/handle_redirection.c index d6218f84..3b49f2bb 100644 --- a/exec/src/spawn_cmd/handle_redirection.c +++ b/exec/src/spawn_cmd/handle_redirection.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/04 22:27:00 by maiboyer #+# #+# */ -/* Updated: 2024/07/30 14:53:11 by maiboyer ### ########.fr */ +/* Updated: 2024/07/30 16:03:43 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,7 @@ #include "exec/spawn_cmd/process.h" #include "me/types.h" -t_error handle_redirections(t_spawn_info *info, t_process *process) +t_error handle_redirections(t_exec_spawn_info *info, t_exec_process *process) { return (ERROR); } diff --git a/stdme/Filelist.me.mk b/stdme/Filelist.me.mk index e96d23e9..b56a029e 100644 --- a/stdme/Filelist.me.mk +++ b/stdme/Filelist.me.mk @@ -27,16 +27,12 @@ char/isupper \ char/tolower \ char/toupper \ convert/numbers_to_str \ -fs/close \ +fs/directory \ +fs/fd \ +fs/file \ fs/fs_internal \ -fs/open \ -fs/putchar_fd \ -fs/putendl_fd \ -fs/putnbr_fd \ -fs/putstr_fd \ -fs/read \ -fs/read_to_vec \ -fs/write \ +fs/getters \ +fs/putfd \ gnl/get_next_line \ hash/hash_signed \ hash/hash_str \ diff --git a/stdme/include/me/fs/close.h b/stdme/include/me/fs/close.h deleted file mode 100644 index 8bedd585..00000000 --- a/stdme/include/me/fs/close.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* close.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/04 15:56:56 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:49:22 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef CLOSE_H -# define CLOSE_H - -# include "me/types.h" - -bool me_close(int file, t_i32 *error); - -#endif diff --git a/stdme/include/me/fs/open.h b/stdme/include/me/fs/open.h deleted file mode 100644 index 29204d0c..00000000 --- a/stdme/include/me/fs/open.h +++ /dev/null @@ -1,22 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* open.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/03 15:29:38 by maiboyer #+# #+# */ -/* Updated: 2024/01/05 16:43:37 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef OPEN_H -# define OPEN_H - -# include "me/types.h" - -t_error me_open(t_const_str path, bool read, bool write, int *file_out); -t_error me_open_truncate(t_const_str path, int *file_out); -t_error me_open_create(t_const_str path, int *file_out); - -#endif diff --git a/stdme/include/me/fs/putchar_fd.h b/stdme/include/me/fs/putchar_fd.h deleted file mode 100644 index ed8e4532..00000000 --- a/stdme/include/me/fs/putchar_fd.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* putchar_fd.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/08 04:42:45 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:49:06 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef PUTCHAR_FD_H -# define PUTCHAR_FD_H - -# include "me/types.h" - -void me_putchar_fd(char chr, int file); - -#endif diff --git a/stdme/include/me/fs/putendl_fd.h b/stdme/include/me/fs/putendl_fd.h deleted file mode 100644 index b4455e66..00000000 --- a/stdme/include/me/fs/putendl_fd.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* putendl_fd.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/08 04:42:45 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:31:54 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef PUTENDL_FD_H -# define PUTENDL_FD_H - -# include "me/types.h" - -void me_putendl_fd(t_str str, int file); - -#endif \ No newline at end of file diff --git a/stdme/include/me/fs/putnbr_fd.h b/stdme/include/me/fs/putnbr_fd.h deleted file mode 100644 index 8a0b58f3..00000000 --- a/stdme/include/me/fs/putnbr_fd.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* putnbr_fd.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/08 12:45:06 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:32:41 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef PUTNBR_FD_H -# define PUTNBR_FD_H - -# include "me/types.h" - -void me_putnbr_fd(t_i32 n, int file); - -#endif \ No newline at end of file diff --git a/stdme/include/me/fs/putstr_fd.h b/stdme/include/me/fs/putstr_fd.h deleted file mode 100644 index 67b0f436..00000000 --- a/stdme/include/me/fs/putstr_fd.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* putstr_fd.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/08 04:42:45 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:35:53 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef PUTSTR_FD_H -# define PUTSTR_FD_H - -# include "me/types.h" - -void me_putstr_fd(t_str str, int file); - -#endif diff --git a/stdme/include/me/fs/read.h b/stdme/include/me/fs/read.h deleted file mode 100644 index 24cc2b59..00000000 --- a/stdme/include/me/fs/read.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* read.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/03 15:21:19 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:37:03 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef READ_H -# define READ_H - -# include "me/types.h" - -t_usize me_read(int fd, t_u8 *buffer, t_i64 buffer_max, bool *eof_out); - -#endif \ No newline at end of file diff --git a/stdme/include/me/fs/read_to_vec.h b/stdme/include/me/fs/read_to_vec.h deleted file mode 100644 index 94375ae5..00000000 --- a/stdme/include/me/fs/read_to_vec.h +++ /dev/null @@ -1,25 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* read_to_vec.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/24 18:50:37 by maiboyer #+# #+# */ -/* Updated: 2023/12/24 18:57:36 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef READ_TO_VEC_H -# define READ_TO_VEC_H - -# include "me/types.h" -# include "me/vec/vec_u8.h" - -# ifndef READ_BUFFER_SIZE -# define READ_BUFFER_SIZE 4096 -# endif - -bool read_to_vec(t_const_str path, t_vec_u8 *out); - -#endif diff --git a/stdme/include/me/fs/write.h b/stdme/include/me/fs/write.h deleted file mode 100644 index fec32afb..00000000 --- a/stdme/include/me/fs/write.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* write.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/03 15:27:33 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 16:36:48 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef WRITE_H -# define WRITE_H - -# include "me/types.h" - -bool me_write(int fd, t_u8 *buffer, t_i64 size); - -#endif diff --git a/stdme/src/img/qoi/qoi_fs.c b/stdme/src/img/qoi/qoi_fs.c index a17ebe69..768c356a 100644 --- a/stdme/src/img/qoi/qoi_fs.c +++ b/stdme/src/img/qoi/qoi_fs.c @@ -6,33 +6,35 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/24 19:06:05 by maiboyer #+# #+# */ -/* Updated: 2024/07/10 17:46:34 by maiboyer ### ########.fr */ +/* Updated: 2024/07/30 16:26:28 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ -#include "me/fs/close.h" -#include "me/fs/open.h" -#include "me/fs/read_to_vec.h" -#include "me/fs/write.h" +#include "me/fs/fs.h" #include "me/img/qoi.h" #include "me/mem/mem.h" +#include "me/vec/vec_u8.h" #include +/// This has to be added into the me/fs/fs.h header at one point +t_error read_to_vec(t_const_str filename, t_vec_u8 *out); + t_i32 qoi_write(t_const_str filename, const void *data, const t_qoi_desc *desc) { - int f; + t_fd *f; void *encoded; t_i32 size; - if (me_open(filename, false, true, &f)) + f = open_fd((t_str)filename, FD_WRITE, 0, FP_ALL_EXEC); + if (f == NULL) return (0); encoded = qoi_encode(data, desc, &size); if (!encoded) - return (me_close(f, NULL), 0); - if (me_write(f, encoded, size)) - return (me_close(f, NULL), 0); - me_close(f, NULL); + return (close_fd(f), 0); + if (write_fd(f, encoded, size, NULL)) + return (close_fd(f), 0); + close_fd(f); mem_free(encoded); return (size); } diff --git a/stdme/src/os/abort.c b/stdme/src/os/abort.c index b394f86e..06acceeb 100644 --- a/stdme/src/os/abort.c +++ b/stdme/src/os/abort.c @@ -6,13 +6,12 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/07 11:08:03 by maiboyer #+# #+# */ -/* Updated: 2024/07/30 16:09:47 by rparodi ### ########.fr */ +/* Updated: 2024/07/30 16:20:50 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ #include "./gnu_source.h" -#include "me/fs/putendl_fd.h" -#include "me/fs/putstr_fd.h" +#include "me/fs/fs.h" #include "me/types.h" #include #include @@ -87,9 +86,10 @@ void print_trace(void) void me_abort(t_str msg) { if (msg == NULL) - msg = "No message (msg was NULL)"; - me_putstr_fd("Abort: ", 2); - me_putendl_fd(msg, 2); + msg = "No message provided"; + put_string_fd(get_stderr(),"Abort: "); + put_string_fd(get_stderr(),msg); + put_char_fd(get_stderr(),'\n'); print_trace(); me_exit(134); }