7#include <sysio/vm/allocator.hpp>
8#include <sysio/vm/constants.hpp>
9#include <sysio/vm/exceptions.hpp>
10#include <sysio/vm/stack_elem.hpp>
11#include <sysio/vm/types.hpp>
12#include <sysio/vm/vector.hpp>
14namespace sysio {
namespace vm {
17 template <
typename ElemT,
size_t ElemSz,
typename Allocator =
nullptr_t >
20 template <
typename Alloc=Allocator,
typename = std::enable_if_t<std::is_same_v<Alloc, std::
nullptr_t>,
int>>
24 template <
typename Alloc=Allocator,
typename = std::enable_if_t<!std::is_same_v<Alloc,
nullptr_t>,
int>>
26 : _store(alloc, ElemSz) {}
28 template <
typename Alloc=Allocator,
typename = std::enable_if_t<!std::is_same_v<Alloc,
nullptr_t>,
int>>
33 if constexpr (std::is_same_v<Allocator, nullptr_t>) {
34 if (_index >= _store.size())
35 _store.resize(_store.size()*2);
37 _store[_index++] = std::forward<ElemT>(e);
40 ElemT
pop() {
return _store[--_index]; }
43 SYS_VM_ASSERT(index <= _index, wasm_interpreter_exception,
"invalid stack index");
44 return (ElemT&)_store[index];
47 SYS_VM_ASSERT(index <= _index, wasm_interpreter_exception,
"invalid stack index");
53 _store[index] = _store[_index-1];
57 ElemT&
peek() {
return _store[_index - 1]; }
58 const ElemT&
peek()
const {
return _store[_index - 1]; }
59 ElemT&
peek(
size_t i) {
return _store[_index - 1 - i]; }
60 ElemT&
get_back(
size_t i) {
return _store[_index - 1 - i]; }
61 const ElemT&
get_back(
size_t i)
const {
return _store[_index - 1 - i]; }
62 void trim(
size_t amt) { _index -= amt; }
63 size_t size()
const {
return _index; }
64 size_t capacity()
const {
return _store.size(); }
69 base_data_store_t _store;
73 using operand_stack = stack<operand_stack_elem, constants::initial_stack_size>;
74 using call_stack = stack<activation_frame, constants::max_call_depth + 1, bounded_allocator>;
void set(uint32_t index, const ElemT &el)
ElemT & get_back(size_t i)
const ElemT & peek() const
const ElemT & get_back(size_t i) const
ElemT & get(uint32_t index) const
void compact(uint32_t index)
size_t current_index() const
stack(uint32_t n, Alloc &&alloc)
stack< activation_frame, constants::max_call_depth+1, bounded_allocator > call_stack
stack< operand_stack_elem, constants::initial_stack_size > operand_stack
std::vector< T > unmanaged_vector
#define SYS_VM_ASSERT(expr, exc_type, msg)