Mercurial > hg > Members > nobuyasu > myCompiler
comparison Bison-Flex/BasicCompiler-StackBase/UTF8/vm.h @ 2:fbe42292d479
upload test
author | nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 10 May 2011 06:43:55 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1:a3ea4c73696b | 2:fbe42292d479 |
---|---|
1 #ifndef __VM_H__ | |
2 #define __VM_H__ | |
3 | |
4 #include <vector> | |
5 #include "vm_value.h" | |
6 | |
7 #define VM_ENUMDEF | |
8 enum { | |
9 #include "vm_code.h" | |
10 VM_MAXCOMMAND, | |
11 } ; | |
12 #undef VM_ENUMDEF | |
13 | |
14 namespace vm { | |
15 | |
16 class data { | |
17 public: | |
18 data(): command_(0) | |
19 { | |
20 } | |
21 ~data() | |
22 { | |
23 delete[] command_; | |
24 } | |
25 | |
26 public: | |
27 unsigned char *command_; // コマンドテーブル | |
28 int command_size_; // コマンドサイズ | |
29 int value_size_; // グローバル変数サイズ | |
30 } ; | |
31 | |
32 class vcpu { | |
33 public: | |
34 const static int STACK_SIZE = 1000; | |
35 | |
36 public: | |
37 vcpu(data &mem) | |
38 : data_(mem) | |
39 { | |
40 } | |
41 ~vcpu() | |
42 { | |
43 } | |
44 | |
45 int run(); | |
46 | |
47 private: | |
48 #define VM_EXEC | |
49 #include "vm_code.h" | |
50 #undef VM_EXEC | |
51 | |
52 private: | |
53 int value() { int v = *(int *)command_ptr_; command_ptr_ += 4; return v; } | |
54 int addr() const { return (int)(command_ptr_ - command_); } | |
55 void jmp(int addr) { command_ptr_ = command_ + addr; } | |
56 void push(int v) { stack.push(v); } | |
57 void pop() { stack.pop(); } | |
58 const int top() const { return stack.top(); } | |
59 int &top() { return stack.top(); } | |
60 | |
61 private: | |
62 data &data_; | |
63 unsigned char *command_; | |
64 unsigned char *command_ptr_; | |
65 int command_size_; | |
66 bool active; | |
67 | |
68 vm::stack<int, STACK_SIZE> stack; | |
69 std::vector<int> global_value; | |
70 | |
71 static void (vcpu::*cmd_[])(); | |
72 } ; | |
73 | |
74 } | |
75 | |
76 #endif |