mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
...
This commit is contained in:
parent
79ac343eb2
commit
614fc27f03
@ -314,7 +314,6 @@ bool py_callmethod(py_Ref self, py_Name, int argc, py_Ref argv);
|
||||
bool py_callmagic(py_Name name, int argc, py_Ref argv);
|
||||
|
||||
bool py_str(py_Ref val);
|
||||
|
||||
#define py_repr(val) py_callmagic(__repr__, 1, val)
|
||||
#define py_len(val) py_callmagic(__len__, 1, val)
|
||||
|
||||
@ -327,13 +326,14 @@ py_GlobalRef py_retval();
|
||||
/* tuple */
|
||||
|
||||
// unchecked functions, if self is not a tuple, the behavior is undefined
|
||||
py_ObjectRef py_tuple__data(const py_Ref self);
|
||||
py_ObjectRef py_tuple__getitem(const py_Ref self, int i);
|
||||
void py_tuple__setitem(py_Ref self, int i, const py_Ref val);
|
||||
int py_tuple__len(const py_Ref self);
|
||||
|
||||
// unchecked functions, if self is not a list, the behavior is undefined
|
||||
py_ObjectRef py_list__getitem(const py_Ref self, int i);
|
||||
py_ObjectRef py_list__data(const py_Ref self);
|
||||
py_ObjectRef py_list__getitem(const py_Ref self, int i);
|
||||
void py_list__setitem(py_Ref self, int i, const py_Ref val);
|
||||
void py_list__delitem(py_Ref self, int i);
|
||||
int py_list__len(const py_Ref self);
|
||||
@ -342,10 +342,6 @@ void py_list__clear(py_Ref self);
|
||||
void py_list__insert(py_Ref self, int i, const py_Ref val);
|
||||
void py_list__reverse(py_Ref self);
|
||||
|
||||
// internal functions
|
||||
typedef struct pk_TypeInfo pk_TypeInfo;
|
||||
pk_TypeInfo* pk_tpinfo(const py_Ref self);
|
||||
|
||||
/// Search the magic method from the given type to the base type.
|
||||
/// Return the reference or NULL if not found.
|
||||
py_GlobalRef py_tpfindmagic(py_Type, py_Name name);
|
||||
|
@ -497,9 +497,7 @@ pk_FrameResult pk_VM__run_top_frame(pk_VM* self) {
|
||||
c11_sbuf__ctor(&ss);
|
||||
for(int i = 0; i < byte.arg; i++) {
|
||||
if(!py_str(begin + i)) goto __ERROR;
|
||||
int size;
|
||||
const char* data = py_tostrn(&self->last_retval, &size);
|
||||
c11_sbuf__write_cstrn(&ss, data, size);
|
||||
c11_sbuf__write_sv(&ss, py_tosv(&self->last_retval));
|
||||
}
|
||||
SP() = begin;
|
||||
c11_string* res = c11_sbuf__submit(&ss);
|
||||
|
@ -596,9 +596,7 @@ void pk_print_stack(pk_VM* self, Frame* frame, Bytecode byte) {
|
||||
break;
|
||||
}
|
||||
case tp_str: {
|
||||
int size;
|
||||
const char* data = py_tostrn(p, &size);
|
||||
pk_sprintf(&buf, "%q", (c11_sv){data, size});
|
||||
pk_sprintf(&buf, "%q", py_tosv(p));
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
|
@ -237,9 +237,7 @@ static bool _py_list__repr__(int argc, py_Ref argv) {
|
||||
c11_sbuf__dtor(&buf);
|
||||
return false;
|
||||
}
|
||||
int size;
|
||||
const char* data = py_tostrn(py_retval(), &size);
|
||||
c11_sbuf__write_cstrn(&buf, data, size);
|
||||
c11_sbuf__write_sv(&buf, py_tosv(py_retval()));
|
||||
if(i != self->count - 1) c11_sbuf__write_cstr(&buf, ", ");
|
||||
}
|
||||
c11_sbuf__write_char(&buf, ']');
|
||||
|
@ -153,9 +153,7 @@ static bool _py_str__repr__(int argc, py_Ref argv) {
|
||||
PY_CHECK_ARGC(1);
|
||||
c11_sbuf buf;
|
||||
c11_sbuf__ctor(&buf);
|
||||
int size;
|
||||
const char* data = py_tostrn(&argv[0], &size);
|
||||
c11_sbuf__write_quoted(&buf, (c11_sv){data, size}, '\'');
|
||||
c11_sbuf__write_quoted(&buf, py_tosv(&argv[0]), '\'');
|
||||
c11_string* res = c11_sbuf__submit(&buf);
|
||||
py_newstrn(py_retval(), res->data, res->size);
|
||||
c11_string__delete(res);
|
||||
|
@ -15,6 +15,8 @@ void py_newtuple(py_Ref out, int n) {
|
||||
|
||||
py_Ref py_tuple__getitem(const py_Ref self, int i) { return py_getslot(self, i); }
|
||||
|
||||
py_Ref py_tuple__data(const py_Ref self) { return PyObject__slots(self->_obj); }
|
||||
|
||||
void py_tuple__setitem(py_Ref self, int i, const py_Ref val) { py_setslot(self, i, val); }
|
||||
|
||||
int py_tuple__len(const py_Ref self) { return self->_obj->slots; }
|
||||
@ -37,9 +39,7 @@ static bool _py_tuple__repr__(int argc, py_Ref argv) {
|
||||
c11_sbuf__dtor(&buf);
|
||||
return false;
|
||||
}
|
||||
int size;
|
||||
const char* data = py_tostrn(py_retval(), &size);
|
||||
c11_sbuf__write_cstrn(&buf, data, size);
|
||||
c11_sbuf__write_sv(&buf, py_tosv(py_retval()));
|
||||
if(i != length - 1) c11_sbuf__write_cstr(&buf, ", ");
|
||||
}
|
||||
if(length == 1) c11_sbuf__write_char(&buf, ',');
|
||||
|
@ -248,11 +248,6 @@ bool py_getunboundmethod(py_Ref self, py_Name name, py_Ref out, py_Ref out_self)
|
||||
return false;
|
||||
}
|
||||
|
||||
pk_TypeInfo* pk_tpinfo(const py_Ref self) {
|
||||
pk_VM* vm = pk_current_vm;
|
||||
return c11__at(pk_TypeInfo, &vm->types, self->type);
|
||||
}
|
||||
|
||||
py_Ref py_tpfindmagic(py_Type t, py_Name name) {
|
||||
assert(py_ismagicname(name));
|
||||
pk_TypeInfo* types = (pk_TypeInfo*)pk_current_vm->types.data;
|
||||
|
Loading…
x
Reference in New Issue
Block a user