forked from Rust-related/RustPython
Merge pull request #720 from RustPython/cleaning-tweaks
Use the extend class macro more.
This commit is contained in:
@@ -356,29 +356,31 @@ pub fn init(context: &PyContext) {
|
||||
|
||||
let float_doc = "Convert a string or number to a floating point number, if possible.";
|
||||
|
||||
context.set_attr(&float_type, "__eq__", context.new_rustfunc(PyFloatRef::eq));
|
||||
context.set_attr(&float_type, "__lt__", context.new_rustfunc(PyFloatRef::lt));
|
||||
context.set_attr(&float_type, "__le__", context.new_rustfunc(PyFloatRef::le));
|
||||
context.set_attr(&float_type, "__gt__", context.new_rustfunc(PyFloatRef::gt));
|
||||
context.set_attr(&float_type, "__ge__", context.new_rustfunc(PyFloatRef::ge));
|
||||
context.set_attr(&float_type, "__abs__", context.new_rustfunc(PyFloatRef::abs));
|
||||
context.set_attr(&float_type, "__add__", context.new_rustfunc(PyFloatRef::add));
|
||||
context.set_attr(&float_type, "__radd__", context.new_rustfunc(PyFloatRef::add));
|
||||
context.set_attr(&float_type, "__divmod__", context.new_rustfunc(PyFloatRef::divmod));
|
||||
context.set_attr(&float_type, "__floordiv__", context.new_rustfunc(PyFloatRef::floordiv));
|
||||
context.set_attr(&float_type, "__new__", context.new_rustfunc(PyFloatRef::new_float));
|
||||
context.set_attr(&float_type, "__mod__", context.new_rustfunc(PyFloatRef::mod_));
|
||||
context.set_attr(&float_type, "__neg__", context.new_rustfunc(PyFloatRef::neg));
|
||||
context.set_attr(&float_type, "__pow__", context.new_rustfunc(PyFloatRef::pow));
|
||||
context.set_attr(&float_type, "__sub__", context.new_rustfunc(PyFloatRef::sub));
|
||||
context.set_attr(&float_type, "__rsub__", context.new_rustfunc(PyFloatRef::rsub));
|
||||
context.set_attr(&float_type, "__repr__", context.new_rustfunc(PyFloatRef::repr));
|
||||
context.set_attr(&float_type, "__doc__", context.new_str(float_doc.to_string()));
|
||||
context.set_attr(&float_type, "__truediv__", context.new_rustfunc(PyFloatRef::truediv));
|
||||
context.set_attr(&float_type, "__rtruediv__", context.new_rustfunc(PyFloatRef::rtruediv));
|
||||
context.set_attr(&float_type, "__mul__", context.new_rustfunc(PyFloatRef::mul));
|
||||
context.set_attr(&float_type, "__rmul__", context.new_rustfunc(PyFloatRef::mul));
|
||||
context.set_attr(&float_type, "real", context.new_property(PyFloatRef::real));
|
||||
context.set_attr(&float_type, "is_integer", context.new_rustfunc(PyFloatRef::is_integer));
|
||||
context.set_attr(&float_type, "as_integer_ratio", context.new_rustfunc(PyFloatRef::as_integer_ratio));
|
||||
extend_class!(context, float_type, {
|
||||
"__eq__" => context.new_rustfunc(PyFloatRef::eq),
|
||||
"__lt__" => context.new_rustfunc(PyFloatRef::lt),
|
||||
"__le__" => context.new_rustfunc(PyFloatRef::le),
|
||||
"__gt__" => context.new_rustfunc(PyFloatRef::gt),
|
||||
"__ge__" => context.new_rustfunc(PyFloatRef::ge),
|
||||
"__abs__" => context.new_rustfunc(PyFloatRef::abs),
|
||||
"__add__" => context.new_rustfunc(PyFloatRef::add),
|
||||
"__radd__" => context.new_rustfunc(PyFloatRef::add),
|
||||
"__divmod__" => context.new_rustfunc(PyFloatRef::divmod),
|
||||
"__floordiv__" => context.new_rustfunc(PyFloatRef::floordiv),
|
||||
"__new__" => context.new_rustfunc(PyFloatRef::new_float),
|
||||
"__mod__" => context.new_rustfunc(PyFloatRef::mod_),
|
||||
"__neg__" => context.new_rustfunc(PyFloatRef::neg),
|
||||
"__pow__" => context.new_rustfunc(PyFloatRef::pow),
|
||||
"__sub__" => context.new_rustfunc(PyFloatRef::sub),
|
||||
"__rsub__" => context.new_rustfunc(PyFloatRef::rsub),
|
||||
"__repr__" => context.new_rustfunc(PyFloatRef::repr),
|
||||
"__doc__" => context.new_str(float_doc.to_string()),
|
||||
"__truediv__" => context.new_rustfunc(PyFloatRef::truediv),
|
||||
"__rtruediv__" => context.new_rustfunc(PyFloatRef::rtruediv),
|
||||
"__mul__" => context.new_rustfunc(PyFloatRef::mul),
|
||||
"__rmul__" => context.new_rustfunc(PyFloatRef::mul),
|
||||
"real" => context.new_property(PyFloatRef::real),
|
||||
"is_integer" => context.new_rustfunc(PyFloatRef::is_integer),
|
||||
"as_integer_ratio" => context.new_rustfunc(PyFloatRef::as_integer_ratio)
|
||||
});
|
||||
}
|
||||
|
||||
@@ -474,50 +474,51 @@ Base 0 means to interpret the base from the string as an integer literal.
|
||||
>>> int('0b100', base=0)
|
||||
4";
|
||||
let int_type = &context.int_type;
|
||||
|
||||
context.set_attr(&int_type, "__doc__", context.new_str(int_doc.to_string()));
|
||||
context.set_attr(&int_type, "__eq__", context.new_rustfunc(PyIntRef::eq));
|
||||
context.set_attr(&int_type, "__ne__", context.new_rustfunc(PyIntRef::ne));
|
||||
context.set_attr(&int_type, "__lt__", context.new_rustfunc(PyIntRef::lt));
|
||||
context.set_attr(&int_type, "__le__", context.new_rustfunc(PyIntRef::le));
|
||||
context.set_attr(&int_type, "__gt__", context.new_rustfunc(PyIntRef::gt));
|
||||
context.set_attr(&int_type, "__ge__", context.new_rustfunc(PyIntRef::ge));
|
||||
context.set_attr(&int_type, "__abs__", context.new_rustfunc(PyIntRef::abs));
|
||||
context.set_attr(&int_type, "__add__", context.new_rustfunc(PyIntRef::add));
|
||||
context.set_attr(&int_type, "__radd__", context.new_rustfunc(PyIntRef::add));
|
||||
context.set_attr(&int_type, "__and__", context.new_rustfunc(PyIntRef::and));
|
||||
context.set_attr(&int_type, "__divmod__", context.new_rustfunc(PyIntRef::divmod));
|
||||
context.set_attr(&int_type, "__float__", context.new_rustfunc(PyIntRef::float));
|
||||
context.set_attr(&int_type, "__round__", context.new_rustfunc(PyIntRef::round));
|
||||
context.set_attr(&int_type, "__ceil__", context.new_rustfunc(PyIntRef::pass_value));
|
||||
context.set_attr(&int_type, "__floor__", context.new_rustfunc(PyIntRef::pass_value));
|
||||
context.set_attr(&int_type, "__index__", context.new_rustfunc(PyIntRef::pass_value));
|
||||
context.set_attr(&int_type, "__trunc__", context.new_rustfunc(PyIntRef::pass_value));
|
||||
context.set_attr(&int_type, "__int__", context.new_rustfunc(PyIntRef::pass_value));
|
||||
context.set_attr(&int_type, "__floordiv__", context.new_rustfunc(PyIntRef::floordiv));
|
||||
context.set_attr(&int_type, "__hash__", context.new_rustfunc(PyIntRef::hash));
|
||||
context.set_attr(&int_type, "__lshift__", context.new_rustfunc(PyIntRef::lshift));
|
||||
context.set_attr(&int_type, "__rshift__", context.new_rustfunc(PyIntRef::rshift));
|
||||
context.set_attr(&int_type, "__new__", context.new_rustfunc(int_new));
|
||||
context.set_attr(&int_type, "__mod__", context.new_rustfunc(PyIntRef::mod_));
|
||||
context.set_attr(&int_type, "__mul__", context.new_rustfunc(PyIntRef::mul));
|
||||
context.set_attr(&int_type, "__rmul__", context.new_rustfunc(PyIntRef::mul));
|
||||
context.set_attr(&int_type, "__or__", context.new_rustfunc(PyIntRef::or));
|
||||
context.set_attr(&int_type, "__neg__", context.new_rustfunc(PyIntRef::neg));
|
||||
context.set_attr(&int_type, "__pos__", context.new_rustfunc(PyIntRef::pass_value));
|
||||
context.set_attr(&int_type, "__pow__", context.new_rustfunc(PyIntRef::pow));
|
||||
context.set_attr(&int_type, "__repr__", context.new_rustfunc(PyIntRef::repr));
|
||||
context.set_attr(&int_type, "__sub__", context.new_rustfunc(PyIntRef::sub));
|
||||
context.set_attr(&int_type, "__rsub__", context.new_rustfunc(PyIntRef::rsub));
|
||||
context.set_attr(&int_type, "__format__", context.new_rustfunc(PyIntRef::format));
|
||||
context.set_attr(&int_type, "__truediv__", context.new_rustfunc(PyIntRef::truediv));
|
||||
context.set_attr(&int_type, "__rtruediv__", context.new_rustfunc(PyIntRef::rtruediv));
|
||||
context.set_attr(&int_type, "__xor__", context.new_rustfunc(PyIntRef::xor));
|
||||
context.set_attr(&int_type, "__rxor__", context.new_rustfunc(PyIntRef::rxor));
|
||||
context.set_attr(&int_type, "__bool__", context.new_rustfunc(PyIntRef::bool));
|
||||
context.set_attr(&int_type, "__invert__", context.new_rustfunc(PyIntRef::invert));
|
||||
context.set_attr(&int_type, "bit_length", context.new_rustfunc(PyIntRef::bit_length));
|
||||
context.set_attr(&int_type, "conjugate", context.new_rustfunc(PyIntRef::pass_value));
|
||||
context.set_attr(&int_type, "real", context.new_property(PyIntRef::pass_value));
|
||||
context.set_attr(&int_type, "imag", context.new_property(PyIntRef::imag));
|
||||
extend_class!(context, int_type, {
|
||||
"__doc__" => context.new_str(int_doc.to_string()),
|
||||
"__eq__" => context.new_rustfunc(PyIntRef::eq),
|
||||
"__ne__" => context.new_rustfunc(PyIntRef::ne),
|
||||
"__lt__" => context.new_rustfunc(PyIntRef::lt),
|
||||
"__le__" => context.new_rustfunc(PyIntRef::le),
|
||||
"__gt__" => context.new_rustfunc(PyIntRef::gt),
|
||||
"__ge__" => context.new_rustfunc(PyIntRef::ge),
|
||||
"__abs__" => context.new_rustfunc(PyIntRef::abs),
|
||||
"__add__" => context.new_rustfunc(PyIntRef::add),
|
||||
"__radd__" => context.new_rustfunc(PyIntRef::add),
|
||||
"__and__" => context.new_rustfunc(PyIntRef::and),
|
||||
"__divmod__" => context.new_rustfunc(PyIntRef::divmod),
|
||||
"__float__" => context.new_rustfunc(PyIntRef::float),
|
||||
"__round__" => context.new_rustfunc(PyIntRef::round),
|
||||
"__ceil__" => context.new_rustfunc(PyIntRef::pass_value),
|
||||
"__floor__" => context.new_rustfunc(PyIntRef::pass_value),
|
||||
"__index__" => context.new_rustfunc(PyIntRef::pass_value),
|
||||
"__trunc__" => context.new_rustfunc(PyIntRef::pass_value),
|
||||
"__int__" => context.new_rustfunc(PyIntRef::pass_value),
|
||||
"__floordiv__" => context.new_rustfunc(PyIntRef::floordiv),
|
||||
"__hash__" => context.new_rustfunc(PyIntRef::hash),
|
||||
"__lshift__" => context.new_rustfunc(PyIntRef::lshift),
|
||||
"__rshift__" => context.new_rustfunc(PyIntRef::rshift),
|
||||
"__new__" => context.new_rustfunc(int_new),
|
||||
"__mod__" => context.new_rustfunc(PyIntRef::mod_),
|
||||
"__mul__" => context.new_rustfunc(PyIntRef::mul),
|
||||
"__rmul__" => context.new_rustfunc(PyIntRef::mul),
|
||||
"__or__" => context.new_rustfunc(PyIntRef::or),
|
||||
"__neg__" => context.new_rustfunc(PyIntRef::neg),
|
||||
"__pos__" => context.new_rustfunc(PyIntRef::pass_value),
|
||||
"__pow__" => context.new_rustfunc(PyIntRef::pow),
|
||||
"__repr__" => context.new_rustfunc(PyIntRef::repr),
|
||||
"__sub__" => context.new_rustfunc(PyIntRef::sub),
|
||||
"__rsub__" => context.new_rustfunc(PyIntRef::rsub),
|
||||
"__format__" => context.new_rustfunc(PyIntRef::format),
|
||||
"__truediv__" => context.new_rustfunc(PyIntRef::truediv),
|
||||
"__rtruediv__" => context.new_rustfunc(PyIntRef::rtruediv),
|
||||
"__xor__" => context.new_rustfunc(PyIntRef::xor),
|
||||
"__rxor__" => context.new_rustfunc(PyIntRef::rxor),
|
||||
"__bool__" => context.new_rustfunc(PyIntRef::bool),
|
||||
"__invert__" => context.new_rustfunc(PyIntRef::invert),
|
||||
"bit_length" => context.new_rustfunc(PyIntRef::bit_length),
|
||||
"conjugate" => context.new_rustfunc(PyIntRef::pass_value),
|
||||
"real" => context.new_property(PyIntRef::pass_value),
|
||||
"imag" => context.new_property(PyIntRef::imag)
|
||||
});
|
||||
}
|
||||
|
||||
@@ -63,7 +63,9 @@ pub fn init(context: &PyContext) {
|
||||
each of the iterables. Stops when the shortest iterable is exhausted.";
|
||||
|
||||
objiter::iter_type_init(context, map_type);
|
||||
context.set_attr(&map_type, "__new__", context.new_rustfunc(map_new));
|
||||
context.set_attr(&map_type, "__next__", context.new_rustfunc(map_next));
|
||||
context.set_attr(&map_type, "__doc__", context.new_str(map_doc.to_string()));
|
||||
extend_class!(context, map_type, {
|
||||
"__new__" => context.new_rustfunc(map_new),
|
||||
"__next__" => context.new_rustfunc(map_next),
|
||||
"__doc__" => context.new_str(map_doc.to_string())
|
||||
});
|
||||
}
|
||||
|
||||
@@ -164,36 +164,22 @@ pub fn init(context: &PyContext) {
|
||||
These are exactly the valid indices for a list of 4 elements.\n\
|
||||
When step is given, it specifies the increment (or decrement).";
|
||||
|
||||
context.set_attr(&range_type, "__new__", context.new_rustfunc(range_new));
|
||||
context.set_attr(&range_type, "__iter__", context.new_rustfunc(range_iter));
|
||||
context.set_attr(
|
||||
&range_type,
|
||||
"__reversed__",
|
||||
context.new_rustfunc(range_reversed),
|
||||
);
|
||||
context.set_attr(
|
||||
&range_type,
|
||||
"__doc__",
|
||||
context.new_str(range_doc.to_string()),
|
||||
);
|
||||
context.set_attr(&range_type, "__len__", context.new_rustfunc(range_len));
|
||||
context.set_attr(
|
||||
&range_type,
|
||||
"__getitem__",
|
||||
context.new_rustfunc(range_getitem),
|
||||
);
|
||||
context.set_attr(&range_type, "__repr__", context.new_rustfunc(range_repr));
|
||||
context.set_attr(&range_type, "__bool__", context.new_rustfunc(range_bool));
|
||||
context.set_attr(
|
||||
&range_type,
|
||||
"__contains__",
|
||||
context.new_rustfunc(range_contains),
|
||||
);
|
||||
context.set_attr(&range_type, "index", context.new_rustfunc(range_index));
|
||||
context.set_attr(&range_type, "count", context.new_rustfunc(range_count));
|
||||
context.set_attr(&range_type, "start", context.new_property(range_start));
|
||||
context.set_attr(&range_type, "stop", context.new_property(range_stop));
|
||||
context.set_attr(&range_type, "step", context.new_property(range_step));
|
||||
extend_class!(context, range_type, {
|
||||
"__bool__" => context.new_rustfunc(range_bool),
|
||||
"__contains__" => context.new_rustfunc(range_contains),
|
||||
"__doc__" => context.new_str(range_doc.to_string()),
|
||||
"__getitem__" => context.new_rustfunc(range_getitem),
|
||||
"__iter__" => context.new_rustfunc(range_iter),
|
||||
"__len__" => context.new_rustfunc(range_len),
|
||||
"__new__" => context.new_rustfunc(range_new),
|
||||
"__repr__" => context.new_rustfunc(range_repr),
|
||||
"__reversed__" => context.new_rustfunc(range_reversed),
|
||||
"count" => context.new_rustfunc(range_count),
|
||||
"index" => context.new_rustfunc(range_index),
|
||||
"start" => context.new_property(range_start),
|
||||
"step" => context.new_property(range_step),
|
||||
"stop" => context.new_property(range_stop)
|
||||
});
|
||||
}
|
||||
|
||||
fn range_new(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
|
||||
@@ -100,10 +100,12 @@ fn slice_step(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
}
|
||||
|
||||
pub fn init(context: &PyContext) {
|
||||
let zip_type = &context.slice_type;
|
||||
let slice_type = &context.slice_type;
|
||||
|
||||
context.set_attr(zip_type, "__new__", context.new_rustfunc(slice_new));
|
||||
context.set_attr(zip_type, "start", context.new_property(slice_start));
|
||||
context.set_attr(zip_type, "stop", context.new_property(slice_stop));
|
||||
context.set_attr(zip_type, "step", context.new_property(slice_step));
|
||||
extend_class!(context, slice_type, {
|
||||
"__new__" => context.new_rustfunc(slice_new),
|
||||
"start" => context.new_property(slice_start),
|
||||
"stop" => context.new_property(slice_stop),
|
||||
"step" => context.new_property(slice_step)
|
||||
});
|
||||
}
|
||||
|
||||
@@ -629,61 +629,64 @@ pub fn init(context: &PyContext) {
|
||||
or repr(object).\n\
|
||||
encoding defaults to sys.getdefaultencoding().\n\
|
||||
errors defaults to 'strict'.";
|
||||
context.set_attr(&str_type, "__add__", context.new_rustfunc(PyStringRef::add));
|
||||
context.set_attr(&str_type, "__eq__", context.new_rustfunc(PyStringRef::eq));
|
||||
context.set_attr(&str_type, "__contains__", context.new_rustfunc(PyStringRef::contains));
|
||||
context.set_attr(&str_type, "__getitem__", context.new_rustfunc(PyStringRef::getitem));
|
||||
context.set_attr(&str_type, "__gt__", context.new_rustfunc(PyStringRef::gt));
|
||||
context.set_attr(&str_type, "__ge__", context.new_rustfunc(PyStringRef::ge));
|
||||
context.set_attr(&str_type, "__lt__", context.new_rustfunc(PyStringRef::lt));
|
||||
context.set_attr(&str_type, "__le__", context.new_rustfunc(PyStringRef::le));
|
||||
context.set_attr(&str_type, "__hash__", context.new_rustfunc(PyStringRef::hash));
|
||||
context.set_attr(&str_type, "__len__", context.new_rustfunc(PyStringRef::len));
|
||||
context.set_attr(&str_type, "__mul__", context.new_rustfunc(PyStringRef::mul));
|
||||
context.set_attr(&str_type, "__new__", context.new_rustfunc(str_new));
|
||||
context.set_attr(&str_type, "__str__", context.new_rustfunc(PyStringRef::str));
|
||||
context.set_attr(&str_type, "__repr__", context.new_rustfunc(PyStringRef::repr));
|
||||
context.set_attr(&str_type, "format", context.new_rustfunc(str_format));
|
||||
context.set_attr(&str_type, "lower", context.new_rustfunc(PyStringRef::lower));
|
||||
context.set_attr(&str_type, "casefold", context.new_rustfunc(PyStringRef::casefold));
|
||||
context.set_attr(&str_type, "upper", context.new_rustfunc(PyStringRef::upper));
|
||||
context.set_attr(&str_type, "capitalize", context.new_rustfunc(PyStringRef::capitalize));
|
||||
context.set_attr(&str_type, "split", context.new_rustfunc(PyStringRef::split));
|
||||
context.set_attr(&str_type, "rsplit", context.new_rustfunc(PyStringRef::rsplit));
|
||||
context.set_attr(&str_type, "strip", context.new_rustfunc(PyStringRef::strip));
|
||||
context.set_attr(&str_type, "lstrip", context.new_rustfunc(PyStringRef::lstrip));
|
||||
context.set_attr(&str_type, "rstrip", context.new_rustfunc(PyStringRef::rstrip));
|
||||
context.set_attr(&str_type, "endswith", context.new_rustfunc(PyStringRef::endswith));
|
||||
context.set_attr(&str_type, "startswith", context.new_rustfunc(PyStringRef::startswith));
|
||||
context.set_attr(&str_type, "isalnum", context.new_rustfunc(PyStringRef::isalnum));
|
||||
context.set_attr(&str_type, "isnumeric", context.new_rustfunc(PyStringRef::isnumeric));
|
||||
context.set_attr(&str_type, "isdigit", context.new_rustfunc(PyStringRef::isdigit));
|
||||
context.set_attr(&str_type, "isdecimal", context.new_rustfunc(PyStringRef::isdecimal));
|
||||
context.set_attr(&str_type, "title", context.new_rustfunc(PyStringRef::title));
|
||||
context.set_attr(&str_type, "swapcase", context.new_rustfunc(PyStringRef::swapcase));
|
||||
context.set_attr(&str_type, "isalpha", context.new_rustfunc(PyStringRef::isalpha));
|
||||
context.set_attr(&str_type, "replace", context.new_rustfunc(PyStringRef::replace));
|
||||
context.set_attr(&str_type, "isspace", context.new_rustfunc(PyStringRef::isspace));
|
||||
context.set_attr(&str_type, "isupper", context.new_rustfunc(PyStringRef::isupper));
|
||||
context.set_attr(&str_type, "islower", context.new_rustfunc(PyStringRef::islower));
|
||||
context.set_attr(&str_type, "isascii", context.new_rustfunc(PyStringRef::isascii));
|
||||
context.set_attr(&str_type, "splitlines", context.new_rustfunc(PyStringRef::splitlines));
|
||||
context.set_attr(&str_type, "join", context.new_rustfunc(PyStringRef::join));
|
||||
context.set_attr(&str_type, "find", context.new_rustfunc(PyStringRef::find));
|
||||
context.set_attr(&str_type, "rfind", context.new_rustfunc(PyStringRef::rfind));
|
||||
context.set_attr(&str_type, "index", context.new_rustfunc(PyStringRef::index));
|
||||
context.set_attr(&str_type, "rindex", context.new_rustfunc(PyStringRef::rindex));
|
||||
context.set_attr(&str_type, "partition", context.new_rustfunc(PyStringRef::partition));
|
||||
context.set_attr(&str_type, "rpartition", context.new_rustfunc(PyStringRef::rpartition));
|
||||
context.set_attr(&str_type, "istitle", context.new_rustfunc(PyStringRef::istitle));
|
||||
context.set_attr(&str_type, "count", context.new_rustfunc(PyStringRef::count));
|
||||
context.set_attr(&str_type, "zfill", context.new_rustfunc(PyStringRef::zfill));
|
||||
context.set_attr(&str_type, "ljust", context.new_rustfunc(PyStringRef::ljust));
|
||||
context.set_attr(&str_type, "rjust", context.new_rustfunc(PyStringRef::rjust));
|
||||
context.set_attr(&str_type, "center", context.new_rustfunc(PyStringRef::center));
|
||||
context.set_attr(&str_type, "expandtabs", context.new_rustfunc(PyStringRef::expandtabs));
|
||||
context.set_attr(&str_type, "isidentifier", context.new_rustfunc(PyStringRef::isidentifier));
|
||||
context.set_attr(&str_type, "__doc__", context.new_str(str_doc.to_string()));
|
||||
|
||||
extend_class!(context, str_type, {
|
||||
"__add__" => context.new_rustfunc(PyStringRef::add),
|
||||
"__contains__" => context.new_rustfunc(PyStringRef::contains),
|
||||
"__doc__" => context.new_str(str_doc.to_string()),
|
||||
"__eq__" => context.new_rustfunc(PyStringRef::eq),
|
||||
"__ge__" => context.new_rustfunc(PyStringRef::ge),
|
||||
"__getitem__" => context.new_rustfunc(PyStringRef::getitem),
|
||||
"__gt__" => context.new_rustfunc(PyStringRef::gt),
|
||||
"__hash__" => context.new_rustfunc(PyStringRef::hash),
|
||||
"__lt__" => context.new_rustfunc(PyStringRef::lt),
|
||||
"__le__" => context.new_rustfunc(PyStringRef::le),
|
||||
"__len__" => context.new_rustfunc(PyStringRef::len),
|
||||
"__mul__" => context.new_rustfunc(PyStringRef::mul),
|
||||
"__new__" => context.new_rustfunc(str_new),
|
||||
"__repr__" => context.new_rustfunc(PyStringRef::repr),
|
||||
"__str__" => context.new_rustfunc(PyStringRef::str),
|
||||
"capitalize" => context.new_rustfunc(PyStringRef::capitalize),
|
||||
"casefold" => context.new_rustfunc(PyStringRef::casefold),
|
||||
"center" => context.new_rustfunc(PyStringRef::center),
|
||||
"count" => context.new_rustfunc(PyStringRef::count),
|
||||
"endswith" => context.new_rustfunc(PyStringRef::endswith),
|
||||
"expandtabs" => context.new_rustfunc(PyStringRef::expandtabs),
|
||||
"find" => context.new_rustfunc(PyStringRef::find),
|
||||
"format" => context.new_rustfunc(str_format),
|
||||
"index" => context.new_rustfunc(PyStringRef::index),
|
||||
"isalnum" => context.new_rustfunc(PyStringRef::isalnum),
|
||||
"isalpha" => context.new_rustfunc(PyStringRef::isalpha),
|
||||
"isascii" => context.new_rustfunc(PyStringRef::isascii),
|
||||
"isdecimal" => context.new_rustfunc(PyStringRef::isdecimal),
|
||||
"isdigit" => context.new_rustfunc(PyStringRef::isdigit),
|
||||
"isidentifier" => context.new_rustfunc(PyStringRef::isidentifier),
|
||||
"islower" => context.new_rustfunc(PyStringRef::islower),
|
||||
"isnumeric" => context.new_rustfunc(PyStringRef::isnumeric),
|
||||
"isspace" => context.new_rustfunc(PyStringRef::isspace),
|
||||
"isupper" => context.new_rustfunc(PyStringRef::isupper),
|
||||
"istitle" => context.new_rustfunc(PyStringRef::istitle),
|
||||
"join" => context.new_rustfunc(PyStringRef::join),
|
||||
"lower" => context.new_rustfunc(PyStringRef::lower),
|
||||
"ljust" => context.new_rustfunc(PyStringRef::ljust),
|
||||
"lstrip" => context.new_rustfunc(PyStringRef::lstrip),
|
||||
"partition" => context.new_rustfunc(PyStringRef::partition),
|
||||
"replace" => context.new_rustfunc(PyStringRef::replace),
|
||||
"rfind" => context.new_rustfunc(PyStringRef::rfind),
|
||||
"rindex" => context.new_rustfunc(PyStringRef::rindex),
|
||||
"rjust" => context.new_rustfunc(PyStringRef::rjust),
|
||||
"rpartition" => context.new_rustfunc(PyStringRef::rpartition),
|
||||
"rsplit" => context.new_rustfunc(PyStringRef::rsplit),
|
||||
"rstrip" => context.new_rustfunc(PyStringRef::rstrip),
|
||||
"split" => context.new_rustfunc(PyStringRef::split),
|
||||
"splitlines" => context.new_rustfunc(PyStringRef::splitlines),
|
||||
"startswith" => context.new_rustfunc(PyStringRef::startswith),
|
||||
"strip" => context.new_rustfunc(PyStringRef::strip),
|
||||
"swapcase" => context.new_rustfunc(PyStringRef::swapcase),
|
||||
"title" => context.new_rustfunc(PyStringRef::title),
|
||||
"upper" => context.new_rustfunc(PyStringRef::upper),
|
||||
"zfill" => context.new_rustfunc(PyStringRef::zfill),
|
||||
});
|
||||
}
|
||||
|
||||
pub fn get_value(obj: &PyObjectRef) -> String {
|
||||
|
||||
@@ -909,7 +909,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_add_py_integers() {
|
||||
let mut vm = VirtualMachine::new();
|
||||
let vm = VirtualMachine::new();
|
||||
let a = vm.ctx.new_int(33_i32);
|
||||
let b = vm.ctx.new_int(12_i32);
|
||||
let res = vm._add(a, b).unwrap();
|
||||
@@ -919,7 +919,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_multiply_str() {
|
||||
let mut vm = VirtualMachine::new();
|
||||
let vm = VirtualMachine::new();
|
||||
let a = vm.ctx.new_str(String::from("Hello "));
|
||||
let b = vm.ctx.new_int(4_i32);
|
||||
let res = vm._mul(a, b).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user