From 878db5a828e2e2543a5cf35b1e38a6d4d805b100 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Tue, 11 Jun 2024 10:47:54 +0800 Subject: [PATCH] some rename --- include/pocketpy/common/str.h | 2 +- include/pocketpy/common/vector.h | 4 ++-- src/common/str.c | 16 ++++++++-------- src/compiler/lexer.cpp | 2 +- src/interpreter/iter.cpp | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/include/pocketpy/common/str.h b/include/pocketpy/common/str.h index 585073c9..c2336680 100644 --- a/include/pocketpy/common/str.h +++ b/include/pocketpy/common/str.h @@ -24,7 +24,7 @@ inline int pkpy_Str__size(const pkpy_Str* self){ return self->size; } -int pkpy_utils__u8len(unsigned char c, bool suppress); +int pkpy_utils__u8_header(unsigned char c, bool suppress); void pkpy_Str__ctor(pkpy_Str* self, const char* data); void pkpy_Str__ctor2(pkpy_Str* self, const char* data, int size); void pkpy_Str__dtor(pkpy_Str* self); diff --git a/include/pocketpy/common/vector.h b/include/pocketpy/common/vector.h index 6c9c33d1..ad32e216 100644 --- a/include/pocketpy/common/vector.h +++ b/include/pocketpy/common/vector.h @@ -31,7 +31,7 @@ void c11_vector__reserve(c11_vector* self, int capacity); #define c11__getitem(T, self, index) ((T*)(self)->data)[index] #define c11__setitem(T, self, index, value) ((T*)(self)->data)[index] = value; -#define c11_vector__push_back(T, self, elem) \ +#define c11_vector__append(T, self, elem) \ do{ \ if((self)->count == (self)->capacity) c11_vector__reserve((self), (self)->capacity*2); \ ((T*)(self)->data)[(self)->count] = (elem); \ @@ -43,7 +43,7 @@ void c11_vector__reserve(c11_vector* self, int capacity); (self)->count--; \ }while(0) -#define c11_vector__extend(T, self, p, size) \ +#define c11_vector__push(T, self, p, size) \ do{ \ c11_vector__reserve((self), (self)->count + (size)); \ memcpy((T*)(self)->data + (self)->count, (p), (size) * sizeof(T)); \ diff --git a/src/common/str.c b/src/common/str.c index 1e5bbade..2dcd000d 100644 --- a/src/common/str.c +++ b/src/common/str.c @@ -8,7 +8,7 @@ #include #include -int pkpy_utils__u8len(unsigned char c, bool suppress) { +int pkpy_utils__u8_header(unsigned char c, bool suppress) { if((c & 0b10000000) == 0) return 1; if((c & 0b11100000) == 0b11000000) return 2; if((c & 0b11110000) == 0b11100000) return 3; @@ -135,13 +135,13 @@ pkpy_Str pkpy_Str__replace2(const pkpy_Str *self, const pkpy_Str *old, const pkp int i = pkpy_Str__index(self, old, start); if(i == -1) break; pkpy_Str tmp = pkpy_Str__substr2(self, start, i - start); - c11_vector__extend(char, &buffer, pkpy_Str__data(&tmp), tmp.size); + c11_vector__push(char, &buffer, pkpy_Str__data(&tmp), tmp.size); pkpy_Str__dtor(&tmp); - c11_vector__extend(char, &buffer, pkpy_Str__data(new_), new_->size); + c11_vector__push(char, &buffer, pkpy_Str__data(new_), new_->size); start = i + old->size; } pkpy_Str tmp = pkpy_Str__substr2(self, start, self->size - start); - c11_vector__extend(char, &buffer, pkpy_Str__data(&tmp), tmp.size); + c11_vector__push(char, &buffer, pkpy_Str__data(&tmp), tmp.size); pkpy_Str__dtor(&tmp); pkpy_Str retval = { .size = buffer.count, @@ -166,7 +166,7 @@ pkpy_Str pkpy_Str__u8_getitem(const pkpy_Str *self, int i){ i = pkpy_Str__unicode_index_to_byte(self, i); return pkpy_Str__substr2( self, i, - pkpy_utils__u8len(pkpy_Str__data(self)[i], false) + pkpy_utils__u8_header(pkpy_Str__data(self)[i], false) ); } @@ -177,14 +177,14 @@ pkpy_Str pkpy_Str__u8_slice(const pkpy_Str *self, int start, int stop, int step) if(self->is_ascii){ const char* p = pkpy_Str__data(self); for (int i=start; step>0 ? istop; i+=step) { - c11_vector__push_back(char, &buffer, p[i]); + c11_vector__append(char, &buffer, p[i]); } }else{ for (int i=start; step>0 ? istop; i+=step) { pkpy_Str unicode = pkpy_Str__u8_getitem(self, i); const char* p = pkpy_Str__data(&unicode); for(int j = 0; j < unicode.size; j++){ - c11_vector__push_back(char, &buffer, p[j]); + c11_vector__append(char, &buffer, p[j]); } pkpy_Str__dtor(&unicode); } @@ -207,7 +207,7 @@ int pkpy_Str__unicode_index_to_byte(const pkpy_Str* self, int i) { const char* p = pkpy_Str__data(self); int j = 0; while(i > 0) { - j += pkpy_utils__u8len(p[j], false); + j += pkpy_utils__u8_header(p[j], false); i--; } return j; diff --git a/src/compiler/lexer.cpp b/src/compiler/lexer.cpp index 13226239..77130ad4 100644 --- a/src/compiler/lexer.cpp +++ b/src/compiler/lexer.cpp @@ -108,7 +108,7 @@ Error* Lexer::eat_name() noexcept{ curr_char--; while(true) { unsigned char c = peekchar(); - int u8bytes = pkpy_utils__u8len(c, true); + int u8bytes = pkpy_utils__u8_header(c, true); if(u8bytes == 0) return SyntaxError("invalid char: %c", c); if(u8bytes == 1) { if(isalpha(c) || c == '_' || isdigit(c)) { diff --git a/src/interpreter/iter.cpp b/src/interpreter/iter.cpp index 390df813..089df39c 100644 --- a/src/interpreter/iter.cpp +++ b/src/interpreter/iter.cpp @@ -49,7 +49,7 @@ void StringIter::_register(VM* vm, PyObject* mod, PyObject* type) { Str& s = PK_OBJ_GET(Str, self.ref); if(self.i == s.size) return 0; int start = self.i; - int len = pkpy_utils__u8len(s[self.i], false); + int len = pkpy_utils__u8_header(s[self.i], false); self.i += len; vm->s_data.push(VAR(s.substr(start, len))); return 1;