def update_var_value(path, value): import function_utils invoked_function = function_utils.get_currently_invoked_function() if not invoked_function.variable_stack.check_if_var_exists_by_path( path): error_factory.ErrorFactory.var_not_defined_error(path) else: var_value = invoked_function.variable_stack.get_var_by_path(path) var_value.value = value
def attach_variable(path, name, value, clazz): import function_utils invoked_function = function_utils.get_currently_invoked_function() variable_id = VariableId(path, name) variable_value = VariableHolder(clazz, value) if invoked_function.variable_stack.check_if_var_exists_by_path( path) or invoked_function.variable_stack.check_if_var_exists_by_name(name): error_factory.ErrorFactory.var_already_defined_error(name) else: invoked_function.variable_stack.create_var(variable_id, variable_value)
def let(directory): if directory.dirlen() != 2: error_factory.ErrorFactory.invalid_command_dir_number([2], directory.path, directory.dirlen(), "LET") var_directory = directory.navigate_to_nth_child(1) logger.debug(let.__name__ + f" VAR TYPES LET {directory.path}") var_link = parse_link(directory.navigate_to_nth_child(0)) import function_utils invoked_function = function_utils.get_currently_invoked_function() var_type = invoked_function.get_var(var_link).type new_value = parse_value(var_directory, var_type, types_len[var_type]) update_var_value(var_link, new_value)
def _function(directory): logger.debug(_function.__name__ + f" EXECUTING FUNC AT PATH {directory.path}") if directory.dirlen() != 2: # logical condition, list of commands error_factory.ErrorFactory.invalid_command_dir_number( [2], directory.path, directory.dirlen(), "EXEC FUNC") else: logger.debug(directory.children_paths) var_link = directory.navigate_to_nth_child(0).get_link_path() logger.debug(var_link) import function_utils invoked_function = function_utils.get_currently_invoked_function() fun_instance_template = invoked_function.variable_stack.get_var_by_path( var_link).value fun_instance = copy.deepcopy(fun_instance_template) logger.debug(directory.navigate_to_nth_child(1).path) args_list = parse_list_value([directory.navigate_to_nth_child(1)]) logger.info(_function.__name__ + " FUNCTION ARGS_LIST " + str(args_list)) if len(args_list) != fun_instance.get_arguments_len(): error_factory.ErrorFactory.invalid_arg_no_passed( len(args_list), fun_instance.get_arguments_len(), fun_instance.name) else: var_stack = VariableStack() for item in list(zip(fun_instance.args_no, args_list)): var_stack.create_var( VariableId(item[0], str(item[0])), VariableHolder(match_type(item[1]), item[1])) fun_instance.variable_stack = var_stack Function.function_stack.append(fun_instance) logger.debug(_function.__name__ + " FUNC BEFORE EXEC STACK" + str(fun_instance.variable_stack)) value_returning = fun_instance.perform_function_code() fun_instance.clear_var_stack() logger.debug(_function.__name__ + " FUNC AFTER EXEC STACK " + str(fun_instance.variable_stack)) Function.function_stack.pop() if value_returning: function_utils.set_last_returned_value(value_returning)
def parse_operation_argument(operation_arg_dir: Directory): # assuming none var type has size 3 (int 16, float 32, bool 1, char 8, string 2) is_link_val = operation_arg_dir.is_var_linked() if is_link_val: # is link import function_utils invoked_function: Function = function_utils.get_currently_invoked_function() arg_val = invoked_function.get_var(value_parsing.parse_link(operation_arg_dir)).value elif operation_arg_dir.dirlen() == 2 and operation_arg_dir.navigate_to_nth_child(0).dirlen() == 0 \ and operation_arg_dir.navigate_to_nth_child(1).dirlen() == 2: # function result import function_utils return function_utils.get_last_returned_value() elif operation_arg_dir.dirlen() != 3: # not link and not operation -> simple type _type = value_parsing.len_types[operation_arg_dir.dirlen()] arg_val = value_parsing.parse_generic_value(operation_arg_dir, _type, value_parsing.types_len[_type]) else: # arg is operation arg_val = operation_parsing(operation_arg_dir) return arg_val
def remove_var_from_scope(path): import function_utils invoked_function = function_utils.get_currently_invoked_function() del invoked_function.variable_stack[path]