@devaloop/devalang 0.0.1-alpha.2 → 0.0.1-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/.devalang +1 -1
  2. package/Cargo.toml +46 -46
  3. package/README.md +48 -30
  4. package/docs/CHANGELOG.md +28 -6
  5. package/docs/COMMANDS.md +31 -0
  6. package/docs/CONFIG.md +6 -4
  7. package/docs/ROADMAP.md +5 -1
  8. package/docs/TODO.md +10 -35
  9. package/examples/exported.deva +1 -1
  10. package/examples/index.deva +8 -1
  11. package/examples/samples/hat-808.wav +0 -0
  12. package/out-tsc/bin/devalang.exe +0 -0
  13. package/package.json +41 -42
  14. package/project-version.json +5 -5
  15. package/rust/audio/engine.rs +130 -0
  16. package/rust/audio/interpreter.rs +143 -0
  17. package/rust/audio/loader.rs +46 -0
  18. package/rust/audio/mod.rs +5 -1
  19. package/rust/audio/player.rs +54 -0
  20. package/rust/audio/render.rs +57 -0
  21. package/rust/cli/build.rs +73 -45
  22. package/rust/cli/check.rs +47 -111
  23. package/rust/cli/init.rs +1 -1
  24. package/rust/cli/mod.rs +203 -2
  25. package/rust/cli/play.rs +191 -0
  26. package/rust/{utils/config.rs → config/loader.rs} +3 -2
  27. package/rust/config/mod.rs +16 -0
  28. package/rust/core/builder/mod.rs +69 -27
  29. package/rust/core/debugger/lexer.rs +27 -0
  30. package/rust/core/debugger/mod.rs +12 -49
  31. package/rust/core/debugger/preprocessor.rs +27 -0
  32. package/rust/core/error/mod.rs +60 -0
  33. package/rust/core/lexer/{at.rs → handler/at.rs} +1 -1
  34. package/rust/core/lexer/{brace.rs → handler/brace.rs} +1 -1
  35. package/rust/core/lexer/{colon.rs → handler/colon.rs} +1 -1
  36. package/rust/core/lexer/{comment.rs → handler/comment.rs} +3 -3
  37. package/rust/core/lexer/{dot.rs → handler/dot.rs} +1 -1
  38. package/rust/core/lexer/{equal.rs → handler/equal.rs} +1 -1
  39. package/rust/core/lexer/{identifier.rs → handler/identifier.rs} +1 -1
  40. package/rust/core/lexer/{indent.rs → handler/indent.rs} +10 -5
  41. package/rust/core/lexer/handler/mod.rs +238 -0
  42. package/rust/core/lexer/{newline.rs → handler/newline.rs} +6 -10
  43. package/rust/core/lexer/{number.rs → handler/number.rs} +1 -1
  44. package/rust/core/lexer/handler/string.rs +66 -0
  45. package/rust/core/lexer/mod.rs +25 -14
  46. package/rust/core/lexer/token.rs +55 -0
  47. package/rust/core/mod.rs +5 -2
  48. package/rust/core/parser/handler/at.rs +166 -0
  49. package/rust/core/parser/handler/bank.rs +38 -0
  50. package/rust/core/parser/handler/dot.rs +112 -0
  51. package/rust/core/parser/handler/identifier.rs +134 -0
  52. package/rust/core/parser/handler/loop_.rs +55 -0
  53. package/rust/core/parser/handler/mod.rs +6 -0
  54. package/rust/core/parser/handler/tempo.rs +47 -0
  55. package/rust/core/parser/mod.rs +204 -166
  56. package/rust/core/parser/statement.rs +91 -0
  57. package/rust/core/preprocessor/loader.rs +116 -0
  58. package/rust/core/preprocessor/mod.rs +2 -24
  59. package/rust/core/preprocessor/module.rs +37 -56
  60. package/rust/core/preprocessor/processor.rs +41 -0
  61. package/rust/core/preprocessor/resolver/bank.rs +38 -51
  62. package/rust/core/preprocessor/resolver/loop_.rs +126 -65
  63. package/rust/core/preprocessor/resolver/mod.rs +119 -80
  64. package/rust/core/preprocessor/resolver/tempo.rs +40 -61
  65. package/rust/core/preprocessor/resolver/trigger.rs +93 -155
  66. package/rust/core/shared/duration.rs +8 -0
  67. package/rust/core/shared/mod.rs +2 -0
  68. package/rust/core/shared/value.rs +18 -0
  69. package/rust/core/store/export.rs +28 -0
  70. package/rust/core/store/global.rs +39 -0
  71. package/rust/core/store/import.rs +28 -0
  72. package/rust/core/store/mod.rs +4 -0
  73. package/rust/core/store/variable.rs +28 -0
  74. package/rust/core/utils/mod.rs +2 -0
  75. package/rust/core/utils/validation.rs +35 -0
  76. package/rust/lib.rs +0 -1
  77. package/rust/main.rs +22 -18
  78. package/rust/utils/logger.rs +69 -34
  79. package/rust/utils/mod.rs +3 -5
  80. package/rust/utils/watcher.rs +10 -2
  81. package/templates/minimal/.devalang +1 -1
  82. package/templates/welcome/.devalang +1 -1
  83. package/rust/core/lexer/bracket.rs +0 -41
  84. package/rust/core/lexer/driver.rs +0 -286
  85. package/rust/core/lexer/quote.rs +0 -61
  86. package/rust/core/parser/at.rs +0 -142
  87. package/rust/core/parser/bank.rs +0 -42
  88. package/rust/core/parser/dot.rs +0 -137
  89. package/rust/core/parser/identifer.rs +0 -91
  90. package/rust/core/parser/loop_.rs +0 -62
  91. package/rust/core/parser/tempo.rs +0 -42
  92. package/rust/core/parser/variable.rs +0 -129
  93. package/rust/core/preprocessor/dependencies.rs +0 -54
  94. package/rust/core/preprocessor/resolver/at.rs +0 -24
  95. package/rust/core/types/cli.rs +0 -182
  96. package/rust/core/types/config.rs +0 -15
  97. package/rust/core/types/mod.rs +0 -8
  98. package/rust/core/types/module.rs +0 -41
  99. package/rust/core/types/parser.rs +0 -73
  100. package/rust/core/types/statement.rs +0 -105
  101. package/rust/core/types/store.rs +0 -116
  102. package/rust/core/types/token.rs +0 -83
  103. package/rust/core/types/variable.rs +0 -32
  104. package/rust/runner/executer.rs +0 -44
  105. package/rust/runner/mod.rs +0 -1
  106. /package/rust/{utils → core/utils}/path.rs +0 -0
  107. /package/rust/utils/{loader.rs → spinner.rs} +0 -0
@@ -1,70 +1,51 @@
1
1
  use crate::core::{
2
- lexer::driver::lex,
3
- parser::{ parse_without_resolving },
4
- preprocessor::{
5
- collect_dependencies_recursively,
6
- resolver::{ resolve_exports, resolve_imports },
2
+ lexer::token::Token,
3
+ parser::statement::Statement,
4
+ store::{
5
+ export::ExportTable,
6
+ global::GlobalStore,
7
+ import::ImportTable,
8
+ variable::VariableTable,
7
9
  },
8
- types::{ module::Module, parser::Parser, store::{ ExportTable, GlobalStore, ImportTable } },
9
10
  };
10
11
 
11
- pub fn load_all_modules(entry_file: &str) -> GlobalStore {
12
- let mut global_store = GlobalStore::default();
13
- let files = collect_dependencies_recursively(entry_file);
12
+ #[derive(Debug, Clone)]
13
+ pub struct Module {
14
+ pub path: String,
15
+ pub resolved: bool,
16
+ pub tokens: Vec<Token>,
17
+ pub statements: Vec<Statement>,
18
+ pub variable_table: VariableTable,
19
+ pub export_table: ExportTable,
20
+ pub import_table: ImportTable,
21
+ }
14
22
 
15
- for file in &files {
16
- if let Err(e) = load_module_into_global_store(file, &mut global_store) {
17
- eprintln!("❌ Error loading {}: {}", file, e);
23
+ impl Module {
24
+ pub fn new(path: &str) -> Self {
25
+ Module {
26
+ path: path.to_string(),
27
+ tokens: Vec::new(),
28
+ statements: Vec::new(),
29
+ variable_table: VariableTable::new(),
30
+ export_table: ExportTable::new(),
31
+ import_table: ImportTable::new(),
32
+ resolved: false,
18
33
  }
19
34
  }
20
35
 
21
- for file in &files {
22
- if let Some(module) = global_store.modules.clone().get_mut(file) {
23
- let imports = resolve_imports(module, &mut global_store);
24
- module.import_table = imports.clone();
25
-
26
- let global_store_module = global_store.modules.get(&file.clone().to_string());
27
- if let Some(global_store_module_found) = global_store_module {
28
- global_store.insert_module(file.to_string(), module.clone());
29
- } else {
30
- eprintln!("❌ Module {} not found in global store after import resolution", file);
31
- }
32
- }
36
+ pub fn is_resolved(&self) -> bool {
37
+ self.resolved
33
38
  }
34
39
 
35
- global_store
36
- }
37
-
38
- pub fn load_module_into_global_store(
39
- path: &str,
40
- global_store: &mut GlobalStore
41
- ) -> Result<(), String> {
42
- if global_store.modules.contains_key(path) {
43
- return Ok(());
40
+ pub fn set_resolved(&mut self, resolved: bool) {
41
+ self.resolved = resolved;
44
42
  }
45
43
 
46
- let content = std::fs::read_to_string(path).map_err(|_| format!("Cannot read file: {}", path))?;
47
-
48
- let tokens = lex(content);
49
-
50
- let mut parser = Parser::new(tokens.clone());
51
-
52
- parser.current_module = path.to_string();
53
-
54
- let raw_statements = parse_without_resolving(tokens.clone(), &mut parser, global_store);
55
-
56
- let export_table = resolve_exports(&raw_statements, &mut parser);
57
-
58
- let mut module = Module {
59
- path: path.to_string(),
60
- tokens: tokens.clone(),
61
- statements: raw_statements,
62
- variable_table: parser.variable_table.clone(),
63
- export_table: export_table.clone(),
64
- import_table: parser.import_table.clone(),
65
- };
66
-
67
- global_store.insert_module(path.to_string(), module.clone());
44
+ pub fn add_token(&mut self, token: Token) {
45
+ self.tokens.push(token);
46
+ }
68
47
 
69
- Ok(())
48
+ pub fn add_statement(&mut self, statement: Statement) {
49
+ self.statements.push(statement);
50
+ }
70
51
  }
@@ -0,0 +1,41 @@
1
+ use crate::core::{
2
+ parser::{ statement::StatementKind, Parser },
3
+ preprocessor::loader::ModuleLoader,
4
+ shared::value::Value,
5
+ store::global::GlobalStore,
6
+ };
7
+
8
+ pub fn process_modules(module_loader: &ModuleLoader, global_store: &mut GlobalStore) {
9
+ for module in global_store.modules.values_mut() {
10
+ for stmt in &module.statements {
11
+ match &stmt.kind {
12
+ StatementKind::Let { name } => {
13
+ module.variable_table.variables.insert(name.clone(), stmt.value.clone());
14
+ }
15
+
16
+ StatementKind::Load { source, alias } => {
17
+ module.variable_table.variables.insert(
18
+ alias.clone(),
19
+ Value::Sample(source.clone())
20
+ );
21
+ }
22
+
23
+ StatementKind::Export { names, source } => {
24
+ for name in names {
25
+ if let Some(val) = module.variable_table.get(name) {
26
+ module.export_table.add_export(name.clone(), val.clone());
27
+ }
28
+ }
29
+ }
30
+
31
+ StatementKind::Import { names, source } => {
32
+ for name in names {
33
+ module.import_table.add_import(name.clone(), Value::String(source.clone()));
34
+ }
35
+ }
36
+
37
+ _ => {}
38
+ }
39
+ }
40
+ }
41
+ }
@@ -1,59 +1,46 @@
1
- use crate::core::{parser::parse_with_resolving_with_module, types::{
2
- module::Module,
3
- statement::{ Statement, StatementKind, StatementResolved, StatementResolvedValue },
4
- variable::VariableValue,
5
- }};
1
+ use crate::{core::{
2
+ parser::statement::{Statement, StatementKind},
3
+ preprocessor::module::Module,
4
+ shared::value::Value,
5
+ store::global::GlobalStore,
6
+ }, utils::logger::Logger};
6
7
 
7
- pub fn resolve_bank_statement(stmt: &Statement, module: &Module) -> StatementResolved {
8
- match &stmt.value {
9
- VariableValue::Text(name) => {
10
- if
11
- let Some(value) = module.import_table.imports
12
- .get(name)
13
- .or_else(|| module.variable_table.variables.get(name))
14
- {
15
- let statement_value: StatementResolvedValue = match value {
16
- VariableValue::Array(arr) => {
17
- StatementResolvedValue::Array(
18
- parse_with_resolving_with_module(arr.clone(), module)
19
- )
20
- }
21
- VariableValue::Text(text) => StatementResolvedValue::String(text.clone()),
22
- VariableValue::Number(num) => StatementResolvedValue::Number(*num),
23
- VariableValue::Boolean(b) => StatementResolvedValue::Boolean(*b),
24
- _ => {
25
- eprintln!("⚠️ Unsupported variable type for Bank: {:?}", value);
26
- StatementResolvedValue::Unknown
27
- }
28
- };
8
+ pub fn resolve_bank(
9
+ stmt: &Statement,
10
+ module: &Module,
11
+ path: &str,
12
+ _global_store: &GlobalStore
13
+ ) -> Statement {
14
+ let mut new_stmt = stmt.clone();
15
+ let logger = Logger::new();
29
16
 
30
- StatementResolved {
31
- kind: StatementKind::Bank,
32
- value: statement_value,
33
- indent: stmt.indent,
34
- line: stmt.line,
35
- column: stmt.column,
36
- }
17
+ match &stmt.value {
18
+ Value::Identifier(ident) => {
19
+ if let Some(val) = module.variable_table.get(ident) {
20
+ new_stmt.value = val.clone();
37
21
  } else {
38
- eprintln!("⚠️ Bank variable '{}' not found", name);
39
- StatementResolved {
40
- kind: StatementKind::Bank,
41
- value: StatementResolvedValue::Unknown,
42
- indent: stmt.indent,
43
- line: stmt.line,
44
- column: stmt.column,
45
- }
22
+ let message = format!("Bank identifier '{ident}' not found in variable table");
23
+ logger.log_error_with_stacktrace(&message, &module.path);
24
+ new_stmt.kind = StatementKind::Error {
25
+ message: message.clone(),
26
+ };
27
+ new_stmt.value = Value::Null;
46
28
  }
47
29
  }
48
- _ => {
49
- eprintln!("⚠️ Invalid value type for Bank statement: {:?}", stmt.value);
50
- StatementResolved {
51
- kind: StatementKind::Bank,
52
- value: StatementResolvedValue::Unknown,
53
- indent: stmt.indent,
54
- line: stmt.line,
55
- column: stmt.column,
56
- }
30
+
31
+ Value::String(_) => {
32
+ // Pas de résolution nécessaire
33
+ }
34
+
35
+ other => {
36
+ let message = format!("Expected a string or identifier for bank, found {:?}", other);
37
+ logger.log_error_with_stacktrace(&message, &module.path);
38
+ new_stmt.kind = StatementKind::Error {
39
+ message: "Expected a string or identifier for bank".to_string(),
40
+ };
41
+ new_stmt.value = Value::Null;
57
42
  }
58
43
  }
44
+
45
+ new_stmt
59
46
  }
@@ -1,82 +1,143 @@
1
- use crate::core::{
2
- parser::parse_without_resolving_with_module,
3
- preprocessor::resolver::resolve_statement,
4
- types::{
5
- module::Module,
6
- statement::{
7
- Statement,
8
- StatementIterator,
9
- StatementKind,
10
- StatementResolved,
11
- StatementResolvedValue,
12
- },
13
- variable::VariableValue,
1
+ use crate::{
2
+ core::{
3
+ parser::statement::{ Statement, StatementKind },
4
+ preprocessor::{ module::Module, resolver::trigger::resolve_trigger },
5
+ shared::value::Value,
6
+ store::global::GlobalStore,
14
7
  },
8
+ utils::logger::Logger,
15
9
  };
16
10
 
17
- pub fn resolve_loop_statement(
18
- loop_statement: &Statement,
19
- iterator: StatementIterator,
20
- module: &Module
21
- ) -> StatementResolved {
22
- let mut resolved_iterator = StatementIterator::Unknown;
11
+ pub fn resolve_loop(
12
+ stmt: &Statement,
13
+ module: &Module,
14
+ path: &str,
15
+ global_store: &GlobalStore
16
+ ) -> Statement {
17
+ let logger = Logger::new();
23
18
 
24
- match iterator.clone() {
25
- StatementIterator::Identifier(id) => {
26
- if let Some(value) = module.variable_table.variables.get(&id) {
27
- match value {
28
- VariableValue::Array(arr) => {
29
- resolved_iterator = StatementIterator::Array(
30
- parse_without_resolving_with_module(arr.clone(), module)
19
+ // Vérifie que stmt.value est bien une Map
20
+ if let Value::Map(value_map) = &stmt.value {
21
+ // Résolution de l'iterator
22
+ let iterator_value = match value_map.get("iterator") {
23
+ Some(Value::Identifier(ident)) => {
24
+ match module.variable_table.get(ident) {
25
+ Some(Value::Number(n)) => Value::Number(*n),
26
+ Some(_) => {
27
+ log_type_error(
28
+ &logger,
29
+ module,
30
+ stmt,
31
+ format!("Loop iterator '{ident}' must resolve to a number")
31
32
  );
33
+ Value::Null
32
34
  }
33
- VariableValue::Number(num) => {
34
- resolved_iterator = StatementIterator::Number(*num);
35
- }
36
- _ => {
37
- eprintln!("⚠️ Unsupported variable type for loop iterator: {:?}", value);
38
- resolved_iterator = StatementIterator::Unknown;
35
+ None => {
36
+ log_type_error(
37
+ &logger,
38
+ module,
39
+ stmt,
40
+ format!("Loop iterator '{ident}' not found")
41
+ );
42
+ Value::Null
39
43
  }
40
44
  }
41
- } else {
42
- eprintln!("⚠️ Loop iterator variable '{}' not found", id);
43
- resolved_iterator = StatementIterator::Unknown;
44
45
  }
45
- }
46
- StatementIterator::Number(num) => {
47
- resolved_iterator = StatementIterator::Number(num);
48
- }
49
- _ => {
50
- resolved_iterator = iterator.clone();
51
- }
52
- }
53
-
54
- let mut resolved_body: StatementResolvedValue = StatementResolvedValue::Unknown;
55
-
56
- match &loop_statement.value {
57
- VariableValue::Array(arr) => {
58
- let raw_statements = parse_without_resolving_with_module(arr.clone(), &module.clone());
59
-
60
- let mut resolved_statements = Vec::new();
46
+ Some(Value::Number(n)) => Value::Number(*n),
47
+ Some(other) => {
48
+ log_type_error(
49
+ &logger,
50
+ module,
51
+ stmt,
52
+ format!("Unexpected value for loop iterator: {:?}", other)
53
+ );
54
+ Value::Null
55
+ }
56
+ None => {
57
+ log_type_error(
58
+ &logger,
59
+ module,
60
+ stmt,
61
+ "Missing 'iterator' key in loop statement map".to_string()
62
+ );
63
+ Value::Null
64
+ }
65
+ };
61
66
 
62
- for raw_stmt in raw_statements {
63
- let resolved_stmt = resolve_statement(&raw_stmt, &mut module.clone());
64
- resolved_statements.push(resolved_stmt);
67
+ // Résolution du body
68
+ let body_value = match value_map.get("body") {
69
+ Some(Value::Block(block)) => {
70
+ let mut resolved_block = Vec::new();
71
+ for ref statement in block.clone() {
72
+ match &statement.kind {
73
+ StatementKind::Trigger { entity, duration } => {
74
+ let resolved = resolve_trigger(
75
+ &mut statement.clone(),
76
+ &entity,
77
+ &mut duration.clone(),
78
+ module,
79
+ path,
80
+ global_store
81
+ );
82
+ resolved_block.push(resolved);
83
+ }
84
+ _ => {
85
+ println!("Unhandled loop body statement: {:?}", statement);
86
+ }
87
+ }
88
+ }
89
+ Value::Block(resolved_block)
90
+ }
91
+ Some(other) => {
92
+ log_type_error(
93
+ &logger,
94
+ module,
95
+ stmt,
96
+ format!("Unexpected value for loop body: {:?}", other)
97
+ );
98
+ Value::Null
65
99
  }
100
+ None => {
101
+ log_type_error(
102
+ &logger,
103
+ module,
104
+ stmt,
105
+ "Missing 'body' key in loop statement map".to_string()
106
+ );
107
+ Value::Null
108
+ }
109
+ };
110
+
111
+ // ✅ Reconstruit proprement la valeur résolue
112
+ let mut resolved_map = std::collections::HashMap::new();
113
+ resolved_map.insert("iterator".to_string(), iterator_value);
114
+ resolved_map.insert("body".to_string(), body_value);
66
115
 
67
- resolved_body = StatementResolvedValue::Array(resolved_statements);
116
+ // Reconstruit le StatementLoop à partir des éléments résolus
117
+ Statement {
118
+ kind: StatementKind::Loop,
119
+ value: Value::Map(resolved_map),
120
+ ..stmt.clone()
68
121
  }
69
- _ => {
70
- resolved_body = StatementResolvedValue::Unknown;
71
- eprintln!("⚠️ Unsupported value type for loop body: {:?}", loop_statement.value);
122
+ } else {
123
+ log_type_error(
124
+ &logger,
125
+ module,
126
+ stmt,
127
+ format!("Expected a map for loop value, found {:?}", stmt.value)
128
+ );
129
+
130
+ Statement {
131
+ kind: StatementKind::Error {
132
+ message: "Expected a map for loop value".to_string(),
133
+ },
134
+ value: Value::Null,
135
+ ..stmt.clone()
72
136
  }
73
137
  }
138
+ }
74
139
 
75
- return StatementResolved {
76
- kind: StatementKind::Loop { iterator: resolved_iterator },
77
- value: resolved_body,
78
- indent: loop_statement.indent,
79
- line: loop_statement.line,
80
- column: loop_statement.column,
81
- };
140
+ fn log_type_error(logger: &Logger, module: &Module, stmt: &Statement, message: String) {
141
+ let stacktrace = format!("{}:{}:{}", module.path, stmt.line, stmt.column);
142
+ logger.log_error_with_stacktrace(&message, &stacktrace);
82
143
  }