54 lines
2.2 KiB
Python
54 lines
2.2 KiB
Python
# processors/process_not.py
|
|
# -*- coding: utf-8 -*-
|
|
import sympy
|
|
import traceback
|
|
# Usar las nuevas utilidades
|
|
from .processor_utils import get_sympy_representation
|
|
from .symbol_manager import SymbolManager
|
|
|
|
SCL_SUFFIX = "_sympy_processed" # Nuevo sufijo
|
|
|
|
def process_not(instruction, network_id, sympy_map, symbol_manager: SymbolManager, data):
|
|
"""Genera la expresión SymPy para la inversión lógica NOT."""
|
|
instr_uid = instruction["instruction_uid"]
|
|
instr_type_original = instruction.get("type", "Not")
|
|
if instr_type_original.endswith(SCL_SUFFIX) or "_error" in instr_type_original:
|
|
return False
|
|
|
|
# Obtener entrada como expresión SymPy
|
|
in_info = instruction["inputs"].get("in")
|
|
sympy_expr_in = get_sympy_representation(in_info, network_id, sympy_map, symbol_manager)
|
|
|
|
# Verificar dependencias
|
|
if sympy_expr_in is None:
|
|
# print(f"DEBUG Not {instr_uid}: Dependency not ready")
|
|
return False
|
|
|
|
# Crear la expresión NOT de SymPy
|
|
try:
|
|
not_expr = sympy.Not(sympy_expr_in)
|
|
# ¿Simplificar aquí? NOT(NOT A) -> A; NOT(TRUE) -> FALSE, etc.
|
|
# simplify_logic podría hacer esto, pero puede ser costoso en cada paso.
|
|
# SymPy podría manejar simplificaciones básicas automáticamente.
|
|
# Opcional: not_expr = sympy.simplify_logic(not_expr)
|
|
except Exception as e:
|
|
print(f"Error creating SymPy Not for {instr_uid}: {e}")
|
|
instruction["scl"] = f"// ERROR creando expr SymPy NOT {instr_uid}: {e}"
|
|
instruction["type"] = instr_type_original + "_error"
|
|
return True
|
|
|
|
# Guardar resultado (Expresión SymPy) en el mapa para 'out'
|
|
map_key_out = (network_id, instr_uid, "out")
|
|
sympy_map[map_key_out] = not_expr
|
|
|
|
# Marcar como procesado, SCL principal es solo comentario
|
|
instruction["scl"] = f"// SymPy NOT: {not_expr}" # Comentario opcional
|
|
instruction["type"] = instr_type_original + SCL_SUFFIX
|
|
# NOT no tiene EN/ENO explícito en LAD, modifica el RLO ('out')
|
|
|
|
return True
|
|
|
|
# --- Processor Information Function ---
|
|
def get_processor_info():
|
|
"""Devuelve la información para la operación Not."""
|
|
return {'type_name': 'not', 'processor_func': process_not, 'priority': 1} |