Ver Fonte

some fix

blueloveTH há 1 ano atrás
pai
commit
649fb3cd98

+ 2 - 21
.clang-format

@@ -1,16 +1,14 @@
 # clang-format configuration
 # clang-format configuration
-# compatible with clang-format 18
+# compatible with clang-format 15
 
 
 UseTab: Never
 UseTab: Never
-ColumnLimit: 120
+ColumnLimit: 100
 
 
 # Indent
 # Indent
 IndentWidth: 4
 IndentWidth: 4
-BracedInitializerIndentWidth: 4
 AccessModifierOffset: -4
 AccessModifierOffset: -4
 IndentAccessModifiers: false
 IndentAccessModifiers: false
 IndentCaseLabels: true
 IndentCaseLabels: true
-IndentExternBlock: Indent
 IndentGotoLabels: true
 IndentGotoLabels: true
 IndentRequiresClause: true
 IndentRequiresClause: true
 IndentWrappedFunctionNames: true
 IndentWrappedFunctionNames: true
@@ -20,25 +18,18 @@ BitFieldColonSpacing: Both
 
 
 # Insert
 # Insert
 InsertBraces: false
 InsertBraces: false
-InsertNewlineAtEOF: true
-KeepEmptyLinesAtEOF: true
 
 
 # Align
 # Align
 AlignAfterOpenBracket: true
 AlignAfterOpenBracket: true
-AlignTrailingComments:
-  Kind: Always
 
 
 AlignArrayOfStructures: Left
 AlignArrayOfStructures: Left
 PointerAlignment: Left
 PointerAlignment: Left
 
 
-BreakAfterAttributes: Leave
 BreakBeforeBinaryOperators: None
 BreakBeforeBinaryOperators: None
 BreakBeforeConceptDeclarations: Always
 BreakBeforeConceptDeclarations: Always
-BreakBeforeInlineASMColon: OnlyMultiline
 BreakBeforeTernaryOperators: true
 BreakBeforeTernaryOperators: true
 BreakConstructorInitializers: AfterColon
 BreakConstructorInitializers: AfterColon
 BreakInheritanceList: AfterColon
 BreakInheritanceList: AfterColon
-BreakAdjacentStringLiterals: false
 BreakStringLiterals: false
 BreakStringLiterals: false
 CompactNamespaces: false
 CompactNamespaces: false
 Cpp11BracedListStyle: true
 Cpp11BracedListStyle: true
@@ -47,10 +38,8 @@ EmptyLineBeforeAccessModifier: Always
 
 
 AllowAllArgumentsOnNextLine: false
 AllowAllArgumentsOnNextLine: false
 AllowAllParametersOfDeclarationOnNextLine: false
 AllowAllParametersOfDeclarationOnNextLine: false
-AllowBreakBeforeNoexceptSpecifier: Never
 AllowShortBlocksOnASingleLine: Always
 AllowShortBlocksOnASingleLine: Always
 AllowShortCaseLabelsOnASingleLine: true
 AllowShortCaseLabelsOnASingleLine: true
-AllowShortCompoundRequirementOnASingleLine: true
 AllowShortEnumsOnASingleLine: true
 AllowShortEnumsOnASingleLine: true
 AllowShortFunctionsOnASingleLine: All
 AllowShortFunctionsOnASingleLine: All
 AllowShortIfStatementsOnASingleLine: WithoutElse
 AllowShortIfStatementsOnASingleLine: WithoutElse
@@ -83,20 +72,12 @@ SpaceInEmptyBlock: false
 SpacesBeforeTrailingComments: 2
 SpacesBeforeTrailingComments: 2
 SpacesInAngles: Never
 SpacesInAngles: Never
 
 
-SpacesInParens: Custom
-SpacesInParensOptions:
-  InConditionalStatements: false
-  InCStyleCasts: false
-  InEmptyParentheses: false
-  Other: false
-
 SpacesInSquareBrackets: false
 SpacesInSquareBrackets: false
 
 
 # Order
 # Order
 QualifierAlignment: Custom
 QualifierAlignment: Custom
 QualifierOrder: ["constexpr", "const", "inline", "static", "type"]
 QualifierOrder: ["constexpr", "const", "inline", "static", "type"]
 SortIncludes: Never
 SortIncludes: Never
-SortUsingDeclarations: LexicographicNumeric
 IncludeBlocks: Merge
 IncludeBlocks: Merge
 
 
 WhitespaceSensitiveMacros: ["PK_PROTECTED", "LUA_PROTECTED"]
 WhitespaceSensitiveMacros: ["PK_PROTECTED", "LUA_PROTECTED"]

+ 16 - 16
include/pocketpy/common/algorithm.h

@@ -8,22 +8,22 @@ extern "C" {
 
 
 #define c11__less(a, b) ((a) < (b))
 #define c11__less(a, b) ((a) < (b))
 
 
-#define c11__lower_bound(T, ptr, count, key, less, out)                        \
-  do {                                                                         \
-    const T *__first = ptr;                                                    \
-    int __len = count;                                                         \
-    while (__len != 0) {                                                       \
-      int __l2 = (int)((unsigned int)__len / 2);                               \
-      const T *__m = __first + __l2;                                           \
-      if (less((*__m), (key))) {                                               \
-        __first = ++__m;                                                       \
-        __len -= __l2 + 1;                                                     \
-      } else {                                                                 \
-        __len = __l2;                                                          \
-      }                                                                        \
-    }                                                                          \
-    *(out) = __first;                                                          \
-  } while (0)
+#define c11__lower_bound(T, ptr, count, key, less, out)                                            \
+    do {                                                                                           \
+        T* __first = ptr;                                                                          \
+        int __len = count;                                                                         \
+        while(__len != 0) {                                                                        \
+            int __l2 = (int)((unsigned int)__len / 2);                                             \
+            T* __m = __first + __l2;                                                               \
+            if(less((*__m), (key))) {                                                              \
+                __first = ++__m;                                                                   \
+                __len -= __l2 + 1;                                                                 \
+            } else {                                                                               \
+                __len = __l2;                                                                      \
+            }                                                                                      \
+        }                                                                                          \
+        *(out) = __first;                                                                          \
+    } while(0)
 
 
 #ifdef __cplusplus
 #ifdef __cplusplus
 }
 }

+ 6 - 6
include/pocketpy/common/vector.h

@@ -56,19 +56,19 @@ void c11_vector__clear(c11_vector* self);
     }while(0)
     }while(0)
 
 
 
 
-#define c11_vector__insert(T, self, index, elem) \
+#define c11_vector__insert(T, self, p, elem) \
     do{ \
     do{ \
         if((self)->count == (self)->capacity) c11_vector__reserve((self), (self)->capacity*2); \
         if((self)->count == (self)->capacity) c11_vector__reserve((self), (self)->capacity*2); \
-        T* p = (T*)(self)->data + (index); \
-        memmove(p + 1, p, ((self)->count - (index)) * sizeof(T)); \
+        int __n = (self)->count - (p - (T*)(self)->data); \
+        memmove(p + 1, p, __n * sizeof(T)); \
         *p = (elem); \
         *p = (elem); \
         (self)->count++; \
         (self)->count++; \
     }while(0)
     }while(0)
 
 
-#define c11_vector__erase(T, self, index) \
+#define c11_vector__erase(T, self, p) \
     do{ \
     do{ \
-        T* p = (T*)(self)->data + (index); \
-        memmove(p, p + 1, ((self)->count - (index) - 1) * sizeof(T)); \
+        int __n = (self)->count - (p - (T*)(self)->data) - 1; \
+        memmove(p, p + 1, __n * sizeof(T)); \
         (self)->count--; \
         (self)->count--; \
     }while(0)
     }while(0)
 
 

+ 1 - 1
src/common/str.c

@@ -387,7 +387,7 @@ static const int kLoRangeB[] = {170,186,443,451,660,1514,1522,1599,1610,1647,174
 bool c11__is_unicode_Lo_char(int c){
 bool c11__is_unicode_Lo_char(int c){
     if(c == 0x1f955) return true;
     if(c == 0x1f955) return true;
     const int* p;
     const int* p;
-    c11__lower_bound(int, kLoRangeA, 476, c, c11__less, &p);
+    c11__lower_bound(const int, kLoRangeA, 476, c, c11__less, &p);
     int index = p - kLoRangeA;
     int index = p - kLoRangeA;
     if(c == kLoRangeA[index]) return true;
     if(c == kLoRangeA[index]) return true;
     index -= 1;
     index -= 1;

+ 1 - 1
src/modules/random.cpp

@@ -199,7 +199,7 @@ struct Random {
             List result(k);
             List result(k);
             for(int i = 0; i < k; i++) {
             for(int i = 0; i < k; i++) {
                 f64 key = self.gen.uniform(0.0, cum_weights[size - 1]);
                 f64 key = self.gen.uniform(0.0, cum_weights[size - 1]);
-                const f64* p;
+                f64* p;
                 c11__lower_bound(f64, cum_weights.begin(), cum_weights.size(), key, c11__less, &p);
                 c11__lower_bound(f64, cum_weights.begin(), cum_weights.size(), key, c11__less, &p);
                 result[i] = data[p - cum_weights.begin()];
                 result[i] = data[p - cum_weights.begin()];
             }
             }