Best Python code snippet using slash
VMCodeWriter.py
Source:VMCodeWriter.py
...42 self._write_function(arg1, arg2)43 if command_name == VMCmd.C_CALL:44 self._write_call(arg1, arg2)45 if command_name == VMCmd.C_RETURN:46 self._write_return()47 def _get_label_counter(self) -> int:48 current_counter: int = self._label_counter49 self._label_counter += 150 return current_counter51 def _write_init(self) -> None:52 """53 Writes assembly code that affects the VM initialization, also called bootstrap code.54 This code will be placed at the beginning of the output file.55 """56 label_num: int = self._get_label_counter()57 translated_command: str = self._command_translation_provider.get_command_translation(VMCmd.C_INIT)58 translated_command += self._command_translation_provider.get_command_translation(VMCmd.C_CALL) \59 .format('Sys.init', label_num, 0, 'Sys.init', 'Sys.init', label_num)60 self.result += translated_command61 def _write_arithmetic(self, command_name: str) -> None:62 label_num: int = self._get_label_counter()63 translated_command = self._command_translation_provider.get_command_translation(command_name)64 if command_name in [VMCmd.C_EQ, VMCmd.C_GT, VMCmd.C_LT]:65 translated_command = translated_command.format(label_num, label_num, label_num, label_num)66 self.result += translated_command67 def _write_push_pop(self, command_name: str, segment: str, i: str) -> None:68 translated_command = self._command_translation_provider.get_command_translation(command_name, segment)69 if segment == VMSegment.S_CONSTANT:70 translated_command = translated_command.format(i)71 if segment in [VMSegment.S_LOCAL, VMSegment.S_ARGUMENT, VMSegment.S_THIS, VMSegment.S_THAT]:72 translated_command = translated_command.format(i, SEGMENT_TRANSLATION.get(segment))73 if segment == VMSegment.S_STATIC:74 translated_command = translated_command.format(self._vm_file_name_without_dir, i)75 if segment == VMSegment.S_TEMP:76 translated_command = translated_command.format(TEMP_LOCATION_IN_RAM, i)77 if segment == VMSegment.S_POINTER:78 new_segment = VMSegment.S_THIS if int(i) == 0 else VMSegment.S_THAT79 translated_command = translated_command.format(SEGMENT_TRANSLATION.get(new_segment))80 self.result += translated_command81 def _write_label(self, label: str) -> None:82 translated_command = self._command_translation_provider.get_command_translation(VMCmd.C_LABEL)\83 .format(str(self._current_function_scope), label)84 self.result += translated_command85 def _write_goto(self, label: str) -> None:86 translated_command = self._command_translation_provider.get_command_translation(VMCmd.C_GOTO)\87 .format(str(self._current_function_scope), label)88 self.result += translated_command89 def _write_if(self, label: str):90 translated_command = self._command_translation_provider.get_command_translation(VMCmd.C_IF)\91 .format(str(self._current_function_scope), label)92 self.result += translated_command93 def _write_call(self, function_name: str, n_args: str) -> None:94 label_num: int = self._get_label_counter()95 translated_command = self._command_translation_provider.get_command_translation(VMCmd.C_CALL)\96 .format(function_name, label_num, n_args, function_name, function_name, label_num)97 self.result += translated_command98 def _write_return(self) -> None:99 translated_command = self._command_translation_provider.get_command_translation(VMCmd.C_RETURN)100 self.result += translated_command101 def _write_function(self, function_name: str, n_locals: str) -> None:102 translated_command = self._command_translation_provider.get_command_translation(VMCmd.C_FUNCTION)\103 .format(function_name, n_locals, function_name, function_name, function_name, function_name)104 self._current_function_scope = function_name...
function.py
Source:function.py
...59 self._write_deferred_events(code_formatter)60 self._write_prologue(code_formatter)61 yield62 self._write_epilogue(code_formatter)63 self._write_return(code_formatter)64 code_formatter.writeln()65 def _get_parameter_string(self):66 returned = ', '.join(self._get_argument_strings())67 if returned and self._additional_parameter_string:68 returned += ', '69 returned += self._additional_parameter_string70 return returned71 def _write_prologue(self, code_formatter):72 pass73 def _write_epilogue(self, code_formatter):74 pass75 def _write_immediate_events(self, code_formatter):76 for event in self._events:77 self._write_event(code_formatter, event)78 def _write_deferred_events(self, code_formatter):79 if not self.suite.debug_info:80 return81 for index, deferred in enumerate(self._deferred_events, 1):82 deferred_func_name = '_deferred{}'.format(index)83 adder = deferred['adder']84 if adder is None:85 code_formatter.writeln('@{[decorator]}'.format(deferred))86 code_formatter.writeln('def {}():'.format(deferred_func_name))87 with code_formatter.indented():88 code_formatter.writeln('__ut__.events.add({[event]!r})'.format(deferred))89 for line in deferred['extra_code']:90 code_formatter.writeln(line)91 if adder is not None:92 code_formatter.write(adder.format(deferred_func_name))93 code_formatter.writeln()94 def _write_return(self, code_formatter):95 pass96 def _write_decorators(self, code_formatter):97 for d in self._decorators:98 code_formatter.write('@')99 code_formatter.writeln(d)100 for p in self._parameters:101 p.write_decorator(code_formatter)102 def _write_parameter_values(self, code_formatter):103 if (not self.suite.debug_info) and (not self.suite.is_parallel):104 return105 for p in self._iter_notify_parameters():106 if self.suite.is_parallel:107 code_formatter.writeln("slash.context.result.data.setdefault('param_values', {{}})[{!r}] = {}".format(108 p.id, p.name))...
keyword.py
Source:keyword.py
...31 def write_content(self):32 op: SsbOperation = self.start_vertex['op']33 self.decompiler.source_map_add_opcode(op.offset)34 if op.op_code.name == OP_RETURN:35 self._write_return()36 elif op.op_code.name == OP_END:37 self._write_end()38 elif op.op_code.name == OP_HOLD:39 self._write_hold()40 else:41 raise ValueError(f"Unknown keyword opcode: {op}")42 exits = self.start_vertex.out_edges()43 if len(exits) == 1:44 next_vertex = exits[0].target_vertex45 elif len(exits) == 0:46 next_vertex = None47 else:48 raise ValueError(f"After a simple opcode there must be exactly 0 or 1 immediate opcode.")49 return next_vertex50 def _write_return(self):51 self.decompiler.write_return()52 def _write_end(self):53 self.decompiler.write_end()54 def _write_hold(self):...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!