Joeri Exelmans 2 éve
szülő
commit
aed0f352e4

+ 1 - 1
README.md

@@ -24,7 +24,7 @@ Tip: Users of the Nix package manager can get a usable development environment t
 
 There's a `setup.py` script in the `src` directory.
 
-Alternatively, you can just set your `PYTHONPATH` environment variable to the absolute path of the `src` directory. This is recommended for development.
+Alternatively, you can just add the toplevel `python` directory of this project to your `PYTHONPATH` environment variable. This is recommended for development.
 
 ## Running the tests
 

+ 3 - 3
examples/digitalwatch/python/DigitalWatchGUI.py

@@ -173,9 +173,9 @@ class DigitalWatchGUI_Static(Frame):
         tmpDate = list(localtime()[0:3]) 
         self.curDate = [tmpDate[1], tmpDate[2], int(str(tmpDate[0])[3:]) ] 
         self.dateTag = None
-        
-        # self.curTime = list(localtime()[3:6])
-        self.curTime = [11, 59, 55]
+
+        self.curTime = list(localtime()[3:6])
+        # self.curTime = [11, 59, 55]
         self.timeTag = None
         
         self.curAlarm = [12, 0, 0]

+ 1 - 2
examples/microwave/run.py

@@ -18,8 +18,7 @@ if __name__ == '__main__':
     GUI.gui.send_event = send_event
 
     def on_output(event):
-        if event.port == "out":
-            GUI.gui.handle_event(event)
+        GUI.gui.handle_event(event)
 
     controller = Controller(cd, output_callback=on_output)
     eventloop = EventLoop(controller, TkInterImplementation(GUI.tk))

+ 15 - 1
examples/semantics/run.py

@@ -13,7 +13,21 @@ if __name__ == "__main__":
   # Generate semantic variants, and filter invalid ones
   variants = statechart_model.generate_semantic_variants()
 
-  variants_filtered = [v for v in variants if v.semantics.enabledness_memory_protocol == v.semantics.assignment_memory_protocol]
+  def filter(semantics):
+    if semantics.enabledness_memory_protocol != semantics.assignment_memory_protocol:
+      return False
+    if semantics.input_event_lifeline == InputEventLifeline.FIRST_SMALL_STEP:
+      if semantics.internal_event_lifeline != InternalEventLifeline.NEXT_SMALL_STEP:
+        return False
+    if semantics.input_event_lifeline == InputEventLifeline.FIRST_COMBO_STEP:
+      if semantics.internal_event_lifeline != InternalEventLifeline.NEXT_COMBO_STEP:
+        return False
+    if semantics.input_event_lifeline == InputEventLifeline.WHOLE:
+      if semantics.internal_event_lifeline != InternalEventLifeline.REMAINDER:
+        return False
+    return True
+
+  variants_filtered = [v for v in variants if filter(v.semantics)]
 
   print("Total variants:", len(variants_filtered))
   

+ 11 - 2
notes.txt

@@ -16,9 +16,16 @@ Long-term vision:
   - improve action language:
     - highest priority:
       - interfacing with external code only works with Python modules
-    - less important, deal with it when it becomes a problem: 
+          envisioned approach:
+          - import external functions: type-safe bindings with other language (check IDL?)
+          - also: declare external types
+              these types cannot be manipulated within SCCD,
+              but can be used as parameters for imported functions
+                -> typical use case: "self" parameter of a method call
+    - less important, deal with it when it becomes a problem:
+      - explicit syntactic distinction between pass-by-value and pass-by-reference, like in C/C++/Rust
       - statically typed (good), but no generics (bad)
-      - user cannot define his/her own types
+      - user cannot define his/her own (complex) types
 
   - dynamic creation/destruction of instances (the "CD" part of SCCD)
 
@@ -37,6 +44,8 @@ Long-term vision:
 
 Random notes:
 
+  - Apparently Python3's standard library XML parser (ElementTree) also features event-driven parsing. Probably we no longer need 'lxml'.
+
   - Refactor XML parsing code to use domain-specific types for parsing rules instead of tuples, dicts and lists.
 
   - (DONE) Currently event IDs are unique within a CD model. They only have to be unique within a statechart model.

+ 2 - 2
python/sccd/action_lang/cmd/prompt.py

@@ -21,7 +21,7 @@ if __name__ == "__main__":
   print("    apply(10, func(i: int) { return i+1; })")
   print()
 
-  parser = ActionLangParser()
+  parser = TextParser()
 
   while True:
     try:
@@ -54,4 +54,4 @@ if __name__ == "__main__":
       print(type(e).__name__+":", e)
     except (KeyboardInterrupt, EOFError):
       print()
-      exit()
+      exit()

+ 1 - 1
python/sccd/action_lang/parser/text.py

@@ -147,4 +147,4 @@ class TextParser:
     return self.parser.parse(text, start="expr")
 
   def parse_stmt(self, text: str) -> Statement:
-    return self.parser.parse(text, start="block")
+    return self.parser.parse(text, start="stmt")

+ 2 - 2
python/sccd/statechart/dynamic/statechart_instance.py

@@ -5,7 +5,7 @@ from sccd.util.debug import print_debug
 from sccd.util.bitmap import *
 from sccd.statechart.static.statechart import *
 from sccd.statechart.static import priority, concurrency
-from sccd.statechart.dynamic.builtin_scope import *
+# from sccd.statechart.dynamic.builtin_scope import *
 from sccd.statechart.dynamic.round import *
 from sccd.statechart.dynamic.statechart_execution import *
 from sccd.statechart.dynamic.memory_snapshot import *
@@ -122,7 +122,7 @@ class StatechartInstance(Instance):
         # Memory protocol semantics
 
         memory = Memory()
-        load_builtins(memory, self.execution)
+        # load_builtins(memory, self.execution)
         memory.push_frame(statechart.scope)
 
         instance_frame = memory.current_frame() # this is the stack frame that contains the statechart's "instance" variables

+ 3 - 1
python/sccd/statechart/parser/text.py

@@ -102,4 +102,6 @@ class TextParser(action_lang.TextParser):
 
   def parse_type(self, text: str):
     return self.parser.parse(text, start="type_annot")
-    
+
+  def parse_block(self, text: str) -> Statement:
+    return self.parser.parse(text, start="block")

+ 2 - 2
python/sccd/statechart/parser/xml.py

@@ -51,7 +51,7 @@ def statechart_parser_rules(globals, path, load_external = True, parse_f = parse
         setattr(statechart.semantics, aspect_name, semantic_choice)
 
     def parse_datamodel(el):
-      body = text_parser.parse_stmt(el.text)
+      body = text_parser.parse_block(el.text)
       body.init_stmt(statechart.scope)
       statechart.datamodel = body
 
@@ -165,7 +165,7 @@ def statechart_parser_rules(globals, path, load_external = True, parse_f = parse
           def parse_code(el):
             def finish_code():
               # Every block of code becomes a function, with the event trigger's parameters as parameters
-              block = text_parser.parse_stmt(el.text)
+              block = text_parser.parse_block(el.text)
               function = wrap_transition_params(block, transition=transition)
               function.init_expr(scope)
               function.scope.name = "code"

+ 20 - 7
shell.nix

@@ -4,12 +4,25 @@
 
 pkgs.mkShell {
   buildInputs = [
-    pkgs.python38
-    pkgs.python38Packages.tkinter
-    pkgs.python38Packages.lark-parser
-    pkgs.python38Packages.lxml
-    pkgs.python38Packages.termcolor
+    pkgs.python3
+    pkgs.python3Packages.tkinter
+    pkgs.python3Packages.lark
+    pkgs.python3Packages.lxml
+    pkgs.python3Packages.termcolor
+
+    #pkgs.rustc
+    pkgs.rustup
+    #pkgs.cargo
+    pkgs.wasm-pack
+
+    pkgs.perf-tools
+
   ];
 
-  PYTHONPATH = ./. + "/src";
-}
+  shellHook =
+    ''
+      export PYTHONPATH=$PYTHONPATH:$pwd/python
+    '';
+
+   PYTHONPATH = ./python;
+}