@devaloop/devalang 0.0.1-beta.3 → 0.1.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/README.md +182 -152
- package/out-tsc/api.d.ts +180 -0
- package/out-tsc/api.d.ts.map +1 -0
- package/out-tsc/api.js +286 -0
- package/out-tsc/api.js.map +1 -0
- package/out-tsc/bin/index.d.ts +12 -0
- package/out-tsc/bin/index.d.ts.map +1 -0
- package/out-tsc/bin/index.js +20 -54
- package/out-tsc/bin/index.js.map +1 -0
- package/out-tsc/examples/basic-usage.d.ts +8 -0
- package/out-tsc/examples/basic-usage.d.ts.map +1 -0
- package/out-tsc/examples/basic-usage.js +113 -0
- package/out-tsc/examples/basic-usage.js.map +1 -0
- package/out-tsc/index.d.ts +19 -5
- package/out-tsc/index.d.ts.map +1 -0
- package/out-tsc/index.js +24 -6
- package/out-tsc/index.js.map +1 -0
- package/out-tsc/scripts/copy-wasm-dts.d.ts +7 -0
- package/out-tsc/scripts/copy-wasm-dts.d.ts.map +1 -0
- package/out-tsc/scripts/copy-wasm-dts.js +36 -32
- package/out-tsc/scripts/copy-wasm-dts.js.map +1 -0
- package/out-tsc/scripts/postinstall.d.ts +1 -0
- package/out-tsc/scripts/postinstall.d.ts.map +1 -0
- package/out-tsc/scripts/postinstall.js +4 -1
- package/out-tsc/scripts/postinstall.js.map +1 -0
- package/out-tsc/scripts/version/bump.d.ts +5 -1
- package/out-tsc/scripts/version/bump.d.ts.map +1 -0
- package/out-tsc/scripts/version/bump.js +114 -44
- package/out-tsc/scripts/version/bump.js.map +1 -0
- package/out-tsc/scripts/version/fetch.d.ts +12 -1
- package/out-tsc/scripts/version/fetch.d.ts.map +1 -0
- package/out-tsc/scripts/version/fetch.js +68 -24
- package/out-tsc/scripts/version/fetch.js.map +1 -0
- package/out-tsc/scripts/version/index.d.ts +6 -0
- package/out-tsc/scripts/version/index.d.ts.map +1 -0
- package/out-tsc/scripts/version/index.js +44 -22
- package/out-tsc/scripts/version/index.js.map +1 -0
- package/out-tsc/scripts/version/sync.d.ts +5 -1
- package/out-tsc/scripts/version/sync.d.ts.map +1 -0
- package/out-tsc/scripts/version/sync.js +78 -29
- package/out-tsc/scripts/version/sync.js.map +1 -0
- package/out-tsc/types.d.ts +68 -0
- package/out-tsc/types.d.ts.map +1 -0
- package/out-tsc/{core/types/value.js → types.js} +4 -0
- package/out-tsc/types.js.map +1 -0
- package/out-tsc/wasm.d.ts +8 -0
- package/out-tsc/wasm.d.ts.map +1 -0
- package/out-tsc/{core/index.js → wasm.js} +9 -6
- package/out-tsc/wasm.js.map +1 -0
- package/package.json +42 -42
- package/.cargo/config.toml +0 -2
- package/.devalang +0 -9
- package/.github/workflows/ci.yml +0 -103
- package/Cargo.toml +0 -84
- package/docs/CHANGELOG.md +0 -622
- package/docs/CONTRIBUTING.md +0 -101
- package/docs/ROADMAP.md +0 -38
- package/docs/TODO.md +0 -71
- package/examples/automation.deva +0 -42
- package/examples/bank.deva +0 -7
- package/examples/bus.deva +0 -10
- package/examples/chain.deva +0 -19
- package/examples/condition.deva +0 -20
- package/examples/duration.deva +0 -9
- package/examples/effect.deva +0 -2
- package/examples/events.deva +0 -12
- package/examples/filter.deva +0 -11
- package/examples/function.deva +0 -15
- package/examples/group.deva +0 -12
- package/examples/index.deva +0 -63
- package/examples/lfo.deva +0 -9
- package/examples/loop.deva +0 -10
- package/examples/pattern.deva +0 -8
- package/examples/plugin.deva +0 -16
- package/examples/routing.deva +0 -23
- package/examples/samples/hat-808.wav +0 -0
- package/examples/samples/kick-808.wav +0 -0
- package/examples/synth.deva +0 -24
- package/examples/synth_types.deva +0 -17
- package/examples/variables.deva +0 -9
- package/out-tsc/bin/project-version.json +0 -6
- package/out-tsc/core/functions/index.d.ts +0 -42
- package/out-tsc/core/functions/index.js +0 -87
- package/out-tsc/core/index.d.ts +0 -6
- package/out-tsc/core/types/index.d.ts +0 -4
- package/out-tsc/core/types/index.js +0 -20
- package/out-tsc/core/types/plugin.d.ts +0 -18
- package/out-tsc/core/types/plugin.js +0 -2
- package/out-tsc/core/types/result.d.ts +0 -27
- package/out-tsc/core/types/result.js +0 -2
- package/out-tsc/core/types/statement.d.ts +0 -106
- package/out-tsc/core/types/statement.js +0 -2
- package/out-tsc/core/types/value.d.ts +0 -43
- package/out-tsc/pkg/devalang_core.d.ts +0 -15
- package/out-tsc/pkg/devalang_core.js +0 -65
- package/out-tsc/pkg/devalang_core_bg.wasm.d.ts +0 -34
- package/out-tsc/scripts/version/copy-to-binary.d.ts +0 -1
- package/out-tsc/scripts/version/copy-to-binary.js +0 -79
- package/project-version.json +0 -6
- package/rust/bindings/Cargo.toml +0 -9
- package/rust/bindings/src/lib.rs +0 -86
- package/rust/cli/addon/commands.rs +0 -35
- package/rust/cli/addon/download.rs +0 -234
- package/rust/cli/addon/install.rs +0 -33
- package/rust/cli/addon/list.rs +0 -224
- package/rust/cli/addon/metadata.rs +0 -124
- package/rust/cli/addon/mod.rs +0 -8
- package/rust/cli/addon/remove.rs +0 -271
- package/rust/cli/addon/update.rs +0 -305
- package/rust/cli/addon/utils.rs +0 -109
- package/rust/cli/build/commands.rs +0 -153
- package/rust/cli/build/mod.rs +0 -2
- package/rust/cli/build/process.rs +0 -165
- package/rust/cli/check/mod.rs +0 -208
- package/rust/cli/discover/commands.rs +0 -275
- package/rust/cli/discover/config.rs +0 -109
- package/rust/cli/discover/fs.rs +0 -19
- package/rust/cli/discover/install.rs +0 -214
- package/rust/cli/discover/metadata.rs +0 -48
- package/rust/cli/discover/mod.rs +0 -5
- package/rust/cli/init/commands.rs +0 -88
- package/rust/cli/init/mod.rs +0 -1
- package/rust/cli/login/commands.rs +0 -124
- package/rust/cli/login/mod.rs +0 -1
- package/rust/cli/me/commands.rs +0 -52
- package/rust/cli/me/mod.rs +0 -1
- package/rust/cli/mod.rs +0 -12
- package/rust/cli/parser.rs +0 -320
- package/rust/cli/play/commands.rs +0 -375
- package/rust/cli/play/io.rs +0 -17
- package/rust/cli/play/mod.rs +0 -5
- package/rust/cli/play/process.rs +0 -159
- package/rust/cli/play/realtime.rs +0 -91
- package/rust/cli/play/utils.rs +0 -23
- package/rust/cli/telemetry/commands.rs +0 -22
- package/rust/cli/telemetry/event_creator.rs +0 -80
- package/rust/cli/telemetry/mod.rs +0 -3
- package/rust/cli/telemetry/send.rs +0 -51
- package/rust/cli/template/commands.rs +0 -69
- package/rust/cli/template/mod.rs +0 -1
- package/rust/cli/update/commands.rs +0 -6
- package/rust/cli/update/mod.rs +0 -1
- package/rust/config/driver.rs +0 -112
- package/rust/config/mod.rs +0 -3
- package/rust/config/ops.rs +0 -26
- package/rust/config/settings.rs +0 -101
- package/rust/core/audio/engine/driver.rs +0 -237
- package/rust/core/audio/engine/export.rs +0 -169
- package/rust/core/audio/engine/helpers.rs +0 -178
- package/rust/core/audio/engine/mod.rs +0 -56
- package/rust/core/audio/engine/notes/dsp.rs +0 -88
- package/rust/core/audio/engine/notes/mod.rs +0 -53
- package/rust/core/audio/engine/notes/params.rs +0 -294
- package/rust/core/audio/engine/sample/insert.rs +0 -300
- package/rust/core/audio/engine/sample/mod.rs +0 -40
- package/rust/core/audio/engine/sample/padding.rs +0 -170
- package/rust/core/audio/evaluator/condition.rs +0 -61
- package/rust/core/audio/evaluator/mod.rs +0 -9
- package/rust/core/audio/evaluator/numeric.rs +0 -152
- package/rust/core/audio/evaluator/rhs.rs +0 -16
- package/rust/core/audio/evaluator/string_expr.rs +0 -94
- package/rust/core/audio/interpreter/driver.rs +0 -574
- package/rust/core/audio/interpreter/mod.rs +0 -2
- package/rust/core/audio/interpreter/statements/arrow_call/interprete.rs +0 -179
- package/rust/core/audio/interpreter/statements/arrow_call/methods/chord.rs +0 -398
- package/rust/core/audio/interpreter/statements/arrow_call/methods/effects.rs +0 -323
- package/rust/core/audio/interpreter/statements/arrow_call/methods/mod.rs +0 -3
- package/rust/core/audio/interpreter/statements/arrow_call/methods/note.rs +0 -371
- package/rust/core/audio/interpreter/statements/arrow_call/mod.rs +0 -3
- package/rust/core/audio/interpreter/statements/arrow_call/types/arp.rs +0 -192
- package/rust/core/audio/interpreter/statements/arrow_call/types/mod.rs +0 -24
- package/rust/core/audio/interpreter/statements/arrow_call/types/pad.rs +0 -116
- package/rust/core/audio/interpreter/statements/arrow_call/types/pluck.rs +0 -97
- package/rust/core/audio/interpreter/statements/arrow_call/types/sub.rs +0 -100
- package/rust/core/audio/interpreter/statements/automate.rs +0 -16
- package/rust/core/audio/interpreter/statements/call.rs +0 -325
- package/rust/core/audio/interpreter/statements/condition.rs +0 -72
- package/rust/core/audio/interpreter/statements/function.rs +0 -24
- package/rust/core/audio/interpreter/statements/let_.rs +0 -36
- package/rust/core/audio/interpreter/statements/load.rs +0 -17
- package/rust/core/audio/interpreter/statements/loop_.rs +0 -115
- package/rust/core/audio/interpreter/statements/mod.rs +0 -12
- package/rust/core/audio/interpreter/statements/sleep.rs +0 -28
- package/rust/core/audio/interpreter/statements/spawn.rs +0 -302
- package/rust/core/audio/interpreter/statements/tempo.rs +0 -40
- package/rust/core/audio/interpreter/statements/trigger.rs +0 -242
- package/rust/core/audio/loader/mod.rs +0 -1
- package/rust/core/audio/loader/trigger.rs +0 -98
- package/rust/core/audio/mod.rs +0 -6
- package/rust/core/audio/player.rs +0 -70
- package/rust/core/audio/special/easing.rs +0 -189
- package/rust/core/audio/special/env.rs +0 -45
- package/rust/core/audio/special/math.rs +0 -134
- package/rust/core/audio/special/mod.rs +0 -9
- package/rust/core/audio/special/modulator.rs +0 -143
- package/rust/core/builder/mod.rs +0 -129
- package/rust/core/debugger/lexer.rs +0 -27
- package/rust/core/debugger/logs.rs +0 -52
- package/rust/core/debugger/mod.rs +0 -30
- package/rust/core/debugger/preprocessor.rs +0 -27
- package/rust/core/debugger/store.rs +0 -38
- package/rust/core/error/mod.rs +0 -269
- package/rust/core/lexer/driver.rs +0 -59
- package/rust/core/lexer/handler/arrow.rs +0 -82
- package/rust/core/lexer/handler/at.rs +0 -21
- package/rust/core/lexer/handler/brace.rs +0 -41
- package/rust/core/lexer/handler/colon.rs +0 -21
- package/rust/core/lexer/handler/comment.rs +0 -30
- package/rust/core/lexer/handler/dot.rs +0 -21
- package/rust/core/lexer/handler/driver.rs +0 -337
- package/rust/core/lexer/handler/identifier.rs +0 -47
- package/rust/core/lexer/handler/indent.rs +0 -66
- package/rust/core/lexer/handler/mod.rs +0 -15
- package/rust/core/lexer/handler/newline.rs +0 -23
- package/rust/core/lexer/handler/number.rs +0 -31
- package/rust/core/lexer/handler/operator.rs +0 -46
- package/rust/core/lexer/handler/parenthesis.rs +0 -41
- package/rust/core/lexer/handler/slash.rs +0 -21
- package/rust/core/lexer/handler/string.rs +0 -63
- package/rust/core/lexer/mod.rs +0 -3
- package/rust/core/lexer/token.rs +0 -91
- package/rust/core/mod.rs +0 -9
- package/rust/core/parser/driver/block.rs +0 -111
- package/rust/core/parser/driver/cursor.rs +0 -82
- package/rust/core/parser/driver/driver_impl.rs +0 -159
- package/rust/core/parser/driver/mod.rs +0 -6
- package/rust/core/parser/driver/parse_array.rs +0 -120
- package/rust/core/parser/driver/parse_map.rs +0 -247
- package/rust/core/parser/driver/parser.rs +0 -160
- package/rust/core/parser/handler/arrow_call.rs +0 -328
- package/rust/core/parser/handler/at.rs +0 -279
- package/rust/core/parser/handler/bank.rs +0 -104
- package/rust/core/parser/handler/condition.rs +0 -83
- package/rust/core/parser/handler/dot.rs +0 -148
- package/rust/core/parser/handler/identifier/automate.rs +0 -254
- package/rust/core/parser/handler/identifier/call.rs +0 -91
- package/rust/core/parser/handler/identifier/emit.rs +0 -70
- package/rust/core/parser/handler/identifier/function.rs +0 -113
- package/rust/core/parser/handler/identifier/group.rs +0 -89
- package/rust/core/parser/handler/identifier/let_.rs +0 -173
- package/rust/core/parser/handler/identifier/mod.rs +0 -55
- package/rust/core/parser/handler/identifier/on.rs +0 -107
- package/rust/core/parser/handler/identifier/print.rs +0 -49
- package/rust/core/parser/handler/identifier/sleep.rs +0 -96
- package/rust/core/parser/handler/identifier/spawn.rs +0 -91
- package/rust/core/parser/handler/identifier/synth.rs +0 -171
- package/rust/core/parser/handler/loop_.rs +0 -194
- package/rust/core/parser/handler/mod.rs +0 -9
- package/rust/core/parser/handler/pattern.rs +0 -97
- package/rust/core/parser/handler/tempo.rs +0 -105
- package/rust/core/parser/mod.rs +0 -3
- package/rust/core/parser/statement.rs +0 -10
- package/rust/core/plugin/loader.rs +0 -137
- package/rust/core/plugin/mod.rs +0 -2
- package/rust/core/plugin/runner/mod.rs +0 -11
- package/rust/core/plugin/runner/non_wasm.rs +0 -481
- package/rust/core/plugin/runner/wasm32.rs +0 -44
- package/rust/core/preprocessor/loader/inject.rs +0 -313
- package/rust/core/preprocessor/loader/loader_helpers.rs +0 -110
- package/rust/core/preprocessor/loader/mod.rs +0 -235
- package/rust/core/preprocessor/mod.rs +0 -4
- package/rust/core/preprocessor/module.rs +0 -55
- package/rust/core/preprocessor/processor/handlers.rs +0 -107
- package/rust/core/preprocessor/processor/mod.rs +0 -1
- package/rust/core/preprocessor/resolver/bank.rs +0 -49
- package/rust/core/preprocessor/resolver/call.rs +0 -124
- package/rust/core/preprocessor/resolver/condition.rs +0 -95
- package/rust/core/preprocessor/resolver/driver.rs +0 -324
- package/rust/core/preprocessor/resolver/function.rs +0 -69
- package/rust/core/preprocessor/resolver/group.rs +0 -122
- package/rust/core/preprocessor/resolver/let_.rs +0 -32
- package/rust/core/preprocessor/resolver/loop_.rs +0 -318
- package/rust/core/preprocessor/resolver/mod.rs +0 -16
- package/rust/core/preprocessor/resolver/pattern.rs +0 -95
- package/rust/core/preprocessor/resolver/spawn.rs +0 -99
- package/rust/core/preprocessor/resolver/synth.rs +0 -54
- package/rust/core/preprocessor/resolver/tempo.rs +0 -48
- package/rust/core/preprocessor/resolver/trigger.rs +0 -116
- package/rust/core/preprocessor/resolver/value.rs +0 -176
- package/rust/core/store/global.rs +0 -57
- package/rust/core/store/mod.rs +0 -1
- package/rust/lib.rs +0 -323
- package/rust/macros/Cargo.toml +0 -14
- package/rust/macros/src/lib.rs +0 -52
- package/rust/main.rs +0 -557
- package/rust/types/Cargo.toml +0 -11
- package/rust/types/src/addons.rs +0 -57
- package/rust/types/src/ast.rs +0 -202
- package/rust/types/src/config.rs +0 -82
- package/rust/types/src/lib.rs +0 -15
- package/rust/types/src/plugin.rs +0 -20
- package/rust/types/src/store.rs +0 -139
- package/rust/types/src/telemetry.rs +0 -85
- package/rust/utils/Cargo.toml +0 -29
- package/rust/utils/src/error.rs +0 -186
- package/rust/utils/src/file.rs +0 -477
- package/rust/utils/src/first_usage.rs +0 -97
- package/rust/utils/src/lib.rs +0 -9
- package/rust/utils/src/logger.rs +0 -200
- package/rust/utils/src/path.rs +0 -158
- package/rust/utils/src/signature.rs +0 -41
- package/rust/utils/src/spinner.rs +0 -20
- package/rust/utils/src/version.rs +0 -58
- package/rust/utils/src/watcher.rs +0 -46
- package/rust/web/api.rs +0 -5
- package/rust/web/auth.rs +0 -5
- package/rust/web/cdn.rs +0 -34
- package/rust/web/forge.rs +0 -5
- package/rust/web/mod.rs +0 -5
- package/rust/web/sso.rs +0 -5
- package/templates/minimal/.devalang +0 -5
- package/templates/minimal/README.md +0 -218
- package/templates/minimal/src/index.deva +0 -2
- package/templates/welcome/.devalang +0 -5
- package/templates/welcome/README.md +0 -218
- package/templates/welcome/samples/kick-808.wav +0 -0
- package/templates/welcome/src/index.deva +0 -61
- package/templates/welcome/src/variables.deva +0 -3
- package/tests/integration.rs +0 -21
- package/tests/rust/cli_check_build.rs +0 -21
- package/tests/rust/cli_help.rs +0 -12
- package/tests/rust/cli_template_list.rs +0 -10
- package/tests/rust/cli_version.rs +0 -11
- package/tests/typescript/index.spec.ts +0 -136
- package/tests/typescript/playhead.spec.ts +0 -36
- package/tests/typescript/render_e2e.spec.ts +0 -77
- package/tsconfig.json +0 -115
- package/typescript/bin/index.ts +0 -28
- package/typescript/core/functions/index.ts +0 -94
- package/typescript/core/index.ts +0 -6
- package/typescript/core/types/index.ts +0 -4
- package/typescript/core/types/plugin.ts +0 -19
- package/typescript/core/types/result.ts +0 -29
- package/typescript/core/types/statement.ts +0 -47
- package/typescript/core/types/value.ts +0 -29
- package/typescript/index.ts +0 -8
- package/typescript/pkg/devalang_core.d.ts +0 -4
- package/typescript/pkg/devalang_core.ts +0 -65
- package/typescript/scripts/copy-wasm-dts.ts +0 -41
- package/typescript/scripts/postinstall.ts +0 -85
- package/typescript/scripts/version/bump.ts +0 -44
- package/typescript/scripts/version/copy-to-binary.ts +0 -82
- package/typescript/scripts/version/fetch.ts +0 -18
- package/typescript/scripts/version/index.ts +0 -25
- package/typescript/scripts/version/sync.ts +0 -24
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
use crate::core::{
|
|
2
|
-
parser::statement::{Statement, StatementKind},
|
|
3
|
-
preprocessor::module::Module,
|
|
4
|
-
store::global::GlobalStore,
|
|
5
|
-
};
|
|
6
|
-
use devalang_types::{Duration, Value};
|
|
7
|
-
use devalang_utils::logger::Logger;
|
|
8
|
-
use std::collections::HashMap;
|
|
9
|
-
|
|
10
|
-
pub fn resolve_trigger(
|
|
11
|
-
stmt: &Statement,
|
|
12
|
-
entity: &str,
|
|
13
|
-
duration: &mut Duration,
|
|
14
|
-
_effects: Option<Value>,
|
|
15
|
-
module: &Module,
|
|
16
|
-
path: &str,
|
|
17
|
-
global_store: &GlobalStore,
|
|
18
|
-
) -> Statement {
|
|
19
|
-
let logger = Logger::new();
|
|
20
|
-
|
|
21
|
-
let mut final_duration = duration.clone();
|
|
22
|
-
|
|
23
|
-
// Duration resolution
|
|
24
|
-
if let Duration::Identifier(ident) = duration {
|
|
25
|
-
if let Some(val) = resolve_identifier(ident, module, global_store) {
|
|
26
|
-
match val {
|
|
27
|
-
Value::Number(n) => {
|
|
28
|
-
final_duration = Duration::Number(n);
|
|
29
|
-
}
|
|
30
|
-
Value::String(s) => {
|
|
31
|
-
final_duration = Duration::Identifier(s);
|
|
32
|
-
}
|
|
33
|
-
Value::Identifier(s) if s == "auto" => {
|
|
34
|
-
final_duration = Duration::Auto;
|
|
35
|
-
}
|
|
36
|
-
_ => {}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Params value resolution
|
|
42
|
-
let final_value = match &stmt.value {
|
|
43
|
-
Value::Identifier(ident) => {
|
|
44
|
-
logger.log_message(
|
|
45
|
-
devalang_utils::logger::LogLevel::Debug,
|
|
46
|
-
&format!("Resolving identifier: {}", ident),
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
match resolve_identifier(ident, module, global_store) {
|
|
50
|
-
Some(v) => v,
|
|
51
|
-
None => {
|
|
52
|
-
logger.log_error_with_stacktrace(
|
|
53
|
-
&format!("'{path}': value identifier '{ident}' not found"),
|
|
54
|
-
&format!("{}:{}:{}", module.path, stmt.line, stmt.column),
|
|
55
|
-
);
|
|
56
|
-
Value::Null
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
Value::Map(map) => {
|
|
61
|
-
let mut resolved_map = HashMap::new();
|
|
62
|
-
for (k, v) in map {
|
|
63
|
-
let resolved = match v {
|
|
64
|
-
Value::Identifier(id) => {
|
|
65
|
-
resolve_identifier(id, module, global_store).unwrap_or(Value::Null)
|
|
66
|
-
}
|
|
67
|
-
other => other.clone(),
|
|
68
|
-
};
|
|
69
|
-
resolved_map.insert(k.clone(), resolved);
|
|
70
|
-
}
|
|
71
|
-
Value::Map(resolved_map)
|
|
72
|
-
}
|
|
73
|
-
other => other.clone(),
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
Statement {
|
|
77
|
-
kind: StatementKind::Trigger {
|
|
78
|
-
entity: entity.to_string(),
|
|
79
|
-
duration: final_duration.clone(),
|
|
80
|
-
effects: Some(final_value.clone()),
|
|
81
|
-
},
|
|
82
|
-
value: Value::Null,
|
|
83
|
-
line: stmt.line,
|
|
84
|
-
column: stmt.column,
|
|
85
|
-
indent: stmt.indent,
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
fn resolve_identifier(ident: &str, module: &Module, global_store: &GlobalStore) -> Option<Value> {
|
|
90
|
-
if let Some(val) = module.variable_table.get(ident) {
|
|
91
|
-
return Some(resolve_value(val, module, global_store));
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
for other_mod in global_store.modules.values() {
|
|
95
|
-
if let Some(val) = other_mod.variable_table.get(ident) {
|
|
96
|
-
return Some(resolve_value(val, other_mod, global_store));
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
None
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
fn resolve_value(val: &Value, module: &Module, global_store: &GlobalStore) -> Value {
|
|
104
|
-
match val {
|
|
105
|
-
Value::Identifier(inner) => resolve_identifier(inner, module, global_store)
|
|
106
|
-
.unwrap_or(Value::Identifier(inner.clone())),
|
|
107
|
-
Value::Map(map) => {
|
|
108
|
-
let mut resolved = HashMap::new();
|
|
109
|
-
for (k, v) in map {
|
|
110
|
-
resolved.insert(k.clone(), resolve_value(v, module, global_store));
|
|
111
|
-
}
|
|
112
|
-
Value::Map(resolved)
|
|
113
|
-
}
|
|
114
|
-
other => other.clone(),
|
|
115
|
-
}
|
|
116
|
-
}
|
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
use std::collections::HashMap;
|
|
2
|
-
use toml::Value as TomlValue;
|
|
3
|
-
|
|
4
|
-
use crate::core::{
|
|
5
|
-
preprocessor::{module::Module, resolver::driver::resolve_statement},
|
|
6
|
-
store::global::GlobalStore,
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
use devalang_types::Value;
|
|
10
|
-
|
|
11
|
-
fn find_export_value(name: &str, global_store: &GlobalStore) -> Option<Value> {
|
|
12
|
-
for module in global_store.modules.values() {
|
|
13
|
-
if let Some(val) = module.export_table.get_export(name) {
|
|
14
|
-
return Some(val.clone());
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
None
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
pub fn resolve_value(value: &Value, module: &Module, global_store: &mut GlobalStore) -> Value {
|
|
22
|
-
match value {
|
|
23
|
-
Value::String(s) => {
|
|
24
|
-
// Keep raw strings as-is; they may be runtime-evaluated (e.g., expressions)
|
|
25
|
-
Value::String(s.clone())
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
Value::Identifier(name) => {
|
|
29
|
-
if let Some(original_val) = module.variable_table.get(name) {
|
|
30
|
-
return resolve_value(original_val, module, global_store);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if let Some(export_val) = find_export_value(name, global_store) {
|
|
34
|
-
return resolve_value(&export_val, module, global_store);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Leave unresolved identifiers as-is; may be runtime-bound (e.g., foreach variable)
|
|
38
|
-
Value::Identifier(name.clone())
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
Value::Map(map) => {
|
|
42
|
-
if let Some(Value::Identifier(entity)) = map.get("entity") {
|
|
43
|
-
// SECTION Synth
|
|
44
|
-
if entity == "synth" {
|
|
45
|
-
if let Some(Value::Map(synth_data)) = map.get("value") {
|
|
46
|
-
let resolved_waveform = synth_data
|
|
47
|
-
.get("waveform")
|
|
48
|
-
.map(|wf| resolve_value(wf, module, global_store))
|
|
49
|
-
.unwrap_or(Value::Null);
|
|
50
|
-
|
|
51
|
-
let resolved_params = synth_data
|
|
52
|
-
.get("parameters")
|
|
53
|
-
.map(|p| resolve_value(p, module, global_store))
|
|
54
|
-
.unwrap_or(Value::Map(HashMap::new()));
|
|
55
|
-
|
|
56
|
-
// If waveform refers to a plugin synth (e.g., alias.synth),
|
|
57
|
-
// merge plugin-exported defaults (dynamic) into parameters and
|
|
58
|
-
// allow 'waveform' override from parameters map.
|
|
59
|
-
let mut final_waveform = resolved_waveform.clone();
|
|
60
|
-
let mut params_map = match resolved_params.clone() {
|
|
61
|
-
Value::Map(m) => m,
|
|
62
|
-
_ => HashMap::new(),
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
// Helper: convert TomlValue into runtime Value
|
|
66
|
-
fn toml_to_value(tv: &TomlValue) -> Value {
|
|
67
|
-
match tv {
|
|
68
|
-
TomlValue::String(s) => Value::String(s.clone()),
|
|
69
|
-
TomlValue::Integer(i) => Value::Number(*i as f32),
|
|
70
|
-
TomlValue::Float(f) => Value::Number(*f as f32),
|
|
71
|
-
TomlValue::Boolean(b) => Value::Boolean(*b),
|
|
72
|
-
TomlValue::Array(arr) => {
|
|
73
|
-
Value::Array(arr.iter().map(toml_to_value).collect())
|
|
74
|
-
}
|
|
75
|
-
TomlValue::Table(t) => {
|
|
76
|
-
let mut m = HashMap::new();
|
|
77
|
-
for (k, v) in t.iter() {
|
|
78
|
-
m.insert(k.clone(), toml_to_value(v));
|
|
79
|
-
}
|
|
80
|
-
Value::Map(m)
|
|
81
|
-
}
|
|
82
|
-
_ => Value::Null,
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Detect plugin alias from waveform string like "alias.synth" OR just "alias"
|
|
87
|
-
let (alias_opt, explicit_synth_export) = match &final_waveform {
|
|
88
|
-
Value::String(s) | Value::Identifier(s) => {
|
|
89
|
-
let parts: Vec<&str> = s.split('.').collect();
|
|
90
|
-
if parts.len() >= 2 && parts[1] == "synth" {
|
|
91
|
-
(Some(parts[0].to_string()), true)
|
|
92
|
-
} else if parts.len() == 1 {
|
|
93
|
-
(Some(parts[0].to_string()), false)
|
|
94
|
-
} else {
|
|
95
|
-
(None, false)
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
_ => (None, false),
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
if let Some(alias) = alias_opt {
|
|
102
|
-
// Resolve alias -> plugin uri -> plugin info
|
|
103
|
-
if let Some(Value::String(uri)) = module.variable_table.get(&alias) {
|
|
104
|
-
if let Some(id) = uri.strip_prefix("devalang://plugin/") {
|
|
105
|
-
let mut parts = id.split('.');
|
|
106
|
-
let author = parts.next().unwrap_or("");
|
|
107
|
-
let pname = parts.next().unwrap_or("");
|
|
108
|
-
let key = format!("{}:{}", author, pname);
|
|
109
|
-
if let Some((plugin_info, _wasm)) =
|
|
110
|
-
global_store.plugins.get(&key)
|
|
111
|
-
{
|
|
112
|
-
// Merge defaults dynamically from exports
|
|
113
|
-
for exp in &plugin_info.exports {
|
|
114
|
-
// Skip entry named 'synth' which is used as the flag
|
|
115
|
-
if exp.name == "synth" {
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
if let Some(def) = &exp.default {
|
|
119
|
-
let val = toml_to_value(def);
|
|
120
|
-
// only apply if not overridden by user params
|
|
121
|
-
params_map.entry(exp.name.clone()).or_insert(val);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// If 'waveform' is provided in params (by user or default), use it
|
|
126
|
-
if let Some(wf_val) = params_map.remove("waveform") {
|
|
127
|
-
final_waveform =
|
|
128
|
-
resolve_value(&wf_val, module, global_store);
|
|
129
|
-
} else if let Some(wf_default) = plugin_info
|
|
130
|
-
.exports
|
|
131
|
-
.iter()
|
|
132
|
-
.find(|e| e.name == "waveform")
|
|
133
|
-
.and_then(|e| e.default.as_ref())
|
|
134
|
-
{
|
|
135
|
-
final_waveform = toml_to_value(wf_default);
|
|
136
|
-
} else if explicit_synth_export {
|
|
137
|
-
// keep as alias.synth if no default waveform
|
|
138
|
-
} else {
|
|
139
|
-
// If no explicit .synth in waveform, but alias is a plugin,
|
|
140
|
-
// treat it as alias.synth by default to enable plugin synth usage
|
|
141
|
-
final_waveform =
|
|
142
|
-
Value::String(format!("{}.synth", alias));
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
let mut result = HashMap::new();
|
|
150
|
-
result.insert("waveform".to_string(), final_waveform);
|
|
151
|
-
result.insert("parameters".to_string(), Value::Map(params_map));
|
|
152
|
-
|
|
153
|
-
return Value::Map(result);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
let mut resolved = HashMap::new();
|
|
159
|
-
for (k, v) in map {
|
|
160
|
-
resolved.insert(k.clone(), resolve_value(v, module, global_store));
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
Value::Map(resolved)
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
Value::Block(stmts) => {
|
|
167
|
-
let resolved_stmts = stmts
|
|
168
|
-
.iter()
|
|
169
|
-
.map(|stmt| resolve_statement(stmt, module, &module.path, global_store))
|
|
170
|
-
.collect();
|
|
171
|
-
Value::Block(resolved_stmts)
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
other => other.clone(),
|
|
175
|
-
}
|
|
176
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
use crate::core::{parser::statement::Statement, preprocessor::module::Module};
|
|
2
|
-
use devalang_types::{FunctionTable, VariableTable, plugin::PluginInfo};
|
|
3
|
-
use std::collections::HashMap;
|
|
4
|
-
|
|
5
|
-
#[derive(Debug, Clone)]
|
|
6
|
-
pub struct GlobalStore {
|
|
7
|
-
pub modules: HashMap<String, Module>,
|
|
8
|
-
pub variables: VariableTable,
|
|
9
|
-
pub functions: FunctionTable,
|
|
10
|
-
pub events: HashMap<String, Vec<Statement>>,
|
|
11
|
-
pub plugins: HashMap<String, (PluginInfo, Vec<u8>)>,
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
impl Default for GlobalStore {
|
|
15
|
-
fn default() -> Self {
|
|
16
|
-
Self::new()
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
impl GlobalStore {
|
|
21
|
-
pub fn new() -> Self {
|
|
22
|
-
GlobalStore {
|
|
23
|
-
modules: HashMap::new(),
|
|
24
|
-
functions: FunctionTable::new(),
|
|
25
|
-
variables: VariableTable::new(),
|
|
26
|
-
events: HashMap::new(),
|
|
27
|
-
plugins: HashMap::new(),
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
pub fn insert_module(&mut self, path: String, module: Module) {
|
|
32
|
-
self.modules.insert(path, module);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
pub fn modules_mut(&mut self) -> &mut HashMap<String, Module> {
|
|
36
|
-
&mut self.modules
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
pub fn get_module(&self, path: &str) -> Option<&Module> {
|
|
40
|
-
self.modules.get(path)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
pub fn remove_module(&mut self, path: &str) -> Option<Module> {
|
|
44
|
-
self.modules.remove(path)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
pub fn register_event_handler(&mut self, event: &str, handler: Statement) {
|
|
48
|
-
self.events
|
|
49
|
-
.entry(event.to_string())
|
|
50
|
-
.or_default()
|
|
51
|
-
.push(handler);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
pub fn get_event_handlers(&self, event: &str) -> Option<&Vec<Statement>> {
|
|
55
|
-
self.events.get(event)
|
|
56
|
-
}
|
|
57
|
-
}
|
package/rust/core/store/mod.rs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
pub mod global;
|
package/rust/lib.rs
DELETED
|
@@ -1,323 +0,0 @@
|
|
|
1
|
-
pub mod config;
|
|
2
|
-
pub mod core;
|
|
3
|
-
|
|
4
|
-
use crate::core::{
|
|
5
|
-
audio::{engine::AudioEngine, interpreter::driver::run_audio_program},
|
|
6
|
-
parser::statement::{Statement, StatementKind},
|
|
7
|
-
preprocessor::loader::ModuleLoader,
|
|
8
|
-
store::global::GlobalStore,
|
|
9
|
-
};
|
|
10
|
-
use devalang_types::{FunctionTable, Value, VariableTable};
|
|
11
|
-
use devalang_utils::path::normalize_path;
|
|
12
|
-
use serde::{Deserialize, Serialize};
|
|
13
|
-
use serde_wasm_bindgen::to_value;
|
|
14
|
-
use wasm_bindgen::prelude::*;
|
|
15
|
-
|
|
16
|
-
#[derive(Serialize, Deserialize)]
|
|
17
|
-
struct ParseResult {
|
|
18
|
-
ok: bool,
|
|
19
|
-
ast: String,
|
|
20
|
-
errors: Vec<ErrorResult>,
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
#[derive(Serialize, Deserialize)]
|
|
24
|
-
struct ErrorResult {
|
|
25
|
-
message: String,
|
|
26
|
-
line: usize,
|
|
27
|
-
column: usize,
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
#[wasm_bindgen]
|
|
31
|
-
pub fn parse(entry_path: &str, source: &str) -> Result<JsValue, JsValue> {
|
|
32
|
-
let statements = parse_internal_from_string(entry_path, source);
|
|
33
|
-
|
|
34
|
-
match statements {
|
|
35
|
-
Ok(value) => {
|
|
36
|
-
let ast_string = value;
|
|
37
|
-
to_value(&ast_string)
|
|
38
|
-
.map_err(|e| JsValue::from_str(&format!("Error converting AST to JS value: {}", e)))
|
|
39
|
-
}
|
|
40
|
-
Err(e) => Err(JsValue::from_str(&format!("Error: {}", e))),
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
#[wasm_bindgen]
|
|
45
|
-
pub fn debug_render(user_code: &str) -> Result<JsValue, JsValue> {
|
|
46
|
-
console_error_panic_hook::set_once();
|
|
47
|
-
|
|
48
|
-
let entry_path = normalize_path("playground.deva");
|
|
49
|
-
let output_path = normalize_path("./temp");
|
|
50
|
-
|
|
51
|
-
let mut global_store = GlobalStore::new();
|
|
52
|
-
|
|
53
|
-
let loader =
|
|
54
|
-
ModuleLoader::from_raw_source(&entry_path, &output_path, user_code, &mut global_store);
|
|
55
|
-
|
|
56
|
-
loader
|
|
57
|
-
.load_wasm_module(&mut global_store)
|
|
58
|
-
.map_err(|e| JsValue::from_str(&format!("Module loading error: {}", e)))?;
|
|
59
|
-
|
|
60
|
-
let all_statements_map = loader.extract_statements_map(&global_store);
|
|
61
|
-
|
|
62
|
-
let main_statements = all_statements_map
|
|
63
|
-
.get(&entry_path)
|
|
64
|
-
.ok_or(JsValue::from_str("No statements found for entry module"))?
|
|
65
|
-
.clone();
|
|
66
|
-
|
|
67
|
-
let mut audio_engine = AudioEngine::new("wasm_output".to_string());
|
|
68
|
-
|
|
69
|
-
let _ = run_audio_program(
|
|
70
|
-
&main_statements,
|
|
71
|
-
&mut audio_engine,
|
|
72
|
-
"playground".to_string(),
|
|
73
|
-
"wasm_output".to_string(),
|
|
74
|
-
VariableTable::new(),
|
|
75
|
-
FunctionTable::new(),
|
|
76
|
-
&mut global_store,
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
// Inspect buffer to detect if any audio was produced. In test/CI
|
|
80
|
-
// environments it's common to produce no audio (silent program);
|
|
81
|
-
// callers rely on this flag for diagnostics.
|
|
82
|
-
let samples = audio_engine.get_normalized_buffer();
|
|
83
|
-
let any_nonzero = samples.iter().any(|&s| s != 0.0);
|
|
84
|
-
|
|
85
|
-
// Build parsed AST for diagnostics
|
|
86
|
-
let ast_res = parse_internal_from_string("playground.deva", user_code);
|
|
87
|
-
let ast_str = match ast_res {
|
|
88
|
-
Ok(p) => p.ast,
|
|
89
|
-
Err(_) => "".to_string(),
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
#[derive(Serialize)]
|
|
93
|
-
struct DebugResult {
|
|
94
|
-
samples_len: usize,
|
|
95
|
-
any_nonzero: bool,
|
|
96
|
-
ast: String,
|
|
97
|
-
note_count: usize,
|
|
98
|
-
global_vars: Vec<String>,
|
|
99
|
-
statements_count: usize,
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
let out = DebugResult {
|
|
103
|
-
samples_len: samples.len(),
|
|
104
|
-
any_nonzero,
|
|
105
|
-
ast: ast_str,
|
|
106
|
-
note_count: audio_engine.note_count,
|
|
107
|
-
global_vars: global_store.variables.variables.keys().cloned().collect(),
|
|
108
|
-
statements_count: main_statements.len(),
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
to_value(&out).map_err(|e| JsValue::from_str(&format!("Error converting debug result: {}", e)))
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
#[wasm_bindgen]
|
|
115
|
-
pub fn render_audio(user_code: &str) -> Result<js_sys::Float32Array, JsValue> {
|
|
116
|
-
console_error_panic_hook::set_once();
|
|
117
|
-
|
|
118
|
-
let entry_path = normalize_path("playground.deva");
|
|
119
|
-
let output_path = normalize_path("./temp");
|
|
120
|
-
|
|
121
|
-
let mut global_store = GlobalStore::new();
|
|
122
|
-
|
|
123
|
-
let loader =
|
|
124
|
-
ModuleLoader::from_raw_source(&entry_path, &output_path, user_code, &mut global_store);
|
|
125
|
-
|
|
126
|
-
loader
|
|
127
|
-
.load_wasm_module(&mut global_store)
|
|
128
|
-
.map_err(|e| JsValue::from_str(&format!("Module loading error: {}", e)))?;
|
|
129
|
-
|
|
130
|
-
let all_statements_map = loader.extract_statements_map(&global_store);
|
|
131
|
-
|
|
132
|
-
let main_statements = all_statements_map
|
|
133
|
-
.get(&entry_path)
|
|
134
|
-
.ok_or(JsValue::from_str("No statements found for entry module"))?
|
|
135
|
-
.clone();
|
|
136
|
-
|
|
137
|
-
let mut audio_engine = AudioEngine::new("wasm_output".to_string());
|
|
138
|
-
|
|
139
|
-
let _ = run_audio_program(
|
|
140
|
-
&main_statements,
|
|
141
|
-
&mut audio_engine,
|
|
142
|
-
"playground".to_string(),
|
|
143
|
-
"wasm_output".to_string(),
|
|
144
|
-
VariableTable::new(),
|
|
145
|
-
FunctionTable::new(),
|
|
146
|
-
&mut global_store,
|
|
147
|
-
);
|
|
148
|
-
|
|
149
|
-
let samples = audio_engine.get_normalized_buffer();
|
|
150
|
-
|
|
151
|
-
if samples.is_empty() {
|
|
152
|
-
// For test environments where no audio was scheduled, return a small
|
|
153
|
-
// silent buffer instead of failing. This helps tests proceed in CI.
|
|
154
|
-
let silent = vec![0.0f32; 1024];
|
|
155
|
-
return Ok(js_sys::Float32Array::from(silent.as_slice()));
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
Ok(js_sys::Float32Array::from(samples.as_slice()))
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
#[wasm_bindgen]
|
|
162
|
-
#[allow(unused_variables)]
|
|
163
|
-
pub fn register_playhead_callback(cb: &js_sys::Function) {
|
|
164
|
-
// Register a JS callback to receive playhead events during real-time
|
|
165
|
-
// playback. This is a no-op on non-wasm targets to keep the bindings
|
|
166
|
-
// portable for native builds.
|
|
167
|
-
// Only register if target supports wasm callbacks
|
|
168
|
-
#[cfg(target_arch = "wasm32")]
|
|
169
|
-
{
|
|
170
|
-
crate::core::audio::interpreter::driver::register_playhead_callback(cb.clone());
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
#[wasm_bindgen]
|
|
175
|
-
#[allow(unused_variables)]
|
|
176
|
-
pub fn collect_playhead_events() -> Result<JsValue, JsValue> {
|
|
177
|
-
#[cfg(target_arch = "wasm32")]
|
|
178
|
-
{
|
|
179
|
-
let events = crate::core::audio::interpreter::driver::collect_playhead_events();
|
|
180
|
-
to_value(&events).map_err(|e| JsValue::from_str(&format!("Error converting events: {}", e)))
|
|
181
|
-
}
|
|
182
|
-
#[cfg(not(target_arch = "wasm32"))]
|
|
183
|
-
{
|
|
184
|
-
// On non-wasm targets, return an empty array
|
|
185
|
-
to_value(&Vec::<String>::new()).map_err(|e| JsValue::from_str(&format!("Error: {}", e)))
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
#[wasm_bindgen]
|
|
190
|
-
pub fn unregister_playhead_callback() {
|
|
191
|
-
#[cfg(target_arch = "wasm32")]
|
|
192
|
-
{
|
|
193
|
-
crate::core::audio::interpreter::driver::unregister_playhead_callback();
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
fn parse_internal_from_string(virtual_path: &str, source: &str) -> Result<ParseResult, String> {
|
|
198
|
-
let entry_path = normalize_path(virtual_path);
|
|
199
|
-
let output_path = normalize_path("./temp");
|
|
200
|
-
|
|
201
|
-
let mut global_store = GlobalStore::new();
|
|
202
|
-
let loader =
|
|
203
|
-
ModuleLoader::from_raw_source(&entry_path, &output_path, source, &mut global_store);
|
|
204
|
-
|
|
205
|
-
let module = loader
|
|
206
|
-
.load_single_module(&mut global_store)
|
|
207
|
-
.map_err(|e| format!("Error loading module: {}", e))?;
|
|
208
|
-
|
|
209
|
-
let raw_ast = ast_to_string(module.statements.clone());
|
|
210
|
-
|
|
211
|
-
let found_errors = collect_errors_recursively(&module.statements);
|
|
212
|
-
|
|
213
|
-
let result = ParseResult {
|
|
214
|
-
ok: true,
|
|
215
|
-
ast: raw_ast,
|
|
216
|
-
errors: found_errors,
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
Ok(result)
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
fn collect_errors_recursively(statements: &[Statement]) -> Vec<ErrorResult> {
|
|
223
|
-
let mut errors: Vec<ErrorResult> = Vec::new();
|
|
224
|
-
|
|
225
|
-
for stmt in statements {
|
|
226
|
-
match &stmt.kind {
|
|
227
|
-
StatementKind::Unknown => {
|
|
228
|
-
errors.push(ErrorResult {
|
|
229
|
-
message: format!("Unknown statement at line {}:{}", stmt.line, stmt.column),
|
|
230
|
-
line: stmt.line,
|
|
231
|
-
column: stmt.column,
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
StatementKind::Error { message } => {
|
|
235
|
-
errors.push(ErrorResult {
|
|
236
|
-
message: message.clone(),
|
|
237
|
-
line: stmt.line,
|
|
238
|
-
column: stmt.column,
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
StatementKind::Loop => {
|
|
242
|
-
if let Some(body_statements) = extract_loop_body_statements(&stmt.value) {
|
|
243
|
-
errors.extend(collect_errors_recursively(body_statements));
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
_ => {}
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
errors
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
fn extract_loop_body_statements(value: &Value) -> Option<&[Statement]> {
|
|
254
|
-
if let Value::Map(map) = value {
|
|
255
|
-
if let Some(Value::Block(statements)) = map.get("body") {
|
|
256
|
-
return Some(statements);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
None
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
fn ast_to_string(statements: Vec<Statement>) -> String {
|
|
263
|
-
serde_json::to_string_pretty(&statements).expect("Failed to serialize AST")
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
#[cfg(test)]
|
|
267
|
-
mod tests {
|
|
268
|
-
use super::*;
|
|
269
|
-
use devalang_types::{Statement, StatementKind, Value};
|
|
270
|
-
|
|
271
|
-
#[test]
|
|
272
|
-
fn test_extract_loop_body_statements_none() {
|
|
273
|
-
let v = Value::Map(std::collections::HashMap::new());
|
|
274
|
-
assert!(extract_loop_body_statements(&v).is_none());
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
#[test]
|
|
278
|
-
fn test_extract_loop_body_statements_some() {
|
|
279
|
-
let stmt = Statement::unknown();
|
|
280
|
-
let mut map = std::collections::HashMap::new();
|
|
281
|
-
map.insert("body".to_string(), Value::Block(vec![stmt.clone(), stmt]));
|
|
282
|
-
|
|
283
|
-
let v = Value::Map(map);
|
|
284
|
-
let res = extract_loop_body_statements(&v);
|
|
285
|
-
assert!(res.is_some());
|
|
286
|
-
let slice = res.unwrap();
|
|
287
|
-
assert_eq!(slice.len(), 2);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
#[test]
|
|
291
|
-
fn test_collect_errors_recursively_detection() {
|
|
292
|
-
let mut statements: Vec<Statement> = Vec::new();
|
|
293
|
-
|
|
294
|
-
// Unknown statement should be reported
|
|
295
|
-
let s1 = Statement::unknown_with_pos(0, 10, 2);
|
|
296
|
-
statements.push(s1.clone());
|
|
297
|
-
|
|
298
|
-
// Error statement
|
|
299
|
-
let s2 = Statement::error_with_pos(0, 20, 4, "boom".to_string());
|
|
300
|
-
statements.push(s2.clone());
|
|
301
|
-
|
|
302
|
-
// Loop with body containing unknown
|
|
303
|
-
let body_stmt = Statement::unknown_with_pos(1, 30, 5);
|
|
304
|
-
let mut loop_map = std::collections::HashMap::new();
|
|
305
|
-
loop_map.insert("body".to_string(), Value::Block(vec![body_stmt.clone()]));
|
|
306
|
-
|
|
307
|
-
let loop_stmt = Statement {
|
|
308
|
-
kind: StatementKind::Loop,
|
|
309
|
-
value: Value::Map(loop_map),
|
|
310
|
-
indent: 0,
|
|
311
|
-
line: 15,
|
|
312
|
-
column: 1,
|
|
313
|
-
};
|
|
314
|
-
statements.push(loop_stmt);
|
|
315
|
-
|
|
316
|
-
let errors = collect_errors_recursively(&statements);
|
|
317
|
-
// expect three errors: s1 unknown, s2 error, body unknown
|
|
318
|
-
assert_eq!(errors.len(), 3);
|
|
319
|
-
assert!(errors.iter().any(|e| e.line == 10));
|
|
320
|
-
assert!(errors.iter().any(|e| e.line == 20));
|
|
321
|
-
assert!(errors.iter().any(|e| e.line == 30));
|
|
322
|
-
}
|
|
323
|
-
}
|
package/rust/macros/Cargo.toml
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
[package]
|
|
2
|
-
name = "devalang_macros"
|
|
3
|
-
description = "Macros for Devalang"
|
|
4
|
-
license = "MIT"
|
|
5
|
-
version = "0.0.1"
|
|
6
|
-
edition = "2024"
|
|
7
|
-
|
|
8
|
-
[lib]
|
|
9
|
-
proc-macro = true
|
|
10
|
-
|
|
11
|
-
[dependencies]
|
|
12
|
-
proc-macro2 = "1"
|
|
13
|
-
quote = "1"
|
|
14
|
-
syn = { version = "2", features = ["full"] }
|