Quellcode durchsuchen

Rename dir 'src' to 'python'. Rust: Use conditional compilation attributes to automatically generate InEvent+OutEvent WASM bindings when compiling for wasm32.

Joeri Exelmans vor 4 Jahren
Ursprung
Commit
dcd5aa6809
99 geänderte Dateien mit 23 neuen und 59 gelöschten Zeilen
  1. 2 2
      README.md
  2. 5 2
      examples/digitalwatch/webassembly/codegen/Cargo.toml
  3. 3 0
      examples/digitalwatch/webassembly/codegen/digitalwatch.rs
  4. 0 11
      examples/digitalwatch/webassembly/wasm/Cargo.lock
  5. 4 7
      examples/digitalwatch/webassembly/wasm/Cargo.toml
  6. 0 0
      python/MANIFEST.in
  7. 0 0
      python/build.bat
  8. 0 0
      python/install.bat
  9. 0 0
      python/sccd/__init__.py
  10. 0 0
      python/sccd/action_lang/__init__.py
  11. 0 0
      python/sccd/action_lang/cmd/__init__.py
  12. 0 0
      python/sccd/action_lang/cmd/prompt.py
  13. 0 0
      python/sccd/action_lang/codegen/__init__.py
  14. 0 0
      python/sccd/action_lang/codegen/functions.txt
  15. 0 0
      python/sccd/action_lang/codegen/rust.py
  16. 0 0
      python/sccd/action_lang/dynamic/__init__.py
  17. 0 0
      python/sccd/action_lang/dynamic/memory.py
  18. 0 0
      python/sccd/action_lang/lib/__init__.py
  19. 0 0
      python/sccd/action_lang/lib/demo_native_lib.py
  20. 0 0
      python/sccd/action_lang/lib/readme.txt
  21. 0 0
      python/sccd/action_lang/lib/utils.py
  22. 0 0
      python/sccd/action_lang/parser/__init__.py
  23. 0 0
      python/sccd/action_lang/parser/action_lang.g
  24. 0 0
      python/sccd/action_lang/parser/text.py
  25. 0 0
      python/sccd/action_lang/static/__init__.py
  26. 0 0
      python/sccd/action_lang/static/expression.py
  27. 0 0
      python/sccd/action_lang/static/scope.py
  28. 0 0
      python/sccd/action_lang/static/statement.py
  29. 0 0
      python/sccd/action_lang/static/types.py
  30. 0 0
      python/sccd/cd/__init__.py
  31. 0 0
      python/sccd/cd/cmd/gen_rust.py
  32. 0 0
      python/sccd/cd/codegen/rust.py
  33. 0 0
      python/sccd/cd/parser/__init__.py
  34. 0 0
      python/sccd/cd/parser/xml.py
  35. 0 0
      python/sccd/cd/static/__init__.py
  36. 0 0
      python/sccd/cd/static/cd.py
  37. 0 0
      python/sccd/common/exceptions.py
  38. 0 0
      python/sccd/controller/__init__.py
  39. 0 0
      python/sccd/controller/controller.py
  40. 0 0
      python/sccd/controller/event_queue.py
  41. 0 0
      python/sccd/controller/object_manager.py
  42. 0 0
      python/sccd/realtime/eventloop.py
  43. 0 0
      python/sccd/realtime/threads_platform.py
  44. 0 0
      python/sccd/realtime/time.py
  45. 0 0
      python/sccd/realtime/tkinter.py
  46. 0 0
      python/sccd/statechart/__init__.py
  47. 0 0
      python/sccd/statechart/cmd/check_model.py
  48. 0 0
      python/sccd/statechart/cmd/render.py
  49. 0 0
      python/sccd/statechart/cmd/render_priorities.py
  50. 0 0
      python/sccd/statechart/codegen/__init__.py
  51. 2 25
      src/sccd/statechart/codegen/rust.py
  52. 0 0
      python/sccd/statechart/dynamic/__init__.py
  53. 0 0
      python/sccd/statechart/dynamic/builtin_scope.py
  54. 0 0
      python/sccd/statechart/dynamic/candidate_generator.py
  55. 0 0
      python/sccd/statechart/dynamic/event.py
  56. 0 0
      python/sccd/statechart/dynamic/memory_snapshot.py
  57. 0 0
      python/sccd/statechart/dynamic/round.py
  58. 0 0
      python/sccd/statechart/dynamic/statechart_execution.py
  59. 0 0
      python/sccd/statechart/dynamic/statechart_instance.py
  60. 0 0
      python/sccd/statechart/parser/statechart.g
  61. 0 0
      python/sccd/statechart/parser/text.py
  62. 0 0
      python/sccd/statechart/parser/xml.py
  63. 0 0
      python/sccd/statechart/static/__init__.py
  64. 0 0
      python/sccd/statechart/static/action.py
  65. 0 0
      python/sccd/statechart/static/concurrency.py
  66. 0 0
      python/sccd/statechart/static/globals.py
  67. 0 0
      python/sccd/statechart/static/in_state.py
  68. 0 0
      python/sccd/statechart/static/priority.py
  69. 0 0
      python/sccd/statechart/static/semantic_configuration.py
  70. 0 0
      python/sccd/statechart/static/state_ref.py
  71. 0 0
      python/sccd/statechart/static/statechart.py
  72. 0 0
      python/sccd/statechart/static/tree.py
  73. 0 0
      python/sccd/statechart/static/types.py
  74. 0 0
      python/sccd/test/__init__.py
  75. 0 0
      python/sccd/test/cmd/run.py
  76. 0 0
      python/sccd/test/cmd/to_rust.py
  77. 0 0
      python/sccd/test/codegen/rust.py
  78. 7 6
      src/sccd/test/codegen/write_crate.py
  79. 0 0
      python/sccd/test/dynamic/test_interpreter.py
  80. 0 0
      python/sccd/test/dynamic/test_rust.py
  81. 0 0
      python/sccd/test/parser/xml.py
  82. 0 0
      python/sccd/test/static/syntax.py
  83. 0 0
      python/sccd/util/__init__.py
  84. 0 0
      python/sccd/util/bitmap.py
  85. 0 0
      python/sccd/util/debug.py
  86. 0 0
      python/sccd/util/duration.py
  87. 0 0
      python/sccd/util/freezable.py
  88. 0 0
      python/sccd/util/graph.py
  89. 0 0
      python/sccd/util/indenting_writer.py
  90. 0 0
      python/sccd/util/namespace.py
  91. 0 0
      python/sccd/util/os_tools.py
  92. 0 0
      python/sccd/util/test_duration.py
  93. 0 0
      python/sccd/util/timer.py
  94. 0 0
      python/sccd/util/visit_tree.py
  95. 0 0
      python/sccd/util/visitable.py
  96. 0 0
      python/sccd/util/xml_parser.py
  97. 0 0
      python/setup.py
  98. 0 0
      python/setup.sh
  99. 0 6
      src/sccd/util/wasm.py

+ 2 - 2
README.md

@@ -60,8 +60,8 @@ python -m sccd.test.cmd.to_rust path/to/model.xml [--output DIRNAME]
 
 The following environment variables can be set to change the behavior of the runtime. These options can be set while running the tests, or while running one of the examples.
 
-* `SCCDDEBUG`: When set, additional debug information is printed, such as a trace of the individual transitions taken.
-* `SCCDTIMINGS`: When set, at exit, the runtime will print information about how much time in total was spent during various parts of its execution, such as loading the model, generating transition candidates, executing transitions, executing actions, and more.
+* `SCCDDEBUG`: When set to 1, additional debug information is printed, such as a trace of the individual transitions taken.
+* `SCCDTIMINGS`: When set to 1, at exit, the runtime will print information about how much time in total was spent during various parts of its execution, such as loading the model, generating transition candidates, executing transitions, executing actions, and more.
 
 ## Included tools
 

+ 5 - 2
examples/digitalwatch/webassembly/codegen/Cargo.toml

@@ -4,8 +4,11 @@ version = "0.1.0"
 edition = "2018"
 
 [dependencies]
-sccd = { path = "/home/maestro/thesis/repos/SCCD/src/sccd/../../rust" }
-wasm-bindgen = "*"
+sccd = { path = "/home/maestro/thesis/repos/SCCD/python/sccd/../../rust" }
+
+# Only depend on wasm-bindgen when building for wasm32 architecture
+[target.'cfg(target_arch = "wasm32")'.dependencies]
+wasm-bindgen = "0.2"
 
 [lib]
 name = "digitalwatch"

+ 3 - 0
examples/digitalwatch/webassembly/codegen/digitalwatch.rs

@@ -9,6 +9,7 @@
 #![allow(unused_mut)]
 #![allow(unused_imports)]
 
+#[cfg(target_arch = "wasm32")]
 use wasm_bindgen::prelude::*;
 
 use std::ops::Deref;
@@ -23,6 +24,7 @@ use sccd::statechart::EventLifeline;
 type Timers<TimerId> = [TimerId; 11];
 
 // Input Events
+#[cfg(target_arch = "wasm32")]
 #[wasm_bindgen]
 #[derive(Copy, Clone, Debug)]
 pub enum InEvent {
@@ -75,6 +77,7 @@ struct Internal {
 type InternalLifeline = statechart::NextRoundLifeline<Internal>;
 
 // Output Events
+#[cfg(target_arch = "wasm32")]
 #[wasm_bindgen]
 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
 pub enum OutEvent {

+ 0 - 11
examples/digitalwatch/webassembly/wasm/Cargo.lock

@@ -18,16 +18,6 @@ version = "1.0.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
 
-[[package]]
-name = "console_error_panic_hook"
-version = "0.1.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b8d976903543e0c48546a91908f21588a680a8c8f984df9a5d69feccb2b2a211"
-dependencies = [
- "cfg-if 0.1.10",
- "wasm-bindgen",
-]
-
 [[package]]
 name = "digitalwatch"
 version = "0.1.0"
@@ -94,7 +84,6 @@ checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
 name = "wasm"
 version = "0.1.0"
 dependencies = [
- "console_error_panic_hook",
  "digitalwatch",
  "sccd",
  "wasm-bindgen",

+ 4 - 7
examples/digitalwatch/webassembly/wasm/Cargo.toml

@@ -6,13 +6,13 @@ edition = "2018"
 [dependencies]
 digitalwatch = { path = "../codegen" }
 sccd = { path = "/home/maestro/thesis/repos/SCCD/src/sccd/../../rust" }
-wasm-bindgen = "^0.2"
+wasm-bindgen = "0.2"
 
 # The `console_error_panic_hook` crate provides better debugging of panics by
 # logging them with `console.error`. This is great for development, but requires
 # all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
 # code size when deploying.
-console_error_panic_hook = { version = "0.1.6", optional = true }
+# console_error_panic_hook = { version = "0.1.6", optional = true }
 
 # `wee_alloc` is a tiny allocator for wasm that is only ~1K in code size
 # compared to the default allocator's ~10K. It is slower than the default
@@ -26,8 +26,5 @@ name = "dwatch"
 path = "lib.rs"
 crate-type = ["cdylib", "rlib"]
 
-[features]
-default = ["console_error_panic_hook"]
-
-[profile.release]
-opt-level = 3
+# [features]
+# default = ["console_error_panic_hook"]

src/MANIFEST.in → python/MANIFEST.in


src/build.bat → python/build.bat


src/install.bat → python/install.bat


src/sccd/__init__.py → python/sccd/__init__.py


src/sccd/action_lang/__init__.py → python/sccd/action_lang/__init__.py


src/sccd/action_lang/cmd/__init__.py → python/sccd/action_lang/cmd/__init__.py


src/sccd/action_lang/cmd/prompt.py → python/sccd/action_lang/cmd/prompt.py


src/sccd/action_lang/codegen/__init__.py → python/sccd/action_lang/codegen/__init__.py


src/sccd/action_lang/codegen/functions.txt → python/sccd/action_lang/codegen/functions.txt


src/sccd/action_lang/codegen/rust.py → python/sccd/action_lang/codegen/rust.py


src/sccd/action_lang/dynamic/__init__.py → python/sccd/action_lang/dynamic/__init__.py


src/sccd/action_lang/dynamic/memory.py → python/sccd/action_lang/dynamic/memory.py


src/sccd/action_lang/lib/__init__.py → python/sccd/action_lang/lib/__init__.py


src/sccd/action_lang/lib/demo_native_lib.py → python/sccd/action_lang/lib/demo_native_lib.py


src/sccd/action_lang/lib/readme.txt → python/sccd/action_lang/lib/readme.txt


src/sccd/action_lang/lib/utils.py → python/sccd/action_lang/lib/utils.py


src/sccd/action_lang/parser/__init__.py → python/sccd/action_lang/parser/__init__.py


src/sccd/action_lang/parser/action_lang.g → python/sccd/action_lang/parser/action_lang.g


src/sccd/action_lang/parser/text.py → python/sccd/action_lang/parser/text.py


src/sccd/action_lang/static/__init__.py → python/sccd/action_lang/static/__init__.py


src/sccd/action_lang/static/expression.py → python/sccd/action_lang/static/expression.py


src/sccd/action_lang/static/scope.py → python/sccd/action_lang/static/scope.py


src/sccd/action_lang/static/statement.py → python/sccd/action_lang/static/statement.py


src/sccd/action_lang/static/types.py → python/sccd/action_lang/static/types.py


src/sccd/cd/__init__.py → python/sccd/cd/__init__.py


src/sccd/cd/cmd/gen_rust.py → python/sccd/cd/cmd/gen_rust.py


src/sccd/cd/codegen/rust.py → python/sccd/cd/codegen/rust.py


src/sccd/cd/parser/__init__.py → python/sccd/cd/parser/__init__.py


src/sccd/cd/parser/xml.py → python/sccd/cd/parser/xml.py


src/sccd/cd/static/__init__.py → python/sccd/cd/static/__init__.py


src/sccd/cd/static/cd.py → python/sccd/cd/static/cd.py


src/sccd/common/exceptions.py → python/sccd/common/exceptions.py


src/sccd/controller/__init__.py → python/sccd/controller/__init__.py


src/sccd/controller/controller.py → python/sccd/controller/controller.py


src/sccd/controller/event_queue.py → python/sccd/controller/event_queue.py


src/sccd/controller/object_manager.py → python/sccd/controller/object_manager.py


src/sccd/realtime/eventloop.py → python/sccd/realtime/eventloop.py


src/sccd/realtime/threads_platform.py → python/sccd/realtime/threads_platform.py


src/sccd/realtime/time.py → python/sccd/realtime/time.py


src/sccd/realtime/tkinter.py → python/sccd/realtime/tkinter.py


src/sccd/statechart/__init__.py → python/sccd/statechart/__init__.py


src/sccd/statechart/cmd/check_model.py → python/sccd/statechart/cmd/check_model.py


src/sccd/statechart/cmd/render.py → python/sccd/statechart/cmd/render.py


src/sccd/statechart/cmd/render_priorities.py → python/sccd/statechart/cmd/render_priorities.py


src/sccd/statechart/codegen/__init__.py → python/sccd/statechart/codegen/__init__.py


+ 2 - 25
src/sccd/statechart/codegen/rust.py

@@ -7,7 +7,6 @@ from sccd.statechart.static.statechart import *
 from sccd.statechart.static.globals import *
 from sccd.statechart.static import priority
 from sccd.util.indenting_writer import *
-from sccd.util.wasm import *
 
 # Hardcoded limit on number of sub-rounds of combo and big step to detect never-ending superrounds.
 # TODO: make this a model parameter, also allowing for +infinity
@@ -354,23 +353,11 @@ class StatechartRustGenerator(ActionLangRustGenerator):
             sc.semantics.internal_event_lifeline == InternalEventLifeline.REMAINDER or
             sc.semantics.internal_event_lifeline == InternalEventLifeline.SAME)
 
-        # Until we implement event parameters, event types are just empty structs
-
         self.w.writeln("// Input Events")
-        # for event_name in input_event_names:
-        #     if WASM:
-        #         self.w.writeln("#[wasm_bindgen]")
-        #     self.w.writeln("#[derive(Copy, Clone, Debug)]")
-        #     self.w.writeln("pub struct %s {" % ident_event_type(event_name))
-        #     self.w.writeln("  // TODO: input event parameters")
-        #     self.w.writeln("}")
-
-        if WASM:
-            self.w.writeln("#[wasm_bindgen]")
+        self.w.writeln("#[cfg_attr(target_arch = \"wasm32\", wasm_bindgen)]")
         self.w.writeln("#[derive(Copy, Clone, Debug)]")
         self.w.writeln("pub enum InEvent {")
         for event_name in input_event_names:
-            # self.w.writeln("  %s(%s)," % (ident_event_enum_variant(event_name), ident_event_type(event_name)))
             self.w.writeln("  %s," % (ident_event_enum_variant(event_name)))
         self.w.writeln("}")
         self.w.writeln()
@@ -401,20 +388,10 @@ class StatechartRustGenerator(ActionLangRustGenerator):
         # Output events
         output_event_names = self.globals.out_events.names
         self.w.writeln("// Output Events")
-        # for event_name in output_event_names:
-        #     if WASM:
-        #         self.w.writeln("#[wasm_bindgen]")
-        #     self.w.writeln("#[derive(Copy, Clone, Debug, PartialEq, Eq)]")
-        #     self.w.writeln("pub struct %s {" % ident_event_type(event_name))
-        #     self.w.writeln("  // TODO: output event parameters")
-        #     self.w.writeln("}")
-
-        if WASM:
-            self.w.writeln("#[wasm_bindgen]")
+        self.w.writeln("#[cfg_attr(target_arch = \"wasm32\", wasm_bindgen)]")
         self.w.writeln("#[derive(Copy, Clone, Debug, PartialEq, Eq)]")
         self.w.writeln("pub enum OutEvent {")
         for event_name in output_event_names:
-            # self.w.writeln("  %s(%s)," % (ident_event_enum_variant(event_name), ident_event_type(event_name)))
             self.w.writeln("  %s," % (ident_event_enum_variant(event_name)))
         self.w.writeln("}")
         self.w.writeln()

src/sccd/statechart/dynamic/__init__.py → python/sccd/statechart/dynamic/__init__.py


src/sccd/statechart/dynamic/builtin_scope.py → python/sccd/statechart/dynamic/builtin_scope.py


src/sccd/statechart/dynamic/candidate_generator.py → python/sccd/statechart/dynamic/candidate_generator.py


src/sccd/statechart/dynamic/event.py → python/sccd/statechart/dynamic/event.py


src/sccd/statechart/dynamic/memory_snapshot.py → python/sccd/statechart/dynamic/memory_snapshot.py


src/sccd/statechart/dynamic/round.py → python/sccd/statechart/dynamic/round.py


src/sccd/statechart/dynamic/statechart_execution.py → python/sccd/statechart/dynamic/statechart_execution.py


src/sccd/statechart/dynamic/statechart_instance.py → python/sccd/statechart/dynamic/statechart_instance.py


src/sccd/statechart/parser/statechart.g → python/sccd/statechart/parser/statechart.g


src/sccd/statechart/parser/text.py → python/sccd/statechart/parser/text.py


src/sccd/statechart/parser/xml.py → python/sccd/statechart/parser/xml.py


src/sccd/statechart/static/__init__.py → python/sccd/statechart/static/__init__.py


src/sccd/statechart/static/action.py → python/sccd/statechart/static/action.py


src/sccd/statechart/static/concurrency.py → python/sccd/statechart/static/concurrency.py


src/sccd/statechart/static/globals.py → python/sccd/statechart/static/globals.py


src/sccd/statechart/static/in_state.py → python/sccd/statechart/static/in_state.py


src/sccd/statechart/static/priority.py → python/sccd/statechart/static/priority.py


src/sccd/statechart/static/semantic_configuration.py → python/sccd/statechart/static/semantic_configuration.py


src/sccd/statechart/static/state_ref.py → python/sccd/statechart/static/state_ref.py


src/sccd/statechart/static/statechart.py → python/sccd/statechart/static/statechart.py


src/sccd/statechart/static/tree.py → python/sccd/statechart/static/tree.py


src/sccd/statechart/static/types.py → python/sccd/statechart/static/types.py


src/sccd/test/__init__.py → python/sccd/test/__init__.py


src/sccd/test/cmd/run.py → python/sccd/test/cmd/run.py


src/sccd/test/cmd/to_rust.py → python/sccd/test/cmd/to_rust.py


src/sccd/test/codegen/rust.py → python/sccd/test/codegen/rust.py


+ 7 - 6
src/sccd/test/codegen/write_crate.py

@@ -2,7 +2,6 @@ from sccd.cd.parser.xml import *
 from sccd.test.parser.xml import *
 from sccd.util.indenting_writer import *
 from functools import partial
-from sccd.util.wasm import *
 
 import sccd
 RUST_DIR = os.path.dirname(sccd.__file__) + "/../../rust"
@@ -42,9 +41,9 @@ def write_crate(src, target):
         w.writeln("#![allow(unused_imports)]")
         w.writeln()
 
-        if WASM:
-            w.writeln("use wasm_bindgen::prelude::*;")
-            w.writeln()
+        w.writeln("#[cfg(target_arch = \"wasm32\")]")
+        w.writeln("use wasm_bindgen::prelude::*;")
+        w.writeln()
 
         if isinstance(parsed, Statechart):
             from sccd.statechart.codegen.rust import StatechartRustGenerator
@@ -69,8 +68,10 @@ def write_crate(src, target):
         w.writeln()
         w.writeln("[dependencies]")
         w.writeln("sccd = { path = \"%s\" }" % RUST_DIR)
-        if WASM:
-            w.writeln("wasm-bindgen = \"*\"")
+        w.writeln()
+        w.writeln("# Only depend on wasm-bindgen when building for wasm32 architecture")
+        w.writeln("[target.'cfg(target_arch = \"wasm32\")'.dependencies]")
+        w.writeln("wasm-bindgen = \"0.2\"")
         w.writeln()
         if isinstance(parsed, Test):
             # Tests are compiled to binaries

src/sccd/test/dynamic/test_interpreter.py → python/sccd/test/dynamic/test_interpreter.py


src/sccd/test/dynamic/test_rust.py → python/sccd/test/dynamic/test_rust.py


src/sccd/test/parser/xml.py → python/sccd/test/parser/xml.py


src/sccd/test/static/syntax.py → python/sccd/test/static/syntax.py


src/sccd/util/__init__.py → python/sccd/util/__init__.py


src/sccd/util/bitmap.py → python/sccd/util/bitmap.py


src/sccd/util/debug.py → python/sccd/util/debug.py


src/sccd/util/duration.py → python/sccd/util/duration.py


src/sccd/util/freezable.py → python/sccd/util/freezable.py


src/sccd/util/graph.py → python/sccd/util/graph.py


src/sccd/util/indenting_writer.py → python/sccd/util/indenting_writer.py


src/sccd/util/namespace.py → python/sccd/util/namespace.py


src/sccd/util/os_tools.py → python/sccd/util/os_tools.py


src/sccd/util/test_duration.py → python/sccd/util/test_duration.py


src/sccd/util/timer.py → python/sccd/util/timer.py


src/sccd/util/visit_tree.py → python/sccd/util/visit_tree.py


src/sccd/util/visitable.py → python/sccd/util/visitable.py


src/sccd/util/xml_parser.py → python/sccd/util/xml_parser.py


src/setup.py → python/setup.py


src/setup.sh → python/setup.sh


+ 0 - 6
src/sccd/util/wasm.py

@@ -1,6 +0,0 @@
-import os
-
-try:
-  WASM = bool(os.environ['SCCDWASM']=="1")
-except KeyError:
-  WASM = False