mirror of
https://github.com/Ed94/pikuma_ps1.git
synced 2026-06-01 18:41:13 -07:00
Sorting Primitives into the OT
Started to add some ergonomic definitions into duffle.
This commit is contained in:
+43
-2
@@ -1,5 +1,6 @@
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "assert.h"
|
||||
#endif
|
||||
|
||||
typedef unsigned char U8;
|
||||
@@ -27,7 +28,7 @@ enum {
|
||||
|
||||
#define alignas _Alignas
|
||||
#define alignof _Alignof
|
||||
#define byte_pad(amount, ...) Byte glue(_PAD_, __VA_ARGS__) [amount]
|
||||
#define byte_pad(amount, ...) BYTE glue(_PAD_, __VA_ARGS__) [amount]
|
||||
#define farray_len(array) (SSIZE)sizeof(array) / size_of( typeof((array)[0]))
|
||||
#define farray_init(type, ...) (type[]){__VA_ARGS__}
|
||||
#define def_farray(type, len) type A ## len ## _ ## type[len]
|
||||
@@ -38,7 +39,10 @@ enum {
|
||||
#define opt_args(symbol, ...) &(symbol){__VA_ARGS__}
|
||||
#define ret_type(type) type
|
||||
#define local_persist static
|
||||
#define global static
|
||||
#define internal static
|
||||
#define global
|
||||
#define gknown
|
||||
#define ct_lit
|
||||
#define offset_of(type, member) cast(SSIZE, & (((type*) 0)->member))
|
||||
#define static_assert _Static_assert
|
||||
#define typeof __typeof__
|
||||
@@ -70,3 +74,40 @@ typedef def_span(U32);
|
||||
typedef def_span(SSIZE);
|
||||
|
||||
typedef void def_proc(VoidFn) (void);
|
||||
|
||||
#define def_Slice(type) \
|
||||
def_struct(tmpl(Slice,type)) { \
|
||||
type* ptr; \
|
||||
SSIZE len; \
|
||||
}
|
||||
#define slice_assert(slice) do { assert((slice).ptr != nullptr); assert((slice).len > 0); } while(0)
|
||||
#define slice_end(slice) ((slice).ptr + (slice).len)
|
||||
#define size_of_slice_type(slice) size_of( * (slice).ptr )
|
||||
|
||||
typedef def_Slice(void);
|
||||
typedef def_Slice(BYTE);
|
||||
#define slice_byte(slice) ((Slice_BYTE){cast(Byte*, (slice).ptr), (slice).len * size_of_slice_type(slice)})
|
||||
#define slice_fmem(mem) ((Slice_BYTE){ mem, size_of(mem) })
|
||||
|
||||
void slice__copy(Slice_BYTE dest, SSIZE dest_typewidth, Slice_BYTE src, SSIZE src_typewidth);
|
||||
void slice__zero(Slice_BYTE mem, SSIZE typewidth);
|
||||
#define slice_copy(dest, src) do { \
|
||||
static_assert(typeof_same(dest, src)); \
|
||||
slice__copy(slice_byte(dest), size_of_slice_type(dest), slice_byte(src), size_of_slice_type(src)); \
|
||||
} while (0)
|
||||
#define slice_zero(slice) slice__zero(slice_byte(slice), size_of_slice_type(slice))
|
||||
|
||||
#define slice_iter(container, iter) \
|
||||
typeof((container).ptr) iter = (container).ptr; \
|
||||
iter != slice_end(container); \
|
||||
++ iter
|
||||
#define slice_arg_from_array(type, ...) & (tmpl(Slice,type)) { \
|
||||
.ptr = farray_init(type, __VA_ARGS__), \
|
||||
.len = farray_len( farray_init(type, __VA_ARGS__)) \
|
||||
}
|
||||
|
||||
typedef unsigned char UTF8;
|
||||
typedef def_Slice(UTF8);
|
||||
typedef Slice_UTF8 Str8;
|
||||
typedef def_Slice(Str8);
|
||||
#define txt(string_literal) (Str8){ (UTF8*) string_literal, size_of(string_literal) - 1 }
|
||||
|
||||
Reference in New Issue
Block a user