some update

This commit is contained in:
blueloveTH 2024-02-19 11:42:18 +08:00
parent 32b41af8dd
commit cbe8945d37
5 changed files with 10 additions and 9 deletions

View File

@ -71,7 +71,8 @@ struct CodeObject {
std::vector<int> iblocks; // block index for each bytecode
std::vector<LineInfo> lines;
List consts;
small_vector<PyObject*, 8> consts;
pod_vector<StrName> varnames; // local variables
NameDictInt varnames_inv;
std::vector<CodeBlock> blocks;

View File

@ -126,7 +126,7 @@ struct Frame {
}
};
using CallstackContainer = std::vector<Frame>;
using CallstackContainer = small_vector<Frame, 16>;
struct FrameId{
CallstackContainer* data;

View File

@ -162,7 +162,8 @@ public:
const T& top() const { return vec.back(); }
T popx(){ T t = std::move(vec.back()); vec.pop_back(); return t; }
void reserve(int n){ vec.reserve(n); }
Container& data() { return vec; }
Container& container() { return vec; }
const Container& container() const { return vec; }
};
template <typename T, typename Container=std::vector<T>>
@ -229,8 +230,8 @@ namespace pkpy
pointer data() { return m_begin; }
const_pointer data() const { return m_begin; }
reference operator[](size_type index) { return data()[index]; }
const_reference operator[](size_type index) const { return data()[index]; }
reference operator[](size_type index) { return m_begin[index]; }
const_reference operator[](size_type index) const { return m_begin[index]; }
iterator begin() { return m_begin; }
const_iterator begin() const { return m_begin; }
iterator end() { return m_end; }

View File

@ -1011,7 +1011,7 @@ __EAT_DOTS_END:
}
ctx()->emit_(OP_BEGIN_CLASS, namei, BC_KEEPLINE);
for(auto& c: this->contexts.data()){
for(auto& c: this->contexts.container()){
if(c.is_compiling_class){
SyntaxError("nested class is not allowed");
}

View File

@ -69,7 +69,6 @@ namespace pkpy{
VM::VM(bool enable_os) : heap(this), enable_os(enable_os) {
this->vm = this;
this->_c.error = nullptr;
this->callstack.reserve(8);
_stdout = [](const char* buf, int size) { std::cout.write(buf, size); };
_stderr = [](const char* buf, int size) { std::cerr.write(buf, size); };
_main = nullptr;
@ -124,7 +123,7 @@ namespace pkpy{
#if PK_DEBUG_EXTRA_CHECK
if(callstack.empty()) PK_FATAL_ERROR();
#endif
return FrameId(&callstack.data(), callstack.size()-1);
return FrameId(&callstack.container(), callstack.size()-1);
}
void VM::_pop_frame(){
@ -1262,7 +1261,7 @@ void VM::_raise(bool re_raise){
void ManagedHeap::mark() {
for(PyObject* obj: _no_gc) PK_OBJ_MARK(obj);
for(auto& frame : vm->callstack.data()) frame._gc_mark();
for(auto& frame : vm->callstack.container()) frame._gc_mark();
for(PyObject* obj: vm->s_data) PK_OBJ_MARK(obj);
for(auto [_, co]: vm->_cached_codes) co->_gc_mark();
if(vm->_last_exception) PK_OBJ_MARK(vm->_last_exception);