فهرست منبع

add `PK_INLINE`

blueloveTH 1 سال پیش
والد
کامیت
6167cb4a43
3فایلهای تغییر یافته به همراه18 افزوده شده و 10 حذف شده
  1. 9 9
      include/pocketpy/common/sstream.h
  2. 3 1
      include/pocketpy/common/str.h
  3. 6 0
      include/pocketpy/common/utils.h

+ 9 - 9
include/pocketpy/common/sstream.h

@@ -29,15 +29,15 @@ typedef struct pkpy_AnyStr {
     };
 } pkpy_AnyStr;
 
-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; }
-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; }
-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; }
-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; }
-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__int(int x) { pkpy_AnyStr s; s.type = 1; s._int = x; return s; }
+PK_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__float(float x) { pkpy_AnyStr s; s.type = 3; s._float = x; return s; }
+PK_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__char(char x) { pkpy_AnyStr s; s.type = 5; s._char = 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; }
+PK_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__cstr(const char* x) { pkpy_AnyStr s; s.type = 8; s._cstr = 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__dtor(pkpy_SStream* self);

+ 3 - 1
include/pocketpy/common/str.h

@@ -5,7 +5,9 @@ extern "C" {
 #endif
 
 #include <stdbool.h>
+
 #include "pocketpy/common/vector.h"
+#include "pocketpy/common/utils.h"
 
 /* string_view */
 typedef struct c11_string{
@@ -23,7 +25,7 @@ typedef struct 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;
 }
 

+ 6 - 0
include/pocketpy/common/utils.h

@@ -4,6 +4,12 @@
 extern "C" {
 #endif
 
+#ifdef __cplusplus
+#define PK_INLINE inline
+#else
+#define PK_INLINE static inline
+#endif
+
 #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)