mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-21 20:10:17 +00:00
...
This commit is contained in:
parent
8eff9abfbc
commit
e04d4e790c
@ -30,6 +30,7 @@ void c11_sbuf__write_hex(c11_sbuf* self, unsigned char, bool non_zero);
|
|||||||
void c11_sbuf__write_ptr(c11_sbuf* self, void*);
|
void c11_sbuf__write_ptr(c11_sbuf* self, void*);
|
||||||
// Submit the stream and return the final string. The stream becomes invalid after this call
|
// Submit the stream and return the final string. The stream becomes invalid after this call
|
||||||
c11_string* c11_sbuf__submit(c11_sbuf* self);
|
c11_string* c11_sbuf__submit(c11_sbuf* self);
|
||||||
|
void c11_sbuf__py_submit(c11_sbuf* self, py_Ref out);
|
||||||
|
|
||||||
void pk_vsprintf(c11_sbuf* ss, const char* fmt, va_list args);
|
void pk_vsprintf(c11_sbuf* ss, const char* fmt, va_list args);
|
||||||
void pk_sprintf(c11_sbuf* ss, const char* fmt, ...);
|
void pk_sprintf(c11_sbuf* ss, const char* fmt, ...);
|
||||||
|
@ -147,6 +147,12 @@ c11_string* c11_sbuf__submit(c11_sbuf* self) {
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void c11_sbuf__py_submit(c11_sbuf *self, py_Ref out){
|
||||||
|
c11_string* res = c11_sbuf__submit(self);
|
||||||
|
py_newstrn(out, res->data, res->size);
|
||||||
|
c11_string__delete(res);
|
||||||
|
}
|
||||||
|
|
||||||
void pk_vsprintf(c11_sbuf* ss, const char* fmt, va_list args) {
|
void pk_vsprintf(c11_sbuf* ss, const char* fmt, va_list args) {
|
||||||
while(*fmt) {
|
while(*fmt) {
|
||||||
char c = *fmt;
|
char c = *fmt;
|
||||||
|
@ -502,9 +502,7 @@ pk_FrameResult pk_VM__run_top_frame(pk_VM* self) {
|
|||||||
c11_sbuf__write_sv(&ss, py_tosv(&self->last_retval));
|
c11_sbuf__write_sv(&ss, py_tosv(&self->last_retval));
|
||||||
}
|
}
|
||||||
SP() = begin;
|
SP() = begin;
|
||||||
c11_string* res = c11_sbuf__submit(&ss);
|
c11_sbuf__py_submit(&ss, SP()++);
|
||||||
py_newstrn(SP()++, res->data, res->size);
|
|
||||||
c11_string__delete(res);
|
|
||||||
DISPATCH();
|
DISPATCH();
|
||||||
}
|
}
|
||||||
/*****************************/
|
/*****************************/
|
||||||
@ -1109,8 +1107,6 @@ static bool format_object(py_Ref val, c11_sv spec) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
c11_string__delete(body);
|
c11_string__delete(body);
|
||||||
c11_string* res = c11_sbuf__submit(&buf);
|
c11_sbuf__py_submit(&buf, py_retval());
|
||||||
py_newstrn(py_retval(), res->data, res->size);
|
|
||||||
c11_string__delete(res);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
@ -109,10 +109,8 @@ static bool _py_builtins__hex(int argc, py_Ref argv) {
|
|||||||
c11_sbuf__write_hex(&ss, cpnt, non_zero);
|
c11_sbuf__write_hex(&ss, cpnt, non_zero);
|
||||||
if(cpnt != 0) non_zero = false;
|
if(cpnt != 0) non_zero = false;
|
||||||
}
|
}
|
||||||
// return VAR(ss.str());
|
|
||||||
c11_string* res = c11_sbuf__submit(&ss);
|
c11_sbuf__py_submit(&ss, py_retval());
|
||||||
py_newstrn(py_retval(), res->data, res->size);
|
|
||||||
c11_string__delete(res);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,9 +288,7 @@ static bool _py_dict__repr__(int argc, py_Ref argv) {
|
|||||||
is_first = false;
|
is_first = false;
|
||||||
}
|
}
|
||||||
c11_sbuf__write_char(&buf, '}');
|
c11_sbuf__write_char(&buf, '}');
|
||||||
c11_string* res = c11_sbuf__submit(&buf);
|
c11_sbuf__py_submit(&buf, py_retval());
|
||||||
py_newstrn(py_retval(), res->data, res->size);
|
|
||||||
c11_string__delete(res);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,9 +78,7 @@ static bool _py_BaseException__repr__(int argc, py_Ref argv) {
|
|||||||
c11_sbuf__write_sv(&ss, py_tosv(py_retval()));
|
c11_sbuf__write_sv(&ss, py_tosv(py_retval()));
|
||||||
}
|
}
|
||||||
c11_sbuf__write_char(&ss, ')');
|
c11_sbuf__write_char(&ss, ')');
|
||||||
c11_string* res = c11_sbuf__submit(&ss);
|
c11_sbuf__py_submit(&ss, py_retval());
|
||||||
py_newstrn(py_retval(), res->data, res->size);
|
|
||||||
c11_string__delete(res);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,9 +90,7 @@ static bool _py_BaseException__str__(int argc, py_Ref argv) {
|
|||||||
if(!py_str(arg)) return false;
|
if(!py_str(arg)) return false;
|
||||||
c11_sbuf__write_sv(&ss, py_tosv(py_retval()));
|
c11_sbuf__write_sv(&ss, py_tosv(py_retval()));
|
||||||
}
|
}
|
||||||
c11_string* res = c11_sbuf__submit(&ss);
|
c11_sbuf__py_submit(&ss, py_retval());
|
||||||
py_newstrn(py_retval(), res->data, res->size);
|
|
||||||
c11_string__delete(res);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,10 +168,8 @@ bool py_exception(const char* name, const char* fmt, ...) {
|
|||||||
pk_vsprintf(&buf, fmt, args);
|
pk_vsprintf(&buf, fmt, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
c11_string* res = c11_sbuf__submit(&buf);
|
|
||||||
py_Ref message = py_pushtmp();
|
py_Ref message = py_pushtmp();
|
||||||
py_newstrn(message, res->data, res->size);
|
c11_sbuf__py_submit(&buf, message);
|
||||||
c11_string__delete(res);
|
|
||||||
|
|
||||||
py_Ref exc_type = py_getdict(&pk_current_vm->builtins, py_name(name));
|
py_Ref exc_type = py_getdict(&pk_current_vm->builtins, py_name(name));
|
||||||
if(exc_type == NULL) c11__abort("py_exception(): '%s' not found", name);
|
if(exc_type == NULL) c11__abort("py_exception(): '%s' not found", name);
|
||||||
|
@ -239,9 +239,7 @@ static bool _py_list__repr__(int argc, py_Ref argv) {
|
|||||||
if(i != self->count - 1) c11_sbuf__write_cstr(&buf, ", ");
|
if(i != self->count - 1) c11_sbuf__write_cstr(&buf, ", ");
|
||||||
}
|
}
|
||||||
c11_sbuf__write_char(&buf, ']');
|
c11_sbuf__write_char(&buf, ']');
|
||||||
c11_string* res = c11_sbuf__submit(&buf);
|
c11_sbuf__py_submit(&buf, py_retval());
|
||||||
py_newstrn(py_retval(), res->data, res->size);
|
|
||||||
c11_string__delete(res);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,9 +201,7 @@ static bool _py_float__repr__(int argc, py_Ref argv) {
|
|||||||
c11_sbuf buf;
|
c11_sbuf buf;
|
||||||
c11_sbuf__ctor(&buf);
|
c11_sbuf__ctor(&buf);
|
||||||
c11_sbuf__write_f64(&buf, val, -1);
|
c11_sbuf__write_f64(&buf, val, -1);
|
||||||
c11_string* res = c11_sbuf__submit(&buf);
|
c11_sbuf__py_submit(&buf, py_retval());
|
||||||
py_newstrn(py_retval(), res->data, res->size);
|
|
||||||
c11_string__delete(res);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,9 +40,7 @@ static bool _py_object__repr__(int argc, py_Ref argv) {
|
|||||||
c11_sbuf buf;
|
c11_sbuf buf;
|
||||||
c11_sbuf__ctor(&buf);
|
c11_sbuf__ctor(&buf);
|
||||||
pk_sprintf(&buf, "<%t object at %p>", argv->type, argv->_obj);
|
pk_sprintf(&buf, "<%t object at %p>", argv->type, argv->_obj);
|
||||||
c11_string* res = c11_sbuf__submit(&buf);
|
c11_sbuf__py_submit(&buf, py_retval());
|
||||||
py_newstrn(py_retval(), res->data, res->size);
|
|
||||||
c11_string__delete(res);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,9 +49,7 @@ static bool _py_type__repr__(int argc, py_Ref argv) {
|
|||||||
c11_sbuf buf;
|
c11_sbuf buf;
|
||||||
c11_sbuf__ctor(&buf);
|
c11_sbuf__ctor(&buf);
|
||||||
pk_sprintf(&buf, "<class '%t'>", py_totype(argv));
|
pk_sprintf(&buf, "<class '%t'>", py_totype(argv));
|
||||||
c11_string* res = c11_sbuf__submit(&buf);
|
c11_sbuf__py_submit(&buf, py_retval());
|
||||||
py_newstrn(py_retval(), res->data, res->size);
|
|
||||||
c11_string__delete(res);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,9 +38,7 @@ static bool _py_slice__repr__(int argc, py_Ref argv) {
|
|||||||
if(i != 2) c11_sbuf__write_cstr(&buf, ", ");
|
if(i != 2) c11_sbuf__write_cstr(&buf, ", ");
|
||||||
}
|
}
|
||||||
c11_sbuf__write_char(&buf, ')');
|
c11_sbuf__write_char(&buf, ')');
|
||||||
c11_string* res = c11_sbuf__submit(&buf);
|
c11_sbuf__py_submit(&buf, py_retval());
|
||||||
py_newstrn(py_retval(), res->data, res->size);
|
|
||||||
c11_string__delete(res);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,9 +154,7 @@ static bool _py_str__repr__(int argc, py_Ref argv) {
|
|||||||
c11_sbuf buf;
|
c11_sbuf buf;
|
||||||
c11_sbuf__ctor(&buf);
|
c11_sbuf__ctor(&buf);
|
||||||
c11_sbuf__write_quoted(&buf, py_tosv(&argv[0]), '\'');
|
c11_sbuf__write_quoted(&buf, py_tosv(&argv[0]), '\'');
|
||||||
c11_string* res = c11_sbuf__submit(&buf);
|
c11_sbuf__py_submit(&buf, py_retval());
|
||||||
py_newstrn(py_retval(), res->data, res->size);
|
|
||||||
c11_string__delete(res);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -294,9 +292,7 @@ static bool _py_str__join(int argc, py_Ref argv) {
|
|||||||
c11_string* item = py_touserdata(&p[i]);
|
c11_string* item = py_touserdata(&p[i]);
|
||||||
c11_sbuf__write_cstrn(&buf, item->data, item->size);
|
c11_sbuf__write_cstrn(&buf, item->data, item->size);
|
||||||
}
|
}
|
||||||
c11_string* res = c11_sbuf__submit(&buf);
|
c11_sbuf__py_submit(&buf, py_retval());
|
||||||
py_newstrn(py_retval(), res->data, res->size);
|
|
||||||
c11_string__delete(res);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -391,9 +387,7 @@ static bool _py_str__zfill(int argc, py_Ref argv) {
|
|||||||
c11_sbuf__write_char(&buf, '0');
|
c11_sbuf__write_char(&buf, '0');
|
||||||
}
|
}
|
||||||
c11_sbuf__write_sv(&buf, self);
|
c11_sbuf__write_sv(&buf, self);
|
||||||
c11_string* res = c11_sbuf__submit(&buf);
|
c11_sbuf__py_submit(&buf, py_retval());
|
||||||
py_newstrn(py_retval(), res->data, res->size);
|
|
||||||
c11_string__delete(res);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -429,9 +423,7 @@ static bool _py_str__widthjust_impl(bool left, int argc, py_Ref argv) {
|
|||||||
}
|
}
|
||||||
c11_sbuf__write_sv(&buf, self);
|
c11_sbuf__write_sv(&buf, self);
|
||||||
}
|
}
|
||||||
c11_string* res = c11_sbuf__submit(&buf);
|
c11_sbuf__py_submit(&buf, py_retval());
|
||||||
py_newstrn(py_retval(), res->data, res->size);
|
|
||||||
c11_string__delete(res);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,9 +44,7 @@ static bool _py_tuple__repr__(int argc, py_Ref argv) {
|
|||||||
}
|
}
|
||||||
if(length == 1) c11_sbuf__write_char(&buf, ',');
|
if(length == 1) c11_sbuf__write_char(&buf, ',');
|
||||||
c11_sbuf__write_char(&buf, ')');
|
c11_sbuf__write_char(&buf, ')');
|
||||||
c11_string* res = c11_sbuf__submit(&buf);
|
c11_sbuf__py_submit(&buf, py_retval());
|
||||||
py_newstrn(py_retval(), res->data, res->size);
|
|
||||||
c11_string__delete(res);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user