@devaloop/devalang 0.0.1-alpha.7 → 0.0.1-alpha.8
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.toml +1 -1
- package/README.md +29 -10
- package/docs/CHANGELOG.md +22 -2
- package/docs/ROADMAP.md +2 -2
- package/docs/SYNTAX.md +41 -7
- package/docs/TODO.md +3 -3
- package/examples/condition.deva +24 -0
- package/examples/index.deva +4 -5
- package/examples/variables.deva +1 -1
- package/out-tsc/bin/devalang.exe +0 -0
- package/package.json +1 -1
- package/project-version.json +3 -3
- package/rust/cli/build.rs +6 -1
- package/rust/core/audio/evaluator.rs +31 -0
- package/rust/core/audio/interpreter/call.rs +42 -0
- package/rust/core/audio/interpreter/condition.rs +65 -0
- package/rust/core/audio/interpreter/driver.rs +204 -0
- package/rust/core/audio/interpreter/let_.rs +19 -0
- package/rust/core/audio/interpreter/load.rs +18 -0
- package/rust/core/audio/interpreter/loop_.rs +59 -0
- package/rust/core/audio/interpreter/mod.rs +11 -0
- package/rust/core/audio/interpreter/sleep.rs +36 -0
- package/rust/core/audio/interpreter/spawn.rs +65 -0
- package/rust/core/audio/interpreter/tempo.rs +16 -0
- package/rust/core/audio/interpreter/trigger.rs +69 -0
- package/rust/core/audio/loader/mod.rs +1 -0
- package/rust/core/audio/{loader.rs → loader/trigger.rs} +3 -1
- package/rust/core/audio/mod.rs +2 -1
- package/rust/core/audio/{render.rs → renderer.rs} +6 -2
- package/rust/core/builder/mod.rs +1 -1
- package/rust/core/debugger/lexer.rs +1 -1
- package/rust/core/debugger/mod.rs +1 -0
- package/rust/core/debugger/store.rs +25 -0
- package/rust/core/error/mod.rs +1 -1
- package/rust/core/lexer/handler/driver.rs +215 -0
- package/rust/core/lexer/handler/identifier.rs +2 -0
- package/rust/core/lexer/handler/mod.rs +3 -227
- package/rust/core/lexer/handler/operator.rs +44 -0
- package/rust/core/lexer/mod.rs +1 -1
- package/rust/core/lexer/token.rs +36 -9
- package/rust/core/parser/driver.rs +312 -0
- package/rust/core/parser/handler/at.rs +3 -7
- package/rust/core/parser/handler/bank.rs +5 -2
- package/rust/core/parser/handler/condition.rs +74 -0
- package/rust/core/parser/handler/dot.rs +1 -1
- package/rust/core/parser/handler/identifier.rs +38 -36
- package/rust/core/parser/handler/loop_.rs +1 -1
- package/rust/core/parser/handler/mod.rs +2 -1
- package/rust/core/parser/handler/tempo.rs +1 -1
- package/rust/core/parser/mod.rs +3 -237
- package/rust/core/parser/statement.rs +29 -36
- package/rust/core/preprocessor/loader.rs +7 -6
- package/rust/core/preprocessor/processor.rs +1 -1
- package/rust/core/preprocessor/resolver/call.rs +53 -0
- package/rust/core/preprocessor/resolver/condition.rs +66 -0
- package/rust/core/preprocessor/resolver/driver.rs +182 -0
- package/rust/core/preprocessor/resolver/group.rs +89 -84
- package/rust/core/preprocessor/resolver/mod.rs +5 -153
- package/rust/core/preprocessor/resolver/spawn.rs +53 -0
- package/rust/core/audio/interpreter.rs +0 -317
- package/rust/core/lexer/handler/equal.rs +0 -32
|
@@ -3,7 +3,7 @@ use std::collections::HashMap;
|
|
|
3
3
|
use crate::{
|
|
4
4
|
core::{
|
|
5
5
|
parser::statement::{ Statement, StatementKind },
|
|
6
|
-
preprocessor::{ module::Module, resolver::trigger::resolve_trigger },
|
|
6
|
+
preprocessor::{ module::Module, resolver::{condition::resolve_condition, trigger::resolve_trigger} },
|
|
7
7
|
shared::value::Value,
|
|
8
8
|
store::global::GlobalStore,
|
|
9
9
|
},
|
|
@@ -18,96 +18,101 @@ pub fn resolve_group(
|
|
|
18
18
|
) -> Statement {
|
|
19
19
|
let logger = Logger::new();
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
21
|
+
let Value::Map(value_map) = &stmt.value else {
|
|
22
|
+
return type_error(&logger, module, stmt, "Expected a map for group statement".to_string());
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
let group_name = match value_map.get("identifier") {
|
|
26
|
+
Some(Value::String(name)) => name.clone(),
|
|
27
|
+
Some(other) => {
|
|
28
|
+
return type_error(
|
|
29
|
+
&logger,
|
|
30
|
+
module,
|
|
31
|
+
stmt,
|
|
32
|
+
format!("Group name must be a string, found {:?}", other)
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
None => {
|
|
36
|
+
return type_error(&logger, module, stmt, "Group name is required".to_string());
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
let resolved_body = match value_map.get("body") {
|
|
41
|
+
Some(Value::Block(statements)) => {
|
|
42
|
+
let mut resolved = Vec::new();
|
|
43
|
+
|
|
44
|
+
for stmt in statements {
|
|
45
|
+
match &stmt.kind {
|
|
46
|
+
StatementKind::Trigger { entity, duration } => {
|
|
47
|
+
let resolved_trigger = resolve_trigger(
|
|
48
|
+
&mut stmt.clone(),
|
|
49
|
+
entity,
|
|
50
|
+
&mut duration.clone(),
|
|
51
|
+
module,
|
|
52
|
+
path,
|
|
53
|
+
global_store
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
resolved.push(resolved_trigger);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
StatementKind::If => {
|
|
60
|
+
let resolved_condition = resolve_condition(
|
|
61
|
+
&mut stmt.clone(),
|
|
62
|
+
module,
|
|
63
|
+
path,
|
|
64
|
+
global_store
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
resolved.push(resolved_condition);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
_ => {
|
|
71
|
+
println!("Unhandled group body statement: {:?}", stmt);
|
|
58
72
|
}
|
|
59
73
|
}
|
|
60
|
-
Value::Block(resolved_block)
|
|
61
|
-
}
|
|
62
|
-
Some(other) => {
|
|
63
|
-
log_type_error(
|
|
64
|
-
&logger,
|
|
65
|
-
module,
|
|
66
|
-
stmt,
|
|
67
|
-
format!("Unexpected value for group body: {:?}", other)
|
|
68
|
-
);
|
|
69
|
-
Value::Null
|
|
70
|
-
}
|
|
71
|
-
None => {
|
|
72
|
-
log_type_error(
|
|
73
|
-
&logger,
|
|
74
|
-
module,
|
|
75
|
-
stmt,
|
|
76
|
-
"Missing 'body' key in group statement map".to_string()
|
|
77
|
-
);
|
|
78
|
-
Value::Null
|
|
79
74
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
};
|
|
92
|
-
} else {
|
|
93
|
-
log_type_error(
|
|
94
|
-
&logger,
|
|
95
|
-
module,
|
|
96
|
-
stmt,
|
|
97
|
-
format!("Expected Map for group statement, found {:?}", stmt.value)
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
Statement {
|
|
101
|
-
kind: StatementKind::Error {
|
|
102
|
-
message: "Expected a map for group statement".to_string(),
|
|
103
|
-
},
|
|
104
|
-
value: Value::Null,
|
|
105
|
-
..stmt.clone()
|
|
75
|
+
|
|
76
|
+
Value::Block(resolved)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
Some(other) => {
|
|
80
|
+
return type_error(
|
|
81
|
+
&logger,
|
|
82
|
+
module,
|
|
83
|
+
stmt,
|
|
84
|
+
format!("Unexpected value for group body: {:?}", other)
|
|
85
|
+
);
|
|
106
86
|
}
|
|
87
|
+
|
|
88
|
+
None => {
|
|
89
|
+
return type_error(
|
|
90
|
+
&logger,
|
|
91
|
+
module,
|
|
92
|
+
stmt,
|
|
93
|
+
"Missing 'body' key in group statement".to_string()
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
let mut resolved_map = HashMap::new();
|
|
99
|
+
resolved_map.insert("identifier".to_string(), Value::String(group_name));
|
|
100
|
+
resolved_map.insert("body".to_string(), resolved_body);
|
|
101
|
+
|
|
102
|
+
Statement {
|
|
103
|
+
kind: StatementKind::Group,
|
|
104
|
+
value: Value::Map(resolved_map),
|
|
105
|
+
..stmt.clone()
|
|
107
106
|
}
|
|
108
107
|
}
|
|
109
108
|
|
|
110
|
-
fn
|
|
109
|
+
fn type_error(logger: &Logger, module: &Module, stmt: &Statement, message: String) -> Statement {
|
|
111
110
|
let stacktrace = format!("{}:{}:{}", module.path, stmt.line, stmt.column);
|
|
112
111
|
logger.log_error_with_stacktrace(&message, &stacktrace);
|
|
112
|
+
|
|
113
|
+
Statement {
|
|
114
|
+
kind: StatementKind::Error { message },
|
|
115
|
+
value: Value::Null,
|
|
116
|
+
..stmt.clone()
|
|
117
|
+
}
|
|
113
118
|
}
|
|
@@ -1,158 +1,10 @@
|
|
|
1
|
+
pub mod driver;
|
|
2
|
+
|
|
1
3
|
pub mod trigger;
|
|
2
4
|
pub mod loop_;
|
|
3
5
|
pub mod bank;
|
|
4
6
|
pub mod tempo;
|
|
5
7
|
pub mod group;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
core::{
|
|
10
|
-
parser::statement::{ self, Statement, StatementKind },
|
|
11
|
-
preprocessor::{
|
|
12
|
-
loader::ModuleLoader,
|
|
13
|
-
resolver::{
|
|
14
|
-
bank::resolve_bank,
|
|
15
|
-
group::resolve_group,
|
|
16
|
-
loop_::resolve_loop,
|
|
17
|
-
tempo::resolve_tempo,
|
|
18
|
-
trigger::resolve_trigger,
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
shared::{ duration::Duration, value::Value },
|
|
22
|
-
store::global::GlobalStore,
|
|
23
|
-
utils::validation::{ is_valid_entity, is_valid_identifier },
|
|
24
|
-
},
|
|
25
|
-
utils::logger::Logger,
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
pub fn resolve_all_modules(module_loader: &ModuleLoader, global_store: &mut GlobalStore) {
|
|
29
|
-
for module in global_store.clone().modules.values_mut() {
|
|
30
|
-
resolve_imports(module_loader, global_store);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
pub fn resolve_imports(module_loader: &ModuleLoader, global_store: &mut GlobalStore) {
|
|
35
|
-
for (module_path, module) in global_store.clone().modules.iter_mut() {
|
|
36
|
-
for (name, source_path) in &module.import_table.imports {
|
|
37
|
-
match source_path {
|
|
38
|
-
Value::String(source_path) => {
|
|
39
|
-
if let Some(source_module) = global_store.modules.get(source_path) {
|
|
40
|
-
if let Some(value) = source_module.export_table.get_export(name) {
|
|
41
|
-
module.variable_table.set(name.clone(), value.clone());
|
|
42
|
-
} else {
|
|
43
|
-
println!(
|
|
44
|
-
"[warn] '{module_path}': '{name}' not found in exports of '{source_path}'"
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
} else {
|
|
48
|
-
println!(
|
|
49
|
-
"[warn] '{module_path}': cannot find source module '{source_path}'"
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
_ => {
|
|
54
|
-
println!(
|
|
55
|
-
"[warn] '{module_path}': expected string for import source, found {:?}",
|
|
56
|
-
source_path
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
pub fn resolve_and_flatten_all_modules(
|
|
65
|
-
global_store: &mut GlobalStore
|
|
66
|
-
) -> HashMap<String, Vec<Statement>> {
|
|
67
|
-
let logger = Logger::new();
|
|
68
|
-
let snapshot = global_store.clone();
|
|
69
|
-
|
|
70
|
-
// 1. Imports resolution
|
|
71
|
-
for (module_path, module) in global_store.modules.iter_mut() {
|
|
72
|
-
for (name, source_path) in &module.import_table.imports {
|
|
73
|
-
if let Value::String(source_path_str) = source_path {
|
|
74
|
-
match snapshot.modules.get(source_path_str) {
|
|
75
|
-
Some(source_module) => {
|
|
76
|
-
if let Some(value) = source_module.export_table.get_export(name) {
|
|
77
|
-
module.variable_table.set(name.clone(), value.clone());
|
|
78
|
-
} else {
|
|
79
|
-
logger.log_error_with_stacktrace(
|
|
80
|
-
&format!("'{name}' not found in exports of '{source_path_str}'"),
|
|
81
|
-
module_path
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
None => {
|
|
86
|
-
logger.log_error_with_stacktrace(
|
|
87
|
-
&format!("Cannot find source module '{source_path_str}'"),
|
|
88
|
-
module_path
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
} else {
|
|
93
|
-
logger.log_error_with_stacktrace(
|
|
94
|
-
&format!("Expected string for import source, found {:?}", source_path),
|
|
95
|
-
module_path
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// 2. Statements resolution
|
|
102
|
-
let mut resolved_map: HashMap<String, Vec<Statement>> = HashMap::new();
|
|
103
|
-
let store_snapshot = global_store.clone();
|
|
104
|
-
|
|
105
|
-
for (path, module) in &store_snapshot.modules {
|
|
106
|
-
let mut resolved = Vec::new();
|
|
107
|
-
|
|
108
|
-
for stmt in &module.statements {
|
|
109
|
-
let mut stmt = stmt.clone();
|
|
110
|
-
|
|
111
|
-
match &stmt.kind {
|
|
112
|
-
StatementKind::Trigger { entity, duration } => {
|
|
113
|
-
let resolved_stmt = resolve_trigger(
|
|
114
|
-
&stmt,
|
|
115
|
-
entity.as_str(),
|
|
116
|
-
&mut duration.clone(),
|
|
117
|
-
&module,
|
|
118
|
-
&path,
|
|
119
|
-
&store_snapshot
|
|
120
|
-
);
|
|
121
|
-
resolved.push(resolved_stmt);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
StatementKind::Loop => {
|
|
125
|
-
let resolved_stmt = resolve_loop(&stmt, &module, &path, &store_snapshot);
|
|
126
|
-
resolved.push(resolved_stmt);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
StatementKind::Bank => {
|
|
130
|
-
let resolved_stmt = resolve_bank(&stmt, &module, &path, &store_snapshot);
|
|
131
|
-
resolved.push(resolved_stmt);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
StatementKind::Tempo => {
|
|
135
|
-
let resolved_stmt = resolve_tempo(&stmt, &module, &path, &store_snapshot);
|
|
136
|
-
resolved.push(resolved_stmt);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
StatementKind::Import { .. } | StatementKind::Export { .. } => {
|
|
140
|
-
resolved.push(stmt.clone());
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
StatementKind::Group => {
|
|
144
|
-
let resolved_stmt = resolve_group(&stmt, &module, &path, &store_snapshot);
|
|
145
|
-
resolved.push(resolved_stmt);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
_ => {
|
|
149
|
-
resolved.push(stmt);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
resolved_map.insert(path.clone(), resolved);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
resolved_map
|
|
158
|
-
}
|
|
8
|
+
pub mod condition;
|
|
9
|
+
pub mod spawn;
|
|
10
|
+
pub mod call;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
use crate::{
|
|
2
|
+
core::{
|
|
3
|
+
parser::statement::{Statement, StatementKind},
|
|
4
|
+
preprocessor::module::Module,
|
|
5
|
+
shared::value::Value,
|
|
6
|
+
store::global::GlobalStore,
|
|
7
|
+
},
|
|
8
|
+
utils::logger::Logger,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
pub fn resolve_spawn(
|
|
12
|
+
stmt: &Statement,
|
|
13
|
+
module: &Module,
|
|
14
|
+
_path: &str,
|
|
15
|
+
_global_store: &GlobalStore,
|
|
16
|
+
) -> Statement {
|
|
17
|
+
let logger = Logger::new();
|
|
18
|
+
|
|
19
|
+
let Value::String(name) = &stmt.value else {
|
|
20
|
+
return type_error(&logger, module, stmt, "Spawn expects a group name as string.".to_string());
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
match module.variable_table.variables.get(name) {
|
|
24
|
+
Some(Value::Map(group_stmt)) => Statement {
|
|
25
|
+
kind: StatementKind::Spawn,
|
|
26
|
+
value: Value::Map(group_stmt.clone()),
|
|
27
|
+
..stmt.clone()
|
|
28
|
+
},
|
|
29
|
+
Some(other) => type_error(
|
|
30
|
+
&logger,
|
|
31
|
+
module,
|
|
32
|
+
stmt,
|
|
33
|
+
format!("Expected a group for '{}', but found {:?}", name, other),
|
|
34
|
+
),
|
|
35
|
+
None => type_error(
|
|
36
|
+
&logger,
|
|
37
|
+
module,
|
|
38
|
+
stmt,
|
|
39
|
+
format!("Group '{}' not found in module '{}'", name, module.path),
|
|
40
|
+
),
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
fn type_error(logger: &Logger, module: &Module, stmt: &Statement, message: String) -> Statement {
|
|
45
|
+
let stacktrace = format!("{}:{}:{}", module.path, stmt.line, stmt.column);
|
|
46
|
+
logger.log_error_with_stacktrace(&message, &stacktrace);
|
|
47
|
+
|
|
48
|
+
Statement {
|
|
49
|
+
kind: StatementKind::Error { message },
|
|
50
|
+
value: Value::Null,
|
|
51
|
+
..stmt.clone()
|
|
52
|
+
}
|
|
53
|
+
}
|