Browse Source

Rename some things

Joeri Exelmans 5 years ago
parent
commit
4311d638af

+ 5 - 5
src/sccd/compiler/generic_generator.py

@@ -135,9 +135,9 @@ class GenericGenerator(Visitor):
             self.writer.addActualParameter("behind_schedule_callback")
         self.writer.endSuperClassConstructorCall()
         for i in class_diagram.inports:
-            self.writer.add(GLC.FunctionCall(GLC.SelfProperty("addInputPort"), [GLC.String(i)]))
+            self.writer.add(GLC.FunctionCall(GLC.SelfProperty("createInputPort"), [GLC.String(i)]))
         for o in class_diagram.outports:
-            self.writer.add(GLC.FunctionCall(GLC.SelfProperty("addOutputPort"), [GLC.String(o)]))
+            self.writer.add(GLC.FunctionCall(GLC.SelfProperty("createOutputPort"), [GLC.String(o)]))
         actual_parameters = [p.getIdent() for p in class_diagram.default_class.constructors[0].parameters]
         self.writer.add(GLC.FunctionCall(GLC.Property(GLC.SelfProperty("object_manager"), "createInstance"), [GLC.String(class_diagram.default_class.name), GLC.ArrayExpression(actual_parameters)]))
         self.writer.endMethodBody()
@@ -291,12 +291,12 @@ class GenericGenerator(Visitor):
             for p in constructor.parent_class.inports:
                 self.writer.addAssignment(
                     GLC.MapIndexedExpression(GLC.SelfProperty("inports"), GLC.String(p)),
-                    GLC.FunctionCall(GLC.Property("controller", "addInputPort"), [GLC.String(p), GLC.SelfExpression()]))
+                    GLC.FunctionCall(GLC.Property("controller", "createInputPort"), [GLC.String(p), GLC.SelfExpression()]))
 
             for p in constructor.parent_class.outports:
                 self.writer.addAssignment(
                     GLC.MapIndexedExpression(GLC.SelfProperty("outports"), GLC.String(p)),
-                    GLC.FunctionCall(GLC.Property("controller", "addOutputPort"), [GLC.String(p), GLC.SelfExpression()]))
+                    GLC.FunctionCall(GLC.Property("controller", "createOutputPort"), [GLC.String(p), GLC.SelfExpression()]))
 
             self.writer.addVSpace()
 
@@ -847,7 +847,7 @@ class GenericGenerator(Visitor):
                             new_event_expr])])]))
         elif raise_event.isLocal():
             self.writer.add(GLC.FunctionCall(
-                GLC.SelfProperty("raiseInternalEvent"),
+                GLC.SelfProperty("_raiseInternalEvent"),
                 [new_event_expr]))
         elif raise_event.isOutput():
             self.writer.add(GLC.FunctionCall(

+ 7 - 4
src/sccd/runtime/controller.py

@@ -45,18 +45,19 @@ class OutputListener(object):
             return None
 
 
+# Data class
 class InputPortEntry(object):
     def __init__(self, virtual_name, instance):
         self.virtual_name = virtual_name
         self.instance = instance
 
+# Data class
 class OutputPortEntry(object):
     def __init__(self, port_name, virtual_name, instance):
         self.port_name = port_name
         self.virtual_name = virtual_name
         self.instance = instance
 
-
 class ControllerBase(object):
     def __init__(self, object_manager):
     
@@ -84,7 +85,7 @@ class ControllerBase(object):
     def getWallClockTime(self):
         return self.accurate_time.get_wct()
             
-    def addInputPort(self, virtual_name, instance = None):
+    def createInputPort(self, virtual_name, instance = None):
         if instance == None:
             port_name = virtual_name
         else:
@@ -93,7 +94,7 @@ class ControllerBase(object):
         self.input_ports[port_name] = InputPortEntry(virtual_name, instance)
         return port_name
         
-    def addOutputPort(self, virtual_name, instance = None):
+    def createOutputPort(self, virtual_name, instance = None):
         if instance == None:
             port_name = virtual_name
         else:
@@ -311,6 +312,7 @@ class ThreadsControllerBase(ControllerBase):
         self.stop_thread = False
         self.last_print_time = 0
 
+    # may be called from another thread than run
     def addInput(self, input_event, time_offset = 0, force_internal=False):
         with self.input_condition:
             ControllerBase.addInput(self, input_event, time_offset, force_internal)
@@ -318,7 +320,8 @@ class ThreadsControllerBase(ControllerBase):
         
     def start(self):
         self.run()
-        
+    
+    # may be called from another thread than run
     def stop(self):
         with self.input_condition:
             self.stop_thread = True

+ 1 - 0
src/sccd/runtime/event_queue.py

@@ -1,5 +1,6 @@
 from sccd.runtime.infinity import INFINITY
 from heapq import heappush, heappop
+import traceback
 
 class EventQueue(object):
     def __init__(self):

+ 10 - 8
src/sccd/runtime/statecharts_core.py

@@ -177,7 +177,7 @@ class ObjectManagerBase(object):
                
     def start(self):
         for i in self.instances:
-            i.start()          
+            i.start()
                
     def handleEvent(self, e):
         self.handlers[e.getName()](e.getParameters())
@@ -386,13 +386,14 @@ class ObjectManagerBase(object):
                     raise AssociationReferenceException("Incorrect index in association reference.")
             currents = nexts
         return currents
-            
+
+    """ Implemented by compiled class ObjectManager """
     @abc.abstractmethod
     def instantiate(self, class_name, construct_params):
         pass
         
-    def createInstance(self, to_class, construct_params = []):
-        instance = self.instantiate(to_class, construct_params)
+    def createInstance(self, class_name, construct_params = []):
+        instance = self.instantiate(class_name, construct_params)
         self.instances.add(instance)
         return instance
     
@@ -685,7 +686,7 @@ class RuntimeClassBase(object):
         self.transition_mem = {}
         self.config_mem = {}
         
-        self.narrow_cast_port = self.controller.addInputPort("<narrow_cast>", self)
+        self.narrow_cast_port = self.controller.createInputPort("<narrow_cast>", self)
 
         self.semantics = StatechartSemantics()
 
@@ -835,7 +836,7 @@ class RuntimeClassBase(object):
         except:
             self.transition_mem[key] = transitions = [t for s in self.configuration if not (2**s.state_id & changed_bitmap) for t in s.transitions]
         
-        enabledEvents = self.getEnabledEvents()
+        enabledEvents = self._getEnabledEvents()
         enabledTransitions = []
         for t in transitions:
             if t.isEnabled(enabledEvents, enabledTransitions):
@@ -884,7 +885,7 @@ class RuntimeClassBase(object):
         return self.small_step.has_stepped
 
     # @profile
-    def getEnabledEvents(self):
+    def _getEnabledEvents(self):
         result = self.small_step.current_events + self.combo_step.current_events
         if self.semantics.input_event_lifeline == StatechartSemantics.Whole or (
             not self.big_step.has_stepped and
@@ -894,7 +895,7 @@ class RuntimeClassBase(object):
             result += self.big_step.input_events
         return result
 
-    def raiseInternalEvent(self, event):
+    def _raiseInternalEvent(self, event):
         if self.semantics.internal_event_lifeline == StatechartSemantics.NextSmallStep:
             self.small_step.addNextEvent(event)
         elif self.semantics.internal_event_lifeline == StatechartSemantics.NextComboStep:
@@ -902,6 +903,7 @@ class RuntimeClassBase(object):
         elif self.semantics.internal_event_lifeline == StatechartSemantics.Queue:
             self.addEvent(event)
 
+    # overridden by compiled classes to set 'self.default_targets'. called when instance is started.
     def initializeStatechart(self):
         self.updateConfiguration(self.default_targets)
         for state in self.default_targets:

+ 4 - 4
test/test.py

@@ -69,13 +69,13 @@ class PyTestCase(unittest.TestCase):
         # check output
         for (slot_index, slot) in enumerate(expected_result) : 
             output_events = output_listener.fetch_blocking()
-            # print("slot:", slot_index, ", events: ", output_events)
+            print("slot:", slot_index, ", events: ", output_events)
 
             # sort both expected and actual lists of events before comparing,
             # in theory the set of events at the end of a big step is unordered
-            sort_events = lambda e: "%s.%s"%(e.port, e.name)
-            slot.sort(key=sort_events)
-            output_events.sort(key=sort_events)
+            sortkey_f = lambda e: "%s.%s"%(e.port, e.name)
+            slot.sort(key=sortkey_f)
+            output_events.sort(key=sortkey_f)
             self.assertEqual(len(slot), len(output_events), "Expected %d output events, instead got: %d" % (len(slot), len(output_events)))
             for (expected, actual) in zip(slot, output_events):
                 matches = True