comparison Bison-Flex/BasicCompiler-MemoryBase/vm.cpp @ 4:805d39d28230

add Compiler-stackbase
author nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
date Tue, 17 May 2011 08:00:38 +0900
parents
children
comparison
equal deleted inserted replaced
3:3cea2e8a0e4b 4:805d39d28230
1 //
2 // 仮想CPU
3 //
4 // switch-caseでの実装例
5 //
6 // (c)2007 Chihiro.SAKAMOTO HyperWorks
7 //
8 #include <exception>
9 #include "vm.h"
10
11 // 実行
12 int vm::vcpu::run()
13 {
14 command_ = data_.command_; // プログラム格納位置
15 command_size_ = data_.command_size_; // プログラムの大きさ
16
17 global_value.resize(data_.value_size_); // 外部変数テーブル確保
18 command_ptr_ = command_; // プログラムカウンター初期化
19
20 try {
21 while (*command_ptr_ != VM_HALT) { // Haltするまでループ
22 int op = *command_ptr_++;
23 switch (op) {
24 #define VM_SWITCHTABLE
25 #include "vm_code.h"
26 #undef VM_SWITCHTABLE
27 } ;
28 }
29 }
30 catch (const std::exception &e) {
31 std::cerr << "例外発生(" << e.what() << ")" << std::endl;
32 return -1;
33 }
34 return 0;
35 }