# -*- coding: utf-8 -*- from .processor_utils import get_scl_representation, format_variable_name,get_target_scl_name # TODO: Import necessary functions from processor_utils # Example: from .processor_utils import get_scl_representation, format_variable_name # Or: import processors.processor_utils as utils # TODO: Define constants if needed (e.g., SCL_SUFFIX) or import them SCL_SUFFIX = "_scl" # --- Function code starts --- def process_move(instruction, network_id, scl_map, access_map, data): instr_uid = instruction["instruction_uid"] instr_type = instruction["type"] if instr_type.endswith(SCL_SUFFIX) or "_error" in instr_type: return False en_input = instruction["inputs"].get("en") en_scl = ( get_scl_representation(en_input, network_id, scl_map, access_map) if en_input else "TRUE" ) in_info = instruction["inputs"].get("in") in_scl = get_scl_representation(in_info, network_id, scl_map, access_map) if en_scl is None or in_scl is None: return False # Intentar obtener el destino de 'out1' (o 'out' si es el estándar) target_scl = get_target_scl_name( instruction, "out1", network_id, default_to_temp=False ) if target_scl is None: target_scl = get_target_scl_name( instruction, "out", network_id, default_to_temp=False ) if target_scl is None: # Si no hay destino explícito, podríamos usar una temp si la lógica lo requiere, # pero MOVE generalmente necesita un destino claro. Marcar como advertencia/error. print( f"Advertencia/Error: MOVE {instr_uid} sin destino claro en 'out' o 'out1'. Se requiere destino explícito." ) # Decidir si generar error o simplemente no hacer nada. No hacer nada es más seguro. # instruction["scl"] = f"// ERROR: MOVE {instr_uid} sin destino" # instruction["type"] += "_error" # return True return False # No procesar si no hay destino claro # Formatear entrada si es variable in_scl_formatted = ( format_variable_name(in_scl) if in_info and in_info.get("type") == "variable" else in_scl ) scl_core = f"{target_scl} := {in_scl_formatted};" scl_final = ( f"IF {en_scl} THEN\n {scl_core}\nEND_IF;" if en_scl != "TRUE" else scl_core ) instruction["scl"] = scl_final instruction["type"] = instr_type + SCL_SUFFIX # Propagar el valor movido a través de scl_map si se usa 'out' o 'out1' como fuente map_key_out = (network_id, instr_uid, "out") # Asumir 'out' como estándar scl_map[map_key_out] = target_scl # El valor es lo que está en el destino map_key_out1 = (network_id, instr_uid, "out1") # Si existe out1 scl_map[map_key_out1] = target_scl map_key_eno = (network_id, instr_uid, "eno") scl_map[map_key_eno] = en_scl return True # EN x2_process.py # --- Function code ends --- # --- Processor Information Function --- def get_processor_info(): """Devuelve la información para la operación Move.""" return {'type_name': 'move', 'processor_func': process_move, 'priority': 3}