@devaloop/devalang 0.0.1-alpha.9 → 0.0.1-beta.1
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.
- package/.cargo/config.toml +2 -0
- package/.devalang +10 -4
- package/.github/workflows/ci.yml +103 -0
- package/Cargo.toml +80 -48
- package/README.md +135 -154
- package/docs/CHANGELOG.md +386 -1
- package/docs/CONTRIBUTING.md +101 -0
- package/docs/ROADMAP.md +10 -7
- package/docs/TODO.md +21 -9
- package/examples/automation.deva +42 -0
- package/examples/bank.deva +7 -0
- package/examples/duration.deva +9 -0
- package/examples/events.deva +12 -0
- package/examples/function.deva +15 -0
- package/examples/index.deva +57 -12
- package/examples/loop.deva +5 -12
- package/examples/pattern.deva +8 -0
- package/examples/plugin.deva +16 -0
- package/examples/variables.deva +1 -1
- package/out-tsc/bin/index.d.ts +2 -0
- package/out-tsc/bin/index.js +51 -7
- package/out-tsc/core/functions/index.d.ts +37 -0
- package/out-tsc/core/functions/index.js +76 -0
- package/out-tsc/core/index.d.ts +6 -0
- package/out-tsc/core/index.js +22 -0
- package/out-tsc/core/types/index.d.ts +4 -0
- package/out-tsc/core/types/index.js +20 -0
- package/out-tsc/core/types/plugin.d.ts +18 -0
- package/out-tsc/core/types/plugin.js +2 -0
- package/out-tsc/core/types/result.d.ts +27 -0
- package/out-tsc/core/types/result.js +2 -0
- package/out-tsc/core/types/statement.d.ts +106 -0
- package/out-tsc/core/types/statement.js +2 -0
- package/out-tsc/core/types/value.d.ts +43 -0
- package/out-tsc/core/types/value.js +2 -0
- package/out-tsc/index.d.ts +7 -0
- package/out-tsc/index.js +42 -1
- package/out-tsc/pkg/devalang_core.d.ts +13 -0
- package/out-tsc/pkg/devalang_core.js +50 -0
- package/out-tsc/pkg/devalang_core_bg.wasm.d.ts +33 -0
- package/out-tsc/scripts/copy-wasm-dts.d.ts +1 -0
- package/out-tsc/scripts/copy-wasm-dts.js +73 -0
- package/out-tsc/scripts/postinstall.d.ts +1 -0
- package/out-tsc/scripts/postinstall.js +83 -0
- package/out-tsc/scripts/version/bump.d.ts +1 -0
- package/out-tsc/scripts/version/fetch.d.ts +1 -0
- package/out-tsc/scripts/version/index.d.ts +1 -0
- package/out-tsc/scripts/version/sync.d.ts +1 -0
- package/package.json +28 -7
- package/project-version.json +4 -4
- package/rust/cli/bank/api.rs +122 -0
- package/rust/cli/bank/commands.rs +275 -0
- package/rust/cli/bank/mod.rs +29 -0
- package/rust/cli/build/commands.rs +103 -0
- package/rust/cli/build/mod.rs +2 -0
- package/rust/cli/build/process.rs +146 -0
- package/rust/cli/check/mod.rs +208 -0
- package/rust/cli/discover/commands.rs +253 -0
- package/rust/cli/discover/config.rs +111 -0
- package/rust/cli/discover/fs.rs +19 -0
- package/rust/cli/discover/install.rs +103 -0
- package/rust/cli/discover/metadata.rs +48 -0
- package/rust/cli/discover/mod.rs +5 -0
- package/rust/cli/{init.rs → init/commands.rs} +32 -23
- package/rust/cli/init/mod.rs +1 -0
- package/rust/cli/install/addon.rs +118 -0
- package/rust/cli/install/bank.rs +53 -0
- package/rust/cli/install/commands.rs +35 -0
- package/rust/cli/install/mod.rs +4 -0
- package/rust/cli/install/plugin.rs +61 -0
- package/rust/cli/login/commands.rs +124 -0
- package/rust/cli/login/mod.rs +1 -0
- package/rust/cli/mod.rs +12 -205
- package/rust/cli/parser.rs +314 -0
- package/rust/cli/play/commands.rs +324 -0
- package/rust/cli/play/io.rs +17 -0
- package/rust/cli/play/mod.rs +5 -0
- package/rust/cli/play/process.rs +150 -0
- package/rust/cli/play/realtime.rs +91 -0
- package/rust/cli/play/utils.rs +23 -0
- package/rust/cli/telemetry/commands.rs +22 -0
- package/rust/cli/telemetry/event_creator.rs +80 -0
- package/rust/cli/telemetry/mod.rs +3 -0
- package/rust/cli/telemetry/send.rs +51 -0
- package/rust/cli/{template.rs → template/commands.rs} +69 -57
- package/rust/cli/template/mod.rs +1 -0
- package/rust/cli/update/commands.rs +6 -0
- package/rust/cli/update/mod.rs +1 -0
- package/rust/config/driver.rs +103 -0
- package/rust/config/mod.rs +3 -16
- package/rust/config/ops.rs +26 -0
- package/rust/config/settings.rs +101 -0
- package/rust/core/audio/engine/helpers.rs +170 -0
- package/rust/core/audio/engine/mod.rs +7 -0
- package/rust/core/audio/engine/sample.rs +366 -0
- package/rust/core/audio/engine/synth.rs +325 -0
- package/rust/core/audio/evaluator.rs +310 -31
- package/rust/core/audio/interpreter/arrow_call.rs +311 -129
- package/rust/core/audio/interpreter/automate.rs +18 -0
- package/rust/core/audio/interpreter/call.rs +294 -64
- package/rust/core/audio/interpreter/condition.rs +71 -69
- package/rust/core/audio/interpreter/driver.rs +542 -216
- package/rust/core/audio/interpreter/function.rs +26 -0
- package/rust/core/audio/interpreter/let_.rs +38 -19
- package/rust/core/audio/interpreter/load.rs +19 -18
- package/rust/core/audio/interpreter/loop_.rs +114 -67
- package/rust/core/audio/interpreter/mod.rs +14 -12
- package/rust/core/audio/interpreter/sleep.rs +28 -36
- package/rust/core/audio/interpreter/spawn.rs +252 -66
- package/rust/core/audio/interpreter/tempo.rs +40 -16
- package/rust/core/audio/interpreter/trigger.rs +239 -69
- package/rust/core/audio/loader/mod.rs +1 -1
- package/rust/core/audio/loader/trigger.rs +97 -52
- package/rust/core/audio/mod.rs +7 -6
- package/rust/core/audio/player.rs +70 -54
- package/rust/core/audio/renderer.rs +54 -54
- package/rust/core/audio/special/easing.rs +189 -0
- package/rust/core/audio/special/env.rs +45 -0
- package/rust/core/audio/special/math.rs +134 -0
- package/rust/core/audio/special/mod.rs +9 -0
- package/rust/core/audio/special/modulator.rs +143 -0
- package/rust/core/builder/mod.rs +86 -80
- package/rust/core/debugger/lexer.rs +27 -27
- package/rust/core/debugger/mod.rs +30 -21
- package/rust/core/debugger/module.rs +55 -0
- package/rust/core/debugger/preprocessor.rs +27 -27
- package/rust/core/debugger/store.rs +40 -25
- package/rust/core/error/mod.rs +269 -60
- package/rust/core/lexer/driver.rs +61 -0
- package/rust/core/lexer/handler/arrow.rs +82 -31
- package/rust/core/lexer/handler/at.rs +21 -21
- package/rust/core/lexer/handler/brace.rs +41 -41
- package/rust/core/lexer/handler/colon.rs +21 -21
- package/rust/core/lexer/handler/comment.rs +30 -30
- package/rust/core/lexer/handler/dot.rs +21 -21
- package/rust/core/lexer/handler/driver.rs +337 -226
- package/rust/core/lexer/handler/identifier.rs +47 -41
- package/rust/core/lexer/handler/indent.rs +66 -52
- package/rust/core/lexer/handler/mod.rs +15 -14
- package/rust/core/lexer/handler/newline.rs +23 -23
- package/rust/core/lexer/handler/number.rs +31 -31
- package/rust/core/lexer/handler/operator.rs +46 -44
- package/rust/core/lexer/handler/parenthesis.rs +41 -0
- package/rust/core/lexer/handler/slash.rs +21 -0
- package/rust/core/lexer/handler/string.rs +63 -63
- package/rust/core/lexer/mod.rs +3 -51
- package/rust/core/lexer/token.rs +17 -12
- package/rust/core/mod.rs +10 -10
- package/rust/core/parser/driver.rs +584 -331
- package/rust/core/parser/handler/arrow_call.rs +253 -126
- package/rust/core/parser/handler/at.rs +279 -162
- package/rust/core/parser/handler/bank.rs +104 -41
- package/rust/core/parser/handler/condition.rs +83 -74
- package/rust/core/parser/handler/dot.rs +148 -112
- package/rust/core/parser/handler/identifier/automate.rs +254 -0
- package/rust/core/parser/handler/identifier/call.rs +91 -41
- package/rust/core/parser/handler/identifier/emit.rs +70 -0
- package/rust/core/parser/handler/identifier/function.rs +113 -0
- package/rust/core/parser/handler/identifier/group.rs +89 -75
- package/rust/core/parser/handler/identifier/let_.rs +173 -133
- package/rust/core/parser/handler/identifier/mod.rs +55 -51
- package/rust/core/parser/handler/identifier/on.rs +107 -0
- package/rust/core/parser/handler/identifier/print.rs +49 -0
- package/rust/core/parser/handler/identifier/sleep.rs +43 -33
- package/rust/core/parser/handler/identifier/spawn.rs +91 -41
- package/rust/core/parser/handler/identifier/synth.rs +135 -65
- package/rust/core/parser/handler/loop_.rs +194 -72
- package/rust/core/parser/handler/mod.rs +9 -8
- package/rust/core/parser/handler/pattern.rs +74 -0
- package/rust/core/parser/handler/tempo.rs +57 -47
- package/rust/core/parser/mod.rs +3 -4
- package/rust/core/parser/statement.rs +11 -96
- package/rust/core/plugin/loader.rs +137 -0
- package/rust/core/plugin/mod.rs +2 -0
- package/rust/core/plugin/runner.rs +347 -0
- package/rust/core/preprocessor/loader.rs +637 -193
- package/rust/core/preprocessor/mod.rs +4 -4
- package/rust/core/preprocessor/module.rs +60 -50
- package/rust/core/preprocessor/processor.rs +114 -76
- package/rust/core/preprocessor/resolver/bank.rs +49 -47
- package/rust/core/preprocessor/resolver/call.rs +124 -123
- package/rust/core/preprocessor/resolver/condition.rs +95 -92
- package/rust/core/preprocessor/resolver/driver.rs +324 -227
- package/rust/core/preprocessor/resolver/function.rs +69 -0
- package/rust/core/preprocessor/resolver/group.rs +94 -61
- package/rust/core/preprocessor/resolver/let_.rs +32 -31
- package/rust/core/preprocessor/resolver/loop_.rs +318 -91
- package/rust/core/preprocessor/resolver/mod.rs +16 -14
- package/rust/core/preprocessor/resolver/pattern.rs +83 -0
- package/rust/core/preprocessor/resolver/spawn.rs +99 -58
- package/rust/core/preprocessor/resolver/synth.rs +54 -50
- package/rust/core/preprocessor/resolver/tempo.rs +48 -49
- package/rust/core/preprocessor/resolver/trigger.rs +116 -112
- package/rust/core/preprocessor/resolver/value.rs +176 -78
- package/rust/core/store/export.rs +28 -28
- package/rust/core/store/function.rs +40 -0
- package/rust/core/store/global.rs +61 -39
- package/rust/core/store/import.rs +28 -28
- package/rust/core/store/mod.rs +5 -4
- package/rust/core/store/variable.rs +51 -28
- package/rust/core/utils/mod.rs +1 -2
- package/rust/core/utils/path.rs +37 -31
- package/rust/lib.rs +308 -117
- package/rust/main.rs +364 -65
- package/rust/types/Cargo.toml +11 -0
- package/rust/types/src/addons.rs +55 -0
- package/rust/types/src/ast.rs +202 -0
- package/rust/types/src/config.rs +74 -0
- package/rust/types/src/lib.rs +12 -0
- package/rust/types/src/telemetry.rs +85 -0
- package/rust/utils/Cargo.toml +26 -0
- package/rust/utils/src/error.rs +186 -0
- package/rust/utils/src/file.rs +94 -0
- package/rust/utils/src/first_usage.rs +97 -0
- package/rust/utils/{mod.rs → src/lib.rs} +9 -6
- package/rust/utils/{logger.rs → src/logger.rs} +200 -123
- package/rust/utils/src/path.rs +88 -0
- package/rust/utils/src/signature.rs +41 -0
- package/rust/utils/{spinner.rs → src/spinner.rs} +20 -21
- package/rust/utils/src/version.rs +27 -0
- package/rust/utils/{watcher.rs → src/watcher.rs} +46 -33
- package/rust/web/api.rs +5 -0
- package/rust/web/cdn.rs +34 -0
- package/rust/web/mod.rs +3 -0
- package/rust/web/sso.rs +5 -0
- package/templates/minimal/README.md +143 -127
- package/templates/welcome/README.md +143 -127
- package/templates/welcome/src/index.deva +56 -8
- package/templates/welcome/src/variables.deva +2 -4
- package/tests/integration.rs +21 -0
- package/tests/rust/cli_check_build.rs +21 -0
- package/tests/rust/cli_help.rs +12 -0
- package/tests/rust/cli_template_list.rs +10 -0
- package/tests/rust/cli_version.rs +11 -0
- package/tests/typescript/index.spec.ts +136 -0
- package/tests/typescript/playhead.spec.ts +36 -0
- package/tests/typescript/render_e2e.spec.ts +77 -0
- package/tsconfig.json +12 -10
- package/typescript/bin/index.ts +19 -5
- package/typescript/core/functions/index.ts +83 -0
- package/typescript/core/index.ts +6 -0
- package/typescript/core/types/index.ts +4 -0
- package/typescript/core/types/plugin.ts +19 -0
- package/typescript/core/types/result.ts +29 -0
- package/typescript/core/types/statement.ts +47 -0
- package/typescript/core/types/value.ts +29 -0
- package/typescript/index.ts +8 -1
- package/typescript/pkg/devalang_core.d.ts +4 -0
- package/typescript/pkg/devalang_core.ts +49 -0
- package/typescript/scripts/copy-wasm-dts.ts +41 -0
- package/typescript/scripts/postinstall.ts +85 -0
- package/typescript/scripts/version/bump.ts +0 -1
- package/typescript/scripts/version/index.ts +0 -1
- package/docs/COMMANDS.md +0 -85
- package/docs/CONFIG.md +0 -30
- package/docs/SYNTAX.md +0 -210
- package/out-tsc/bin/devalang.exe +0 -0
- package/out-tsc/scripts/postbuild.js +0 -11
- package/rust/cli/build.rs +0 -137
- package/rust/cli/check.rs +0 -117
- package/rust/cli/play.rs +0 -193
- package/rust/config/loader.rs +0 -13
- package/rust/core/audio/engine.rs +0 -203
- package/rust/core/shared/duration.rs +0 -8
- package/rust/core/shared/mod.rs +0 -2
- package/rust/core/shared/value.rs +0 -18
- package/rust/core/utils/validation.rs +0 -37
- package/rust/utils/file.rs +0 -35
- package/rust/utils/signature.rs +0 -17
- package/rust/utils/version.rs +0 -15
- package/typescript/scripts/postbuild.ts +0 -8
|
@@ -1,193 +1,637 @@
|
|
|
1
|
-
|
|
2
|
-
use crate::{
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
},
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
pub
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
module
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
let
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
let
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
//
|
|
138
|
-
let mut
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
module
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
.
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
1
|
+
#[cfg(feature = "cli")]
|
|
2
|
+
use crate::core::preprocessor::resolver::driver::{
|
|
3
|
+
resolve_all_modules, resolve_and_flatten_all_modules,
|
|
4
|
+
};
|
|
5
|
+
#[cfg(feature = "cli")]
|
|
6
|
+
use crate::core::utils::path::resolve_relative_path;
|
|
7
|
+
#[cfg_attr(not(feature = "cli"), allow(unused_imports))]
|
|
8
|
+
use crate::core::{
|
|
9
|
+
error::ErrorHandler,
|
|
10
|
+
lexer::{driver::Lexer, token::Token},
|
|
11
|
+
parser::{
|
|
12
|
+
driver::Parser,
|
|
13
|
+
statement::{Statement, StatementKind},
|
|
14
|
+
},
|
|
15
|
+
plugin::loader::load_plugin,
|
|
16
|
+
preprocessor::{module::Module, processor::process_modules},
|
|
17
|
+
store::global::GlobalStore,
|
|
18
|
+
utils::path::normalize_path,
|
|
19
|
+
};
|
|
20
|
+
use devalang_types::{BankFile, Value};
|
|
21
|
+
#[cfg(feature = "cli")]
|
|
22
|
+
use devalang_utils::logger::{LogLevel, Logger};
|
|
23
|
+
use std::{collections::HashMap, path::Path};
|
|
24
|
+
|
|
25
|
+
pub struct ModuleLoader {
|
|
26
|
+
pub entry: String,
|
|
27
|
+
pub output: String,
|
|
28
|
+
pub base_dir: String,
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
impl ModuleLoader {
|
|
32
|
+
pub fn new(entry: &str, output: &str) -> Self {
|
|
33
|
+
let base_dir = Path::new(entry)
|
|
34
|
+
.parent()
|
|
35
|
+
.unwrap_or(Path::new(""))
|
|
36
|
+
.to_string_lossy()
|
|
37
|
+
.replace('\\', "/");
|
|
38
|
+
|
|
39
|
+
Self {
|
|
40
|
+
entry: entry.to_string(),
|
|
41
|
+
output: output.to_string(),
|
|
42
|
+
base_dir,
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
pub fn from_raw_source(
|
|
47
|
+
entry_path: &str,
|
|
48
|
+
output_path: &str,
|
|
49
|
+
content: &str,
|
|
50
|
+
global_store: &mut GlobalStore,
|
|
51
|
+
) -> Self {
|
|
52
|
+
let normalized_entry_path = normalize_path(entry_path);
|
|
53
|
+
|
|
54
|
+
let mut module = Module::new(entry_path);
|
|
55
|
+
module.content = content.to_string();
|
|
56
|
+
|
|
57
|
+
// Insert a module stub containing the provided content into the
|
|
58
|
+
// global store. This is used by the WASM APIs and tests which
|
|
59
|
+
// operate on in-memory sources instead of files on disk.
|
|
60
|
+
global_store.insert_module(normalized_entry_path.to_string(), module);
|
|
61
|
+
|
|
62
|
+
Self {
|
|
63
|
+
entry: normalized_entry_path.to_string(),
|
|
64
|
+
output: output_path.to_string(),
|
|
65
|
+
base_dir: "".to_string(),
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
pub fn extract_statements_map(
|
|
70
|
+
&self,
|
|
71
|
+
global_store: &GlobalStore,
|
|
72
|
+
) -> HashMap<String, Vec<Statement>> {
|
|
73
|
+
global_store
|
|
74
|
+
.modules
|
|
75
|
+
.iter()
|
|
76
|
+
.map(|(path, module)| (path.clone(), module.statements.clone()))
|
|
77
|
+
.collect()
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
pub fn load_single_module(&self, global_store: &mut GlobalStore) -> Result<Module, String> {
|
|
81
|
+
let mut module = global_store
|
|
82
|
+
.modules
|
|
83
|
+
.remove(&self.entry)
|
|
84
|
+
.ok_or_else(|| format!("Module not found in store for path: {}", self.entry))?;
|
|
85
|
+
|
|
86
|
+
// SECTION Lexing the module content
|
|
87
|
+
let lexer = Lexer::new();
|
|
88
|
+
let tokens = lexer
|
|
89
|
+
.lex_from_source(&module.content)
|
|
90
|
+
.map_err(|e| format!("Lexer failed: {}", e))?;
|
|
91
|
+
|
|
92
|
+
module.tokens = tokens.clone();
|
|
93
|
+
|
|
94
|
+
// SECTION Parsing tokens into statements
|
|
95
|
+
let mut parser = Parser::new();
|
|
96
|
+
parser.set_current_module(self.entry.clone());
|
|
97
|
+
let statements = parser.parse_tokens(tokens, global_store);
|
|
98
|
+
module.statements = statements;
|
|
99
|
+
|
|
100
|
+
// SECTION Injecting bank triggers if any (legacy default for single-module run)
|
|
101
|
+
if let Err(e) = self.inject_bank_triggers(&mut module, "808", None) {
|
|
102
|
+
return Err(format!("Failed to inject bank triggers: {}", e));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
for (plugin_name, alias) in self.extract_plugin_uses(&module.statements) {
|
|
106
|
+
self.load_plugin_and_register(&mut module, &plugin_name, &alias, global_store);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
global_store
|
|
110
|
+
.modules
|
|
111
|
+
.insert(self.entry.clone(), module.clone());
|
|
112
|
+
|
|
113
|
+
// SECTION Error handling
|
|
114
|
+
let mut error_handler = ErrorHandler::new();
|
|
115
|
+
error_handler.detect_from_statements(&mut parser, &module.statements);
|
|
116
|
+
|
|
117
|
+
Ok(module)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
pub fn load_wasm_module(&self, global_store: &mut GlobalStore) -> Result<(), String> {
|
|
121
|
+
// Step one : Load the module from the global store
|
|
122
|
+
let module = {
|
|
123
|
+
let module_ref = global_store
|
|
124
|
+
.modules
|
|
125
|
+
.get(&self.entry)
|
|
126
|
+
.ok_or_else(|| format!("❌ Module not found for path: {}", self.entry))?;
|
|
127
|
+
|
|
128
|
+
Module::from_existing(&self.entry, module_ref.content.clone())
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// Step two : lexing
|
|
132
|
+
let lexer = Lexer::new();
|
|
133
|
+
let tokens = lexer
|
|
134
|
+
.lex_from_source(&module.content)
|
|
135
|
+
.map_err(|e| format!("Lexer failed: {}", e))?;
|
|
136
|
+
|
|
137
|
+
// Step three : parsing
|
|
138
|
+
let mut parser = Parser::new();
|
|
139
|
+
parser.set_current_module(self.entry.clone());
|
|
140
|
+
|
|
141
|
+
let statements = parser.parse_tokens(tokens.clone(), global_store);
|
|
142
|
+
|
|
143
|
+
let mut updated_module = module;
|
|
144
|
+
updated_module.tokens = tokens;
|
|
145
|
+
updated_module.statements = statements;
|
|
146
|
+
|
|
147
|
+
// Step four : Injecting bank triggers if any
|
|
148
|
+
if let Err(e) = self.inject_bank_triggers(&mut updated_module, "808", None) {
|
|
149
|
+
return Err(format!("Failed to inject bank triggers: {}", e));
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Insert the updated module into the global store before processing so
|
|
153
|
+
// process_modules can operate on it and populate variable_table, imports,
|
|
154
|
+
// and other derived structures.
|
|
155
|
+
global_store
|
|
156
|
+
.modules
|
|
157
|
+
.insert(self.entry.clone(), updated_module.clone());
|
|
158
|
+
|
|
159
|
+
// Process modules to populate module.variable_table, import/export tables,
|
|
160
|
+
// and other derived structures so runtime execution can resolve groups/synths.
|
|
161
|
+
process_modules(self, global_store);
|
|
162
|
+
|
|
163
|
+
for (plugin_name, alias) in self.extract_plugin_uses(&updated_module.statements) {
|
|
164
|
+
self.load_plugin_and_register(&mut updated_module, &plugin_name, &alias, global_store);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Step four : error handling
|
|
168
|
+
let mut error_handler = ErrorHandler::new();
|
|
169
|
+
error_handler.detect_from_statements(&mut parser, &updated_module.statements);
|
|
170
|
+
|
|
171
|
+
// Final step : also expose module-level variables and functions into the global store
|
|
172
|
+
// so runtime evaluation (render_audio) can find group/synth definitions.
|
|
173
|
+
// Use the module instance that was actually processed by `process_modules`
|
|
174
|
+
// (it lives in `global_store.modules`) because `updated_module` is a local
|
|
175
|
+
// clone and won't contain the mutations applied by `process_modules`.
|
|
176
|
+
if let Some(stored_module) = global_store.modules.get(&self.entry) {
|
|
177
|
+
global_store
|
|
178
|
+
.variables
|
|
179
|
+
.variables
|
|
180
|
+
.extend(stored_module.variable_table.variables.clone());
|
|
181
|
+
global_store
|
|
182
|
+
.functions
|
|
183
|
+
.functions
|
|
184
|
+
.extend(stored_module.function_table.functions.clone());
|
|
185
|
+
} else {
|
|
186
|
+
// Fallback to the local updated_module if for any reason the module
|
|
187
|
+
// wasn't inserted into the store (defensive programming).
|
|
188
|
+
global_store
|
|
189
|
+
.variables
|
|
190
|
+
.variables
|
|
191
|
+
.extend(updated_module.variable_table.variables.clone());
|
|
192
|
+
global_store
|
|
193
|
+
.functions
|
|
194
|
+
.functions
|
|
195
|
+
.extend(updated_module.function_table.functions.clone());
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
Ok(())
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
#[cfg(feature = "cli")]
|
|
202
|
+
pub fn load_all_modules(
|
|
203
|
+
&self,
|
|
204
|
+
global_store: &mut GlobalStore,
|
|
205
|
+
) -> (HashMap<String, Vec<Token>>, HashMap<String, Vec<Statement>>) {
|
|
206
|
+
// SECTION Load the entry module and its dependencies
|
|
207
|
+
let tokens_by_module = self.load_module_recursively(&self.entry, global_store);
|
|
208
|
+
|
|
209
|
+
// SECTION Process and resolve modules
|
|
210
|
+
process_modules(self, global_store);
|
|
211
|
+
resolve_all_modules(self, global_store);
|
|
212
|
+
|
|
213
|
+
// SECTION Flatten all modules to get statements (+ injects)
|
|
214
|
+
let statements_by_module = resolve_and_flatten_all_modules(global_store);
|
|
215
|
+
|
|
216
|
+
(tokens_by_module, statements_by_module)
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
#[cfg(feature = "cli")]
|
|
220
|
+
fn load_module_recursively(
|
|
221
|
+
&self,
|
|
222
|
+
raw_path: &str,
|
|
223
|
+
global_store: &mut GlobalStore,
|
|
224
|
+
) -> HashMap<String, Vec<Token>> {
|
|
225
|
+
let path = normalize_path(raw_path);
|
|
226
|
+
|
|
227
|
+
// Check if already loaded
|
|
228
|
+
if global_store.modules.contains_key(&path) {
|
|
229
|
+
return HashMap::new();
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
let lexer = Lexer::new();
|
|
233
|
+
let tokens = match lexer.lex_tokens(&path) {
|
|
234
|
+
Ok(t) => t,
|
|
235
|
+
Err(e) => {
|
|
236
|
+
let logger = Logger::new();
|
|
237
|
+
logger.log_message(LogLevel::Error, &format!("Failed to lex '{}': {}", path, e));
|
|
238
|
+
return HashMap::new();
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
let mut parser = Parser::new();
|
|
243
|
+
parser.set_current_module(path.clone());
|
|
244
|
+
|
|
245
|
+
let statements = parser.parse_tokens(tokens.clone(), global_store);
|
|
246
|
+
|
|
247
|
+
// Insert module into store
|
|
248
|
+
let mut module = Module::new(&path);
|
|
249
|
+
module.tokens = tokens.clone();
|
|
250
|
+
module.statements = statements.clone();
|
|
251
|
+
|
|
252
|
+
// Inject triggers for each bank used in module, respecting aliases
|
|
253
|
+
for (bank_name, alias_opt) in self.extract_bank_decls(&statements) {
|
|
254
|
+
if let Err(e) = self.inject_bank_triggers(&mut module, &bank_name, alias_opt) {
|
|
255
|
+
eprintln!("Failed to inject bank triggers for '{}': {}", bank_name, e);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
for (plugin_name, alias) in self.extract_plugin_uses(&statements) {
|
|
260
|
+
self.load_plugin_and_register(&mut module, &plugin_name, &alias, global_store);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// Inject module variables and functions into global store
|
|
264
|
+
global_store
|
|
265
|
+
.variables
|
|
266
|
+
.variables
|
|
267
|
+
.extend(module.variable_table.variables.clone());
|
|
268
|
+
global_store
|
|
269
|
+
.functions
|
|
270
|
+
.functions
|
|
271
|
+
.extend(module.function_table.functions.clone());
|
|
272
|
+
|
|
273
|
+
// Inject the module into the global store
|
|
274
|
+
global_store.insert_module(path.clone(), module);
|
|
275
|
+
|
|
276
|
+
// Load dependencies
|
|
277
|
+
self.load_module_imports(&path, global_store);
|
|
278
|
+
|
|
279
|
+
// Error handling (use the module now in the store to include injected errors)
|
|
280
|
+
let mut error_handler = ErrorHandler::new();
|
|
281
|
+
if let Some(current_module) = global_store.modules.get(&path) {
|
|
282
|
+
error_handler.detect_from_statements(&mut parser, ¤t_module.statements);
|
|
283
|
+
} else {
|
|
284
|
+
error_handler.detect_from_statements(&mut parser, &statements);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
if error_handler.has_errors() {
|
|
288
|
+
let logger = Logger::new();
|
|
289
|
+
for error in error_handler.get_errors() {
|
|
290
|
+
let trace = format!("{}:{}:{}", path, error.line, error.column);
|
|
291
|
+
logger.log_error_with_stacktrace(&error.message, &trace);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// Return tokens per module
|
|
296
|
+
global_store
|
|
297
|
+
.modules
|
|
298
|
+
.iter()
|
|
299
|
+
.map(|(p, m)| (p.clone(), m.tokens.clone()))
|
|
300
|
+
.collect()
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
#[cfg(feature = "cli")]
|
|
304
|
+
fn load_module_imports(&self, path: &String, global_store: &mut GlobalStore) {
|
|
305
|
+
let import_paths: Vec<String> = {
|
|
306
|
+
let current_module = match global_store.modules.get(path) {
|
|
307
|
+
Some(module) => module,
|
|
308
|
+
None => {
|
|
309
|
+
eprintln!(
|
|
310
|
+
"[warn] Cannot resolve imports: module '{}' not found in store",
|
|
311
|
+
path
|
|
312
|
+
);
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
current_module
|
|
318
|
+
.statements
|
|
319
|
+
.iter()
|
|
320
|
+
.filter_map(|stmt| {
|
|
321
|
+
if let StatementKind::Import { source, .. } = &stmt.kind {
|
|
322
|
+
Some(source.clone())
|
|
323
|
+
} else {
|
|
324
|
+
None
|
|
325
|
+
}
|
|
326
|
+
})
|
|
327
|
+
.collect()
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
for import_path in import_paths {
|
|
331
|
+
let resolved = resolve_relative_path(path, &import_path);
|
|
332
|
+
self.load_module_recursively(&resolved, global_store);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
pub fn inject_bank_triggers(
|
|
337
|
+
&self,
|
|
338
|
+
module: &mut Module,
|
|
339
|
+
bank_name: &str,
|
|
340
|
+
alias_override: Option<String>,
|
|
341
|
+
) -> Result<Module, String> {
|
|
342
|
+
let default_alias = bank_name
|
|
343
|
+
.split('.')
|
|
344
|
+
.next_back()
|
|
345
|
+
.unwrap_or(bank_name)
|
|
346
|
+
.to_string();
|
|
347
|
+
let alias_ref = alias_override.as_deref().unwrap_or(&default_alias);
|
|
348
|
+
|
|
349
|
+
let bank_path = match devalang_utils::path::get_deva_dir() {
|
|
350
|
+
Ok(dir) => dir.join("banks").join(bank_name),
|
|
351
|
+
Err(_) => Path::new("./.deva").join("banks").join(bank_name),
|
|
352
|
+
};
|
|
353
|
+
let bank_toml_path = bank_path.join("bank.toml");
|
|
354
|
+
|
|
355
|
+
if !bank_toml_path.exists() {
|
|
356
|
+
return Ok(module.clone());
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
let content = std::fs::read_to_string(&bank_toml_path)
|
|
360
|
+
.map_err(|e| format!("Failed to read '{}': {}", bank_toml_path.display(), e))?;
|
|
361
|
+
|
|
362
|
+
let parsed_bankfile: BankFile = toml::from_str(&content)
|
|
363
|
+
.map_err(|e| format!("Failed to parse '{}': {}", bank_toml_path.display(), e))?;
|
|
364
|
+
|
|
365
|
+
let mut bank_map = HashMap::new();
|
|
366
|
+
|
|
367
|
+
for bank_trigger in parsed_bankfile.triggers.unwrap_or_default() {
|
|
368
|
+
// Use the configured path from the bank file as the entity reference so
|
|
369
|
+
// that bank entries can point to files or nested paths. Clean common
|
|
370
|
+
// local prefixes like "./" to keep the URI tidy.
|
|
371
|
+
let entity_ref = bank_trigger
|
|
372
|
+
.path
|
|
373
|
+
.clone()
|
|
374
|
+
.replace("\\", "/")
|
|
375
|
+
.replace("./", "");
|
|
376
|
+
let bank_trigger_path = format!("devalang://bank/{}/{}", bank_name, entity_ref);
|
|
377
|
+
|
|
378
|
+
// Keep the trigger key as declared (bank_trigger.name) but expose its
|
|
379
|
+
// value as a devalang://bank URI pointing to the configured path.
|
|
380
|
+
bank_map.insert(
|
|
381
|
+
bank_trigger.name.clone(),
|
|
382
|
+
Value::String(bank_trigger_path.clone()),
|
|
383
|
+
);
|
|
384
|
+
|
|
385
|
+
if module.variable_table.variables.contains_key(alias_ref) {
|
|
386
|
+
eprintln!(
|
|
387
|
+
"⚠️ Trigger '{}' already defined in module '{}', skipping injection.",
|
|
388
|
+
alias_ref, module.path
|
|
389
|
+
);
|
|
390
|
+
continue;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
module.variable_table.set(
|
|
394
|
+
format!("{}.{}", alias_ref, bank_trigger.name),
|
|
395
|
+
Value::String(bank_trigger_path.clone()),
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
// Inject the map under the bank name
|
|
400
|
+
module
|
|
401
|
+
.variable_table
|
|
402
|
+
.set(alias_ref.to_string(), Value::Map(bank_map));
|
|
403
|
+
|
|
404
|
+
Ok(module.clone())
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
#[cfg_attr(not(feature = "cli"), allow(dead_code))]
|
|
408
|
+
fn extract_bank_decls(&self, statements: &[Statement]) -> Vec<(String, Option<String>)> {
|
|
409
|
+
let mut banks = Vec::new();
|
|
410
|
+
|
|
411
|
+
for stmt in statements {
|
|
412
|
+
if let StatementKind::Bank { alias } = &stmt.kind {
|
|
413
|
+
let name_opt = match &stmt.value {
|
|
414
|
+
Value::String(s) => Some(s.clone()),
|
|
415
|
+
Value::Identifier(s) => Some(s.clone()),
|
|
416
|
+
Value::Number(n) => Some(n.to_string()),
|
|
417
|
+
_ => None,
|
|
418
|
+
};
|
|
419
|
+
if let Some(name) = name_opt {
|
|
420
|
+
banks.push((name, alias.clone()));
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
banks
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
fn extract_plugin_uses(&self, statements: &[Statement]) -> Vec<(String, String)> {
|
|
429
|
+
let mut plugins = Vec::new();
|
|
430
|
+
|
|
431
|
+
for stmt in statements {
|
|
432
|
+
if let StatementKind::Use { name, alias } = &stmt.kind {
|
|
433
|
+
let alias_name = alias
|
|
434
|
+
.clone()
|
|
435
|
+
.unwrap_or_else(|| name.split('.').next_back().unwrap_or(name).to_string());
|
|
436
|
+
plugins.push((name.clone(), alias_name));
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
plugins
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
fn load_plugin_and_register(
|
|
444
|
+
&self,
|
|
445
|
+
module: &mut Module,
|
|
446
|
+
plugin_name: &str,
|
|
447
|
+
alias: &str,
|
|
448
|
+
global_store: &mut GlobalStore,
|
|
449
|
+
) {
|
|
450
|
+
// plugin_name expected format: "author.name"
|
|
451
|
+
let mut parts = plugin_name.split('.');
|
|
452
|
+
let author = match parts.next() {
|
|
453
|
+
Some(a) if !a.is_empty() => a,
|
|
454
|
+
_ => {
|
|
455
|
+
eprintln!("Invalid plugin name '{}': missing author", plugin_name);
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
};
|
|
459
|
+
let name = match parts.next() {
|
|
460
|
+
Some(n) if !n.is_empty() => n,
|
|
461
|
+
_ => {
|
|
462
|
+
eprintln!("Invalid plugin name '{}': missing name", plugin_name);
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
if parts.next().is_some() {
|
|
467
|
+
eprintln!(
|
|
468
|
+
"Invalid plugin name '{}': expected <author>.<name>",
|
|
469
|
+
plugin_name
|
|
470
|
+
);
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// Enforce presence in .devalang config when plugin exists locally
|
|
475
|
+
// Build expected URI from author/name
|
|
476
|
+
let expected_uri = format!("devalang://plugin/{}.{}", author, name);
|
|
477
|
+
|
|
478
|
+
// Detect local presence (preferred and legacy layouts)
|
|
479
|
+
let root = match devalang_utils::path::get_deva_dir() {
|
|
480
|
+
Ok(dir) => dir,
|
|
481
|
+
Err(_) => Path::new("./.deva").to_path_buf(),
|
|
482
|
+
};
|
|
483
|
+
let plugin_dir_preferred = root.join("plugins").join(format!("{}.{}", author, name));
|
|
484
|
+
let toml_path_preferred = plugin_dir_preferred.join("plugin.toml");
|
|
485
|
+
let plugin_dir_fallback = root.join("plugins").join(author).join(name);
|
|
486
|
+
let toml_path_fallback = plugin_dir_fallback.join("plugin.toml");
|
|
487
|
+
let exists_locally = toml_path_preferred.exists() || toml_path_fallback.exists();
|
|
488
|
+
|
|
489
|
+
if exists_locally {
|
|
490
|
+
// Load config and verify plugin is declared
|
|
491
|
+
let cfg_opt = crate::config::ops::load_config(None);
|
|
492
|
+
let mut declared = false;
|
|
493
|
+
if let Some(cfg) = cfg_opt {
|
|
494
|
+
if let Some(list) = cfg.plugins {
|
|
495
|
+
declared = list.iter().any(|p| p.path == expected_uri);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
if !declared {
|
|
499
|
+
// Inject a single, clear error into the module so it is reported once by the error handler
|
|
500
|
+
module.statements.push(Statement {
|
|
501
|
+
kind: StatementKind::Error {
|
|
502
|
+
message: "plugin present in local files but missing in .devalang config"
|
|
503
|
+
.to_string(),
|
|
504
|
+
},
|
|
505
|
+
value: Value::Null,
|
|
506
|
+
indent: 0,
|
|
507
|
+
line: 0,
|
|
508
|
+
column: 0,
|
|
509
|
+
});
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
match load_plugin(author, name) {
|
|
515
|
+
Ok((info, wasm)) => {
|
|
516
|
+
let uri = format!("devalang://plugin/{}.{}", author, name);
|
|
517
|
+
global_store
|
|
518
|
+
.plugins
|
|
519
|
+
.insert(format!("{}:{}", author, name), (info, wasm));
|
|
520
|
+
// Set alias to URI, and inject exported variables
|
|
521
|
+
module
|
|
522
|
+
.variable_table
|
|
523
|
+
.set(alias.to_string(), Value::String(uri.clone()));
|
|
524
|
+
// Also expose alias at global level so runtime can resolve it
|
|
525
|
+
global_store
|
|
526
|
+
.variables
|
|
527
|
+
.set(alias.to_string(), Value::String(uri.clone()));
|
|
528
|
+
|
|
529
|
+
if let Some((plugin_info, _)) =
|
|
530
|
+
global_store.plugins.get(&format!("{}:{}", author, name))
|
|
531
|
+
{
|
|
532
|
+
for exp in &plugin_info.exports {
|
|
533
|
+
match exp.kind.as_str() {
|
|
534
|
+
"number" => {
|
|
535
|
+
if let Some(toml::Value::String(s)) = &exp.default {
|
|
536
|
+
if let Ok(n) = s.parse::<f32>() {
|
|
537
|
+
module.variable_table.set(
|
|
538
|
+
format!("{}.{}", alias, exp.name),
|
|
539
|
+
Value::Number(n),
|
|
540
|
+
);
|
|
541
|
+
}
|
|
542
|
+
} else if let Some(toml::Value::Integer(i)) = &exp.default {
|
|
543
|
+
module.variable_table.set(
|
|
544
|
+
format!("{}.{}", alias, exp.name),
|
|
545
|
+
Value::Number(*i as f32),
|
|
546
|
+
);
|
|
547
|
+
} else if let Some(toml::Value::Float(f)) = &exp.default {
|
|
548
|
+
module.variable_table.set(
|
|
549
|
+
format!("{}.{}", alias, exp.name),
|
|
550
|
+
Value::Number(*f as f32),
|
|
551
|
+
);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
"string" => {
|
|
555
|
+
if let Some(toml::Value::String(s)) = &exp.default {
|
|
556
|
+
module.variable_table.set(
|
|
557
|
+
format!("{}.{}", alias, exp.name),
|
|
558
|
+
Value::String(s.clone()),
|
|
559
|
+
);
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
"bool" => {
|
|
563
|
+
if let Some(toml::Value::Boolean(b)) = &exp.default {
|
|
564
|
+
module
|
|
565
|
+
.variable_table
|
|
566
|
+
.set(format!("{}.{}", alias, exp.name), Value::Boolean(*b));
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
"synth" => {
|
|
570
|
+
// Provide a discoverable marker: alias.<synthName> resolves to alias.synthName waveform string
|
|
571
|
+
module.variable_table.set(
|
|
572
|
+
format!("{}.{}", alias, exp.name),
|
|
573
|
+
Value::String(format!("{}.{}", alias, exp.name)),
|
|
574
|
+
);
|
|
575
|
+
}
|
|
576
|
+
_ => {
|
|
577
|
+
// Fallback: if default is present, map it to a Value dynamically
|
|
578
|
+
if let Some(def) = &exp.default {
|
|
579
|
+
let val = match def {
|
|
580
|
+
toml::Value::String(s) => Value::String(s.clone()),
|
|
581
|
+
toml::Value::Integer(i) => Value::Number(*i as f32),
|
|
582
|
+
toml::Value::Float(f) => Value::Number(*f as f32),
|
|
583
|
+
toml::Value::Boolean(b) => Value::Boolean(*b),
|
|
584
|
+
toml::Value::Array(arr) => Value::Array(
|
|
585
|
+
arr.iter()
|
|
586
|
+
.map(|v| match v {
|
|
587
|
+
toml::Value::String(s) => {
|
|
588
|
+
Value::String(s.clone())
|
|
589
|
+
}
|
|
590
|
+
toml::Value::Integer(i) => {
|
|
591
|
+
Value::Number(*i as f32)
|
|
592
|
+
}
|
|
593
|
+
toml::Value::Float(f) => {
|
|
594
|
+
Value::Number(*f as f32)
|
|
595
|
+
}
|
|
596
|
+
toml::Value::Boolean(b) => Value::Boolean(*b),
|
|
597
|
+
_ => Value::Null,
|
|
598
|
+
})
|
|
599
|
+
.collect(),
|
|
600
|
+
),
|
|
601
|
+
toml::Value::Table(t) => {
|
|
602
|
+
let mut m = std::collections::HashMap::new();
|
|
603
|
+
for (k, v) in t.iter() {
|
|
604
|
+
let vv = match v {
|
|
605
|
+
toml::Value::String(s) => {
|
|
606
|
+
Value::String(s.clone())
|
|
607
|
+
}
|
|
608
|
+
toml::Value::Integer(i) => {
|
|
609
|
+
Value::Number(*i as f32)
|
|
610
|
+
}
|
|
611
|
+
toml::Value::Float(f) => {
|
|
612
|
+
Value::Number(*f as f32)
|
|
613
|
+
}
|
|
614
|
+
toml::Value::Boolean(b) => Value::Boolean(*b),
|
|
615
|
+
_ => Value::Null,
|
|
616
|
+
};
|
|
617
|
+
m.insert(k.clone(), vv);
|
|
618
|
+
}
|
|
619
|
+
Value::Map(m)
|
|
620
|
+
}
|
|
621
|
+
_ => Value::Null,
|
|
622
|
+
};
|
|
623
|
+
if val != Value::Null {
|
|
624
|
+
module
|
|
625
|
+
.variable_table
|
|
626
|
+
.set(format!("{}.{}", alias, exp.name), val);
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
Err(e) => eprintln!("Failed to load plugin {}: {}", plugin_name, e),
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
}
|