@devaloop/devalang 0.0.1-alpha.17 → 0.0.1-alpha.18

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 (44) hide show
  1. package/.devalang +5 -1
  2. package/Cargo.toml +4 -4
  3. package/README.md +9 -6
  4. package/docs/CHANGELOG.md +46 -1
  5. package/docs/TODO.md +1 -1
  6. package/examples/index.deva +9 -6
  7. package/examples/pattern.deva +5 -5
  8. package/out-tsc/pkg/devalang_core.d.ts +1 -1
  9. package/out-tsc/pkg/devalang_core_bg.wasm.d.ts +7 -7
  10. package/package.json +1 -1
  11. package/project-version.json +3 -3
  12. package/rust/cli/build/commands.rs +10 -0
  13. package/rust/cli/install/addon.rs +84 -38
  14. package/rust/cli/telemetry/event_creator.rs +17 -17
  15. package/rust/core/audio/engine/helpers.rs +21 -9
  16. package/rust/core/audio/engine/sample.rs +68 -7
  17. package/rust/core/audio/engine/synth.rs +19 -4
  18. package/rust/core/audio/evaluator.rs +64 -26
  19. package/rust/core/audio/interpreter/arrow_call.rs +21 -16
  20. package/rust/core/audio/interpreter/call.rs +156 -1
  21. package/rust/core/audio/interpreter/spawn.rs +145 -1
  22. package/rust/core/audio/special/math.rs +22 -2
  23. package/rust/core/lexer/driver.rs +61 -0
  24. package/rust/core/lexer/handler/identifier.rs +3 -2
  25. package/rust/core/lexer/mod.rs +1 -62
  26. package/rust/core/lexer/token.rs +1 -0
  27. package/rust/core/parser/driver.rs +12 -9
  28. package/rust/core/parser/handler/dot.rs +3 -2
  29. package/rust/core/parser/handler/loop_.rs +2 -2
  30. package/rust/core/parser/handler/mod.rs +1 -0
  31. package/rust/core/parser/handler/pattern.rs +74 -0
  32. package/rust/core/preprocessor/loader.rs +87 -127
  33. package/rust/core/preprocessor/processor.rs +7 -7
  34. package/rust/core/preprocessor/resolver/call.rs +28 -0
  35. package/rust/core/preprocessor/resolver/driver.rs +15 -13
  36. package/rust/core/preprocessor/resolver/mod.rs +1 -0
  37. package/rust/core/preprocessor/resolver/pattern.rs +75 -0
  38. package/rust/core/preprocessor/resolver/spawn.rs +27 -0
  39. package/rust/core/store/variable.rs +15 -1
  40. package/rust/main.rs +4 -1
  41. package/rust/types/Cargo.toml +3 -0
  42. package/rust/types/src/ast.rs +4 -0
  43. package/rust/utils/Cargo.toml +4 -1
  44. package/rust/web/api.rs +2 -2
@@ -0,0 +1,75 @@
1
+ use crate::core::{
2
+ parser::statement::{Statement, StatementKind},
3
+ preprocessor::{module::Module},
4
+ store::global::GlobalStore,
5
+ };
6
+ use devalang_types::Value;
7
+ use devalang_utils::logger::{LogLevel, Logger};
8
+
9
+ pub fn resolve_pattern(
10
+ stmt: &Statement,
11
+ module: &Module,
12
+ path: &str,
13
+ global_store: &mut GlobalStore,
14
+ ) -> Statement {
15
+ let logger = Logger::new();
16
+
17
+ // Expecting pattern name stored on the Statement.kind; value may contain the string
18
+ if let StatementKind::Pattern { name, target } = &stmt.kind {
19
+ // Ensure name doesn't already exist
20
+ if global_store.variables.variables.contains_key(name) {
21
+ logger.log_error_with_stacktrace(&format!("Pattern identifier '{}' already exists", name), path);
22
+ return Statement {
23
+ kind: StatementKind::Error { message: format!("Pattern '{}' already exists", name) },
24
+ ..stmt.clone()
25
+ };
26
+ }
27
+
28
+ // Resolve potential target and pattern string value
29
+ let resolved_value = resolve_value(&stmt.value, module, global_store);
30
+
31
+ // Build a map to store the pattern definition
32
+ let mut map = std::collections::HashMap::new();
33
+ map.insert("identifier".to_string(), Value::String(name.clone()));
34
+ if let Some(t) = target {
35
+ map.insert("target".to_string(), Value::String(t.clone()));
36
+ }
37
+ // Keep raw pattern in 'pattern' key
38
+ map.insert("pattern".to_string(), resolved_value.clone());
39
+
40
+ let resolved_stmt = Statement {
41
+ kind: StatementKind::Pattern {
42
+ name: name.clone(),
43
+ target: target.clone(),
44
+ },
45
+ value: resolved_value,
46
+ ..stmt.clone()
47
+ };
48
+
49
+ // Store into global variables as a Statement
50
+ global_store.variables.variables.insert(
51
+ name.clone(),
52
+ Value::Statement(Box::new(resolved_stmt.clone())),
53
+ );
54
+
55
+ return resolved_stmt;
56
+ }
57
+
58
+ logger.log_message(LogLevel::Warning, "resolve_pattern called on non-pattern statement");
59
+ stmt.clone()
60
+ }
61
+
62
+ fn resolve_value(value: &Value, module: &Module, global_store: &mut GlobalStore) -> Value {
63
+ // reuse driver::resolve_value logic; simple local resolution for pattern value
64
+ match value {
65
+ Value::String(s) => Value::String(s.clone()),
66
+ Value::Map(m) => {
67
+ let mut resolved = std::collections::HashMap::new();
68
+ for (k, v) in m {
69
+ resolved.insert(k.clone(), resolve_value(v, module, global_store));
70
+ }
71
+ Value::Map(resolved)
72
+ }
73
+ other => other.clone(),
74
+ }
75
+ }
@@ -48,6 +48,33 @@ pub fn resolve_spawn(
48
48
  }
49
49
  }
50
50
  }
51
+ // Pattern case (make spawn accept patterns stored as variables)
52
+ if let StatementKind::Pattern { .. } = stmt_box.kind {
53
+ let mut resolved_map = std::collections::HashMap::new();
54
+ resolved_map.insert("identifier".to_string(), Value::String(name.clone()));
55
+ // pattern value may be a string or a map stored on the statement
56
+ match &stmt_box.value {
57
+ Value::String(s) => {
58
+ resolved_map.insert("pattern".to_string(), Value::String(s.clone()));
59
+ }
60
+ Value::Map(m) => {
61
+ if let Some(val) = m.get("pattern") {
62
+ resolved_map.insert("pattern".to_string(), val.clone());
63
+ }
64
+ if let Some(val) = m.get("target") {
65
+ resolved_map.insert("target".to_string(), val.clone());
66
+ }
67
+ }
68
+ _ => {}
69
+ }
70
+ resolved_map.insert("args".to_string(), Value::Array(args.clone()));
71
+
72
+ return Statement {
73
+ kind: StatementKind::Spawn { name, args },
74
+ value: Value::Map(resolved_map),
75
+ ..stmt.clone()
76
+ };
77
+ }
51
78
  }
52
79
 
53
80
  // Otherwise, log an error
@@ -28,7 +28,21 @@ impl VariableTable {
28
28
  }
29
29
 
30
30
  pub fn get(&self, name: &str) -> Option<&Value> {
31
- self.variables.get(name)
31
+ // First try the local table
32
+ if let Some(v) = self.variables.get(name) {
33
+ return Some(v);
34
+ }
35
+
36
+ // Then walk parent chain if present
37
+ let mut current = &self.parent;
38
+ while let Some(boxed) = current {
39
+ if let Some(v) = boxed.variables.get(name) {
40
+ return Some(v);
41
+ }
42
+ current = &boxed.parent;
43
+ }
44
+
45
+ None
32
46
  }
33
47
 
34
48
  pub fn remove(&mut self, name: &str) -> Option<Value> {
package/rust/main.rs CHANGED
@@ -4,6 +4,7 @@ pub mod cli;
4
4
  pub mod config;
5
5
  pub mod core;
6
6
  pub mod web;
7
+ use devalang_utils::path::ensure_deva_dir;
7
8
  pub use devalang_utils as utils;
8
9
 
9
10
  use crate::cli::telemetry::send::send_telemetry_event;
@@ -50,7 +51,7 @@ async fn main() -> io::Result<()> {
50
51
  cmd = cmd.version(version_static).before_help(signature_static);
51
52
 
52
53
  let raw_args: Vec<String> = std::env::args().collect();
53
- if raw_args.iter().any(|a| (a == "--version" || a == "-V")) {
54
+ if raw_args.iter().any(|a| a == "--version" || a == "-V") {
54
55
  println!("{}", signature_static);
55
56
  return Ok(());
56
57
  }
@@ -66,6 +67,8 @@ async fn main() -> io::Result<()> {
66
67
  let mut last_error_message: Option<String> = None;
67
68
  let mut exit_code: Option<i32> = None;
68
69
 
70
+ let _ = ensure_deva_dir();
71
+
69
72
  if check_is_first_usage() == true {
70
73
  write_user_config_file();
71
74
  } else {
@@ -1,6 +1,9 @@
1
1
  [package]
2
2
  name = "devalang_types"
3
3
  version = "0.0.1"
4
+ description = "Types and traits for Devalang"
5
+ license = "MIT"
6
+ authors = ["Devaloop <contact@devaloop.com>"]
4
7
  edition = "2024"
5
8
 
6
9
  [dependencies]
@@ -87,6 +87,10 @@ pub enum StatementKind {
87
87
 
88
88
  // ───── Structure & Logic ─────
89
89
  Group,
90
+ Pattern {
91
+ name: String,
92
+ target: Option<String>,
93
+ },
90
94
 
91
95
  // ───── Module System ─────
92
96
  Include(String),
@@ -1,10 +1,13 @@
1
1
  [package]
2
2
  name = "devalang_utils"
3
3
  version = "0.0.1"
4
+ description = "Utility functions and types for Devalang"
5
+ license = "MIT"
6
+ authors = ["Devaloop <contact@devaloop.com>"]
4
7
  edition = "2024"
5
8
 
6
9
  [dependencies]
7
- devalang_types = { path = "../types" }
10
+ devalang_types = { path = "../types", version = "0.0.1" }
8
11
  serde = { version = "1.0", features = ["derive"] }
9
12
  serde_json = "1.0"
10
13
  include_dir = "0.7"
package/rust/web/api.rs CHANGED
@@ -1,5 +1,5 @@
1
1
  pub fn get_api_url() -> String {
2
- // let api_url = "https://api.devalang.com";
3
- let api_url = "http://127.0.0.1:8989";
2
+ let api_url = "https://api.devalang.com";
3
+ // let api_url = "http://127.0.0.1:8989";
4
4
  api_url.to_string()
5
5
  }