many things, cosmo build!

This commit is contained in:
veclavtlica
2026-10-12 21:12:47 +03:00
parent ba4131abbf
commit 8d2bb5575e
29 changed files with 699 additions and 312 deletions
+48 -2
View File
@@ -10,6 +10,16 @@
#include <stddef.h>
#include <stdint.h>
#if COM_DEF_TARGET == COM_DEF_TARGET_WASM
#define COM_STD_INFD 0
#define COM_STD_OUTFD 1
#else
/* TODO: Make it more graceful, probably with static func. */
#include <unistd.h>
#define COM_STD_INFD (fdopen(STDIN_FILENO, "r"))
#define COM_STD_OUTFD (fdopen(STDOUT_FILENO, "w"))
#endif
/* Generic system interface, linux/bsd derived. */
typedef void *com_std_fd;
#define COM_STD_OPEN_READ (1 << 0)
@@ -17,6 +27,7 @@ typedef void *com_std_fd;
com_std_fd com_std_open(char const *path, uint32_t flags);
bool com_std_write(com_std_fd fd, void const *data, uint32_t bytes);
int32_t com_std_read(com_std_fd fd, void *data, uint32_t upto);
bool com_std_has_data(com_std_fd);
bool com_std_sfwd(com_std_fd fd, uint32_t bytes);
com_std_fd com_std_socket(bool isnetwork);
bool com_std_connect(com_std_fd sock, bool isnetwork, char const *address);
@@ -31,9 +42,44 @@ void *com_std_alloc(void *ptr, size_t size);
/* Note: Functions listed below are only available for dev builds. */
/* Trigonometry functions are for reference testing of our own fixed point
* implementations. Do not use otherwise. */
void com_std_assert(bool holds);
void com_std_printf(char const *fmt, ...);
#define com_std_assert(p_h) \
do { \
if (!(p_h)) { \
const char msg[] = \
"Assertion failed at "__FILE__ \
":" COM_DEF_STRLIT(__LINE__) ": " COM_DEF_STRLIT(p_h); \
com_std_print_str(msg, sizeof msg, true); \
com_std_exit(-1); \
} \
} while (0)
/*
Basic printing utility that doesn't utilize format string.
Instead a vector of arguments is passed and concatenated, based on type.
Newline is implied at the end.
Example: com_std_print("My unit32_t: ", 'u', value, 's', " is here");
Format specifiers:
'u' = uint32_t
'i' = int32_t
'd' = float (upcast to double with vargs)
'c' = null terminated C string
Our own types:
'f' = com_fix value
'p' = com_pnt pointer
'v' = com_vec pointer
's' = pointer to com_str structure
'b' = pointer to com_buf structure
'.' is placed at the end implicitly with macro,
it is needed to know when to end.
*/
void com_std_print_(int32_t start, ...);
#define com_std_print(...) com_std_print_(__VA_ARGS__, '.')
void com_std_print_str(char const *str, uint32_t len, bool newline);
double com_std_sqrt(double v);
double com_std_fabs(double v);
double com_std_sin(double v);