Selaa lähdekoodia

Most action lang tests now passing with Rust. Closures work, but recursion does not (and may be left unsupported).

Joeri Exelmans 4 vuotta sitten
vanhempi
commit
354576dd47

+ 4 - 2
src/sccd/action_lang/codegen/rust.py

@@ -81,8 +81,8 @@ class ActionLangRustGenerator(Visitor):
         self.function_types = {} # maps Function to Rust type
 
     def default(self, what):
-        self.w.wno("<%s>" % what)
-        # raise UnsupportedFeature(what)
+        # self.w.wno("<%s>" % what)
+        raise UnsupportedFeature(what)
 
     def debug_print_stack(self):
         # Print Python stack in Rust file as a comment
@@ -306,6 +306,8 @@ class ActionLangRustGenerator(Visitor):
                 # a child scope exists at the current offset (typically because we encountered a function declaration) - so we must commit our scope
                 self.scope.commit(lval.offset, self.w)
 
+
+            # self.w.wno("/* is_lvalue */")
             self.w.write('') # indent
 
         if lval.is_init:

+ 2 - 2
src/sccd/action_lang/static/expression.py

@@ -83,8 +83,8 @@ class Identifier(LValue):
 
     offset: Optional[int] = None
     type: Optional[SCCDType] = None
-    is_init: Optional[bool] = None
     is_lvalue: Optional[bool] = None
+    is_init: Optional[bool] = None
 
     # is_function_call_result: Optional[SCCDFunctionCallResult] = None
 
@@ -101,8 +101,8 @@ class Identifier(LValue):
         # if isinstance(rhs_t, SCCDFunctionCallResult):
             # self.is_function_call_result = rhs_t
             # rhs_t = rhs_t.return_type
-        self.offset, self.is_init = scope.put_lvalue(self.name, rhs_t, rhs)
         self.is_lvalue = True
+        self.offset, self.is_init = scope.put_lvalue(self.name, rhs_t, rhs)
         return self.is_init
 
     def assign(self, memory: MemoryInterface, value: Any):

+ 9 - 9
src/sccd/statechart/codegen/rust.py

@@ -314,7 +314,7 @@ class StatechartRustGenerator(ActionLangRustGenerator):
         # Function fair_step: a single "Take One" Maximality 'round' (= nonoverlapping arenas allowed to fire 1 transition)
         self.w.writeln("fn fair_step<OutputCallback: FnMut(OutEvent)>(sc: &mut Statechart, input: Option<InEvent>, internal: &mut InternalLifeline, ctrl: &mut Controller<InEvent, OutputCallback>, dirty: Arenas) -> Arenas {")
         self.w.writeln("  let mut fired: Arenas = ARENA_NONE;")
-        self.w.writeln("  let scope = &mut sc.data;")
+        self.w.writeln("  let mut scope = &mut sc.data;")
         self.w.writeln("  let %s = &mut sc.current_state;" % ident_var(tree.root))
         self.w.indent()
 
@@ -345,7 +345,7 @@ class StatechartRustGenerator(ActionLangRustGenerator):
 
                     if len(exit_path) == 1:
                         # Exit s:
-                        self.w.writeln("%s.exit_current(&mut sc.timers, scope, internal, ctrl);" % (ident_var(s)))
+                        self.w.writeln("%s.exit_current(&mut sc.timers, *parent1, internal, ctrl);" % (ident_var(s)))
                     else:
                         # Exit children:
                         if isinstance(s.type, AndState):
@@ -353,12 +353,12 @@ class StatechartRustGenerator(ActionLangRustGenerator):
                                 if exit_path[1] is c:
                                     write_exit(exit_path[1:]) # continue recursively
                                 else:
-                                    self.w.writeln("%s.exit_current(&mut sc.timers, scope, internal, ctrl);" % (ident_var(c)))
+                                    self.w.writeln("%s.exit_current(&mut sc.timers, *parent1, internal, ctrl);" % (ident_var(c)))
                         elif isinstance(s.type, OrState):
                             write_exit(exit_path[1:]) # continue recursively with the next child on the exit path
 
                         # Exit s:
-                        self.w.writeln("%s::exit_actions(&mut sc.timers, scope, internal, ctrl);" % (ident_type(s)))
+                        self.w.writeln("%s::exit_actions(&mut sc.timers, *parent1, internal, ctrl);" % (ident_type(s)))
 
                     # Store history
                     if s.deep_history:
@@ -382,19 +382,19 @@ class StatechartRustGenerator(ActionLangRustGenerator):
                     if len(enter_path) == 1:
                         # Target state.
                         if isinstance(s, HistoryState):
-                            self.w.writeln("sc.%s.enter_current(&mut sc.timers, scope, internal, ctrl); // Enter actions for history state" %(ident_history_field(s)))
+                            self.w.writeln("sc.%s.enter_current(&mut sc.timers, *parent1, internal, ctrl); // Enter actions for history state" %(ident_history_field(s)))
                         else:
-                            self.w.writeln("%s::enter_default(&mut sc.timers, scope, internal, ctrl);" % (ident_type(s)))
+                            self.w.writeln("%s::enter_default(&mut sc.timers, *parent1, internal, ctrl);" % (ident_type(s)))
                     else:
                         # Enter s:
-                        self.w.writeln("%s::enter_actions(&mut sc.timers, scope, internal, ctrl);" % (ident_type(s)))
+                        self.w.writeln("%s::enter_actions(&mut sc.timers, *parent1, internal, ctrl);" % (ident_type(s)))
                         # Enter children:
                         if isinstance(s.type, AndState):
                             for c in s.children:
                                 if enter_path[1] is c:
                                     write_enter(enter_path[1:]) # continue recursively
                                 else:
-                                    self.w.writeln("%s::enter_default(&mut sc.timers, scope, internal, ctrl);" % (ident_type(c)))
+                                    self.w.writeln("%s::enter_default(&mut sc.timers, *parent1, internal, ctrl);" % (ident_type(c)))
                         elif isinstance(s.type, OrState):
                             if len(s.children) > 0:
                                 write_enter(enter_path[1:]) # continue recursively with the next child on the enter path
@@ -467,7 +467,7 @@ class StatechartRustGenerator(ActionLangRustGenerator):
                         self.w.writeln("if %s {" % " && ".join(condition))
                         self.w.indent()
 
-                    self.w.writeln("let parent1 = &scope;")
+                    self.w.writeln("let parent1 = &mut scope;")
 
                     if t.guard is not None:
                         self.w.write("if ")