mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
...
This commit is contained in:
parent
721b7a2959
commit
1e3849319e
@ -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
|
||||
|
1
src/vm.h
1
src/vm.h
@ -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++){
|
||||
|
Loading…
x
Reference in New Issue
Block a user