Quellcode durchsuchen

Moved some more files.

Joeri Exelmans vor 5 Jahren
Ursprung
Commit
f796f29b60

src/sccd/execution/exceptions.py → src/sccd/action_lang/dynamic/exceptions.py


+ 1 - 1
src/sccd/action_lang/dynamic/memory.py

@@ -3,7 +3,7 @@ from dataclasses import *
 from sccd.util.bitmap import *
 from sccd.util.debug import *
 from sccd.action_lang.static.scope import *
-from sccd.execution.exceptions import *
+from sccd.action_lang.dynamic.exceptions import *
 from sccd.action_lang.static.expression import *
 
 @dataclass(frozen=True)

+ 5 - 4
src/sccd/controller/controller.py

@@ -14,6 +14,8 @@ class InputEvent:
   params: List[Any]
   time_offset: Duration
 
+Timestamp = int
+
 # The Controller class is a primitive that can be used to build backends of any kind:
 # Threads, integration with existing event loop, game loop, test framework, ...
 # The Controller class itself is NOT thread-safe.
@@ -27,7 +29,7 @@ class Controller:
     def __init__(self, model: AbstractModel):
         self.model = model
         self.object_manager = ObjectManager(model)
-        self.queue: EventQueue[EventQueueEntry] = EventQueue()
+        self.queue: EventQueue[Timestamp, EventQueueEntry] = EventQueue()
 
         self.simulated_time = 0 # integer
         self.initialized = False
@@ -102,11 +104,10 @@ class Controller:
             # initialize the object manager, in turn initializing our default class
             # and adding the generated events to the queue
             for i in self.object_manager.instances:
-                events = i.initialize(self.simulated_time)
+                events = i.initialize()
                 process_big_step_output(events)
             print_debug("initialized. time is now %s" % str(self.get_simulated_duration()))
 
-
         # Actual "event loop"
         for timestamp, entry in self.queue.due(now):
             if timestamp != self.simulated_time:
@@ -115,7 +116,7 @@ class Controller:
                 print_debug("\ntime is now %s" % str(self.get_simulated_duration()))
             # run all instances for whom there are events
             for instance in entry.targets:
-                output = instance.big_step(timestamp, [entry.event])
+                output = instance.big_step([entry.event])
                 # print_debug("completed big step (time = %s)" % str(self.model.globals.delta * self.simulated_time))
                 process_big_step_output(output)
 

+ 3 - 3
src/sccd/controller/event_queue.py

@@ -3,11 +3,11 @@ from abc import ABC
 from typing import List, Set, Tuple, Deque, Any, TypeVar, Generic, Generator, Optional
 from collections import deque
 
-Timestamp = int
+Timestamp = TypeVar('Timestamp')
 
 Item = TypeVar('Item')
 
-class EventQueue(Generic[Item]):
+class EventQueue(Generic[Timestamp, Item]):
     def __init__(self):
         self.queue: List[Tuple[Timestamp, int, Item]] = []
         self.counters = {} # mapping from timestamp to number of items at timestamp
@@ -61,7 +61,7 @@ class EventQueue(Generic[Item]):
             yield self.pop()
 
 # Alternative implementation: A heapq with unique entries for each timestamp, and a deque with items for each timestamp.
-class EventQueueDeque(Generic[Item]):
+class EventQueueDeque(Generic[Timestamp, Item]):
 
     def __init__(self):
         self.queue: List[Tuple[Timestamp, Deque[Item]]] = []

+ 2 - 2
src/sccd/controller/object_manager.py

@@ -25,11 +25,11 @@ class ObjectManager(Instance):
         self.instances.append(i)
         return i
 
-    def initialize(self, now: Timestamp) -> List[OutputEvent]:
+    def initialize(self) -> List[OutputEvent]:
         return []
 
     # Implementation of super class: Instance
-    def big_step(self, timestamp: Timestamp, input_events: List[Event]) -> List[OutputEvent]:
+    def big_step(self, input_events: List[Event]) -> List[OutputEvent]:
         output = []
         for e in input_events:
             try:

+ 0 - 14
src/sccd/execution/instance.py

@@ -1,14 +0,0 @@
-from abc import *
-from typing import *
-from sccd.statechart.dynamic.event import *
-from sccd.execution.timestamp import *
-
-# Interface for all instances and also the Object Manager
-class Instance(ABC):
-    @abstractmethod
-    def initialize(self, timestamp: Timestamp) -> List[OutputEvent]:
-        pass
-
-    @abstractmethod
-    def big_step(self, timestamp: Timestamp, input_events: List[Event]) -> List[OutputEvent]:
-        pass

+ 0 - 2
src/sccd/execution/timestamp.py

@@ -1,2 +0,0 @@
-
-Timestamp = int

+ 1 - 1
src/sccd/statechart/dynamic/round.py

@@ -3,7 +3,7 @@ from sccd.statechart.dynamic.event import *
 from sccd.util.bitmap import *
 from sccd.statechart.static.tree import *
 from sccd.util.debug import *
-from sccd.execution.exceptions import *
+from sccd.action_lang.dynamic.exceptions import *
 
 class CandidatesGenerator:
     def __init__(self, reverse: bool):

+ 1 - 1
src/sccd/statechart/dynamic/statechart_execution.py

@@ -4,7 +4,7 @@ from sccd.statechart.dynamic.event import *
 from sccd.util.debug import print_debug
 from sccd.util.bitmap import *
 from sccd.action_lang.static.scope import *
-from sccd.execution.exceptions import *
+from sccd.action_lang.dynamic.exceptions import *
 
 # Set of current states etc.
 class StatechartExecution:

+ 12 - 3
src/sccd/statechart/dynamic/statechart_instance.py

@@ -1,7 +1,6 @@
 import termcolor
 import functools
 from typing import List, Tuple, Iterable
-from sccd.execution.instance import *
 from sccd.statechart.dynamic.builtin_scope import *
 from sccd.statechart.static.statechart import *
 from sccd.util.debug import print_debug
@@ -10,6 +9,16 @@ from sccd.statechart.dynamic.round import *
 from sccd.statechart.dynamic.statechart_execution import *
 from sccd.action_lang.dynamic.memory import *
 
+# Interface for all instances and also the Object Manager
+class Instance(ABC):
+    @abstractmethod
+    def initialize(self) -> List[OutputEvent]:
+        pass
+
+    @abstractmethod
+    def big_step(self, input_events: List[Event]) -> List[OutputEvent]:
+        pass
+
 # Hardcoded limit on number of sub-rounds of combo and big step to detect never-ending superrounds.
 # TODO: make this configurable
 LIMIT = 100
@@ -126,12 +135,12 @@ class StatechartInstance(Instance):
 
 
     # enter default states, generating a set of output events
-    def initialize(self, now: Timestamp) -> List[OutputEvent]:
+    def initialize(self) -> List[OutputEvent]:
         self.execution.initialize()
         return self.execution.collect_output()
 
     # perform a big step. generating a set of output events
-    def big_step(self, now: Timestamp, input_events: List[Event]) -> List[OutputEvent]:
+    def big_step(self, input_events: List[Event]) -> List[OutputEvent]:
         # print_debug('attempting big step, input_events='+str(input_events))
         self.set_input(input_events)
         self._big_step.run_and_cycle_events()

src/sccd/execution/__init__.py → src/sccd/statechart/parser/statechart.g