builtin_scope.py 825 B

1234567891011121314151617181920212223242526272829
  1. from sccd.action_lang.static.expression import *
  2. from sccd.util.debug import *
  3. # Builtin "global" functions in statechart language
  4. BuiltIn = Scope("builtin", None)
  5. # The way we add our builtin functions is a bit hackish because they are implemented
  6. # "natively" in Python, rather than in action language code.
  7. BuiltIn.declare("INSTATE", SCCDFunction([SCCDArray(SCCDString)], SCCDBool), const=True)
  8. def load_builtins(memory: MemoryInterface, execution):
  9. import math
  10. import termcolor
  11. memory.push_frame(BuiltIn)
  12. # Wrapper functions of the signature expected by the action language:
  13. def in_state(memory: MemoryInterface, state_list: List[str]) -> bool:
  14. return execution.in_state(state_list)
  15. # Manually write wrapper functions to memory:
  16. frame = memory.current_frame()
  17. frame.storage[0] = in_state