@@ -20,13 +20,18 @@ limitations under the License.
2020#include < cstring>
2121#include " sym_map.h"
2222#include " vmop.h"
23+ #include " vm_type.h"
24+
25+ typedef long VM_INSTRUCTION ;
26+ extern VM_INSTRUCTION * pc;
2327
2428std::stack<tensor_array::value::Tensor> tensor_stack;
25- std::stack<std::string> ptr_stack;
29+ std::stack<std::string> var_stack;
30+ std::stack<std::pair<long , scope>> call_stack;
2631tensor_array::value::Tensor ag;
2732void * aptr;
2833long any_value;
29- long any_type;
34+ VM_TYPE any_type;
3035
3136void new_int ()
3237{
@@ -51,10 +56,21 @@ void new_string()
5156
5257void op_imm ()
5358{
54- if (any_type == 0 ) new_string ();
55- else if (any_type == 1 ) new_int ();
56- else if (any_type == 2 ) new_ptr ();
57- else ;
59+ switch (any_type)
60+ {
61+ case TYPE_INT :
62+ /* code */
63+ new_int ();
64+ break ;
65+ case TYPE_STRING :
66+ new_string ();
67+ break ;
68+ case TYPE_PTR :
69+ new_ptr ();
70+ break ;
71+ default :
72+ break ;
73+ }
5874}
5975
6076void op_add ()
@@ -212,6 +228,19 @@ void op_shr()
212228 // ag = ag >> bg;
213229}
214230
231+ void op_call ()
232+ {
233+ VM_INSTRUCTION pc1 = (VM_INSTRUCTION )*pc++;
234+ call_stack.push ({std::move (pc), std::move (sym_map)});
235+ pc = pc1;
236+ }
237+
238+ void op_ret ()
239+ {
240+ [pc, sym_map] = std::move (call_stack.top ());
241+ call_stack.pop ();
242+ }
243+
215244void op_open ()
216245{
217246 // Implementation for opening a file or resource
@@ -260,7 +289,7 @@ void op_push()
260289
261290void op_ptr_push ()
262291{
263- ptr_stack .push (reinterpret_cast <char *>(aptr));
292+ var_stack .push (reinterpret_cast <char *>(aptr));
264293 std::free (aptr);
265294}
266295
@@ -274,13 +303,13 @@ void op_get()
274303
275304void op_set ()
276305{
277- if (!ptr_stack .empty ())
306+ if (!var_stack .empty ())
278307 {
279- std::string& var_name = ptr_stack .top ();
308+ std::string& var_name = var_stack .top ();
280309 sym_data& temp = sym_map[var_name];
281310 delete temp.data ; // Set the top of the stack to ag
282311 temp.data = new tensor_array::value::Tensor (ag);
283- ptr_stack .pop ();
312+ var_stack .pop ();
284313 }
285314 else
286315 {
0 commit comments