|
1 | 1 | //! WebAssembly Code Generation for JavaScript
|
2 | 2 | //!
|
3 |
| -//! This module provides all the functionality to emit Wasm modules for |
4 |
| -//! a particular JavaScript program. |
| 3 | +//! This module provides functionality to emit Wasm modules which will run |
| 4 | +//! JavaScript source code with the QuickJS interpreter. |
5 | 5 | //!
|
6 | 6 | //! Javy supports two main code generation paths:
|
7 | 7 | //!
|
|
41 | 41 | //! use javy_codegen::{Generator, LinkingKind, Plugin, JS};
|
42 | 42 | //!
|
43 | 43 | //! fn main() -> Result<(), Box<dyn std::error::Error>> {
|
44 |
| -//! // Load your target Javascript. |
45 |
| -//! let js = JS::from_file(Path::new("example.js"))?; |
| 44 | +//! // Load your target Javascript. |
| 45 | +//! let js = JS::from_file(Path::new("example.js"))?; |
46 | 46 | //!
|
47 |
| -//! // Load existing pre-initialized Javy plugin. |
48 |
| -//! let plugin = Plugin::new_from_path(Path::new("example-plugin.wasm"))?; |
| 47 | +//! // Load existing pre-initialized Javy plugin. |
| 48 | +//! let plugin = Plugin::new_from_path(Path::new("example-plugin.wasm"))?; |
49 | 49 | //!
|
50 |
| -//! // Configure code generator. |
51 |
| -//! let mut generator = Generator::new(plugin); |
52 |
| -//! generator.linking(LinkingKind::Static); |
| 50 | +//! // Configure code generator. |
| 51 | +//! let mut generator = Generator::new(plugin); |
| 52 | +//! generator.linking(LinkingKind::Static); |
53 | 53 | //!
|
54 |
| -//! // Generate your WASM module. |
55 |
| -//! let wasm = generator.generate(&js); |
| 54 | +//! // Generate your Wasm module. |
| 55 | +//! let wasm = generator.generate(&js); |
56 | 56 | //!
|
57 |
| -//! Ok(()) |
| 57 | +//! Ok(()) |
58 | 58 | //! }
|
59 | 59 | //! ```
|
60 | 60 | //!
|
61 | 61 | //! ## Core concepts
|
62 | 62 | //! * [`Generator`] - The main entry point for generating Wasm modules.
|
63 |
| -//! * [`Plugin`] - Represents a pre-initialized Javy plugin. |
64 |
| -//! * [`JS`] - Represents a JavaScript bytecode. |
| 63 | +//! * [`Plugin`] - An initialized Javy plugin. |
| 64 | +//! * [`JS`] - JavaScript source code. |
65 | 65 | //!
|
66 | 66 | //! ## Features
|
67 | 67 | //!
|
68 |
| -//! * `plugin_internal` - Enables additional code generation options for internal use. |
69 |
| -//! > Please note that this flag enables an unstable feature. The unstable API's exposed by this future may break in the future without notice. |
| 68 | +//! * `plugin_internal` - Enables additional code generation options for |
| 69 | +//! internal use. Please note that this flag enables an unstable feature. The |
| 70 | +//! unstable API's exposed by this future may break in the future without |
| 71 | +//! notice. |
70 | 72 |
|
71 | 73 | use std::{fs, rc::Rc, sync::OnceLock};
|
72 | 74 |
|
@@ -147,8 +149,7 @@ impl BytecodeMetadata {
|
147 | 149 | }
|
148 | 150 | }
|
149 | 151 |
|
150 |
| -/// Generator used to produce valid Wasm |
151 |
| -/// binaries from JS. |
| 152 | +/// Generator used to produce Wasm binaries from JS source code. |
152 | 153 | #[derive(Default, Clone)]
|
153 | 154 | pub struct Generator {
|
154 | 155 | /// Plugin to use.
|
@@ -558,7 +559,7 @@ impl Generator {
|
558 | 559 | // (data (;0;) "\02\05\18function.mjs\06foo\0econsole\06log\06bar\0f\bc\03\00\01\00\00\be\03\00\00\0e\00\06\01\a0\01\00\00\00\03\01\01\1a\00\be\03\00\01\08\ea\05\c0\00\e1)8\e0\00\00\00B\e1\00\00\00\04\e2\00\00\00$\01\00)\bc\03\01\04\01\00\07\0a\0eC\06\01\be\03\00\00\00\03\00\00\13\008\e0\00\00\00B\e1\00\00\00\04\df\00\00\00$\01\00)\bc\03\01\02\03]")
|
559 | 560 | // (data (;1;) "foo")
|
560 | 561 | // )
|
561 |
| - /// Generate a valid WASM binary from JS. |
| 562 | + /// Generate a Wasm module which will run the provided JS source code. |
562 | 563 | pub fn generate(&mut self, js: &js::JS) -> Result<Vec<u8>> {
|
563 | 564 | if self.wit_opts.defined() {
|
564 | 565 | self.function_exports = exports::process_exports(
|
|
0 commit comments