Sfoglia il codice sorgente

Rust: added support for Take Many.

Joeri Exelmans 4 anni fa
parent
commit
de11b1f6a1
2 ha cambiato i file con 18 aggiunte e 1 eliminazioni
  1. 3 1
      src/sccd/cd/codegen/sccdlib.rs
  2. 15 0
      src/sccd/statechart/codegen/rust.py

+ 3 - 1
src/sccd/cd/codegen/sccdlib.rs

@@ -19,6 +19,8 @@ pub trait SC<EventType, OutputCallback> {
   // meaning that every orthogonal component gets to fire at most 1 transition.
   // Returns whether at least one transition was fired.
   fn fair_step(&mut self, event: Option<EventType>, output: &mut OutputCallback) -> bool;
+
+  fn big_step(&mut self, event: Option<EventType>, output: &mut OutputCallback);
 }
 
 pub struct Entry<EventType> {
@@ -87,7 +89,7 @@ Controller<EventType, OutputCallback, StatechartType> {
 
           let e = entry.event; // copy
 
-          self.statechart.fair_step(Some(e), &mut self.output);
+          self.statechart.big_step(Some(e), &mut self.output);
 
           PeekMut::<'_, Entry<EventType>>::pop(entry);
         },

+ 15 - 0
src/sccd/statechart/codegen/rust.py

@@ -424,6 +424,21 @@ def compile_statechart(sc: Statechart, globals: Globals, w: IndentingWriter):
 
     w.writeln("    fired")
     w.writeln("  }")
+
+    w.writeln("  fn big_step(&mut self, event: Option<Event>, output: &mut OutputCallback) {")
+    if sc.semantics.big_step_maximality == Maximality.TAKE_ONE:
+        w.writeln("    self.fair_step(event, output);")
+    elif sc.semantics.big_step_maximality == Maximality.TAKE_MANY:
+        w.writeln("    loop {")
+        w.writeln("      let fired = self.fair_step(event, output);")
+        w.writeln("      if !fired {")
+        w.writeln("        break;")
+        w.writeln("      }")
+        w.writeln("    }")
+    else:
+        raise Exception("Unsupported semantics %s" % sc.semantics.big_step_maximality)
+    w.writeln("  }")
+
     w.writeln("}")
     w.writeln()