annotate boost-spirit/Compiler-boost-spirit/vm.h @ 0:db40c85cad7a default tip

upload sample source
author nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
date Mon, 09 May 2011 03:11:59 +0900 (2011-05-08)
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #ifndef __VM_H__
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #define __VM_H__
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 #include <vector>
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 #include "vm_value.h"
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 #ifdef _MSC_VER
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 //
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 // VS2008�ł́A�Z�L���A���C�u�����֐��i*_s�j���g���悤�x�����o�܂��B
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 // �����ł́A��ʉ��igcc���̑Ή��j�̂��߁A�����C�u�������g�p���Ă���̂ŁA
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 // �x����}�~���Ă��܂��B
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 //
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 #pragma warning(disable: 4996)
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 #endif
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 #define VM_ENUMDEF
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 enum {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 #include "vm_code.h"
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 VM_MAXCOMMAND,
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 } ;
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 #undef VM_ENUMDEF
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 namespace vm {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 enum {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 SYS_PRINT,
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 SYS_TOSTR,
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 } ;
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 class data {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 public:
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 data(): command_(0), text_buffer_(0)
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 ~data()
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 delete[] command_;
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 delete[] text_buffer_;
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 public:
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 unsigned char *command_; // �R�}���h�e�[�u��
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 char *text_buffer_; // �e�L�X�g�f�[�^
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 int command_size_; // �R�}���h�T�C�Y
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 int text_size_; // �e�L�X�g�T�C�Y
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 int value_size_; // �O���[�o���ϐ��T�C�Y
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 int entry_point_; // �J�n�ʒu
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 } ;
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 // 0���Z��O
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 class devide_by_zero: public std::exception {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 public:
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 const char *what() const throw()
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 return "devide by zero";
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 } ;
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 // ���z�}�V��
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 class vcpu {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 public:
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 const static int STACK_SIZE = 1000;
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 const static int global_flag = 0x4000000;
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 const static int global_mask = 0x3ffffff;
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
66
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
67
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 public:
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 vcpu(data &mem)
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 : data_(mem)
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 ~vcpu()
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
76
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 int run();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
78
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 private:
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 // �萔Push
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 void PushConst(int val)
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 push(val);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
85
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 // �����萔Push
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 void PushString(int val)
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 push(std::string(text_buffer_ + val));
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
91
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 // �ϐ�Push
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 void PushValue(int val)
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 push(global_value[val]);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
97
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 // ���[�J���ϐ�Push
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 void PushLocal(int val)
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 push(stack[val + stack_base]);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
103
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 // �z�񂩂�Push
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 void PushArray(int val)
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 int index = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 push(global_value[val + index]);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
110
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 // ���[�J���̔z�񂩂�Push
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 void PushLocalArray(int val)
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 int index = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 push(stack[val + stack_base + index]);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
117
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 // ���[�J���ϐ�(�Q��)Push
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 void PushLocalRef(int val)
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 int addr = stack[val + stack_base].i_;
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 push(ref_to_value(addr));
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
124
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 // ���[�J���̔z��(�Q��)����Push
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 void PushLocalArrayRef(int val)
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 int addr = stack[val + stack_base].i_;
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 int index = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 push(ref_to_value(addr + index));
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
132
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 // �A�h���X��Push
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 void PushAddr(int val)
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 if ((val & global_flag) == 0) // local
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 val += + stack_base;
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
138 push(val);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
140
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 // �z��̃A�h���X��Push
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 void PushArrayAddr(int val)
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
143 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 if ((val & global_flag) == 0) // local
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 val += + stack_base;
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 int index = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 push(val + index);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
149
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 // �ϐ���Pop
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
151 void PopValue(int val)
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 global_value[val] = top(); pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
155
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
156 // ���[�J���ϐ���Pop
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 void PopLocal(int val)
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 stack[val + stack_base] = top(); pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
161
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
162 // �z��ϐ���Pop
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 void PopArray(int val)
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
165 int index = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 global_value[val + index] = top(); pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
168
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
169 // ���[�J���̔z��ϐ���Pop
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 void PopLocalArray(int val)
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
171 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
172 int index = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
173 stack[val + stack_base + index] = top(); pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
175
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 // ���[�J���ϐ�(�Q��)��Pop
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 void PopLocalRef(int val)
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
178 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
179 int addr = stack[val + stack_base].i_;
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
180 set_ref(addr, top()); pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
182
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 // ���[�J���̔z��ϐ�(�Q��)��Pop
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
184 void PopLocalArrayRef(int val)
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
186 int addr = stack[val + stack_base].i_;
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
187 int index = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
188 set_ref(addr + index, top()); pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
189 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
190
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
191 // ���[�J���ϐ����m��
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 void OpAllocStack(int val)
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
194 stack.resize(stack_base + val);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
196
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
197 // ��Pop�i�X�^�b�N�g�b�v���̂Ă�j
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
198 void OpPop()
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
199 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
200 pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
201 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
202
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 // �P���}�C�i�X
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 void OpNeg()
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
205 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
206 top().i_ = -top().i_;
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
207 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
208
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
209 // ==
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
210 void OpEq()
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
211 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
212 int rhs = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
213 int lhs = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
214 push(lhs == rhs);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
215 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
216
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
217 // !=
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
218 void OpNe()
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
219 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
220 int rhs = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
221 int lhs = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
222 push(lhs != rhs);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
223 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
224
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
225 // >
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
226 void OpGt()
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
227 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
228 int rhs = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
229 int lhs = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
230 push(lhs > rhs);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
231 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
232
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
233 // >=
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
234 void OpGe()
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
235 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
236 int rhs = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
237 int lhs = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
238 push(lhs >= rhs);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
239 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
240
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
241 // <
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
242 void OpLt()
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
243 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
244 int rhs = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
245 int lhs = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
246 push(lhs < rhs);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
247 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
248
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
249 // <=
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
250 void OpLe()
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
251 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
252 int rhs = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
253 int lhs = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
254 push(lhs <= rhs);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
255 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
256
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
257 // &&
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
258 void OpLogAnd()
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
259 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
260 int rhs = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
261 int lhs = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
262 push(lhs && rhs);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
263 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
264
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
265 // ||
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
266 void OpLogOr()
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
267 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
268 int rhs = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
269 int lhs = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
270 push(lhs || rhs);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
271 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
272
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
273 // &
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
274 void OpAnd()
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
275 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
276 int rhs = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
277 int lhs = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
278 push(lhs & rhs);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
279 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
280
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
281 // |
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
282 void OpOr()
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
283 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
284 int rhs = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
285 int lhs = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
286 push(lhs | rhs);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
287 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
288
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
289 // <<
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
290 void OpLeftShift()
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
291 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
292 int rhs = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
293 int lhs = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
294 push(lhs << rhs);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
295 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
296
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
297 // >>
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
298 void OpRightShift()
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
299 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
300 int rhs = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
301 int lhs = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
302 push(lhs >> rhs);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
303 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
304
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
305 // +
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
306 void OpAdd()
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
307 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
308 int rhs = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
309 int lhs = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
310 push(lhs + rhs);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
311 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
312
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
313 // -
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
314 void OpSub()
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
315 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
316 int rhs = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
317 int lhs = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
318 push(lhs - rhs);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
319 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
320
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
321 // *
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
322 void OpMul()
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
323 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
324 int rhs = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
325 int lhs = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
326 push(lhs * rhs);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
327 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
328
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
329 // /
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
330 void OpDiv()
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
331 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
332 int rhs = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
333 if (rhs == 0)
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
334 throw devide_by_zero();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
335 int lhs = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
336 push(lhs / rhs);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
337 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
338
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
339 // %
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
340 void OpMod()
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
341 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
342 int rhs = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
343 if (rhs == 0)
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
344 throw devide_by_zero();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
345 int lhs = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
346 push(lhs % rhs);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
347 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
348
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
349 // �������==
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
350 void OpStrEq()
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
351 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
352 const std::string &rhs = text(top()); pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
353 const std::string &lhs = text(top()); pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
354
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
355 push(lhs == rhs);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
356 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
357
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
358 // �������!=
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
359 void OpStrNe()
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
360 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
361 const std::string &rhs = text(top()); pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
362 const std::string &lhs = text(top()); pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
363
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
364 push(lhs != rhs);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
365 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
366
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
367 // �������>
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
368 void OpStrGt()
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
369 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
370 const std::string &rhs = text(top()); pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
371 const std::string &lhs = text(top()); pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
372
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
373 push(lhs > rhs);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
374 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
375
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
376 // �������>=
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
377 void OpStrGe()
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
378 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
379 const std::string &rhs = text(top()); pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
380 const std::string &lhs = text(top()); pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
381
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
382 push(lhs >= rhs);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
383 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
384
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
385 // �������<
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
386 void OpStrLt()
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
387 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
388 const std::string &rhs = text(top()); pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
389 const std::string &lhs = text(top()); pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
390
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
391 push(lhs < rhs);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
392 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
393
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
394 // �������<=
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
395 void OpStrLe()
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
396 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
397 const std::string &rhs = text(top()); pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
398 const std::string &lhs = text(top()); pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
399
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
400 push(lhs <= rhs);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
401 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
402
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
403 // �������+
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
404 void OpStrAdd()
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
405 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
406 const std::string &rhs = text(top()); pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
407 const std::string &lhs = text(top()); pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
408
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
409 push(lhs + rhs);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
410 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
411
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
412 // �������W�����v
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
413 void OpJmp(int val)
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
414 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
415 jmp(val);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
416 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
417
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
418 // �^�̎��W�����v
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
419 void OpJmpC(int val)
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
420 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
421 int cond = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
422 if (cond)
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
423 jmp(val);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
424 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
425
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
426 // �U�̎��W�����v
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
427 void OpJmpNC(int val)
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
428 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
429 int cond = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
430 if (!cond)
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
431 jmp(val);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
432 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
433
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
434 // switch���p���ꔻ��
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
435 void OpTest(int val)
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
436 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
437 int value = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
438 if (value == top().i_) {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
439 pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
440 jmp(val);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
441 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
442 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
443
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
444 // �֐��R�[��
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
445 void OpCall(int val)
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
446 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
447 push(stack_base);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
448 push(addr()); // ���^�[���A�h���X��Push
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
449 stack_base = stack.size(); // �X�^�b�N�x�[�X�X�V
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
450 jmp(val);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
451 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
452
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
453 // �����Ȃ����^�[��
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
454 void OpReturn()
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
455 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
456 stack.resize(stack_base); // ���[�J���ϐ��r��
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
457 int addr = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
458 stack_base = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
459 int arg_count = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
460 stack.pop(arg_count);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
461 jmp(addr);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
462 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
463
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
464 // �����t�����^�[��
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
465 void OpReturnV()
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
466 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
467 vm::value result = top(); pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
468 stack.resize(stack_base); // ���[�J���ϐ��r��
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
469 int addr = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
470 stack_base = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
471 int arg_count = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
472 stack.pop(arg_count);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
473 push(result);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
474 jmp(addr);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
475 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
476
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
477 // ���zCPU�v���O������~
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
478 void OpHalt()
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
479 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
480 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
481
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
482 // �V�X�e���R�[���i�g�ݍ��݊֐��j
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
483 void OpSysCall(int val)
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
484 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
485 pop(); // arg_count
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
486 switch (val) {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
487 case SYS_PRINT:
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
488 sys_print();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
489 break;
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
490
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
491 case SYS_TOSTR:
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
492 sys_tostr();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
493 break;
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
494 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
495 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
496
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
497 // �V�X�e���R�[���iprint�j
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
498 void sys_print()
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
499 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
500 std::cout << text(top());
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
501 pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
502 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
503
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
504 // �V�X�e���R�[��(���l�𕶎���ɕϊ�)
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
505 void sys_tostr()
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
506 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
507 int v = top().i_; pop();
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
508 char str[16];
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
509 sprintf(str, "%d", v);
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
510 push(std::string(str)); // �߂�l�̓X�^�b�N�ɓ����
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
511 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
512
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
513 private:
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
514 int value() { int v = *(int *)command_ptr_; command_ptr_ += 4; return v; }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
515 int addr() const { return (int)(command_ptr_ - command_); }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
516 void jmp(int addr) { command_ptr_ = command_ + addr; }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
517 void push(int v) { stack.push(vm::value(v)); }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
518 void push(const std::string &v) { stack.push(vm::value(v)); }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
519 void push(const vm::value &v) { stack.push(v); }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
520 void pop() { stack.pop(); }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
521 const vm::value &top() const { return stack.top(); }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
522 vm::value &top() { return stack.top(); }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
523 std::string text(const vm::value &v) { return v.s_->str_; }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
524 const vm::value &ref_to_value(int addr) const
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
525 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
526 if (addr & global_flag)
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
527 return global_value[addr & global_mask];
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
528 return stack[addr];
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
529 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
530 void set_ref(int addr, const vm::value &v)
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
531 {
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
532 if (addr & global_flag)
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
533 global_value[addr & global_mask] = v;
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
534 else
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
535 stack[addr] = v;
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
536 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
537
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
538 private:
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
539 data &data_;
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
540 unsigned char *command_;
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
541 unsigned char *command_ptr_;
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
542 int command_size_;
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
543 char *text_buffer_;
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
544 int text_size_;
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
545
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
546 vm::stack<vm::value, STACK_SIZE> stack;
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
547 std::vector<vm::value> global_value;
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
548 int stack_base;
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
549 } ;
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
550
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
551 }
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
552
db40c85cad7a upload sample source
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
553 #endif