make ValueStack a template class

This commit is contained in:
blueloveTH 2023-05-01 19:59:28 +08:00
parent d93af53776
commit a7ee33c2e3

View File

@ -58,13 +58,13 @@ struct FastLocals{
} }
}; };
struct ValueStack { template<size_t MAX_SIZE>
static const size_t MAX_SIZE = 32768; struct ValueStackImpl {
// We allocate 512 more bytes to keep `_sp` valid when `is_overflow() == true`. // We allocate extra MAX_SIZE/128 places to keep `_sp` valid when `is_overflow() == true`.
PyObject* _begin[MAX_SIZE + 512]; PyObject* _begin[MAX_SIZE + MAX_SIZE/128];
PyObject** _sp; PyObject** _sp;
ValueStack(): _sp(_begin) {} ValueStackImpl(): _sp(_begin) {}
PyObject*& top(){ return _sp[-1]; } PyObject*& top(){ return _sp[-1]; }
PyObject* top() const { return _sp[-1]; } PyObject* top() const { return _sp[-1]; }
@ -92,12 +92,14 @@ struct ValueStack {
void clear() { _sp = _begin; } void clear() { _sp = _begin; }
bool is_overflow() const { return _sp >= _begin + MAX_SIZE; } bool is_overflow() const { return _sp >= _begin + MAX_SIZE; }
ValueStack(const ValueStack&) = delete; ValueStackImpl(const ValueStackImpl&) = delete;
ValueStack(ValueStack&&) = delete; ValueStackImpl(ValueStackImpl&&) = delete;
ValueStack& operator=(const ValueStack&) = delete; ValueStackImpl& operator=(const ValueStackImpl&) = delete;
ValueStack& operator=(ValueStack&&) = delete; ValueStackImpl& operator=(ValueStackImpl&&) = delete;
}; };
using ValueStack = ValueStackImpl<32768>;
struct Frame { struct Frame {
int _ip = -1; int _ip = -1;
int _next_ip = 0; int _next_ip = 0;