1
0
blueloveTH 1 жил өмнө
parent
commit
eb5b84f21a

+ 1 - 1
plugins/flutter/pocketpy/pubspec.yaml

@@ -1,6 +1,6 @@
 name: pocketpy
 description: A lightweight Python interpreter for game engines. It supports Android/iOS/Windows/Linux/MacOS.
-version: 2.0.1+8
+version: 2.0.2
 homepage: https://pocketpy.dev
 repository: https://github.com/pocketpy/pocketpy
 

+ 49 - 0
scripts/check_undef.py

@@ -0,0 +1,49 @@
+import re
+
+def check_define_undef_pairs(code):
+    # 使用正则表达式匹配#define和#undef指令
+    define_pattern = re.compile(r'#define\s+(\w+)')
+    undef_pattern = re.compile(r'#undef\s+(\w+)')
+
+    # 查找所有的#define和#undef
+    defines = define_pattern.findall(code)
+    undefs = undef_pattern.findall(code)
+
+    # 使用集合计算差集,找出不匹配的部分
+    define_set = set(defines)
+    undef_set = set(undefs)
+
+    unmatched_defines = define_set - undef_set
+    unmatched_undefs = undef_set - define_set
+
+    if unmatched_defines or unmatched_undefs:
+        if unmatched_defines:
+            print("mismatched #define")
+            for define in unmatched_defines:
+                print(f"- {define}")
+
+        if unmatched_undefs:
+            print("mismatched #undef")
+            for undef in unmatched_undefs:
+                print(f"- {undef}")
+
+
+# iterate over all the files in `path` directory
+
+import os
+import sys
+
+def check_undef_in_dir(path):
+    for root, dirs, files in os.walk(path):
+        for file in files:
+            if file.endswith(".c") or file.endswith(".h"):
+                with open(os.path.join(root, file), "r", encoding='utf-8') as f:
+                    print(f"==> {os.path.join(root, file)}")
+                    check_define_undef_pairs(f.read())
+
+if __name__ == "__main__":
+    if len(sys.argv) < 2:
+        print("Usage: python scripts/check_undef.py <path>")
+        sys.exit(1)
+
+    check_undef_in_dir(sys.argv[1])

+ 1 - 0
src/common/memorypool.c

@@ -322,3 +322,4 @@ void Pools_debug_info(char* buffer, int size) {
     );
 }
 
+#undef LinkedList__apply

+ 24 - 1
src/compiler/compiler.c

@@ -2865,4 +2865,27 @@ const static PrattRule rules[TK__COUNT__] = {
     [TK_LBRACE] =      { exprMap      },
     [TK_COLON] =       { exprSlice0,    exprSlice1,      PREC_PRIMARY }
 };
-// clang-format on
+// clang-format on
+
+#undef static_assert_expr_size
+#undef vtcall
+#undef vtemit_
+#undef vtemit_del
+#undef vtemit_store
+#undef vtemit_inplace
+#undef vtemit_istore
+#undef vtdelete
+#undef EXPR_COMMON_HEADER
+#undef is_compare_expr
+#undef tk
+#undef prev
+#undef curr
+#undef next
+#undef advance
+#undef mode
+#undef ctx
+#undef match_newlines
+#undef consume
+#undef consume_end_stmt
+#undef check
+#undef match

+ 1 - 0
src/compiler/lexer.c

@@ -708,3 +708,4 @@ const char* TokenSymbols[] = {
     "yield",
 };
 
+#undef is_raw_string_used

+ 18 - 1
src/interpreter/ceval.c

@@ -1350,4 +1350,21 @@ static bool stack_format_object(VM* self, c11_sv spec) {
     // inplace update
     c11_sbuf__py_submit(&buf, val);
     return true;
-}
+}
+
+#undef CHECK_RETURN_FROM_EXCEPT_OR_FINALLY
+#undef DISPATCH
+#undef DISPATCH_JUMP
+#undef DISPATCH_JUMP_ABSOLUTE
+#undef TOP
+#undef SECOND
+#undef THIRD
+#undef FOURTH
+#undef STACK_SHRINK
+#undef STACK_GROW
+#undef PUSH
+#undef POP
+#undef POPX
+#undef SP
+#undef INSERT_THIRD
+#undef vectorcall_opcall

+ 4 - 1
src/interpreter/typeinfo.c

@@ -38,4 +38,7 @@ void TypeList__apply(TypeList* self, void (*f)(py_TypeInfo*, void*), void* ctx)
         py_TypeInfo* info = TypeList__get(self, i);
         f(info, ctx);
     }
-}
+}
+
+#undef CHUNK_SIZE
+#undef LOG2_CHUNK_SIZE

+ 4 - 1
src/modules/array2d.c

@@ -615,4 +615,7 @@ void pk__add_module_array2d() {
     py_bindmethod(array2d, "count", array2d_count);
     py_bindmethod(array2d, "find_bounding_rect", array2d_find_bounding_rect);
     py_bindmethod(array2d, "count_neighbors", array2d_count_neighbors);
-}
+}
+
+#undef INC_COUNT
+#undef HANDLE_SLICE

+ 7 - 1
src/modules/linalg.c

@@ -986,4 +986,10 @@ void pk__add_module_linalg() {
                (c11_vec3){
                    {1, 1, 1}
     });
-}
+}
+
+#undef DEFINE_VEC_FIELD
+#undef DEFINE_BOOL_NE
+#undef DEF_VECTOR_ELEMENT_WISE
+#undef DEF_VECTOR_OPS
+#undef DEF_VECTOR_INT_OPS

+ 4 - 1
src/modules/math.c

@@ -198,4 +198,7 @@ void pk__add_module_math() {
 
     py_bindfunc(mod, "modf", math_modf);
     py_bindfunc(mod, "factorial", math_factorial);
-}
+}
+
+#undef ONE_ARG_FUNC
+#undef TWO_ARG_FUNC

+ 3 - 1
src/modules/pkpy.c

@@ -66,4 +66,6 @@ void pk__add_module_pkpy() {
 
     py_setdict(mod, py_name("TValue"), TValue_dict);
     py_pop();
-}
+}
+
+#undef DEF_TVALUE_METHODS

+ 7 - 0
src/modules/random.c

@@ -303,3 +303,10 @@ __ERROR:
     py_printexc();
     c11__abort("failed to add module random");
 }
+
+#undef N
+#undef M
+#undef MATRIX_A
+#undef UPPER_MASK
+#undef LOWER_MASK
+#undef ADD_INST_BOUNDMETHOD

+ 3 - 0
src/modules/time.c

@@ -104,3 +104,6 @@ void pk__add_module_time() {
     py_bindfunc(mod, "sleep", time_sleep);
     py_bindfunc(mod, "localtime", time_localtime);
 }
+
+#undef NANOS_PER_SEC
+#undef DEF_STRUCT_TIME__PROPERTY

+ 4 - 2
src/public/py_dict.c

@@ -167,7 +167,7 @@ static void Dict__compact_entries(Dict* self) {
     }
     self->entries.length = n;
     // update indices
-    for(int i = 0; i < self->capacity; i++) {
+    for(uint32_t i = 0; i < self->capacity; i++) {
         for(int j = 0; j < PK_DICT_MAX_COLLISION; j++) {
             int idx = self->indices[i]._[j];
             if(idx == -1) continue;
@@ -203,7 +203,7 @@ static bool Dict__set(Dict* self, py_TValue* key, py_TValue* val) {
         if(res == -1) return false;  // error
     }
     // no empty slot found
-    if(self->capacity >= self->entries.length * 10) {
+    if(self->capacity >= (uint32_t)self->entries.length * 10) {
         // raise error if we reach the minimum load factor (10%)
         return RuntimeError("dict has too much collision: %d/%d/%d",
                             self->entries.length,
@@ -623,3 +623,5 @@ bool py_dict_apply(py_Ref self, bool (*f)(py_Ref, py_Ref, void*), void* ctx) {
     }
     return true;
 }
+
+#undef PK_DICT_MAX_COLLISION

+ 5 - 7
src/public/py_number.c

@@ -51,8 +51,6 @@ DEF_NUM_BINARY_OP(__le__, <=, py_newbool, py_newbool)
 DEF_NUM_BINARY_OP(__gt__, >, py_newbool, py_newbool)
 DEF_NUM_BINARY_OP(__ge__, >=, py_newbool, py_newbool)
 
-#undef DEF_NUM_BINARY_OP
-
 static bool int__neg__(int argc, py_Ref argv) {
     PY_CHECK_ARGC(1);
     py_i64 val = py_toint(&argv[0]);
@@ -203,8 +201,6 @@ DEF_INT_BITWISE_OP(__xor__, ^)
 DEF_INT_BITWISE_OP(__lshift__, <<)
 DEF_INT_BITWISE_OP(__rshift__, >>)
 
-#undef DEF_INT_BITWISE_OP
-
 static bool int__repr__(int argc, py_Ref argv) {
     PY_CHECK_ARGC(1);
     py_i64 val = py_toint(&argv[0]);
@@ -442,8 +438,6 @@ DEF_BOOL_BITWISE(__and__, &&)
 DEF_BOOL_BITWISE(__or__, ||)
 DEF_BOOL_BITWISE(__xor__, !=)
 
-#undef DEF_BOOL_BITWISE
-
 void pk_number__register() {
     /****** tp_int & tp_float ******/
     py_bindmagic(tp_int, __add__, int__add__);
@@ -520,4 +514,8 @@ void pk_number__register() {
     py_bindmagic(tp_bool, __and__, bool__and__);
     py_bindmagic(tp_bool, __or__, bool__or__);
     py_bindmagic(tp_bool, __xor__, bool__xor__);
-}
+}
+
+#undef DEF_NUM_BINARY_OP
+#undef DEF_INT_BITWISE_OP
+#undef DEF_BOOL_BITWISE

+ 3 - 1
src/public/py_str.c

@@ -679,4 +679,6 @@ bool py_str(py_Ref val) {
 
 bool py_repr(py_Ref val) { return pk_callmagic(__repr__, 1, val); }
 
-bool py_len(py_Ref val) { return pk_callmagic(__len__, 1, val); }
+bool py_len(py_Ref val) { return pk_callmagic(__len__, 1, val); }
+
+#undef DEF_STR_CMP_OP