@devaloop/devalang 0.0.1-alpha.16-hotfix.3 → 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 (239) hide show
  1. package/.cargo/config.toml +2 -0
  2. package/.devalang +10 -10
  3. package/.github/workflows/ci.yml +0 -1
  4. package/Cargo.toml +18 -2
  5. package/README.md +82 -34
  6. package/docs/CHANGELOG.md +91 -0
  7. package/docs/ROADMAP.md +7 -4
  8. package/docs/TODO.md +1 -1
  9. package/examples/index.deva +55 -35
  10. package/examples/pattern.deva +5 -5
  11. package/out-tsc/bin/index.d.ts +2 -0
  12. package/out-tsc/core/functions/index.d.ts +37 -0
  13. package/out-tsc/core/functions/index.js +76 -0
  14. package/out-tsc/core/index.d.ts +6 -0
  15. package/out-tsc/core/index.js +22 -0
  16. package/out-tsc/core/types/index.d.ts +4 -0
  17. package/out-tsc/core/types/index.js +20 -0
  18. package/out-tsc/core/types/plugin.d.ts +18 -0
  19. package/out-tsc/core/types/plugin.js +2 -0
  20. package/out-tsc/core/types/result.d.ts +27 -0
  21. package/out-tsc/core/types/result.js +2 -0
  22. package/out-tsc/core/types/statement.d.ts +106 -0
  23. package/out-tsc/core/types/statement.js +2 -0
  24. package/out-tsc/core/types/value.d.ts +43 -0
  25. package/out-tsc/core/types/value.js +2 -0
  26. package/out-tsc/index.d.ts +7 -0
  27. package/out-tsc/index.js +41 -2
  28. package/out-tsc/pkg/devalang_core.d.ts +7 -0
  29. package/out-tsc/pkg/devalang_core_bg.wasm.d.ts +33 -0
  30. package/out-tsc/scripts/copy-wasm-dts.d.ts +1 -0
  31. package/out-tsc/scripts/copy-wasm-dts.js +73 -0
  32. package/out-tsc/scripts/postinstall.d.ts +1 -0
  33. package/out-tsc/scripts/postinstall.js +33 -23
  34. package/out-tsc/scripts/version/bump.d.ts +1 -0
  35. package/out-tsc/scripts/version/fetch.d.ts +1 -0
  36. package/out-tsc/scripts/version/index.d.ts +1 -0
  37. package/out-tsc/scripts/version/sync.d.ts +1 -0
  38. package/package.json +16 -4
  39. package/project-version.json +3 -3
  40. package/rust/cli/bank/api.rs +122 -0
  41. package/rust/cli/bank/commands.rs +275 -0
  42. package/rust/cli/bank/mod.rs +29 -0
  43. package/rust/cli/build/commands.rs +107 -0
  44. package/rust/cli/build/mod.rs +2 -0
  45. package/rust/cli/build/process.rs +146 -0
  46. package/rust/cli/{check.rs → check/mod.rs} +18 -31
  47. package/rust/cli/discover/commands.rs +253 -0
  48. package/rust/cli/discover/config.rs +111 -0
  49. package/rust/cli/discover/fs.rs +19 -0
  50. package/rust/cli/discover/install.rs +103 -0
  51. package/rust/cli/discover/metadata.rs +48 -0
  52. package/rust/cli/discover/mod.rs +5 -0
  53. package/rust/cli/{init.rs → init/commands.rs} +88 -87
  54. package/rust/cli/init/mod.rs +1 -0
  55. package/rust/cli/install/addon.rs +126 -0
  56. package/rust/cli/install/bank.rs +53 -0
  57. package/rust/cli/{install.rs → install/commands.rs} +9 -9
  58. package/rust/{installer → cli/install}/mod.rs +2 -3
  59. package/rust/cli/install/plugin.rs +61 -0
  60. package/rust/cli/{login.rs → login/commands.rs} +8 -11
  61. package/rust/cli/login/mod.rs +1 -0
  62. package/rust/cli/mod.rs +2 -2
  63. package/rust/cli/{driver.rs → parser.rs} +7 -2
  64. package/rust/cli/play/commands.rs +324 -0
  65. package/rust/cli/play/io.rs +17 -0
  66. package/rust/cli/play/mod.rs +5 -0
  67. package/rust/cli/play/process.rs +150 -0
  68. package/rust/cli/play/realtime.rs +91 -0
  69. package/rust/cli/play/utils.rs +23 -0
  70. package/rust/cli/{telemetry.rs → telemetry/commands.rs} +4 -4
  71. package/rust/cli/telemetry/event_creator.rs +80 -0
  72. package/rust/cli/telemetry/mod.rs +3 -0
  73. package/rust/cli/telemetry/send.rs +51 -0
  74. package/rust/cli/{template.rs → template/commands.rs} +1 -1
  75. package/rust/cli/template/mod.rs +1 -0
  76. package/rust/cli/{update.rs → update/commands.rs} +6 -6
  77. package/rust/cli/update/mod.rs +1 -0
  78. package/rust/config/driver.rs +57 -72
  79. package/rust/config/mod.rs +1 -2
  80. package/rust/config/ops.rs +26 -0
  81. package/rust/config/settings.rs +40 -42
  82. package/rust/core/audio/engine/helpers.rs +158 -0
  83. package/rust/core/audio/engine/mod.rs +7 -0
  84. package/rust/core/audio/engine/sample.rs +359 -0
  85. package/rust/core/audio/engine/synth.rs +325 -0
  86. package/rust/core/audio/evaluator.rs +68 -27
  87. package/rust/core/audio/interpreter/arrow_call.rs +113 -33
  88. package/rust/core/audio/interpreter/call.rs +232 -56
  89. package/rust/core/audio/interpreter/condition.rs +3 -2
  90. package/rust/core/audio/interpreter/driver.rs +206 -151
  91. package/rust/core/audio/interpreter/let_.rs +1 -1
  92. package/rust/core/audio/interpreter/load.rs +2 -1
  93. package/rust/core/audio/interpreter/loop_.rs +7 -6
  94. package/rust/core/audio/interpreter/sleep.rs +2 -1
  95. package/rust/core/audio/interpreter/spawn.rs +186 -54
  96. package/rust/core/audio/interpreter/tempo.rs +31 -10
  97. package/rust/core/audio/interpreter/trigger.rs +2 -2
  98. package/rust/core/audio/loader/trigger.rs +4 -7
  99. package/rust/core/audio/player.rs +6 -0
  100. package/rust/core/audio/renderer.rs +5 -7
  101. package/rust/core/audio/special/env.rs +3 -1
  102. package/rust/core/audio/special/math.rs +26 -6
  103. package/rust/core/audio/special/modulator.rs +2 -2
  104. package/rust/core/builder/mod.rs +9 -3
  105. package/rust/core/debugger/lexer.rs +1 -1
  106. package/rust/core/debugger/mod.rs +6 -0
  107. package/rust/core/debugger/module.rs +4 -4
  108. package/rust/core/debugger/preprocessor.rs +1 -1
  109. package/rust/core/debugger/store.rs +2 -2
  110. package/rust/core/error/mod.rs +189 -0
  111. package/rust/core/lexer/driver.rs +61 -0
  112. package/rust/core/lexer/handler/arrow.rs +1 -1
  113. package/rust/core/lexer/handler/at.rs +1 -1
  114. package/rust/core/lexer/handler/brace.rs +2 -2
  115. package/rust/core/lexer/handler/colon.rs +1 -1
  116. package/rust/core/lexer/handler/comment.rs +1 -1
  117. package/rust/core/lexer/handler/dot.rs +1 -1
  118. package/rust/core/lexer/handler/driver.rs +1 -1
  119. package/rust/core/lexer/handler/identifier.rs +4 -3
  120. package/rust/core/lexer/handler/mod.rs +1 -2
  121. package/rust/core/lexer/handler/number.rs +1 -1
  122. package/rust/core/lexer/handler/operator.rs +1 -1
  123. package/rust/core/lexer/handler/parenthesis.rs +2 -2
  124. package/rust/core/lexer/handler/slash.rs +1 -1
  125. package/rust/core/lexer/handler/string.rs +1 -1
  126. package/rust/core/lexer/mod.rs +1 -52
  127. package/rust/core/lexer/token.rs +91 -97
  128. package/rust/core/mod.rs +0 -1
  129. package/rust/core/parser/driver.rs +78 -22
  130. package/rust/core/parser/handler/arrow_call.rs +28 -8
  131. package/rust/core/parser/handler/at.rs +55 -21
  132. package/rust/core/parser/handler/bank.rs +14 -4
  133. package/rust/core/parser/handler/condition.rs +6 -3
  134. package/rust/core/parser/handler/dot.rs +5 -3
  135. package/rust/core/parser/handler/identifier/automate.rs +13 -16
  136. package/rust/core/parser/handler/identifier/call.rs +4 -4
  137. package/rust/core/parser/handler/identifier/emit.rs +9 -5
  138. package/rust/core/parser/handler/identifier/function.rs +20 -7
  139. package/rust/core/parser/handler/identifier/group.rs +11 -7
  140. package/rust/core/parser/handler/identifier/let_.rs +24 -9
  141. package/rust/core/parser/handler/identifier/mod.rs +6 -5
  142. package/rust/core/parser/handler/identifier/on.rs +16 -7
  143. package/rust/core/parser/handler/identifier/print.rs +6 -9
  144. package/rust/core/parser/handler/identifier/sleep.rs +12 -5
  145. package/rust/core/parser/handler/identifier/spawn.rs +4 -4
  146. package/rust/core/parser/handler/identifier/synth.rs +79 -9
  147. package/rust/core/parser/handler/loop_.rs +38 -13
  148. package/rust/core/parser/handler/mod.rs +1 -0
  149. package/rust/core/parser/handler/pattern.rs +74 -0
  150. package/rust/core/parser/handler/tempo.rs +9 -5
  151. package/rust/core/parser/mod.rs +0 -1
  152. package/rust/core/parser/statement.rs +6 -137
  153. package/rust/core/plugin/loader.rs +41 -27
  154. package/rust/core/plugin/runner.rs +68 -17
  155. package/rust/core/preprocessor/loader.rs +181 -99
  156. package/rust/core/preprocessor/processor.rs +9 -9
  157. package/rust/core/preprocessor/resolver/bank.rs +6 -8
  158. package/rust/core/preprocessor/resolver/call.rs +47 -23
  159. package/rust/core/preprocessor/resolver/condition.rs +6 -8
  160. package/rust/core/preprocessor/resolver/driver.rs +28 -28
  161. package/rust/core/preprocessor/resolver/function.rs +6 -6
  162. package/rust/core/preprocessor/resolver/group.rs +6 -8
  163. package/rust/core/preprocessor/resolver/loop_.rs +8 -10
  164. package/rust/core/preprocessor/resolver/mod.rs +1 -0
  165. package/rust/core/preprocessor/resolver/pattern.rs +75 -0
  166. package/rust/core/preprocessor/resolver/spawn.rs +45 -22
  167. package/rust/core/preprocessor/resolver/synth.rs +6 -8
  168. package/rust/core/preprocessor/resolver/tempo.rs +6 -8
  169. package/rust/core/preprocessor/resolver/trigger.rs +22 -19
  170. package/rust/core/preprocessor/resolver/value.rs +99 -4
  171. package/rust/core/store/export.rs +28 -28
  172. package/rust/core/store/function.rs +6 -0
  173. package/rust/core/store/global.rs +7 -1
  174. package/rust/core/store/import.rs +28 -28
  175. package/rust/core/store/variable.rs +16 -2
  176. package/rust/core/utils/mod.rs +0 -1
  177. package/rust/lib.rs +102 -9
  178. package/rust/main.rs +159 -45
  179. package/rust/types/Cargo.toml +11 -0
  180. package/rust/types/src/addons.rs +55 -0
  181. package/rust/types/src/ast.rs +202 -0
  182. package/rust/types/src/config.rs +74 -0
  183. package/rust/types/src/lib.rs +12 -0
  184. package/rust/types/src/telemetry.rs +85 -0
  185. package/rust/utils/Cargo.toml +26 -0
  186. package/rust/utils/{error.rs → src/error.rs} +186 -200
  187. package/rust/utils/src/file.rs +94 -0
  188. package/rust/utils/src/first_usage.rs +97 -0
  189. package/rust/utils/{mod.rs → src/lib.rs} +1 -1
  190. package/rust/utils/{logger.rs → src/logger.rs} +17 -12
  191. package/rust/utils/src/path.rs +88 -0
  192. package/rust/utils/src/signature.rs +41 -0
  193. package/rust/utils/{spinner.rs → src/spinner.rs} +3 -5
  194. package/rust/utils/src/version.rs +27 -0
  195. package/rust/utils/{watcher.rs → src/watcher.rs} +13 -1
  196. package/rust/web/cdn.rs +34 -0
  197. package/templates/minimal/README.md +98 -54
  198. package/templates/welcome/README.md +98 -54
  199. package/templates/welcome/src/index.deva +56 -8
  200. package/templates/welcome/src/variables.deva +2 -4
  201. package/tests/rust/TODO.md +0 -0
  202. package/tests/typescript/index.spec.ts +136 -0
  203. package/tests/typescript/playhead.spec.ts +36 -0
  204. package/tests/typescript/render_e2e.spec.ts +77 -0
  205. package/tsconfig.json +1 -1
  206. package/typescript/core/functions/index.ts +83 -0
  207. package/typescript/core/index.ts +6 -0
  208. package/typescript/core/types/index.ts +4 -0
  209. package/typescript/core/types/plugin.ts +19 -0
  210. package/typescript/core/types/result.ts +29 -0
  211. package/typescript/core/types/statement.ts +47 -0
  212. package/typescript/core/types/value.ts +29 -0
  213. package/typescript/index.ts +7 -2
  214. package/typescript/pkg/devalang_core.d.ts +4 -0
  215. package/typescript/scripts/copy-wasm-dts.ts +41 -0
  216. package/rust/cli/bank.rs +0 -462
  217. package/rust/cli/build.rs +0 -252
  218. package/rust/cli/play.rs +0 -1123
  219. package/rust/common/cdn.rs +0 -5
  220. package/rust/config/loader.rs +0 -165
  221. package/rust/config/stats.rs +0 -257
  222. package/rust/core/audio/engine.rs +0 -696
  223. package/rust/core/shared/bank.rs +0 -21
  224. package/rust/core/shared/duration.rs +0 -9
  225. package/rust/core/shared/mod.rs +0 -3
  226. package/rust/core/shared/value.rs +0 -35
  227. package/rust/core/utils/validation.rs +0 -35
  228. package/rust/installer/addon.rs +0 -84
  229. package/rust/installer/bank.rs +0 -62
  230. package/rust/installer/plugin.rs +0 -54
  231. package/rust/installer/utils.rs +0 -56
  232. package/rust/utils/file.rs +0 -38
  233. package/rust/utils/first_usage.rs +0 -83
  234. package/rust/utils/signature.rs +0 -19
  235. package/rust/utils/telemetry.rs +0 -292
  236. package/rust/utils/version.rs +0 -15
  237. /package/rust/{common → web}/api.rs +0 -0
  238. /package/rust/{common → web}/mod.rs +0 -0
  239. /package/rust/{common → web}/sso.rs +0 -0
@@ -0,0 +1,136 @@
1
+ import { expect } from "chai";
2
+ import * as fs from "fs";
3
+ import * as os from "os";
4
+ import * as path from "path";
5
+
6
+ // CommonJS bundle import (TypeScript-friendly)
7
+ const core: any = require("../../out-tsc");
8
+
9
+ describe("devalang typescript index", () => {
10
+ let origCwd: string;
11
+ let tmpDir: string | null = null;
12
+
13
+ before(function () {
14
+ // Prepare a temporary project root so wasm code that looks up project files
15
+ // and `.devalang` config can succeed during E2E runs.
16
+ origCwd = process.cwd();
17
+ tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "devalang-e2e-"));
18
+ // Create minimal .devalang config file so get_project_root finds it
19
+ fs.writeFileSync(
20
+ path.join(tmpDir, ".devalang"),
21
+ 'name = "devalang-test"\n'
22
+ );
23
+ // Ensure .deva exists (optional banks/plugins)
24
+ fs.mkdirSync(path.join(tmpDir, ".deva"), { recursive: true });
25
+ process.chdir(tmpDir);
26
+ });
27
+
28
+ after(function () {
29
+ // restore cwd and attempt cleanup
30
+ if (tmpDir) {
31
+ try {
32
+ process.chdir(origCwd);
33
+ // best-effort cleanup
34
+ fs.rmSync(tmpDir, { recursive: true, force: true });
35
+ } catch (e) {
36
+ // ignore
37
+ }
38
+ }
39
+ });
40
+ it("should expose render_audio and return a Float32Array when wasm is available", function () {
41
+ // Prefer wasm binding if available
42
+ const wasmFn = core.pkg && core.pkg.render_audio;
43
+
44
+ const sampleProgram = `# simple program for tests
45
+ bpm 120
46
+
47
+ group myLead:
48
+ let mySynth = synth sine
49
+ mySynth -> note(C4, { duration: 400 })
50
+ mySynth -> note(G4, { duration: 400 })
51
+ call myLead
52
+ `;
53
+
54
+ if (typeof wasmFn === "function") {
55
+ try {
56
+ // Get parsed AST first for debugging
57
+ if (core.pkg && typeof core.pkg.parse === "function") {
58
+ try {
59
+ const parsed = core.pkg.parse("playground.deva", sampleProgram);
60
+ // parsed may be an object { ok, ast, errors } or a string
61
+ const astStr =
62
+ parsed && parsed.ast
63
+ ? parsed.ast
64
+ : typeof parsed === "string"
65
+ ? parsed
66
+ : JSON.stringify(parsed);
67
+ expect(astStr).to.match(/note|synth/i);
68
+ } catch (e) {
69
+ console.warn(
70
+ "[TEST DEBUG] parse() failed or returned non-standard result:",
71
+ e
72
+ );
73
+ }
74
+ }
75
+
76
+ const result = wasmFn(sampleProgram);
77
+ expect(result.constructor && result.constructor.name).to.match(
78
+ /Float32Array|Float64Array|ArrayBuffer|Uint8Array/
79
+ );
80
+ } catch (err: any) {
81
+ // If the wasm panicked because the audio buffer is empty, skip the test in this env.
82
+ const msg =
83
+ typeof err === "string"
84
+ ? err
85
+ : err && err.message
86
+ ? err.message
87
+ : String(err);
88
+ if (msg.includes("Audio buffer is empty")) {
89
+ // skip this test on environments where generating audio isn't supported
90
+ // eslint-disable-next-line no-invalid-this
91
+ this.skip();
92
+ }
93
+
94
+ throw err;
95
+ }
96
+
97
+ return;
98
+ }
99
+
100
+ // If wasm binding isn't available, ensure a runtime placeholder exists but don't call it
101
+ const runtimeFn = core.render_audio;
102
+ expect(runtimeFn).to.be.a("function");
103
+ });
104
+
105
+ it("should find statements for entry module", function () {
106
+ const parseFn = core.pkg && core.pkg.parse;
107
+ if (typeof parseFn !== "function") {
108
+ // nothing to test if parse binding missing
109
+ // eslint-disable-next-line no-invalid-this
110
+ this.skip();
111
+ }
112
+
113
+ try {
114
+ const res = parseFn("playground.deva", "bpm 120");
115
+ expect(res).to.be.an("object");
116
+ // prefer explicit shape when available
117
+ if (Object.prototype.hasOwnProperty.call(res, "ok")) {
118
+ expect(res.ok).to.equal(true);
119
+ } else {
120
+ expect(res).to.have.property("ast");
121
+ }
122
+ } catch (err: any) {
123
+ const msg = err && err.message ? err.message : String(err);
124
+ if (
125
+ msg.includes("Module loading error") ||
126
+ msg.includes("Project root not found")
127
+ ) {
128
+ // environment not prepared for module loading, skip
129
+ // eslint-disable-next-line no-invalid-this
130
+ this.skip();
131
+ return;
132
+ }
133
+ throw err;
134
+ }
135
+ });
136
+ });
@@ -0,0 +1,36 @@
1
+ import { expect } from "chai";
2
+
3
+ const core: any = require("../../out-tsc");
4
+
5
+ describe("playhead callback", () => {
6
+ it("should call registered callback during run", () => {
7
+ const register = core.pkg && core.pkg.register_playhead_callback;
8
+ const unregister = core.pkg && core.pkg.unregister_playhead_callback;
9
+ if (typeof register !== "function") {
10
+ // skip when wasm not available
11
+ return;
12
+ }
13
+
14
+ let called = false;
15
+ const cb = (ev: any) => {
16
+ called = true;
17
+ expect(ev).to.have.property("time");
18
+ expect(ev).to.have.property("line");
19
+ expect(ev).to.have.property("column");
20
+ };
21
+
22
+ register(cb);
23
+
24
+ // run a simple program to trigger events
25
+ const program = `bpm 120\n\n.myTrigger 1/4\n`;
26
+ // render_audio will schedule triggers and should invoke the callback during execution
27
+ const render = core.pkg && core.pkg.render_audio;
28
+ if (typeof render === "function") {
29
+ render(program);
30
+ }
31
+
32
+ unregister && unregister();
33
+
34
+ expect(called).to.be.true;
35
+ });
36
+ });
@@ -0,0 +1,77 @@
1
+ import { expect } from "chai";
2
+ import * as fs from "fs";
3
+ import * as os from "os";
4
+ import * as path from "path";
5
+
6
+ const core: any = require("../../out-tsc");
7
+
8
+ describe("devalang debug_render and render_audio E2E", () => {
9
+ let origCwd: string;
10
+ let tmpDir: string | null = null;
11
+
12
+ before(function () {
13
+ origCwd = process.cwd();
14
+ tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "devalang-e2e-"));
15
+ fs.writeFileSync(
16
+ path.join(tmpDir, ".devalang"),
17
+ 'name = "devalang-test"\n'
18
+ );
19
+ fs.mkdirSync(path.join(tmpDir, ".deva"), { recursive: true });
20
+ process.chdir(tmpDir as string);
21
+ });
22
+
23
+ after(function () {
24
+ if (tmpDir) {
25
+ try {
26
+ process.chdir(origCwd);
27
+ fs.rmSync(tmpDir, { recursive: true, force: true });
28
+ } catch (e) {
29
+ // ignore
30
+ }
31
+ }
32
+ });
33
+
34
+ it("debug_render should return diagnostics including note_count and global_vars", function () {
35
+ const dbg = core.pkg && core.pkg.debug_render;
36
+ if (typeof dbg !== "function") {
37
+ // skip if wasm binding missing
38
+ // eslint-disable-next-line no-invalid-this
39
+ this.skip();
40
+ }
41
+
42
+ const sampleProgram = `# sample program\nbpm 120\n\ngroup myLead:\n let mySynth = synth sine\n mySynth -> note(C4, { duration: 400 })\n mySynth -> note(G4, { duration: 400 })\ncall myLead\n`;
43
+
44
+ const out = dbg(sampleProgram);
45
+ expect(out).to.be.an("object");
46
+ expect(out).to.have.property("samples_len");
47
+ expect(out).to.have.property("any_nonzero");
48
+ expect(out).to.have.property("note_count");
49
+ expect(out).to.have.property("global_vars");
50
+
51
+ // Basic assertions: at least one non-zero sample or note_count > 0
52
+ expect(out.note_count).to.be.at.least(0);
53
+ expect(out.global_vars).to.include("myLead");
54
+ });
55
+
56
+ it("render_audio should return a Float32Array and not be completely silent", function () {
57
+ const render = (core.pkg && core.pkg.render_audio) || core.render_audio;
58
+ if (typeof render !== "function") {
59
+ // eslint-disable-next-line no-invalid-this
60
+ this.skip();
61
+ }
62
+
63
+ const sampleProgram = `# sample program\nbpm 120\n\ngroup myLead:\n let mySynth = synth sine\n mySynth -> note(C4, { duration: 400 })\n mySynth -> note(G4, { duration: 400 })\ncall myLead\n`;
64
+
65
+ const arr = render(sampleProgram);
66
+ // If wasm returns JS typed array wrapper, check constructor name
67
+ expect(arr.constructor && arr.constructor.name).to.match(
68
+ /Float32Array|Float64Array|ArrayBuffer|Uint8Array/
69
+ );
70
+
71
+ // Convert to plain array if needed
72
+ const samples: number[] = Array.from(arr as any);
73
+ // Expect either note_count > 0 indirectly via nonzero samples
74
+ const anyNonZero = samples.some((s) => s !== 0);
75
+ expect(anyNonZero).to.be.true;
76
+ });
77
+ });
package/tsconfig.json CHANGED
@@ -52,7 +52,7 @@
52
52
  // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
53
53
 
54
54
  /* Emit */
55
- // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
55
+ "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
56
56
  // "declarationMap": true, /* Create sourcemaps for d.ts files. */
57
57
  // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
58
58
  // "sourceMap": true, /* Create source map files for emitted JavaScript files. */
@@ -0,0 +1,83 @@
1
+ import { ParseResult } from "../types/result";
2
+ import { DebugResult } from "../types/result";
3
+
4
+ let wasmPkg: any = undefined;
5
+ try {
6
+ // prefer runtime pkg generated by wasm-pack when available
7
+ // require at runtime so the package can be used even if wasm hasn't been built
8
+ // (this keeps tests and consumers robust).
9
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
10
+ wasmPkg = require("../../pkg/devalang_core");
11
+ } catch (_e) {
12
+ wasmPkg = undefined;
13
+ }
14
+
15
+ /**
16
+ * Parses the user code.
17
+ * @param entry_path The entry path for the code.
18
+ * @param source The source code to parse.
19
+ * @returns ParseResult | any
20
+ */
21
+ export function parse(entry_path: string, source: string): ParseResult | any {
22
+ if (wasmPkg && typeof wasmPkg.parse === "function") {
23
+ return wasmPkg.parse(entry_path, source);
24
+ }
25
+
26
+ throw new Error(
27
+ "WASM binding 'parse' not available. Build the wasm package or use the JS runtime."
28
+ );
29
+ }
30
+
31
+ /**
32
+ * Renders the debug information for the user code.
33
+ * @param user_code The user-provided code to render debug information for.
34
+ * @returns DebugResult | any
35
+ */
36
+ export function debug_render(user_code: string): DebugResult | any {
37
+ if (wasmPkg && typeof wasmPkg.debug_render === "function") {
38
+ return wasmPkg.debug_render(user_code);
39
+ }
40
+
41
+ throw new Error(
42
+ "WASM binding 'debug_render' not available. Build the wasm package or use the JS runtime."
43
+ );
44
+ }
45
+
46
+ /**
47
+ * Renders audio from the user code.
48
+ * @param user_code The user-provided code to render audio from.
49
+ * @returns Float32Array
50
+ */
51
+ export function render_audio(user_code: string): Float32Array {
52
+ if (wasmPkg && typeof wasmPkg.render_audio === "function") {
53
+ return wasmPkg.render_audio(user_code);
54
+ }
55
+
56
+ // Fallback: indicate missing wasm with an empty buffer rather than breaking consumers.
57
+ return new Float32Array(0);
58
+ }
59
+
60
+ /**
61
+ * Register a JS callback to receive playhead events { time, line, column } during playback.
62
+ * The callback will be called with a single object argument.
63
+ * @param cb The callback function to register.
64
+ * @returns void
65
+ */
66
+ export function register_playhead_callback(cb: (ev: { time: number; line: number; column: number }) => void) {
67
+ if (wasmPkg && typeof wasmPkg.register_playhead_callback === "function") {
68
+ return wasmPkg.register_playhead_callback(cb);
69
+ }
70
+ // no-op fallback
71
+ return;
72
+ }
73
+
74
+ /**
75
+ * Unregisters the JS callback for playhead events.
76
+ * @returns void
77
+ */
78
+ export function unregister_playhead_callback() {
79
+ if (wasmPkg && typeof wasmPkg.unregister_playhead_callback === "function") {
80
+ return wasmPkg.unregister_playhead_callback();
81
+ }
82
+ return;
83
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Core functionality for the Devalang language.
3
+ * This module exports all the core types and functions used in the language.
4
+ */
5
+ export * from "./types/index";
6
+ export * from "./functions/index";
@@ -0,0 +1,4 @@
1
+ export * from "./result";
2
+ export * from "./statement";
3
+ export * from "./value";
4
+ export * from "./plugin";
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Represents a plugin export.
3
+ */
4
+ export interface PluginExport {
5
+ name: string;
6
+ kind: string;
7
+ default?: any;
8
+ }
9
+
10
+ /**
11
+ * Represents a plugin.
12
+ */
13
+ export interface PluginInfo {
14
+ author: string;
15
+ name: string;
16
+ version?: string;
17
+ description?: string;
18
+ exports: PluginExport[];
19
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Represents an error that occurred during parsing.
3
+ */
4
+ export interface ErrorResult {
5
+ message: string;
6
+ line: number;
7
+ column: number;
8
+ }
9
+
10
+ /**
11
+ * Represents the result of parsing user code.
12
+ */
13
+ export interface ParseResult {
14
+ ok: boolean;
15
+ ast: string;
16
+ errors: ErrorResult[];
17
+ }
18
+
19
+ /**
20
+ * Represents the result of debugging user code.
21
+ */
22
+ export interface DebugResult {
23
+ samples_len: number;
24
+ any_nonzero: boolean;
25
+ ast: string;
26
+ note_count: number;
27
+ global_vars: string[];
28
+ statements_count: number;
29
+ }
@@ -0,0 +1,47 @@
1
+ import { Value, Duration } from "./value";
2
+
3
+ /**
4
+ * Represents a statement kind in the code.
5
+ */
6
+ export type StatementKind =
7
+ | { kind: "Tempo" }
8
+ | { kind: "Bank"; alias?: string }
9
+ | { kind: "Print" }
10
+ | { kind: "Load"; source: string; alias: string }
11
+ | { kind: "Use"; name: string; alias?: string }
12
+ | { kind: "Let"; name: string }
13
+ | { kind: "Automate"; target: string }
14
+ | { kind: "ArrowCall"; target: string; method: string; args: Value[] }
15
+ | { kind: "Function"; name: string; parameters: string[]; body: Statement[] }
16
+ | { kind: "Synth" }
17
+ | { kind: "Trigger"; entity: string; duration: Duration; effects?: Value }
18
+ | { kind: "Sleep" }
19
+ | { kind: "Call"; name: string; args: Value[] }
20
+ | { kind: "Spawn"; name: string; args: Value[] }
21
+ | { kind: "Loop" }
22
+ | { kind: "Group" }
23
+ | { kind: "Include"; path: string }
24
+ | { kind: "Export"; names: string[]; source: string }
25
+ | { kind: "Import"; names: string[]; source: string }
26
+ | { kind: "If" }
27
+ | { kind: "Else" }
28
+ | { kind: "ElseIf" }
29
+ | { kind: "Comment" }
30
+ | { kind: "Indent" }
31
+ | { kind: "Dedent" }
32
+ | { kind: "NewLine" }
33
+ | { kind: "On"; event: string; args?: Value[]; body: Statement[] }
34
+ | { kind: "Emit"; event: string; payload?: Value }
35
+ | { kind: "Unknown" }
36
+ | { kind: "Error"; message: string };
37
+
38
+ /**
39
+ * Represents a statement in the code.
40
+ */
41
+ export interface Statement {
42
+ kind: StatementKind;
43
+ value: Value;
44
+ indent: number;
45
+ line: number;
46
+ column: number;
47
+ }
@@ -0,0 +1,29 @@
1
+ import { Statement } from "./statement";
2
+
3
+ /**
4
+ * Represents a duration in the code.
5
+ */
6
+ export type Duration =
7
+ | { Number: number }
8
+ | { Identifier: string }
9
+ | { Beat: string }
10
+ | { Auto: null };
11
+
12
+ /**
13
+ * Represents a value in the code.
14
+ */
15
+ export type Value =
16
+ | { Boolean: boolean }
17
+ | { Number: number }
18
+ | { Duration: Duration }
19
+ | { Identifier: string }
20
+ | { String: string }
21
+ | { Array: Value[] }
22
+ | { Map: Record<string, Value> }
23
+ | { Block: Statement[] }
24
+ | { Sample: string }
25
+ | { Beat: string }
26
+ | { Statement: Statement }
27
+ | { StatementKind: any }
28
+ | { Unknown: null }
29
+ | null;
@@ -1,3 +1,8 @@
1
1
  /**
2
- * TypeScript wrapper for Devalang.
3
- */
2
+ * Public TypeScript definitions for Devalang.
3
+ * ————————————————————————————————————————
4
+ * Used to provide TypeScript types for the Devalang WASM package.
5
+ */
6
+
7
+ export * as pkg from "./pkg/devalang_core";
8
+ export * as core from "./core/index";
@@ -0,0 +1,4 @@
1
+ /**
2
+ * This module exports all the core types and functions used in the WASM package.
3
+ */
4
+ export * from "../../pkg/devalang_core";
@@ -0,0 +1,41 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+
4
+ // Copies .d.ts files from pkg/ (wasm-pack output) into out-tsc/pkg/
5
+ const ROOT = path.resolve(__dirname, '..', '..');
6
+ const PKG_DIR = path.join(ROOT, 'pkg');
7
+ const OUT_DIR = path.join(ROOT, 'out-tsc', 'pkg');
8
+
9
+ function ensureDir(p: string): void {
10
+ if (!fs.existsSync(p)) fs.mkdirSync(p, { recursive: true });
11
+ }
12
+
13
+ function copyDir(src: string, dest: string): void {
14
+ ensureDir(dest);
15
+ const items = fs.readdirSync(src, { withFileTypes: true });
16
+ for (const item of items) {
17
+ const srcPath = path.join(src, item.name);
18
+ const destPath = path.join(dest, item.name);
19
+ if (item.isDirectory()) {
20
+ copyDir(srcPath, destPath);
21
+ } else if (item.isFile() && item.name.endsWith('.d.ts')) {
22
+ fs.copyFileSync(srcPath, destPath);
23
+ console.log('copied', srcPath, '->', destPath);
24
+ }
25
+ }
26
+ }
27
+
28
+ function main(): number {
29
+ if (!fs.existsSync(PKG_DIR)) {
30
+ console.error('pkg directory not found at', PKG_DIR);
31
+ return 1;
32
+ }
33
+
34
+ ensureDir(OUT_DIR);
35
+ copyDir(PKG_DIR, OUT_DIR);
36
+ console.log('done');
37
+ return 0;
38
+ }
39
+
40
+ const exitCode = main();
41
+ if (exitCode !== 0) process.exit(exitCode);