Finished the norm in stdme normal code
This commit is contained in:
parent
3cfbf07882
commit
5bc68504f9
19 changed files with 44 additions and 325 deletions
|
|
@ -6,7 +6,7 @@
|
|||
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# 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
|
||||
|
||||
|
|
|
|||
|
|
@ -6,31 +6,17 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <stddef.h>
|
||||
# include <stdio.h>
|
||||
# include <unistd.h>
|
||||
|
||||
# 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 <unistd.h>
|
||||
|
||||
typedef t_error (*t_arith_op_func)(t_ast_node self, t_state *state, t_i64 *out);
|
||||
|
||||
|
|
@ -6,13 +6,14 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 */
|
||||
|
|
|
|||
|
|
@ -6,12 +6,13 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue