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
49
exec/include/exec/arith.h
Normal file
49
exec/include/exec/arith.h
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* arith.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/27 21:13:15 by rparodi #+# #+# */
|
||||
/* Updated: 2024/07/30 15:58:54 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef ARITH_H
|
||||
# define ARITH_H
|
||||
|
||||
# include "app/state.h"
|
||||
# include "ast/ast.h"
|
||||
# include "me/types.h"
|
||||
# include <unistd.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);
|
||||
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);
|
||||
|
||||
#endif
|
||||
|
|
@ -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 */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue