in_state.py 676 B

1234567891011121314151617181920212223
  1. from dataclasses import *
  2. from sccd.action_lang.static.expression import *
  3. from sccd.statechart.static.state_ref import StateRef
  4. @dataclass
  5. class InStateMacroExpansion(Expression):
  6. ref: StateRef
  7. offset: Optional[int] = None
  8. def init_expr(self, scope: Scope) -> SCCDType:
  9. self.offset, _ = scope.get_rvalue("@conf")
  10. return SCCDBool
  11. def get_type(self) -> SCCDType:
  12. return SCCDBool
  13. def eval(self, memory: MemoryInterface):
  14. state_configuration = memory.load(self.offset)
  15. return bool(self.ref.target.state_id_bitmap & state_configuration)
  16. def render(self):
  17. return "@in(" + self.ref.target.full_name + ')'