mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-21 12:00:18 +00:00
up
This commit is contained in:
parent
e5e6c49b29
commit
57fd320ae2
@ -61,9 +61,9 @@ struct CodeObject {
|
||||
std::vector<Bytecode> codes;
|
||||
pkpy::List consts;
|
||||
std::vector<std::pair<StrName, NameScope>> names;
|
||||
emhash8::HashMap<StrName, int> global_names;
|
||||
pkpy::HashMap<StrName, int> global_names;
|
||||
std::vector<CodeBlock> blocks = { CodeBlock{NO_BLOCK, -1} };
|
||||
emhash8::HashMap<StrName, int> labels;
|
||||
pkpy::HashMap<StrName, int> labels;
|
||||
|
||||
void optimize(VM* vm);
|
||||
|
||||
|
@ -27,7 +27,12 @@
|
||||
// #include <filesystem>
|
||||
// namespace fs = std::filesystem;
|
||||
|
||||
#define EMH_EXT 1
|
||||
#include "hash_table8.hpp"
|
||||
namespace pkpy {
|
||||
template<typename... Args>
|
||||
using HashMap = emhash8::HashMap<Args...>;
|
||||
}
|
||||
|
||||
#ifdef POCKETPY_H
|
||||
#define UNREACHABLE() throw std::runtime_error( "L" + std::to_string(__LINE__) + " UNREACHABLE()!");
|
||||
|
@ -23,7 +23,7 @@ class Compiler {
|
||||
int lexing_count = 0;
|
||||
bool used = false;
|
||||
VM* vm;
|
||||
emhash8::HashMap<TokenIndex, GrammarRule> rules;
|
||||
pkpy::HashMap<TokenIndex, GrammarRule> rules;
|
||||
|
||||
CodeObject_ co() const{ return codes.top(); }
|
||||
CompileMode mode() const{ return parser->src->mode; }
|
||||
|
2034
src/hash_table5.hpp
Normal file
2034
src/hash_table5.hpp
Normal file
File diff suppressed because it is too large
Load Diff
1817
src/hash_table6.hpp
Normal file
1817
src/hash_table6.hpp
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,4 @@
|
||||
// emhash8::HashMap for C++11/14/17
|
||||
// pkpy::HashMap for C++11/14/17
|
||||
// version 1.6.3
|
||||
//
|
||||
// Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
|
@ -38,8 +38,8 @@ constexpr TokenIndex TK(const char* const token) {
|
||||
const TokenIndex kTokenKwBegin = TK("class");
|
||||
const TokenIndex kTokenKwEnd = TK("raise");
|
||||
|
||||
const emhash8::HashMap<std::string_view, TokenIndex> kTokenKwMap = [](){
|
||||
emhash8::HashMap<std::string_view, TokenIndex> map;
|
||||
const pkpy::HashMap<std::string_view, TokenIndex> kTokenKwMap = [](){
|
||||
pkpy::HashMap<std::string_view, TokenIndex> map;
|
||||
for(int k=kTokenKwBegin; k<=kTokenKwEnd; k++) map[kTokens[k]] = k;
|
||||
return map;
|
||||
}();
|
||||
|
@ -125,10 +125,13 @@ void init_builtins(VM* _vm) {
|
||||
_vm->bind_builtin_func<1>("dir", [](VM* vm, pkpy::Args& args) {
|
||||
std::vector<StrName> names;
|
||||
if(args[0]->is_attr_valid()){
|
||||
for (auto& [k, _] : args[0]->attr()) names.push_back(k);
|
||||
for(auto it = args[0]->attr().begin(); it != args[0]->attr().end(); ++it){
|
||||
names.push_back(it->first);
|
||||
}
|
||||
}
|
||||
for (auto& [k, _] : vm->_t(args[0])->attr()) {
|
||||
if (std::find(names.begin(), names.end(), k) == names.end()) names.push_back(k);
|
||||
const pkpy::NameDict& t_attr = vm->_t(args[0])->attr();
|
||||
for(auto it = t_attr.begin(); it != t_attr.end(); ++it){
|
||||
if (std::find(names.begin(), names.end(), it->first) == names.end()) names.push_back(it->first);
|
||||
}
|
||||
pkpy::List ret;
|
||||
for (const auto& name : names) ret.push_back(vm->PyStr(name.str()));
|
||||
|
@ -33,7 +33,7 @@ public:
|
||||
using std::vector<PyVar>::vector;
|
||||
};
|
||||
|
||||
typedef emhash8::HashMap<StrName, PyVar> NameDict;
|
||||
typedef pkpy::HashMap<StrName, PyVar> NameDict;
|
||||
|
||||
}
|
||||
|
||||
|
@ -160,7 +160,7 @@ bool is_unicode_Lo_char(uint32_t c) {
|
||||
|
||||
|
||||
struct StrName {
|
||||
const int index;
|
||||
int index;
|
||||
StrName(int index): index(index) {}
|
||||
StrName(const char* s): index(get(s).index) {}
|
||||
StrName(const Str& s): index(get(s).index) {}
|
||||
@ -191,6 +191,10 @@ struct StrName {
|
||||
}
|
||||
};
|
||||
|
||||
// declare static members
|
||||
std::map<Str, int, std::less<>> StrName::_interned;
|
||||
std::vector<Str> StrName::_r_interned;
|
||||
|
||||
template<>
|
||||
struct std::hash<StrName> {
|
||||
inline size_t operator()(const StrName& name) const {
|
||||
|
6
src/vm.h
6
src/vm.h
@ -25,7 +25,7 @@ public:
|
||||
|
||||
pkpy::NameDict _types;
|
||||
pkpy::NameDict _modules; // loaded modules
|
||||
emhash8::HashMap<StrName, Str> _lazy_modules; // lazy loaded modules
|
||||
pkpy::HashMap<StrName, Str> _lazy_modules; // lazy loaded modules
|
||||
PyVar None, True, False, Ellipsis;
|
||||
|
||||
bool use_stdio;
|
||||
@ -634,8 +634,8 @@ public:
|
||||
setattr(_t(tp_type), __base__, _t(tp_object));
|
||||
setattr(_t(tp_object), __base__, None);
|
||||
|
||||
for (auto& [name, type] : _types) {
|
||||
setattr(type, __name__, PyStr(name.str()));
|
||||
for(auto it = _types.begin(); it != _types.end(); it++){
|
||||
setattr(it->second, __name__, PyStr(it->first.str()));
|
||||
}
|
||||
|
||||
std::vector<Str> pb_types = {"type", "object", "bool", "int", "float", "str", "list", "tuple", "range"};
|
||||
|
Loading…
x
Reference in New Issue
Block a user