@onda-lang/wasm-compiler 0.5.4 → 0.7.0

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/README.md CHANGED
@@ -8,12 +8,12 @@ require LLVM, a Wasm linker, Rust, or `wasm-pack` after installation.
8
8
  import { createCompiler } from "@onda-lang/wasm-compiler";
9
9
 
10
10
  const compiler = await createCompiler();
11
- const artifact = await compiler.compileSource(source, {
11
+ const { artifact, sourceFiles } = await compiler.compileSource(source, {
12
12
  sampleRate: 48_000,
13
13
  blockSize: 128,
14
14
  });
15
15
 
16
- console.log(artifact.wasm, artifact.metadata);
16
+ console.log(artifact.wasm, artifact.metadata, sourceFiles);
17
17
  ```
18
18
 
19
19
  The package composes Onda's embedded Rust frontend with its Binaryen backend. The frontend emits
@@ -25,13 +25,13 @@ Release builds post-optimize the Rust frontend Wasm with the package's pinned Bi
25
25
  `dist/build.json`, and fails if the pass does not reduce the shipped module. Generated DSP modules
26
26
  are already optimized independently by the runtime Binaryen O4 pipeline.
27
27
 
28
- ## Projects
28
+ ## Source workspaces
29
29
 
30
30
  Project compilation resolves imports and includes entirely from the supplied source map and the
31
31
  embedded standard library:
32
32
 
33
33
  ```js
34
- const artifact = await compiler.compileProject({
34
+ const { artifact, sourceFiles } = await compiler.compileWorkspace({
35
35
  entry: "main.onda",
36
36
  sources: {
37
37
  "main.onda": mainSource,
@@ -41,10 +41,66 @@ const artifact = await compiler.compileProject({
41
41
  sampleRate: 48_000,
42
42
  blockSize: 128,
43
43
  });
44
+
45
+ // Entry first, then transitive imports/includes. Embedded stdlib is excluded.
46
+ console.log(sourceFiles);
44
47
  ```
45
48
 
46
49
  Compilation failures throw `OndaCompileError`. Its `diagnostics` property contains structured
47
- parse, semantic, MIR, configuration, or code-generation diagnostics.
50
+ parse, semantic, MIR, configuration, or code-generation diagnostics. Its `sourceFiles` property
51
+ contains every project source resolved before compilation stopped, allowing hosts to retain useful
52
+ watch registrations while the project is temporarily invalid. `unresolvedSourceFiles` contains
53
+ referenced non-standard-library candidates which were not present, allowing hosts to watch for their
54
+ creation without treating them as contributing compilation inputs.
55
+
56
+ ## Portable project images
57
+
58
+ Successful workspace compilation also returns `sourceGraph`, the exact documents and resolved
59
+ import/include edges used for that build. Combine it with canonical typed buffers to create a
60
+ portable project image:
61
+
62
+ ```js
63
+ const compiled = await compiler.compileWorkspace(workspace, options);
64
+ const sample = await compiler.encodeBufferAsset({
65
+ element: "f32",
66
+ frames: samples.length,
67
+ channels: 1,
68
+ sampleRate: 48_000,
69
+ data: new Float32Array(samples),
70
+ });
71
+ const image = await compiler.createProjectImage(
72
+ compiled.sourceGraph,
73
+ new Map([["sample", sample]]),
74
+ );
75
+
76
+ const replayed = await compiler.compileProjectImage(image.bytes, options);
77
+ const exported = await compiler.materializeProjectImage(
78
+ image.bytes,
79
+ new Map([["sample", "recording.wav"]]),
80
+ );
81
+
82
+ // WAV and .ondabuffer inputs share the same canonical Rust decoder.
83
+ const decoded = await compiler.decodeBufferFile(fileBytes, "sample.wav");
84
+ ```
85
+
86
+ Project-image buffer maps use physical slot names. A scalar declaration uses its source name;
87
+ fixed arrays use names such as `bank[0]` and `bank[1]`. Omitted slots remain unbound and neutral at
88
+ runtime, so an image contains only the assets the project actually supplies.
89
+
90
+ `materializeProjectImage` emits Onda's canonical publication layout: `code/main.onda`, meaningful
91
+ source subdirectories below `code/`, and typed assets below `assets/`.
92
+ `loadProjectFiles(files, projectFilePath?)` performs the reverse operation from a complete map of
93
+ extracted project-relative files. Pass the `.ondaproject` path when the map contains multiple
94
+ projects; manifests may occur in any directory and resolve their paths relative to that directory.
95
+ Omitting it requires an unambiguous manifest. Loading rejects a reachable source graph
96
+ that cannot be loaded and parsed. Portable project exports must be created from a successful
97
+ compilation, as in the example above. `inspectProjectImage` validates an image and returns its
98
+ source graph, logical buffer bindings, asset metadata, and content digest. `projectCapabilities`
99
+ reports the immutable image, buffer-container, and embedded-standard-library versions. The worker
100
+ client exposes the same methods and transfers binary payloads rather than cloning them.
101
+
102
+ All canonical project and `.ondabuffer` serialization is implemented by the same Rust `onda_project`
103
+ crate used by the native C API. JavaScript only adapts maps, typed arrays, and worker messages.
48
104
 
49
105
  ## Browser workers
50
106
 
@@ -52,7 +108,7 @@ Compilation is CPU-intensive. Use the built-in worker client in interactive brow
52
108
 
53
109
  ```js
54
110
  const compiler = await createCompiler({ worker: true });
55
- const artifact = await compiler.compileSource(source, options);
111
+ const { artifact, sourceFiles } = await compiler.compileSource(source, options);
56
112
  await compiler.dispose();
57
113
  ```
58
114
 
@@ -99,7 +155,7 @@ await compiler.sendLspMessage({
99
155
  Open every virtual project file with `didOpen`; imports and includes resolve from those overlays and
100
156
  the embedded standard library. Diagnostics, semantic tokens, completion, hover, definitions, and
101
157
  document symbols use the native server implementation. The browser transport does not run MIR or a
102
- backend until the host explicitly calls `compileSource` or `compileProject`.
158
+ backend until the host explicitly calls `compileSource` or `compileWorkspace`.
103
159
 
104
160
  ## CLI
105
161
 
package/bin/onda-wasm.js CHANGED
@@ -72,7 +72,7 @@ export async function main(argv = process.argv.slice(2)) {
72
72
  const watOutput = parsed.watOut === undefined ? undefined : resolve(parsed.watOut);
73
73
  const compiler = await createCompiler();
74
74
  try {
75
- const artifact = await compiler.compileProject({ entry, sources }, {
75
+ const { artifact } = await compiler.compileWorkspace({ entry, sources }, {
76
76
  sampleRate: parsed.sampleRate,
77
77
  blockSize: parsed.blockSize,
78
78
  codegen: {
@@ -3,6 +3,8 @@ export {
3
3
  PROCESSOR_ABI_VERSION,
4
4
  PROCESSOR_ARTIFACT_FORMAT,
5
5
  PROCESSOR_ARTIFACT_FORMAT_VERSION,
6
+ PROCESSOR_EXECUTION_OK,
7
+ PROCESSOR_EXECUTION_RUNTIME_SAFETY_FAILURE,
6
8
  PROCESSOR_SNAPSHOT_FORMAT_VERSION,
7
9
  createProcessorArtifactFiles,
8
10
  loadProcessorArtifactFiles,
@@ -1,2 +1,2 @@
1
1
  // Synchronized from format-versions.json; do not edit this copy directly.
2
- export const SUPPORTED_MIR_SCHEMA_VERSION = 1;
2
+ export const SUPPORTED_MIR_SCHEMA_VERSION = 4;
@@ -4,6 +4,8 @@ export {
4
4
  PROCESSOR_ABI_VERSION,
5
5
  PROCESSOR_ARTIFACT_FORMAT,
6
6
  PROCESSOR_ARTIFACT_FORMAT_VERSION,
7
+ PROCESSOR_EXECUTION_OK,
8
+ PROCESSOR_EXECUTION_RUNTIME_SAFETY_FAILURE,
7
9
  PROCESSOR_SNAPSHOT_FORMAT_VERSION,
8
10
  createProcessorArtifactFiles,
9
11
  loadProcessorArtifactFiles,