@@ -50,6 +50,11 @@ class Stack
5050 }
5151};
5252
53+
54+ // / Contains current frame's locals (including arguments) and operand stack.
55+ // / The storage space for locals and operand stack together is allocated as a
56+ // / continuous memory. Elements occupy the storage space in the order:
57+ // / arguments, local variables, operand stack.
5358class OperandStack
5459{
5560 // / The size of the pre-allocated internal storage: 128 bytes.
@@ -75,13 +80,19 @@ class OperandStack
7580public:
7681 // / Default constructor.
7782 // /
78- // / Based on @p max_stack_height decides if to use small pre-allocated storage or allocate
79- // / large storage.
80- // / Sets the top item pointer to below the stack bottom.
81- OperandStack (span<const Value> args, size_t num_locals, size_t max_stack_height)
83+ // / Based on required storage space decides if to use small pre-allocated
84+ // / storage or allocate large storage.
85+ // / Sets the top stack operand pointer to below the operand stack bottom.
86+ // / @param args Function arguments. Values are copied at the beginning of the
87+ // / storage space.
88+ // / @param num_local_variables The number of the function local variables (excluding
89+ // / arguments). This number of values is zeroed in the storage space
90+ // / after the arguments.
91+ // / @param max_stack_height The maximum operand stack height in the function.
92+ OperandStack (span<const Value> args, size_t num_local_variables, size_t max_stack_height)
8293 {
8394 const auto num_args = args.size ();
84- const auto storage_size_required = num_args + num_locals + max_stack_height;
95+ const auto storage_size_required = num_args + num_local_variables + max_stack_height;
8596
8697 Value* storage;
8798 if (storage_size_required <= small_storage_size)
@@ -95,11 +106,11 @@ class OperandStack
95106 }
96107
97108 m_locals = storage;
98- m_bottom = m_locals + num_args + num_locals ;
109+ m_bottom = m_locals + num_args + num_local_variables ;
99110 m_top = m_bottom - 1 ;
100111
101112 std::copy (std::begin (args), std::end (args), m_locals);
102- std::fill_n (m_locals + num_args, num_locals , 0 );
113+ std::fill_n (m_locals + num_args, num_local_variables , 0 );
103114 }
104115
105116 OperandStack (const OperandStack&) = delete ;
0 commit comments