add PK_INLINE

This commit is contained in:
blueloveTH 2024-06-13 20:13:20 +08:00
parent 59537c9bd0
commit 6167cb4a43
3 changed files with 18 additions and 10 deletions

View File

@ -29,15 +29,15 @@ typedef struct pkpy_AnyStr {
}; };
} pkpy_AnyStr; } pkpy_AnyStr;
inline pkpy_AnyStr pkpy_AnyStr__int(int x) { pkpy_AnyStr s; s.type = 1; s._int = x; return s; } PK_INLINE pkpy_AnyStr pkpy_AnyStr__int(int x) { pkpy_AnyStr s; s.type = 1; s._int = x; return s; }
inline pkpy_AnyStr pkpy_AnyStr__i64(int64_t x) { pkpy_AnyStr s; s.type = 2; s._i64 = x; return s; } PK_INLINE pkpy_AnyStr pkpy_AnyStr__i64(int64_t x) { pkpy_AnyStr s; s.type = 2; s._i64 = x; return s; }
inline pkpy_AnyStr pkpy_AnyStr__float(float x) { pkpy_AnyStr s; s.type = 3; s._float = x; return s; } PK_INLINE pkpy_AnyStr pkpy_AnyStr__float(float x) { pkpy_AnyStr s; s.type = 3; s._float = x; return s; }
inline pkpy_AnyStr pkpy_AnyStr__double(double x) { pkpy_AnyStr s; s.type = 4; s._double = x; return s; } PK_INLINE pkpy_AnyStr pkpy_AnyStr__double(double x) { pkpy_AnyStr s; s.type = 4; s._double = x; return s; }
inline pkpy_AnyStr pkpy_AnyStr__char(char x) { pkpy_AnyStr s; s.type = 5; s._char = x; return s; } PK_INLINE pkpy_AnyStr pkpy_AnyStr__char(char x) { pkpy_AnyStr s; s.type = 5; s._char = x; return s; }
inline pkpy_AnyStr pkpy_AnyStr__str(const pkpy_Str* x) { pkpy_AnyStr s; s.type = 6; s._str = x; return s; } PK_INLINE pkpy_AnyStr pkpy_AnyStr__str(const pkpy_Str* x) { pkpy_AnyStr s; s.type = 6; s._str = x; return s; }
inline pkpy_AnyStr pkpy_AnyStr__sv(c11_string x) { pkpy_AnyStr s; s.type = 7; s._sv = x; return s; } PK_INLINE pkpy_AnyStr pkpy_AnyStr__sv(c11_string x) { pkpy_AnyStr s; s.type = 7; s._sv = x; return s; }
inline pkpy_AnyStr pkpy_AnyStr__cstr(const char* x) { pkpy_AnyStr s; s.type = 8; s._cstr = x; return s; } PK_INLINE pkpy_AnyStr pkpy_AnyStr__cstr(const char* x) { pkpy_AnyStr s; s.type = 8; s._cstr = x; return s; }
inline pkpy_AnyStr pkpy_AnyStr__ptr(void* x) { pkpy_AnyStr s; s.type = 9; s._ptr = x; return s; } PK_INLINE pkpy_AnyStr pkpy_AnyStr__ptr(void* x) { pkpy_AnyStr s; s.type = 9; s._ptr = x; return s; }
void pkpy_SStream__ctor(pkpy_SStream* self); void pkpy_SStream__ctor(pkpy_SStream* self);
void pkpy_SStream__dtor(pkpy_SStream* self); void pkpy_SStream__dtor(pkpy_SStream* self);

View File

@ -5,7 +5,9 @@ extern "C" {
#endif #endif
#include <stdbool.h> #include <stdbool.h>
#include "pocketpy/common/vector.h" #include "pocketpy/common/vector.h"
#include "pocketpy/common/utils.h"
/* string_view */ /* string_view */
typedef struct c11_string{ typedef struct c11_string{
@ -23,7 +25,7 @@ typedef struct pkpy_Str{
}; };
} pkpy_Str; } pkpy_Str;
inline const char* pkpy_Str__data(const pkpy_Str* self){ PK_INLINE const char* pkpy_Str__data(const pkpy_Str* self){
return self->is_sso ? self->_inlined : self->_ptr; return self->is_sso ? self->_inlined : self->_ptr;
} }

View File

@ -4,6 +4,12 @@
extern "C" { extern "C" {
#endif #endif
#ifdef __cplusplus
#define PK_INLINE inline
#else
#define PK_INLINE static inline
#endif
#define PK_REGION(name) 1 #define PK_REGION(name) 1
#define PK_SLICE_LOOP(i, start, stop, step) for(int i = start; step > 0 ? i < stop : i > stop; i += step) #define PK_SLICE_LOOP(i, start, stop, step) for(int i = start; step > 0 ? i < stop : i > stop; i += step)