some rename

This commit is contained in:
blueloveTH 2024-07-02 00:58:06 +08:00
parent 9c7d1c5fe1
commit 8f6b539b37
4 changed files with 9 additions and 9 deletions

View File

@ -27,7 +27,7 @@ c11_string* c11_string__new2(const char* data, int size);
c11_string* c11_string__copy(c11_string* self); c11_string* c11_string__copy(c11_string* self);
void c11_string__delete(c11_string* self); void c11_string__delete(c11_string* self);
int c11_string__len(c11_string* self); int c11_string__len(c11_string* self);
c11_sv c11_string__view(c11_string* self); c11_sv c11_string__sv(c11_string* self);
c11_string* c11_string__replace(c11_string* self, char old, char new_); c11_string* c11_string__replace(c11_string* self, char old, char new_);
int c11_string__u8_length(const c11_string* self); int c11_string__u8_length(const c11_string* self);

View File

@ -36,7 +36,7 @@ int c11_string__len(c11_string* self) {
return *p; return *p;
} }
c11_sv c11_string__view(c11_string* self) { c11_sv c11_string__sv(c11_string* self) {
int* p = (int*)self - 1; int* p = (int*)self - 1;
return (c11_sv){self, *p}; return (c11_sv){self, *p};
} }
@ -59,7 +59,7 @@ int c11_string__u8_length(c11_string* self) {
c11_sv c11_string__u8_getitem(c11_string* self, int i) { c11_sv c11_string__u8_getitem(c11_string* self, int i) {
i = c11__unicode_index_to_byte(self, i); i = c11__unicode_index_to_byte(self, i);
int size = c11__u8_header(self[i], false); int size = c11__u8_header(self[i], false);
return c11_sv__slice2(c11_string__view(self), i, i + size); return c11_sv__slice2(c11_string__sv(self), i, i + size);
} }
c11_string* c11_string__u8_slice(c11_string* self, int start, int stop, int step) { c11_string* c11_string__u8_slice(c11_string* self, int start, int stop, int step) {

View File

@ -289,7 +289,7 @@ void LiteralExpr__emit_(Expr* self_, Ctx* ctx) {
break; break;
} }
case TokenValue_STR: { case TokenValue_STR: {
c11_sv sv = c11_string__view(self->value->_str); c11_sv sv = c11_string__sv(self->value->_str);
int index = Ctx__add_const_string(ctx, sv); int index = Ctx__add_const_string(ctx, sv);
Ctx__emit_(ctx, OP_LOAD_CONST, index, self->line); Ctx__emit_(ctx, OP_LOAD_CONST, index, self->line);
break; break;
@ -1354,7 +1354,7 @@ int Ctx__add_const_string(Ctx* self, c11_sv key) {
c11_vector__push(py_TValue, &self->co->consts, tmp); c11_vector__push(py_TValue, &self->co->consts, tmp);
int index = self->co->consts.count - 1; int index = self->co->consts.count - 1;
c11_smallmap_s2n__set(&self->co_consts_string_dedup_map, c11_smallmap_s2n__set(&self->co_consts_string_dedup_map,
c11_string__view(PyObject__value(tmp._obj)), c11_string__sv(PyObject__value(tmp._obj)),
index); index);
return index; return index;
} }
@ -1665,13 +1665,13 @@ static Error* exprLong(Compiler* self) {
} }
static Error* exprBytes(Compiler* self) { static Error* exprBytes(Compiler* self) {
c11_sv sv = c11_string__view(prev()->value._str); c11_sv sv = c11_string__sv(prev()->value._str);
Ctx__s_push(ctx(), (Expr*)RawStringExpr__new(prev()->line, sv, OP_BUILD_BYTES)); Ctx__s_push(ctx(), (Expr*)RawStringExpr__new(prev()->line, sv, OP_BUILD_BYTES));
return NULL; return NULL;
} }
static Error* exprFString(Compiler* self) { static Error* exprFString(Compiler* self) {
c11_sv sv = c11_string__view(prev()->value._str); c11_sv sv = c11_string__sv(prev()->value._str);
Ctx__s_push(ctx(), (Expr*)FStringExpr__new(prev()->line, sv)); Ctx__s_push(ctx(), (Expr*)FStringExpr__new(prev()->line, sv));
return NULL; return NULL;
} }
@ -2064,7 +2064,7 @@ Error* pk_compile(pk_SourceData_ src, CodeObject* out) {
Compiler compiler; Compiler compiler;
Compiler__ctor(&compiler, src, tokens); Compiler__ctor(&compiler, src, tokens);
CodeObject__ctor(out, src, c11_string__view(src->filename)); CodeObject__ctor(out, src, c11_string__sv(src->filename));
err = Compiler__compile(&compiler, out); err = Compiler__compile(&compiler, out);
if(err) { if(err) {
// if error occurs, dispose the code object // if error occurs, dispose the code object

View File

@ -821,7 +821,7 @@ Error* pk_Lexer__process_and_dump(pk_SourceData_ src, c11_string** out) {
break; break;
case TokenValue_STR: { case TokenValue_STR: {
pk_SStream__write_char(&ss, 'S'); pk_SStream__write_char(&ss, 'S');
c11_sv sv = c11_string__view(token->value._str); c11_sv sv = c11_string__sv(token->value._str);
for(int i=0; i<sv.size; i++){ for(int i=0; i<sv.size; i++){
pk_SStream__write_hex(&ss, sv.data[i], false); pk_SStream__write_hex(&ss, sv.data[i], false);
} }