mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-19 19:10:17 +00:00
...
This commit is contained in:
parent
c9926cdcea
commit
d204c67d62
@ -1,5 +1,5 @@
|
||||
clang++ -pg -O2 -std=c++17 -fno-rtti -stdlib=libc++ -Wall -o pocketpy src/main.cpp
|
||||
time ./pocketpy benchmarks/sort.py
|
||||
time ./pocketpy benchmarks/primes.py
|
||||
mv benchmarks/gmon.out .
|
||||
gprof pocketpy gmon.out > gprof.txt
|
||||
rm gmon.out
|
||||
|
@ -389,19 +389,9 @@ inline void init_builtins(VM* _vm) {
|
||||
});
|
||||
|
||||
_vm->bind_method<1>("str", "__getitem__", [](VM* vm, ArgsView args) {
|
||||
const Str& self = _CAST(Str&, args[0]);
|
||||
|
||||
if(is_type(args[1], vm->tp_slice)){
|
||||
const Slice& s = _CAST(Slice&, args[1]);
|
||||
int start, stop, step;
|
||||
vm->parse_int_slice(s, self.u8_length(), start, stop, step);
|
||||
return VAR(self.u8_slice(start, stop, step));
|
||||
}
|
||||
|
||||
int index = CAST(int, args[1]);
|
||||
index = vm->normalized_index(index, self.u8_length());
|
||||
return VAR(self.u8_getitem(index));
|
||||
return PyStrGetItem(vm, args[0], args[1]);
|
||||
});
|
||||
_vm->_type_info("str")->m__getitem__ = PyStrGetItem;
|
||||
|
||||
_vm->bind_method<1>("str", "__gt__", [](VM* vm, ArgsView args) {
|
||||
const Str& self = _CAST(Str&, args[0]);
|
||||
|
15
src/vm.h
15
src/vm.h
@ -1263,4 +1263,19 @@ inline PyObject* PyListSetItem(VM* vm, PyObject* obj, PyObject* index, PyObject*
|
||||
return vm->None;
|
||||
}
|
||||
|
||||
inline PyObject* PyStrGetItem(VM* vm, PyObject* obj, PyObject* index){
|
||||
const Str& self = _CAST(Str&, obj);
|
||||
|
||||
if(is_type(index, vm->tp_slice)){
|
||||
const Slice& s = _CAST(Slice&, index);
|
||||
int start, stop, step;
|
||||
vm->parse_int_slice(s, self.u8_length(), start, stop, step);
|
||||
return VAR(self.u8_slice(start, stop, step));
|
||||
}
|
||||
|
||||
int i = CAST(int, index);
|
||||
i = vm->normalized_index(i, self.u8_length());
|
||||
return VAR(self.u8_getitem(i));
|
||||
}
|
||||
|
||||
} // namespace pkpy
|
Loading…
x
Reference in New Issue
Block a user