Compare commits

..

2 Commits

Author SHA1 Message Date
blueloveTH
b1ffa191d2 ... 2024-08-15 12:01:06 +08:00
blueloveTH
fa61a28740 ... 2024-08-15 11:14:38 +08:00
4 changed files with 24 additions and 3 deletions

View File

@ -468,7 +468,7 @@ PK_EXPORT bool KeyError(py_Ref key) PY_RAISE;
/// Python equivalent to `bool(val)`. /// Python equivalent to `bool(val)`.
/// 1: true, 0: false, -1: error /// 1: true, 0: false, -1: error
PK_EXPORT int py_bool(py_Ref val) PY_RAISE PY_RETURN; PK_EXPORT int py_bool(py_Ref val) PY_RAISE;
/// Compare two objects. /// Compare two objects.
/// 1: lhs == rhs, 0: lhs != rhs, -1: error /// 1: lhs == rhs, 0: lhs != rhs, -1: error
@ -598,7 +598,7 @@ enum py_PredefinedTypes {
tp_nativefunc, tp_nativefunc,
tp_boundmethod, tp_boundmethod,
tp_super, // 1 slot + py_Type tp_super, // 1 slot + py_Type
tp_BaseException, // 2 slots (arg + inner exc) tp_BaseException, // 2 slots (arg + inner_exc)
tp_Exception, tp_Exception,
tp_bytes, tp_bytes,
tp_namedict, tp_namedict,

View File

@ -486,6 +486,10 @@ FrameResult VM__vectorcall(VM* self, uint16_t argc, uint16_t kwargc, bool opcall
} }
if(p0->type == tp_nativefunc) { if(p0->type == tp_nativefunc) {
if(kwargc) {
TypeError("nativefunc does not accept keyword arguments");
return RES_ERROR;
}
bool ok = py_callcfunc(p0->_cfunc, p1 - argv, argv); bool ok = py_callcfunc(p0->_cfunc, p1 - argv, argv);
self->stack.sp = p0; self->stack.sp = p0;
return ok ? RES_RETURN : RES_ERROR; return ok ? RES_RETURN : RES_ERROR;

View File

@ -99,6 +99,18 @@ static bool _py_BaseException__str__(int argc, py_Ref argv) {
return true; return true;
} }
static bool BaseException_args(int argc, py_Ref argv){
PY_CHECK_ARGC(1);
py_Ref arg = py_getslot(argv, 0);
if(!py_isnil(arg)) {
py_newtuple(py_retval(), 1);
py_setslot(py_retval(), 0, arg);
}else{
py_newtuple(py_retval(), 0);
}
return true;
}
py_Type pk_BaseException__register() { py_Type pk_BaseException__register() {
py_Type type = pk_newtype("BaseException", tp_object, NULL, BaseException__dtor, false, false); py_Type type = pk_newtype("BaseException", tp_object, NULL, BaseException__dtor, false, false);
@ -106,6 +118,7 @@ py_Type pk_BaseException__register() {
py_bindmagic(type, __init__, _py_BaseException__init__); py_bindmagic(type, __init__, _py_BaseException__init__);
py_bindmagic(type, __repr__, _py_BaseException__repr__); py_bindmagic(type, __repr__, _py_BaseException__repr__);
py_bindmagic(type, __str__, _py_BaseException__str__); py_bindmagic(type, __str__, _py_BaseException__str__);
py_bindproperty(type, "args", BaseException_args, NULL);
return type; return type;
} }

View File

@ -272,7 +272,11 @@ static bool str_join(int argc, py_Ref argv) {
bool first = true; bool first = true;
while(true) { while(true) {
int res = py_next(py_peek(-1)); int res = py_next(py_peek(-1));
if(res == -1) return false; if(res == -1) {
c11_sbuf__dtor(&buf);
return false;
}
if(res == 0) break; if(res == 0) break;
if(!first) c11_sbuf__write_sv(&buf, self); if(!first) c11_sbuf__write_sv(&buf, self);