@@ -11,6 +11,7 @@ def __init__(self, compiled_yarn_f, names_csv_f, autostart=True) -> None:
1111 self .__construct_string_lookup_table ()
1212
1313 self .visits = {key : 0 for key in self ._compiled_yarn .nodes .keys ()}
14+ self .variables = {}
1415 self .current_node = None
1516 self ._command_handlers = {}
1617 self ._line_buffer = []
@@ -53,6 +54,11 @@ def debug_vm(self):
5354 self .debug_vm_instruction_stack ()
5455 print ("The current VM data stack is:" )
5556 print (self ._vm_data_stack )
57+ self .debug_variables ()
58+
59+ def debug_variables (self ):
60+ print ("The current variables stored are:" )
61+ print (self .variables )
5662
5763 def debug_vm_instruction_stack (self ):
5864 print (f"The current program counter is: { self ._program_counter } " )
@@ -138,6 +144,19 @@ def __add_option(self, instruction):
138144 def __show_options (self , _instruction ):
139145 self .paused = True
140146
147+ def __push_float (self , instruction ):
148+ self ._vm_data_stack .insert (0 , instruction .operands [0 ].float_value )
149+
150+ def __pop (self , _instruction ):
151+ self ._vm_data_stack .pop (0 )
152+
153+ def __push_variable (self , instruction ):
154+ self ._vm_data_stack .insert (
155+ 0 , self .variables [instruction .operands [0 ].string_value ])
156+
157+ def __store_variable (self , instruction ):
158+ self .variables [instruction .operands [0 ].string_value ] = self ._vm_data_stack [0 ]
159+
141160 def __stop (self , _instruction ):
142161 self .finished = True
143162
@@ -181,14 +200,14 @@ def noop(instruction):
181200 Instruction .OpCode .ADD_OPTION : self .__add_option ,
182201 Instruction .OpCode .SHOW_OPTIONS : self .__show_options ,
183202 Instruction .OpCode .PUSH_STRING : noop ,
184- Instruction .OpCode .PUSH_FLOAT : noop ,
203+ Instruction .OpCode .PUSH_FLOAT : self . __push_float ,
185204 Instruction .OpCode .PUSH_BOOL : noop ,
186205 Instruction .OpCode .PUSH_NULL : noop ,
187206 Instruction .OpCode .JUMP_IF_FALSE : noop ,
188- Instruction .OpCode .POP : noop ,
207+ Instruction .OpCode .POP : self . __pop ,
189208 Instruction .OpCode .CALL_FUNC : noop ,
190- Instruction .OpCode .PUSH_VARIABLE : noop ,
191- Instruction .OpCode .STORE_VARIABLE : noop ,
209+ Instruction .OpCode .PUSH_VARIABLE : self . __push_variable ,
210+ Instruction .OpCode .STORE_VARIABLE : self . __store_variable ,
192211 Instruction .OpCode .STOP : self .__stop ,
193212 Instruction .OpCode .RUN_NODE : self .__run_node ,
194213 }
0 commit comments