mirror of
https://github.com/pocketpy/pocketpy
synced 2025-11-10 13:40:16 +00:00
some fix
This commit is contained in:
parent
3de540447a
commit
29421ba691
@ -36,10 +36,10 @@ struct Str{
|
|||||||
bool empty() const { return size == 0; }
|
bool empty() const { return size == 0; }
|
||||||
size_t hash() const{ return std::hash<std::string_view>()(sv()); }
|
size_t hash() const{ return std::hash<std::string_view>()(sv()); }
|
||||||
|
|
||||||
Str& operator=(const Str& other);
|
Str& operator=(const Str&);
|
||||||
Str operator+(const Str& other) const;
|
Str operator+(const Str&) const;
|
||||||
friend Str operator+(const char* p, const Str& str);
|
Str operator+(const char*) const;
|
||||||
Str operator+(const char* p) const;
|
friend Str operator+(const char*, const Str&);
|
||||||
|
|
||||||
bool operator==(const std::string_view other) const;
|
bool operator==(const std::string_view other) const;
|
||||||
bool operator!=(const std::string_view other) const;
|
bool operator!=(const std::string_view other) const;
|
||||||
@ -112,11 +112,11 @@ struct StrName {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool operator<(const StrName& other) const noexcept {
|
bool operator<(const StrName& other) const noexcept {
|
||||||
return this->index < other.index;
|
return sv() < other.sv();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator>(const StrName& other) const noexcept {
|
bool operator>(const StrName& other) const noexcept {
|
||||||
return this->index > other.index;
|
return sv() > other.sv();
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool is_valid(int index);
|
static bool is_valid(int index);
|
||||||
@ -126,10 +126,6 @@ struct StrName {
|
|||||||
static uint32_t _pesudo_random_index;
|
static uint32_t _pesudo_random_index;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct StrNameComparator {
|
|
||||||
bool operator()(const StrName& a, const StrName& b) const;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct SStream{
|
struct SStream{
|
||||||
PK_ALWAYS_PASS_BY_POINTER(SStream)
|
PK_ALWAYS_PASS_BY_POINTER(SStream)
|
||||||
// pod_vector<T> is allocated by pool64 so the buffer can be moved into Str without a copy
|
// pod_vector<T> is allocated by pool64 so the buffer can be moved into Str without a copy
|
||||||
|
|||||||
@ -294,7 +294,7 @@ void init_builtins(VM* _vm) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
_vm->bind_func<1>(_vm->builtins, "dir", [](VM* vm, ArgsView args) {
|
_vm->bind_func<1>(_vm->builtins, "dir", [](VM* vm, ArgsView args) {
|
||||||
std::set<StrName, StrNameComparator> names;
|
std::set<StrName> names;
|
||||||
if(!is_tagged(args[0]) && args[0]->is_attr_valid()){
|
if(!is_tagged(args[0]) && args[0]->is_attr_valid()){
|
||||||
auto keys = args[0]->attr().keys();
|
auto keys = args[0]->attr().keys();
|
||||||
names.insert(keys.begin(), keys.end());
|
names.insert(keys.begin(), keys.end());
|
||||||
|
|||||||
@ -406,10 +406,6 @@ int utf8len(unsigned char c, bool suppress){
|
|||||||
return _r_interned().find(index) != _r_interned().end();
|
return _r_interned().find(index) != _r_interned().end();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StrNameComparator::operator()(const StrName& a, const StrName& b) const {
|
|
||||||
return a._r_interned()[a.index] < b._r_interned()[b.index];
|
|
||||||
}
|
|
||||||
|
|
||||||
Str SStream::str(){
|
Str SStream::str(){
|
||||||
// after this call, the buffer is no longer valid
|
// after this call, the buffer is no longer valid
|
||||||
buffer.reserve(buffer.size() + 1); // allocate one more byte for '\0'
|
buffer.reserve(buffer.size() + 1); // allocate one more byte for '\0'
|
||||||
|
|||||||
@ -276,7 +276,7 @@ namespace pkpy{
|
|||||||
if(i != 0) ss << ".";
|
if(i != 0) ss << ".";
|
||||||
ss << cpnts[i];
|
ss << cpnts[i];
|
||||||
}
|
}
|
||||||
return Str(ss.str());
|
return ss.str();
|
||||||
};
|
};
|
||||||
|
|
||||||
if(path[0] == '.'){
|
if(path[0] == '.'){
|
||||||
|
|||||||
@ -630,3 +630,6 @@ def f(a, b):
|
|||||||
return sum([b, c])
|
return sum([b, c])
|
||||||
|
|
||||||
assert f(1, 2) == 3
|
assert f(1, 2) == 3
|
||||||
|
|
||||||
|
dir_int = dir(int)
|
||||||
|
assert dir_int[:4] == ['__add__', '__and__', '__base__', '__eq__']
|
||||||
Loading…
x
Reference in New Issue
Block a user