Refactor 'port' demo to include starting point for assignment
This commit is contained in:
parent
72c78c664f
commit
86610139d2
7 changed files with 300 additions and 16 deletions
18
examples/semantics/operational/port/helpers.py
Normal file
18
examples/semantics/operational/port/helpers.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# Some helper functions
|
||||
|
||||
def get_num_ships(od, place):
|
||||
place_state = design_to_state(od, place)
|
||||
return od.get_slot_value(place_state, "numShips")
|
||||
|
||||
def design_to_state(od, design):
|
||||
incoming = od.get_incoming(design, "of")
|
||||
if len(incoming) == 1:
|
||||
# not all design-objects have a state
|
||||
return od.get_source(incoming[0])
|
||||
|
||||
def state_to_design(od, state):
|
||||
return od.get_target(od.get_outgoing(state, "of")[0])
|
||||
|
||||
def get_time(od):
|
||||
_, clock = od.get_all_instances("Clock")[0]
|
||||
return clock, od.get_slot_value(clock, "time")
|
||||
Loading…
Add table
Add a link
Reference in a new issue