mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 19:40:18 +00:00
new hashmap
This commit is contained in:
parent
ee6286250d
commit
3c6e69476f
@ -8,10 +8,8 @@
|
||||
|
||||
#include <sstream>
|
||||
#include <regex>
|
||||
#include <unordered_map>
|
||||
#include <memory>
|
||||
#include <variant>
|
||||
#include <functional>
|
||||
#include <stack>
|
||||
#include <cmath>
|
||||
#include <stdexcept>
|
||||
|
@ -47,7 +47,7 @@ struct CodeObject {
|
||||
// for goto use
|
||||
// note: some opcodes moves the bytecode, such as listcomp
|
||||
// goto/label should be put at toplevel statements
|
||||
std::unordered_map<_Str, int> co_labels;
|
||||
emhash8::HashMap<_Str, int> co_labels;
|
||||
|
||||
void addLabel(const _Str& label){
|
||||
if(co_labels.find(label) != co_labels.end()){
|
||||
|
@ -29,7 +29,7 @@ public:
|
||||
bool isCompilingClass = false;
|
||||
VM* vm;
|
||||
|
||||
std::unordered_map<_TokenType, GrammarRule> rules;
|
||||
emhash8::HashMap<_TokenType, GrammarRule> rules;
|
||||
|
||||
_Code getCode() {
|
||||
return codes.top();
|
||||
|
1789
src/hash_table8.hpp
Normal file
1789
src/hash_table8.hpp
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,5 @@
|
||||
#include <fstream>
|
||||
#include <functional>
|
||||
|
||||
#include "pocketpy.h"
|
||||
|
||||
|
@ -41,8 +41,8 @@ constexpr _TokenType TK(const char* const token) {
|
||||
const _TokenType __KW_BEGIN = TK("class");
|
||||
const _TokenType __KW_END = TK("raise");
|
||||
|
||||
const std::unordered_map<std::string_view, _TokenType> __KW_MAP = [](){
|
||||
std::unordered_map<std::string_view, _TokenType> map;
|
||||
const emhash8::HashMap<std::string_view, _TokenType> __KW_MAP = [](){
|
||||
emhash8::HashMap<std::string_view, _TokenType> map;
|
||||
for(int k=__KW_BEGIN; k<=__KW_END; k++) map[__TOKENS[k]] = k;
|
||||
return map;
|
||||
}();
|
||||
|
@ -33,25 +33,26 @@ public:
|
||||
};
|
||||
|
||||
|
||||
class PyVarDict: public std::unordered_map<_Str, PyVar> {
|
||||
#include "hash_table8.hpp"
|
||||
|
||||
class PyVarDict: public emhash8::HashMap<_Str, PyVar> {
|
||||
PyVar& at(const _Str&) = delete;
|
||||
|
||||
public:
|
||||
PyVar& operator[](const _Str& key) {
|
||||
return std::unordered_map<_Str, PyVar>::operator[](key);
|
||||
return emhash8::HashMap<_Str, PyVar>::operator[](key);
|
||||
}
|
||||
|
||||
const PyVar& operator[](const _Str& key) const {
|
||||
auto it = find(key);
|
||||
if (it == end()){
|
||||
auto msg = "std::unordered_map key not found, '" + key.str() + "'";
|
||||
auto msg = "map key not found, '" + key.str() + "'";
|
||||
throw std::out_of_range(msg);
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
// define constructors the same as std::unordered_map
|
||||
using std::unordered_map<_Str, PyVar>::unordered_map;
|
||||
using emhash8::HashMap<_Str, PyVar>::HashMap;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user