@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
|
@@ -1,317 +0,0 @@
|
|
|
1
|
-
use crate::{
|
|
2
|
-
core::{
|
|
3
|
-
audio::{ engine::AudioEngine, loader::load_trigger },
|
|
4
|
-
parser::statement::{ Statement, StatementKind },
|
|
5
|
-
shared::{ duration::Duration, value::Value },
|
|
6
|
-
store::variable::VariableTable,
|
|
7
|
-
},
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
pub fn interprete_statements(
|
|
11
|
-
statements: &Vec<Statement>,
|
|
12
|
-
audio_engine: AudioEngine,
|
|
13
|
-
entry: String,
|
|
14
|
-
output: String
|
|
15
|
-
) -> (AudioEngine, f32, f32) {
|
|
16
|
-
let mut base_bpm = 120.0;
|
|
17
|
-
let mut base_duration = 60.0 / base_bpm;
|
|
18
|
-
|
|
19
|
-
let variable_table = audio_engine.variables.clone();
|
|
20
|
-
|
|
21
|
-
let (updated_audio_engine, base_bpm, max_end_time) = execute_audio_statements(
|
|
22
|
-
audio_engine.clone(),
|
|
23
|
-
variable_table.clone(),
|
|
24
|
-
statements.clone(),
|
|
25
|
-
base_bpm.clone(),
|
|
26
|
-
base_duration.clone(),
|
|
27
|
-
0.0,
|
|
28
|
-
0.0
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
(updated_audio_engine, base_bpm, max_end_time)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
pub fn execute_audio_statements(
|
|
35
|
-
mut audio_engine: AudioEngine,
|
|
36
|
-
mut variable_table: VariableTable,
|
|
37
|
-
mut statements: Vec<Statement>,
|
|
38
|
-
mut base_bpm: f32,
|
|
39
|
-
mut base_duration: f32,
|
|
40
|
-
mut max_end_time: f32,
|
|
41
|
-
mut cursor_time: f32
|
|
42
|
-
) -> (AudioEngine, f32, f32) {
|
|
43
|
-
for stmt in statements {
|
|
44
|
-
match &stmt.kind {
|
|
45
|
-
StatementKind::Load { source, alias } => {
|
|
46
|
-
variable_table.set(alias.to_string(), Value::String(source.clone()));
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
StatementKind::Let { name } => {
|
|
50
|
-
variable_table.set(name.to_string(), stmt.value.clone());
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
StatementKind::Tempo => {
|
|
54
|
-
if let Value::Number(bpm_) = &stmt.value {
|
|
55
|
-
base_bpm = *bpm_ as f32;
|
|
56
|
-
base_duration = 60.0 / base_bpm;
|
|
57
|
-
} else {
|
|
58
|
-
eprintln!("❌ Invalid tempo value: {:?}", stmt.value);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
StatementKind::Trigger { entity, duration } => {
|
|
63
|
-
if let Some(trigger_val) = variable_table.get(entity) {
|
|
64
|
-
// Étape 1 : Résolution de duration
|
|
65
|
-
let duration_secs = match duration {
|
|
66
|
-
Duration::Number(n) => *n,
|
|
67
|
-
|
|
68
|
-
Duration::Identifier(id) => {
|
|
69
|
-
if id == "auto" {
|
|
70
|
-
1.0 // Valeur par défaut pour "auto"
|
|
71
|
-
} else {
|
|
72
|
-
match variable_table.get(id) {
|
|
73
|
-
Some(Value::Number(n)) => *n,
|
|
74
|
-
Some(Value::Identifier(other)) => {
|
|
75
|
-
if other == "auto" {
|
|
76
|
-
1.0 // Valeur par défaut pour "auto"
|
|
77
|
-
} else {
|
|
78
|
-
eprintln!("❌ Invalid duration identifier '{}': expected number or string, got identifier", id);
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
Some(other) => {
|
|
83
|
-
eprintln!(
|
|
84
|
-
"❌ Invalid duration reference '{}': expected number or string, got {:?}",
|
|
85
|
-
id,
|
|
86
|
-
other
|
|
87
|
-
);
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
None => {
|
|
91
|
-
eprintln!("❌ Duration identifier '{}' not found in variable table", id);
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
Duration::Auto => {
|
|
99
|
-
// Si "auto", tu choisis une valeur par défaut ou duration du sample ?
|
|
100
|
-
1.0 // ← par exemple 1.0 beat
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
// Durée réelle en secondes selon tempo
|
|
105
|
-
let duration_final = duration_secs * base_duration;
|
|
106
|
-
|
|
107
|
-
// Chargement de l'audio
|
|
108
|
-
let (src, _) = load_trigger(
|
|
109
|
-
trigger_val,
|
|
110
|
-
duration,
|
|
111
|
-
base_duration,
|
|
112
|
-
variable_table.clone()
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
audio_engine.insert(&src, cursor_time, duration_final, None);
|
|
116
|
-
|
|
117
|
-
cursor_time += duration_final;
|
|
118
|
-
if cursor_time > max_end_time {
|
|
119
|
-
max_end_time = cursor_time;
|
|
120
|
-
}
|
|
121
|
-
} else {
|
|
122
|
-
eprintln!("❌ Unknown trigger entity: {}", entity);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
StatementKind::Spawn => {
|
|
127
|
-
if let Value::String(identifier) = &stmt.value {
|
|
128
|
-
match variable_table.get(identifier) {
|
|
129
|
-
Some(Value::Map(map)) => {
|
|
130
|
-
if let Some(Value::Block(block)) = map.get("body") {
|
|
131
|
-
let mut local_max = cursor_time;
|
|
132
|
-
|
|
133
|
-
for inner_stmt in block {
|
|
134
|
-
let (inner_engine, _, inner_end_time) =
|
|
135
|
-
execute_audio_statements(
|
|
136
|
-
audio_engine.clone(),
|
|
137
|
-
variable_table.clone(),
|
|
138
|
-
vec![inner_stmt.clone()],
|
|
139
|
-
base_bpm,
|
|
140
|
-
base_duration,
|
|
141
|
-
max_end_time,
|
|
142
|
-
cursor_time // <- important: same cursor time
|
|
143
|
-
);
|
|
144
|
-
audio_engine = inner_engine;
|
|
145
|
-
if inner_end_time > local_max {
|
|
146
|
-
local_max = inner_end_time;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// Update cursor once all done
|
|
151
|
-
if local_max > max_end_time {
|
|
152
|
-
max_end_time = local_max;
|
|
153
|
-
}
|
|
154
|
-
cursor_time = local_max;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
_ => eprintln!("❌ Cannot spawn '{}'", identifier),
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
StatementKind::Sleep => {
|
|
163
|
-
let duration_secs = match &stmt.value {
|
|
164
|
-
Value::Number(ms) => *ms / 1000.0,
|
|
165
|
-
|
|
166
|
-
Value::String(s) if s.ends_with("ms") => {
|
|
167
|
-
let ms = s.trim_end_matches("ms").parse::<f32>();
|
|
168
|
-
match ms {
|
|
169
|
-
Ok(ms) => ms / 1000.0,
|
|
170
|
-
Err(_) => {
|
|
171
|
-
eprintln!("❌ Invalid sleep value (ms): {}", s);
|
|
172
|
-
continue;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
Value::String(s) if s.ends_with("s") => {
|
|
178
|
-
let s_ = s.trim_end_matches("s").parse::<f32>();
|
|
179
|
-
match s_ {
|
|
180
|
-
Ok(secs) => secs,
|
|
181
|
-
Err(_) => {
|
|
182
|
-
eprintln!("❌ Invalid sleep value (s): {}", s);
|
|
183
|
-
continue;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
other => {
|
|
189
|
-
eprintln!("❌ Invalid sleep value: {:?}", other);
|
|
190
|
-
continue;
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
cursor_time += duration_secs;
|
|
195
|
-
|
|
196
|
-
if cursor_time > max_end_time {
|
|
197
|
-
max_end_time = cursor_time;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
StatementKind::Loop => {
|
|
202
|
-
if let Value::Map(loop_value) = &stmt.value {
|
|
203
|
-
let iterator = loop_value.get("iterator");
|
|
204
|
-
let body = loop_value.get("body");
|
|
205
|
-
|
|
206
|
-
let loop_count = if let Some(Value::Number(n)) = iterator {
|
|
207
|
-
*n as usize
|
|
208
|
-
} else {
|
|
209
|
-
eprintln!("❌ Loop iterator must be a number: {:?}", iterator);
|
|
210
|
-
continue;
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
let loop_body = if let Some(Value::Block(body)) = body {
|
|
214
|
-
body.clone()
|
|
215
|
-
} else {
|
|
216
|
-
eprintln!("❌ Loop body must be a block: {:?}", body);
|
|
217
|
-
continue;
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
for _ in 0..loop_count {
|
|
221
|
-
let (loop_engine, _, loop_end_time) = execute_audio_statements(
|
|
222
|
-
audio_engine.clone(),
|
|
223
|
-
variable_table.clone(),
|
|
224
|
-
loop_body.clone(),
|
|
225
|
-
base_bpm,
|
|
226
|
-
base_duration,
|
|
227
|
-
max_end_time,
|
|
228
|
-
cursor_time
|
|
229
|
-
);
|
|
230
|
-
|
|
231
|
-
audio_engine = loop_engine;
|
|
232
|
-
|
|
233
|
-
// Update time and max_end_time after each loop iteration
|
|
234
|
-
cursor_time = loop_end_time;
|
|
235
|
-
if loop_end_time > max_end_time {
|
|
236
|
-
max_end_time = loop_end_time;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
StatementKind::Call => {
|
|
243
|
-
if let Value::String(identifier) = &stmt.value {
|
|
244
|
-
match variable_table.get(identifier) {
|
|
245
|
-
Some(Value::Map(map)) => {
|
|
246
|
-
match map.get("body") {
|
|
247
|
-
Some(Value::Block(block)) => {
|
|
248
|
-
let (called_engine, _, called_end_time) =
|
|
249
|
-
execute_audio_statements(
|
|
250
|
-
audio_engine.clone(),
|
|
251
|
-
variable_table.clone(),
|
|
252
|
-
block.clone(),
|
|
253
|
-
base_bpm,
|
|
254
|
-
base_duration,
|
|
255
|
-
max_end_time,
|
|
256
|
-
cursor_time
|
|
257
|
-
);
|
|
258
|
-
|
|
259
|
-
audio_engine = called_engine;
|
|
260
|
-
cursor_time = called_end_time;
|
|
261
|
-
if called_end_time > max_end_time {
|
|
262
|
-
max_end_time = called_end_time;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
Some(other) => {
|
|
266
|
-
eprintln!(
|
|
267
|
-
"❌ Cannot call '{}': expected 'body' to be a block, got {:?}",
|
|
268
|
-
identifier,
|
|
269
|
-
other
|
|
270
|
-
);
|
|
271
|
-
}
|
|
272
|
-
None => {
|
|
273
|
-
eprintln!("❌ Cannot call '{}': missing 'body' in group map", identifier);
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
Some(other) => {
|
|
278
|
-
eprintln!(
|
|
279
|
-
"❌ Cannot call '{}': expected a Map with 'body', got {:?}",
|
|
280
|
-
identifier,
|
|
281
|
-
other
|
|
282
|
-
);
|
|
283
|
-
}
|
|
284
|
-
None => {
|
|
285
|
-
eprintln!("❌ Cannot call '{}': not found in variable table", identifier);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
} else {
|
|
289
|
-
eprintln!(
|
|
290
|
-
"❌ Invalid call statement: expected a string identifier, got {:?}",
|
|
291
|
-
stmt.value
|
|
292
|
-
);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
StatementKind::Bank => {}
|
|
297
|
-
|
|
298
|
-
StatementKind::Import { names, source } => {}
|
|
299
|
-
|
|
300
|
-
StatementKind::Export { names, source } => {}
|
|
301
|
-
|
|
302
|
-
StatementKind::Group => {}
|
|
303
|
-
|
|
304
|
-
StatementKind::Unknown => {
|
|
305
|
-
// Ignore unknown statements
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
_ => {
|
|
309
|
-
eprintln!("Unsupported statement kind: {:?}", stmt);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
audio_engine.set_variables(variable_table);
|
|
315
|
-
|
|
316
|
-
(audio_engine, base_bpm, max_end_time)
|
|
317
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
use crate::core::lexer::token::{Token, TokenKind};
|
|
2
|
-
|
|
3
|
-
pub fn handle_equal_lexer(
|
|
4
|
-
char: char,
|
|
5
|
-
chars: &mut std::iter::Peekable<std::str::Chars>,
|
|
6
|
-
current_indent: &mut usize,
|
|
7
|
-
indent_stack: &mut Vec<usize>,
|
|
8
|
-
tokens: &mut Vec<Token>,
|
|
9
|
-
line: &mut usize,
|
|
10
|
-
column: &mut usize
|
|
11
|
-
) {
|
|
12
|
-
if let Some('=') = chars.peek() {
|
|
13
|
-
chars.next();
|
|
14
|
-
tokens.push(Token {
|
|
15
|
-
kind: TokenKind::DoubleEquals,
|
|
16
|
-
lexeme: char.to_string(),
|
|
17
|
-
line: *line,
|
|
18
|
-
column: *column,
|
|
19
|
-
indent: *current_indent,
|
|
20
|
-
});
|
|
21
|
-
*column += 2;
|
|
22
|
-
} else {
|
|
23
|
-
tokens.push(Token {
|
|
24
|
-
kind: TokenKind::Equals,
|
|
25
|
-
lexeme: char.to_string(),
|
|
26
|
-
line: *line,
|
|
27
|
-
column: *column,
|
|
28
|
-
indent: *current_indent,
|
|
29
|
-
});
|
|
30
|
-
*column += 1;
|
|
31
|
-
}
|
|
32
|
-
}
|