]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/example/x3/calc/calc7/vm.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / spirit / example / x3 / calc / calc7 / vm.hpp
1 /*=============================================================================
2 Copyright (c) 2001-2014 Joel de Guzman
3
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 =============================================================================*/
7 #if !defined(BOOST_SPIRIT_X3_CALC7_VM_HPP)
8 #define BOOST_SPIRIT_X3_CALC7_VM_HPP
9
10 #include <vector>
11
12 namespace client
13 {
14 ///////////////////////////////////////////////////////////////////////////
15 // The Virtual Machine
16 ///////////////////////////////////////////////////////////////////////////
17 enum byte_code
18 {
19 op_neg, // negate the top stack entry
20 op_add, // add top two stack entries
21 op_sub, // subtract top two stack entries
22 op_mul, // multiply top two stack entries
23 op_div, // divide top two stack entries
24 op_int, // push constant integer into the stack
25 };
26
27 class vmachine
28 {
29 public:
30
31 vmachine(unsigned stackSize = 4096)
32 : stack(stackSize)
33 , stack_ptr(stack.begin())
34 {
35 }
36
37 int top() const { return stack_ptr[-1]; };
38 void execute(std::vector<int> const& code);
39
40 private:
41
42 std::vector<int> stack;
43 std::vector<int>::iterator stack_ptr;
44 };
45
46 }
47
48 #endif