mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-22 12:30:19 +00:00
some more replace
This commit is contained in:
parent
3e74e1ee16
commit
415c1f6b38
@ -70,10 +70,11 @@ struct CodeObject {
|
|||||||
std::vector<Bytecode> codes;
|
std::vector<Bytecode> codes;
|
||||||
std::vector<int> iblocks; // block index for each bytecode
|
std::vector<int> iblocks; // block index for each bytecode
|
||||||
std::vector<LineInfo> lines;
|
std::vector<LineInfo> lines;
|
||||||
List consts;
|
|
||||||
pod_vector<StrName> varnames; // local variables
|
small_vector<PyObject*, 6> consts;
|
||||||
|
small_vector<StrName, 16> varnames; // local variables
|
||||||
NameDictInt varnames_inv;
|
NameDictInt varnames_inv;
|
||||||
std::vector<CodeBlock> blocks = { CodeBlock(CodeBlockType::NO_BLOCK, -1, 0, 0) };
|
small_vector<CodeBlock, 4> blocks;
|
||||||
NameDictInt labels;
|
NameDictInt labels;
|
||||||
std::vector<FuncDecl_> func_decls;
|
std::vector<FuncDecl_> func_decls;
|
||||||
|
|
||||||
@ -95,8 +96,8 @@ struct FuncDecl {
|
|||||||
PyObject* value; // default value
|
PyObject* value; // default value
|
||||||
};
|
};
|
||||||
CodeObject_ code; // code object of this function
|
CodeObject_ code; // code object of this function
|
||||||
pod_vector<int> args; // indices in co->varnames
|
small_vector<int, 4> args; // indices in co->varnames
|
||||||
pod_vector<KwArg> kwargs; // indices in co->varnames
|
small_vector<KwArg, 4> kwargs; // indices in co->varnames
|
||||||
int starred_arg = -1; // index in co->varnames, -1 if no *arg
|
int starred_arg = -1; // index in co->varnames, -1 if no *arg
|
||||||
int starred_kwarg = -1; // index in co->varnames, -1 if no **kwarg
|
int starred_kwarg = -1; // index in co->varnames, -1 if no **kwarg
|
||||||
bool nested = false; // whether this function is nested
|
bool nested = false; // whether this function is nested
|
||||||
|
@ -126,10 +126,12 @@ struct Frame {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using CallstackContainer = small_vector<Frame, 8>;
|
||||||
|
|
||||||
struct FrameId{
|
struct FrameId{
|
||||||
std::vector<pkpy::Frame>* data;
|
CallstackContainer* data;
|
||||||
int index;
|
int index;
|
||||||
FrameId(std::vector<pkpy::Frame>* data, int index) : data(data), index(index) {}
|
FrameId(CallstackContainer* data, int index) : data(data), index(index) {}
|
||||||
Frame* operator->() const { return &data->operator[](index); }
|
Frame* operator->() const { return &data->operator[](index); }
|
||||||
Frame* get() const { return &data->operator[](index); }
|
Frame* get() const { return &data->operator[](index); }
|
||||||
};
|
};
|
||||||
|
@ -104,7 +104,7 @@ struct Lexer {
|
|||||||
const char* curr_char;
|
const char* curr_char;
|
||||||
int current_line = 1;
|
int current_line = 1;
|
||||||
std::vector<Token> nexts;
|
std::vector<Token> nexts;
|
||||||
stack_no_copy<int, pod_vector<int>> indents;
|
stack_no_copy<int, small_vector<int, 6>> indents;
|
||||||
int brackets_level = 0;
|
int brackets_level = 0;
|
||||||
bool used = false;
|
bool used = false;
|
||||||
|
|
||||||
|
@ -259,6 +259,8 @@ namespace pkpy {
|
|||||||
|
|
||||||
reverse_iterator rbegin() { return reverse_iterator(end()); }
|
reverse_iterator rbegin() { return reverse_iterator(end()); }
|
||||||
|
|
||||||
|
void clear() { while (m_size > 0) pop_back(); }
|
||||||
|
|
||||||
const_reverse_iterator rbegin() const {
|
const_reverse_iterator rbegin() const {
|
||||||
return const_reverse_iterator(end());
|
return const_reverse_iterator(end());
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,7 @@ class VM {
|
|||||||
public:
|
public:
|
||||||
ManagedHeap heap;
|
ManagedHeap heap;
|
||||||
ValueStack s_data;
|
ValueStack s_data;
|
||||||
stack< Frame > callstack;
|
stack_no_copy<Frame, CallstackContainer> callstack;
|
||||||
std::vector<PyTypeInfo> _all_types;
|
std::vector<PyTypeInfo> _all_types;
|
||||||
|
|
||||||
NameDict _modules; // loaded modules
|
NameDict _modules; // loaded modules
|
||||||
|
@ -3,7 +3,9 @@
|
|||||||
namespace pkpy{
|
namespace pkpy{
|
||||||
|
|
||||||
CodeObject::CodeObject(std::shared_ptr<SourceData> src, const Str& name):
|
CodeObject::CodeObject(std::shared_ptr<SourceData> src, const Str& name):
|
||||||
src(src), name(name), start_line(-1), end_line(-1) {}
|
src(src), name(name), start_line(-1), end_line(-1) {
|
||||||
|
blocks.push_back(CodeBlock(CodeBlockType::NO_BLOCK, -1, 0, 0));
|
||||||
|
}
|
||||||
|
|
||||||
void CodeObject::_gc_mark() const {
|
void CodeObject::_gc_mark() const {
|
||||||
for(PyObject* v : consts) PK_OBJ_MARK(v);
|
for(PyObject* v : consts) PK_OBJ_MARK(v);
|
||||||
|
@ -75,7 +75,6 @@ namespace pkpy{
|
|||||||
_stderr = [](const char* buf, int size) {
|
_stderr = [](const char* buf, int size) {
|
||||||
std::cerr.write(buf, size);
|
std::cerr.write(buf, size);
|
||||||
};
|
};
|
||||||
callstack.reserve(8);
|
|
||||||
_main = nullptr;
|
_main = nullptr;
|
||||||
_last_exception = nullptr;
|
_last_exception = nullptr;
|
||||||
_import_handler = [](const char* name_p, int name_size, int* out_size) -> unsigned char*{
|
_import_handler = [](const char* name_p, int name_size, int* out_size) -> unsigned char*{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user