MCPcopy Create free account
hub / github.com/boostorg/spirit / execute

Method execute

example/qi/compiler_tutorial/calc6.cpp:143–181  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

141 };
142
143 void vmachine::execute(std::vector<int> const& code)
144 {
145 std::vector<int>::const_iterator pc = code.begin();
146 stack_ptr = stack.begin();
147
148 while (pc != code.end())
149 {
150 switch (*pc++)
151 {
152 case op_neg:
153 stack_ptr[-1] = -stack_ptr[-1];
154 break;
155
156 case op_add:
157 --stack_ptr;
158 stack_ptr[-1] += stack_ptr[0];
159 break;
160
161 case op_sub:
162 --stack_ptr;
163 stack_ptr[-1] -= stack_ptr[0];
164 break;
165
166 case op_mul:
167 --stack_ptr;
168 stack_ptr[-1] *= stack_ptr[0];
169 break;
170
171 case op_div:
172 --stack_ptr;
173 stack_ptr[-1] /= stack_ptr[0];
174 break;
175
176 case op_int:
177 *stack_ptr++ = *pc++;
178 break;
179 }
180 }
181 }
182
183 ///////////////////////////////////////////////////////////////////////////
184 // The Compiler

Callers 1

mainFunction · 0.45

Calls 2

beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected