mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-21 12:00:18 +00:00
add py_newtrivial
backup add `py_totrivial`
This commit is contained in:
parent
be9d8774a0
commit
13e82c1913
@ -201,6 +201,8 @@ PK_API py_GlobalRef py_NIL();
|
|||||||
|
|
||||||
/// Create an `int` object.
|
/// Create an `int` object.
|
||||||
PK_API void py_newint(py_OutRef, py_i64);
|
PK_API void py_newint(py_OutRef, py_i64);
|
||||||
|
/// Create a trivial value object.
|
||||||
|
PK_API void py_newtrivial(py_OutRef out, py_Type type, py_i64 data);
|
||||||
/// Create a `float` object.
|
/// Create a `float` object.
|
||||||
PK_API void py_newfloat(py_OutRef, py_f64);
|
PK_API void py_newfloat(py_OutRef, py_f64);
|
||||||
/// Create a `bool` object.
|
/// Create a `bool` object.
|
||||||
@ -282,6 +284,8 @@ PK_API void* py_newobject(py_OutRef out, py_Type type, int slots, int udsize);
|
|||||||
|
|
||||||
/// Convert an `int` object in python to `int64_t`.
|
/// Convert an `int` object in python to `int64_t`.
|
||||||
PK_API py_i64 py_toint(py_Ref);
|
PK_API py_i64 py_toint(py_Ref);
|
||||||
|
/// Convert a trivial value object in python to `int64_t`.
|
||||||
|
PK_API py_i64 py_totrivial(py_Ref);
|
||||||
/// Convert a `float` object in python to `double`.
|
/// Convert a `float` object in python to `double`.
|
||||||
PK_API py_f64 py_tofloat(py_Ref);
|
PK_API py_f64 py_tofloat(py_Ref);
|
||||||
/// Cast a `int` or `float` object in python to `double`.
|
/// Cast a `int` or `float` object in python to `double`.
|
||||||
@ -389,6 +393,7 @@ PK_API void py_setglobal(py_Name name, py_Ref val);
|
|||||||
PK_API py_ItemRef py_getbuiltin(py_Name name);
|
PK_API py_ItemRef py_getbuiltin(py_Name name);
|
||||||
|
|
||||||
/// Get the last return value.
|
/// Get the last return value.
|
||||||
|
/// Please note that `py_retval()` cannot be used as input argument.
|
||||||
PK_API py_GlobalRef py_retval();
|
PK_API py_GlobalRef py_retval();
|
||||||
|
|
||||||
/// Get an item from the object's `__dict__`.
|
/// Get an item from the object's `__dict__`.
|
||||||
|
@ -9,6 +9,8 @@ int64_t py_toint(py_Ref self) {
|
|||||||
return self->_i64;
|
return self->_i64;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
py_i64 py_totrivial(py_Ref self) { return self->_i64; }
|
||||||
|
|
||||||
double py_tofloat(py_Ref self) {
|
double py_tofloat(py_Ref self) {
|
||||||
assert(self->type == tp_float);
|
assert(self->type == tp_float);
|
||||||
return self->_f64;
|
return self->_f64;
|
||||||
|
@ -13,6 +13,12 @@ void py_newint(py_OutRef out, py_i64 val) {
|
|||||||
out->_i64 = val;
|
out->_i64 = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void py_newtrivial(py_OutRef out, py_Type type, py_i64 data) {
|
||||||
|
out->type = type;
|
||||||
|
out->is_ptr = false;
|
||||||
|
out->_i64 = data;
|
||||||
|
}
|
||||||
|
|
||||||
void py_newfloat(py_OutRef out, py_f64 val) {
|
void py_newfloat(py_OutRef out, py_f64 val) {
|
||||||
out->type = tp_float;
|
out->type = tp_float;
|
||||||
out->is_ptr = false;
|
out->is_ptr = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user