This commit is contained in:
blueloveTH 2023-04-27 15:01:37 +08:00
parent 721b7a2959
commit 1e3849319e
2 changed files with 16 additions and 0 deletions

View File

@ -637,6 +637,21 @@ inline void init_builtins(VM* _vm) {
const Bytes& other = CAST(Bytes&, args[1]);
return VAR(self != other);
});
/************ slice ************/
_vm->bind_static_method<3>("slice", "__new__", [](VM* vm, ArgsView args) {
return VAR(Slice(args[0], args[1], args[2]));
});
_vm->bind_method<0>("slice", "__repr__", [](VM* vm, ArgsView args) {
const Slice& self = CAST(Slice&, args[0]);
std::stringstream ss;
ss << "slice(";
ss << CAST(Str, vm->asRepr(self.start)) << ", ";
ss << CAST(Str, vm->asRepr(self.stop)) << ", ";
ss << CAST(Str, vm->asRepr(self.step)) << ")";
return VAR(ss.str());
});
}
#ifdef _WIN32

View File

@ -806,6 +806,7 @@ inline void VM::init_builtin_types(){
builtins->attr().set("range", _t(tp_range));
builtins->attr().set("bytes", _t(tp_bytes));
builtins->attr().set("StopIteration", StopIteration);
builtins->attr().set("slice", _t(tp_slice));
post_init();
for(int i=0; i<_all_types.size(); i++){