@devaloop/devalang 0.0.1-alpha.16-hotfix.3 → 0.0.1-alpha.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (239) hide show
  1. package/.cargo/config.toml +2 -0
  2. package/.devalang +10 -10
  3. package/.github/workflows/ci.yml +0 -1
  4. package/Cargo.toml +18 -2
  5. package/README.md +82 -34
  6. package/docs/CHANGELOG.md +91 -0
  7. package/docs/ROADMAP.md +7 -4
  8. package/docs/TODO.md +1 -1
  9. package/examples/index.deva +55 -35
  10. package/examples/pattern.deva +5 -5
  11. package/out-tsc/bin/index.d.ts +2 -0
  12. package/out-tsc/core/functions/index.d.ts +37 -0
  13. package/out-tsc/core/functions/index.js +76 -0
  14. package/out-tsc/core/index.d.ts +6 -0
  15. package/out-tsc/core/index.js +22 -0
  16. package/out-tsc/core/types/index.d.ts +4 -0
  17. package/out-tsc/core/types/index.js +20 -0
  18. package/out-tsc/core/types/plugin.d.ts +18 -0
  19. package/out-tsc/core/types/plugin.js +2 -0
  20. package/out-tsc/core/types/result.d.ts +27 -0
  21. package/out-tsc/core/types/result.js +2 -0
  22. package/out-tsc/core/types/statement.d.ts +106 -0
  23. package/out-tsc/core/types/statement.js +2 -0
  24. package/out-tsc/core/types/value.d.ts +43 -0
  25. package/out-tsc/core/types/value.js +2 -0
  26. package/out-tsc/index.d.ts +7 -0
  27. package/out-tsc/index.js +41 -2
  28. package/out-tsc/pkg/devalang_core.d.ts +7 -0
  29. package/out-tsc/pkg/devalang_core_bg.wasm.d.ts +33 -0
  30. package/out-tsc/scripts/copy-wasm-dts.d.ts +1 -0
  31. package/out-tsc/scripts/copy-wasm-dts.js +73 -0
  32. package/out-tsc/scripts/postinstall.d.ts +1 -0
  33. package/out-tsc/scripts/postinstall.js +33 -23
  34. package/out-tsc/scripts/version/bump.d.ts +1 -0
  35. package/out-tsc/scripts/version/fetch.d.ts +1 -0
  36. package/out-tsc/scripts/version/index.d.ts +1 -0
  37. package/out-tsc/scripts/version/sync.d.ts +1 -0
  38. package/package.json +16 -4
  39. package/project-version.json +3 -3
  40. package/rust/cli/bank/api.rs +122 -0
  41. package/rust/cli/bank/commands.rs +275 -0
  42. package/rust/cli/bank/mod.rs +29 -0
  43. package/rust/cli/build/commands.rs +107 -0
  44. package/rust/cli/build/mod.rs +2 -0
  45. package/rust/cli/build/process.rs +146 -0
  46. package/rust/cli/{check.rs → check/mod.rs} +18 -31
  47. package/rust/cli/discover/commands.rs +253 -0
  48. package/rust/cli/discover/config.rs +111 -0
  49. package/rust/cli/discover/fs.rs +19 -0
  50. package/rust/cli/discover/install.rs +103 -0
  51. package/rust/cli/discover/metadata.rs +48 -0
  52. package/rust/cli/discover/mod.rs +5 -0
  53. package/rust/cli/{init.rs → init/commands.rs} +88 -87
  54. package/rust/cli/init/mod.rs +1 -0
  55. package/rust/cli/install/addon.rs +126 -0
  56. package/rust/cli/install/bank.rs +53 -0
  57. package/rust/cli/{install.rs → install/commands.rs} +9 -9
  58. package/rust/{installer → cli/install}/mod.rs +2 -3
  59. package/rust/cli/install/plugin.rs +61 -0
  60. package/rust/cli/{login.rs → login/commands.rs} +8 -11
  61. package/rust/cli/login/mod.rs +1 -0
  62. package/rust/cli/mod.rs +2 -2
  63. package/rust/cli/{driver.rs → parser.rs} +7 -2
  64. package/rust/cli/play/commands.rs +324 -0
  65. package/rust/cli/play/io.rs +17 -0
  66. package/rust/cli/play/mod.rs +5 -0
  67. package/rust/cli/play/process.rs +150 -0
  68. package/rust/cli/play/realtime.rs +91 -0
  69. package/rust/cli/play/utils.rs +23 -0
  70. package/rust/cli/{telemetry.rs → telemetry/commands.rs} +4 -4
  71. package/rust/cli/telemetry/event_creator.rs +80 -0
  72. package/rust/cli/telemetry/mod.rs +3 -0
  73. package/rust/cli/telemetry/send.rs +51 -0
  74. package/rust/cli/{template.rs → template/commands.rs} +1 -1
  75. package/rust/cli/template/mod.rs +1 -0
  76. package/rust/cli/{update.rs → update/commands.rs} +6 -6
  77. package/rust/cli/update/mod.rs +1 -0
  78. package/rust/config/driver.rs +57 -72
  79. package/rust/config/mod.rs +1 -2
  80. package/rust/config/ops.rs +26 -0
  81. package/rust/config/settings.rs +40 -42
  82. package/rust/core/audio/engine/helpers.rs +158 -0
  83. package/rust/core/audio/engine/mod.rs +7 -0
  84. package/rust/core/audio/engine/sample.rs +359 -0
  85. package/rust/core/audio/engine/synth.rs +325 -0
  86. package/rust/core/audio/evaluator.rs +68 -27
  87. package/rust/core/audio/interpreter/arrow_call.rs +113 -33
  88. package/rust/core/audio/interpreter/call.rs +232 -56
  89. package/rust/core/audio/interpreter/condition.rs +3 -2
  90. package/rust/core/audio/interpreter/driver.rs +206 -151
  91. package/rust/core/audio/interpreter/let_.rs +1 -1
  92. package/rust/core/audio/interpreter/load.rs +2 -1
  93. package/rust/core/audio/interpreter/loop_.rs +7 -6
  94. package/rust/core/audio/interpreter/sleep.rs +2 -1
  95. package/rust/core/audio/interpreter/spawn.rs +186 -54
  96. package/rust/core/audio/interpreter/tempo.rs +31 -10
  97. package/rust/core/audio/interpreter/trigger.rs +2 -2
  98. package/rust/core/audio/loader/trigger.rs +4 -7
  99. package/rust/core/audio/player.rs +6 -0
  100. package/rust/core/audio/renderer.rs +5 -7
  101. package/rust/core/audio/special/env.rs +3 -1
  102. package/rust/core/audio/special/math.rs +26 -6
  103. package/rust/core/audio/special/modulator.rs +2 -2
  104. package/rust/core/builder/mod.rs +9 -3
  105. package/rust/core/debugger/lexer.rs +1 -1
  106. package/rust/core/debugger/mod.rs +6 -0
  107. package/rust/core/debugger/module.rs +4 -4
  108. package/rust/core/debugger/preprocessor.rs +1 -1
  109. package/rust/core/debugger/store.rs +2 -2
  110. package/rust/core/error/mod.rs +189 -0
  111. package/rust/core/lexer/driver.rs +61 -0
  112. package/rust/core/lexer/handler/arrow.rs +1 -1
  113. package/rust/core/lexer/handler/at.rs +1 -1
  114. package/rust/core/lexer/handler/brace.rs +2 -2
  115. package/rust/core/lexer/handler/colon.rs +1 -1
  116. package/rust/core/lexer/handler/comment.rs +1 -1
  117. package/rust/core/lexer/handler/dot.rs +1 -1
  118. package/rust/core/lexer/handler/driver.rs +1 -1
  119. package/rust/core/lexer/handler/identifier.rs +4 -3
  120. package/rust/core/lexer/handler/mod.rs +1 -2
  121. package/rust/core/lexer/handler/number.rs +1 -1
  122. package/rust/core/lexer/handler/operator.rs +1 -1
  123. package/rust/core/lexer/handler/parenthesis.rs +2 -2
  124. package/rust/core/lexer/handler/slash.rs +1 -1
  125. package/rust/core/lexer/handler/string.rs +1 -1
  126. package/rust/core/lexer/mod.rs +1 -52
  127. package/rust/core/lexer/token.rs +91 -97
  128. package/rust/core/mod.rs +0 -1
  129. package/rust/core/parser/driver.rs +78 -22
  130. package/rust/core/parser/handler/arrow_call.rs +28 -8
  131. package/rust/core/parser/handler/at.rs +55 -21
  132. package/rust/core/parser/handler/bank.rs +14 -4
  133. package/rust/core/parser/handler/condition.rs +6 -3
  134. package/rust/core/parser/handler/dot.rs +5 -3
  135. package/rust/core/parser/handler/identifier/automate.rs +13 -16
  136. package/rust/core/parser/handler/identifier/call.rs +4 -4
  137. package/rust/core/parser/handler/identifier/emit.rs +9 -5
  138. package/rust/core/parser/handler/identifier/function.rs +20 -7
  139. package/rust/core/parser/handler/identifier/group.rs +11 -7
  140. package/rust/core/parser/handler/identifier/let_.rs +24 -9
  141. package/rust/core/parser/handler/identifier/mod.rs +6 -5
  142. package/rust/core/parser/handler/identifier/on.rs +16 -7
  143. package/rust/core/parser/handler/identifier/print.rs +6 -9
  144. package/rust/core/parser/handler/identifier/sleep.rs +12 -5
  145. package/rust/core/parser/handler/identifier/spawn.rs +4 -4
  146. package/rust/core/parser/handler/identifier/synth.rs +79 -9
  147. package/rust/core/parser/handler/loop_.rs +38 -13
  148. package/rust/core/parser/handler/mod.rs +1 -0
  149. package/rust/core/parser/handler/pattern.rs +74 -0
  150. package/rust/core/parser/handler/tempo.rs +9 -5
  151. package/rust/core/parser/mod.rs +0 -1
  152. package/rust/core/parser/statement.rs +6 -137
  153. package/rust/core/plugin/loader.rs +41 -27
  154. package/rust/core/plugin/runner.rs +68 -17
  155. package/rust/core/preprocessor/loader.rs +181 -99
  156. package/rust/core/preprocessor/processor.rs +9 -9
  157. package/rust/core/preprocessor/resolver/bank.rs +6 -8
  158. package/rust/core/preprocessor/resolver/call.rs +47 -23
  159. package/rust/core/preprocessor/resolver/condition.rs +6 -8
  160. package/rust/core/preprocessor/resolver/driver.rs +28 -28
  161. package/rust/core/preprocessor/resolver/function.rs +6 -6
  162. package/rust/core/preprocessor/resolver/group.rs +6 -8
  163. package/rust/core/preprocessor/resolver/loop_.rs +8 -10
  164. package/rust/core/preprocessor/resolver/mod.rs +1 -0
  165. package/rust/core/preprocessor/resolver/pattern.rs +75 -0
  166. package/rust/core/preprocessor/resolver/spawn.rs +45 -22
  167. package/rust/core/preprocessor/resolver/synth.rs +6 -8
  168. package/rust/core/preprocessor/resolver/tempo.rs +6 -8
  169. package/rust/core/preprocessor/resolver/trigger.rs +22 -19
  170. package/rust/core/preprocessor/resolver/value.rs +99 -4
  171. package/rust/core/store/export.rs +28 -28
  172. package/rust/core/store/function.rs +6 -0
  173. package/rust/core/store/global.rs +7 -1
  174. package/rust/core/store/import.rs +28 -28
  175. package/rust/core/store/variable.rs +16 -2
  176. package/rust/core/utils/mod.rs +0 -1
  177. package/rust/lib.rs +102 -9
  178. package/rust/main.rs +159 -45
  179. package/rust/types/Cargo.toml +11 -0
  180. package/rust/types/src/addons.rs +55 -0
  181. package/rust/types/src/ast.rs +202 -0
  182. package/rust/types/src/config.rs +74 -0
  183. package/rust/types/src/lib.rs +12 -0
  184. package/rust/types/src/telemetry.rs +85 -0
  185. package/rust/utils/Cargo.toml +26 -0
  186. package/rust/utils/{error.rs → src/error.rs} +186 -200
  187. package/rust/utils/src/file.rs +94 -0
  188. package/rust/utils/src/first_usage.rs +97 -0
  189. package/rust/utils/{mod.rs → src/lib.rs} +1 -1
  190. package/rust/utils/{logger.rs → src/logger.rs} +17 -12
  191. package/rust/utils/src/path.rs +88 -0
  192. package/rust/utils/src/signature.rs +41 -0
  193. package/rust/utils/{spinner.rs → src/spinner.rs} +3 -5
  194. package/rust/utils/src/version.rs +27 -0
  195. package/rust/utils/{watcher.rs → src/watcher.rs} +13 -1
  196. package/rust/web/cdn.rs +34 -0
  197. package/templates/minimal/README.md +98 -54
  198. package/templates/welcome/README.md +98 -54
  199. package/templates/welcome/src/index.deva +56 -8
  200. package/templates/welcome/src/variables.deva +2 -4
  201. package/tests/rust/TODO.md +0 -0
  202. package/tests/typescript/index.spec.ts +136 -0
  203. package/tests/typescript/playhead.spec.ts +36 -0
  204. package/tests/typescript/render_e2e.spec.ts +77 -0
  205. package/tsconfig.json +1 -1
  206. package/typescript/core/functions/index.ts +83 -0
  207. package/typescript/core/index.ts +6 -0
  208. package/typescript/core/types/index.ts +4 -0
  209. package/typescript/core/types/plugin.ts +19 -0
  210. package/typescript/core/types/result.ts +29 -0
  211. package/typescript/core/types/statement.ts +47 -0
  212. package/typescript/core/types/value.ts +29 -0
  213. package/typescript/index.ts +7 -2
  214. package/typescript/pkg/devalang_core.d.ts +4 -0
  215. package/typescript/scripts/copy-wasm-dts.ts +41 -0
  216. package/rust/cli/bank.rs +0 -462
  217. package/rust/cli/build.rs +0 -252
  218. package/rust/cli/play.rs +0 -1123
  219. package/rust/common/cdn.rs +0 -5
  220. package/rust/config/loader.rs +0 -165
  221. package/rust/config/stats.rs +0 -257
  222. package/rust/core/audio/engine.rs +0 -696
  223. package/rust/core/shared/bank.rs +0 -21
  224. package/rust/core/shared/duration.rs +0 -9
  225. package/rust/core/shared/mod.rs +0 -3
  226. package/rust/core/shared/value.rs +0 -35
  227. package/rust/core/utils/validation.rs +0 -35
  228. package/rust/installer/addon.rs +0 -84
  229. package/rust/installer/bank.rs +0 -62
  230. package/rust/installer/plugin.rs +0 -54
  231. package/rust/installer/utils.rs +0 -56
  232. package/rust/utils/file.rs +0 -38
  233. package/rust/utils/first_usage.rs +0 -83
  234. package/rust/utils/signature.rs +0 -19
  235. package/rust/utils/telemetry.rs +0 -292
  236. package/rust/utils/version.rs +0 -15
  237. /package/rust/{common → web}/api.rs +0 -0
  238. /package/rust/{common → web}/mod.rs +0 -0
  239. /package/rust/{common → web}/sso.rs +0 -0
@@ -1,7 +1,8 @@
1
+ use devalang_types::{Duration, Value};
2
+
1
3
  use crate::core::{
2
4
  audio::{engine::AudioEngine, interpreter::driver::execute_audio_block},
3
5
  parser::statement::{Statement, StatementKind},
4
- shared::value::Value,
5
6
  store::{function::FunctionTable, global::GlobalStore, variable::VariableTable},
6
7
  };
7
8
 
@@ -16,83 +17,258 @@ pub fn interprete_call_statement(
16
17
  max_end_time: f32,
17
18
  cursor_time: f32,
18
19
  ) -> (f32, f32) {
19
- match &stmt.kind {
20
- StatementKind::Call { name, args } => {
21
- // Classic function call case
22
- if let Some(func) = functions.functions.get(name) {
23
- if func.parameters.len() != args.len() {
24
- eprintln!(
25
- "❌ Function '{}' expects {} args, got {}",
26
- name,
27
- func.parameters.len(),
28
- args.len()
20
+ if let StatementKind::Call { name, args } = &stmt.kind {
21
+ // Classic function call case
22
+ if let Some(func) = functions.functions.get(name) {
23
+ // function found
24
+ if func.parameters.len() != args.len() {
25
+ eprintln!(
26
+ "❌ Function '{}' expects {} args, got {}",
27
+ name,
28
+ func.parameters.len(),
29
+ args.len()
30
+ );
31
+ return (max_end_time, cursor_time);
32
+ }
33
+
34
+ let mut local_vars = VariableTable::with_parent(variable_table.clone());
35
+ for (param, arg) in func.parameters.iter().zip(args) {
36
+ local_vars.set(param.clone(), arg.clone());
37
+ }
38
+
39
+ return execute_audio_block(
40
+ audio_engine,
41
+ global_store,
42
+ local_vars,
43
+ functions.clone(),
44
+ &func.body,
45
+ base_bpm,
46
+ base_duration,
47
+ max_end_time,
48
+ cursor_time,
49
+ );
50
+ }
51
+
52
+ // Group case
53
+ if let Some(group_stmt) = find_group(name, variable_table, global_store) {
54
+ // group found
55
+ if let Value::Map(map) = &group_stmt.value {
56
+ if let Some(Value::Block(body)) = map.get("body") {
57
+ return execute_audio_block(
58
+ audio_engine,
59
+ global_store,
60
+ variable_table.clone(),
61
+ functions.clone(),
62
+ body,
63
+ base_bpm,
64
+ base_duration,
65
+ max_end_time,
66
+ cursor_time,
29
67
  );
30
- return (max_end_time, cursor_time);
31
68
  }
69
+ }
70
+ }
32
71
 
33
- let mut local_vars = VariableTable::with_parent(variable_table.clone());
34
- for (param, arg) in func.parameters.iter().zip(args) {
35
- local_vars.set(param.clone(), arg.clone());
72
+ // Pattern case
73
+ if let Some(pattern_stmt) = find_pattern(name, variable_table, global_store) {
74
+ // Extract pattern string from statement value
75
+ if let Value::String(pat) = &pattern_stmt.value {
76
+ // Determine target entity (explicit or inferred)
77
+ let mut target_entity = name.clone();
78
+ if let StatementKind::Pattern { name: _n, target } = &pattern_stmt.kind {
79
+ if let Some(t) = target {
80
+ target_entity = t.clone();
81
+ }
36
82
  }
37
83
 
38
- return execute_audio_block(
39
- audio_engine,
40
- global_store,
41
- local_vars,
42
- functions.clone(),
43
- &func.body,
44
- base_bpm,
45
- base_duration,
46
- max_end_time,
47
- cursor_time,
48
- );
49
- }
84
+ // Build a variable table snapshot for resolution like triggers do
85
+ // Preserve the full parent chain so lookups behave the same as runtime
86
+ fn clone_with_parents(orig: &crate::core::store::variable::VariableTable) -> crate::core::store::variable::VariableTable {
87
+ crate::core::store::variable::VariableTable {
88
+ variables: orig.variables.clone(),
89
+ parent: orig.parent.as_ref().map(|p| Box::new(clone_with_parents(p))),
90
+ }
91
+ }
92
+
93
+ let final_variable_table = clone_with_parents(variable_table);
94
+
95
+ // Normalize pattern: remove spaces and line breaks
96
+ let pattern_str: String = pat.chars().filter(|c| !c.is_whitespace()).collect();
97
+ if pattern_str.is_empty() {
98
+ return (max_end_time, cursor_time);
99
+ }
100
+
101
+ let step_count = pattern_str.len() as f32;
102
+ // Assume pattern spans one bar (4 beats)
103
+ let total_bar = 4.0 * base_duration;
104
+ let step_duration = total_bar / step_count; // seconds per step
105
+
106
+ let mut updated_max = max_end_time;
107
+
108
+ for (i, ch) in pattern_str.chars().enumerate() {
109
+ if ch == '-' {
110
+ continue; // rest
111
+ }
112
+
113
+ // Schedule a trigger at cursor_time + offset
114
+ let event_time = cursor_time + (i as f32) * step_duration;
115
+
116
+ // Resolve trigger value similarly to interprete_trigger_statement
117
+ let mut trigger_val = Value::String(target_entity.clone());
118
+ if let Some(val) = variable_table.variables.get(&target_entity) {
119
+ match val {
120
+ Value::Identifier(id) => {
121
+ // resolve from parent if available
122
+ if let Some(parent) = &variable_table.parent {
123
+ if let Some(v) = parent.get(id) {
124
+ trigger_val = v.clone();
125
+ }
126
+ } else if let Some(v) = variable_table.get(id) {
127
+ trigger_val = v.clone();
128
+ }
129
+ }
130
+ Value::Map(map) => {
131
+ if let Some(Value::String(src)) = map.get("entity") {
132
+ trigger_val = Value::String(src.clone());
133
+ } else if let Some(Value::Identifier(src)) = map.get("entity") {
134
+ trigger_val = Value::Identifier(src.clone());
135
+ }
136
+ }
137
+ Value::Sample(sample_src) => {
138
+ trigger_val = Value::Sample(sample_src.clone());
139
+ }
140
+ _ => {
141
+ // leave as string
142
+ }
143
+ }
144
+ }
145
+
146
+ // Use loader to get sample path and sample length
147
+ let (src, sample_length) =
148
+ crate::core::audio::loader::trigger::load_trigger(&trigger_val, &Duration::Number(step_duration), &None, base_duration, final_variable_table.clone());
149
+
150
+ let play_length = step_duration.min(sample_length);
151
+
152
+ let trigger_src = match trigger_val.get("entity") {
153
+ Some(Value::String(s)) => s.clone(),
154
+ Some(Value::Identifier(id)) => id.clone(),
155
+ Some(Value::Statement(stmt)) => {
156
+ if let StatementKind::Trigger { entity, .. } = &stmt.kind {
157
+ entity.clone()
158
+ } else {
159
+ src.clone()
160
+ }
161
+ }
162
+ _ => src.clone(),
163
+ };
164
+
165
+ audio_engine.insert_sample(&trigger_src, event_time, play_length, None, &final_variable_table);
50
166
 
51
- // Group case
52
- if let Some(group_stmt) = find_group(name, variable_table, global_store) {
53
- if let Value::Map(map) = &group_stmt.value {
54
- if let Some(Value::Block(body)) = map.get("body") {
55
- return execute_audio_block(
56
- audio_engine,
57
- global_store,
58
- variable_table.clone(),
59
- functions.clone(),
60
- &body,
61
- base_bpm,
62
- base_duration,
63
- max_end_time,
64
- cursor_time,
65
- );
167
+ let end_time = event_time + play_length;
168
+ if end_time > updated_max {
169
+ updated_max = end_time;
66
170
  }
67
171
  }
68
- }
69
172
 
70
- eprintln!("❌ Function or group '{}' not found", name);
173
+ return (updated_max, cursor_time);
174
+ }
71
175
  }
72
176
 
73
- _ => eprintln!(
74
- "❌ interprete_call_statement expected Call, got {:?}",
75
- stmt.kind
76
- ),
177
+ // Function or group not found; keep as debug-free fail path
77
178
  }
78
179
 
79
180
  (max_end_time, cursor_time)
80
181
  }
81
182
 
82
- fn find_group<'a>(
183
+ fn find_group(
83
184
  name: &str,
84
- variable_table: &'a VariableTable,
85
- global_store: &'a GlobalStore,
86
- ) -> Option<&'a Statement> {
185
+ variable_table: &VariableTable,
186
+ global_store: &GlobalStore,
187
+ ) -> Option<Statement> {
188
+ use crate::core::parser::statement::Statement;
189
+ use crate::core::parser::statement::StatementKind;
190
+
87
191
  if let Some(Value::Statement(stmt_box)) = variable_table.get(name) {
88
192
  if let StatementKind::Group = stmt_box.kind {
89
- return Some(stmt_box);
193
+ return Some(*stmt_box.clone());
90
194
  }
91
195
  }
92
- if let Some(Value::Statement(stmt_box)) = global_store.variables.variables.get(name) {
93
- if let StatementKind::Group = stmt_box.kind {
94
- return Some(stmt_box);
196
+
197
+ if let Some(val) = global_store.variables.variables.get(name) {
198
+ match val {
199
+ Value::Statement(stmt_box) => {
200
+ if let StatementKind::Group = stmt_box.kind {
201
+ return Some(*stmt_box.clone());
202
+ }
203
+ }
204
+ Value::Map(map) => {
205
+ // Try to rebuild a Group statement from the stored map
206
+ if let (Some(Value::String(_id)), Some(Value::Block(_body))) =
207
+ (map.get("identifier"), map.get("body"))
208
+ {
209
+ let stmt = Statement {
210
+ kind: StatementKind::Group,
211
+ value: Value::Map(map.clone()),
212
+ indent: 0,
213
+ line: 0,
214
+ column: 0,
215
+ };
216
+ return Some(stmt);
217
+ }
218
+ }
219
+ _ => {}
220
+ }
221
+ }
222
+
223
+ None
224
+ }
225
+
226
+ fn find_pattern(
227
+ name: &str,
228
+ variable_table: &VariableTable,
229
+ global_store: &GlobalStore,
230
+ ) -> Option<Statement> {
231
+ use crate::core::parser::statement::Statement;
232
+ use crate::core::parser::statement::StatementKind;
233
+
234
+ if let Some(Value::Statement(stmt_box)) = variable_table.get(name) {
235
+ if let StatementKind::Pattern { .. } = stmt_box.kind {
236
+ return Some(*stmt_box.clone());
95
237
  }
96
238
  }
239
+
240
+ if let Some(val) = global_store.variables.variables.get(name) {
241
+ match val {
242
+ Value::Statement(stmt_box) => {
243
+ if let StatementKind::Pattern { .. } = stmt_box.kind {
244
+ return Some(*stmt_box.clone());
245
+ }
246
+ }
247
+ Value::Map(map) => {
248
+ if let Some(Value::String(_pat)) = map.get("pattern") {
249
+ // Rebuild a Pattern statement from stored map if possible
250
+ let stmt = Statement {
251
+ kind: StatementKind::Pattern {
252
+ name: name.to_string(),
253
+ target: map.get("target").and_then(|v| match v {
254
+ Value::String(s) => Some(s.clone()),
255
+ _ => None,
256
+ }),
257
+ },
258
+ value: Value::String(map.get("pattern").and_then(|v| match v {
259
+ Value::String(s) => Some(s.clone()),
260
+ _ => None,
261
+ }).unwrap_or_default()),
262
+ indent: 0,
263
+ line: 0,
264
+ column: 0,
265
+ };
266
+ return Some(stmt);
267
+ }
268
+ }
269
+ _ => {}
270
+ }
271
+ }
272
+
97
273
  None
98
274
  }
@@ -1,10 +1,11 @@
1
+ use devalang_types::Value;
2
+
1
3
  use crate::core::{
2
4
  audio::{
3
5
  engine::AudioEngine, evaluator::evaluate_condition_string,
4
6
  interpreter::driver::execute_audio_block,
5
7
  },
6
8
  parser::statement::Statement,
7
- shared::value::Value,
8
9
  store::{function::FunctionTable, global::GlobalStore, variable::VariableTable},
9
10
  };
10
11
 
@@ -43,7 +44,7 @@ pub fn interprete_condition_statement(
43
44
  global_store,
44
45
  variable_table.clone(),
45
46
  functions_table.clone(),
46
- &block,
47
+ block,
47
48
  base_bpm,
48
49
  base_duration,
49
50
  max_time,