Skip to content

Commit 15b421b

Browse files
committed
docs(engine): add spec references for bytecode internals (#2426)
1 parent 055ee09 commit 15b421b

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

core/engine/src/bytecompiler/expression/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
//! Lowering for ECMAScript expressions.
2+
//!
3+
//! The functions in this module implement the bytecompiler side of expression evaluation. They
4+
//! preserve the source language evaluation order while translating AST nodes into opcode sequences
5+
//! that the VM can execute later. See the ECMAScript expression grammar and runtime semantics in
6+
//! the [specification][spec].
7+
//!
8+
//! [spec]: https://tc39.es/ecma262/#sec-ecmascript-language-expressions
9+
110
mod assign;
211
mod binary;
312
mod object_literal;

core/engine/src/bytecompiler/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@
77
//! producing code blocks that are later executed by the VM.
88
//!
99
//! This module provides the necessary functionality to compile JavaScript code into bytecode.
10+
//! Conceptually, it is the bridge between the spec's runtime semantics and Boa's opcode-based VM.
11+
//! When the ECMAScript algorithms use the `!` prefix for an abstract operation, Boa treats the
12+
//! corresponding assumption as an internal compiler or bytecode invariant, and documents that
13+
//! mapping near the assertion sites that rely on it.
14+
//!
15+
//! Relevant specification entry points include [script evaluation][script],
16+
//! [module evaluation][module], and the expression and statement [runtime semantics][evaluation]
17+
//! that eventually feed into those top-level algorithms.
18+
//!
19+
//! [script]: https://tc39.es/ecma262/#sec-runtime-semantics-scriptevaluation
20+
//! [module]: https://tc39.es/ecma262/#sec-moduleevaluation
21+
//! [evaluation]: https://tc39.es/ecma262/#sec-runtime-semantics-evaluation
1022
1123
mod class;
1224
mod declaration;

core/engine/src/vm/opcode/args.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
//! Encoding and decoding helpers for opcode operands.
2+
//!
3+
//! The VM only decodes bytecode emitted and patched by Boa. Because of that, these helpers rely on
4+
//! internal invariants instead of returning recoverable errors for malformed operand layouts. If
5+
//! decoding fails, it points to a compiler or bytecode management bug.
6+
17
use thin_vec::ThinVec;
28

39
use super::{Address, IndexOperand, RegisterOperand};
@@ -38,6 +44,8 @@ unsafe impl Readable for (u32, u32, u32, u32, u32) {}
3844
pub(super) fn read<T: Readable>(bytes: &[u8], offset: usize) -> (T, usize) {
3945
let new_offset = offset + size_of::<T>();
4046

47+
// The VM only executes bytecode emitted and patched by Boa, so a short operand stream means an
48+
// internal invariant was broken earlier in compilation or patching.
4149
assert!(bytes.len() >= new_offset, "buffer too small to read type T");
4250

4351
// Safety: The assertion above ensures that the slice is large enough to read T.

core/engine/src/vm/opcode/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
#![allow(clippy::inline_always)]
22
#![allow(clippy::doc_markdown)]
3+
//! Boa's VM opcode definitions and bytecode dispatch.
4+
//!
5+
//! The bytecompiler lowers ECMAScript runtime semantics into these opcode families, which are then
6+
//! executed by the virtual machine. Most opcode submodules mirror a part of the specification,
7+
//! such as function calls, environment records, iteration, property access, or class evaluation.
8+
//! See the general runtime semantics overview in the [specification][spec].
9+
//!
10+
//! When the specification marks an abstract operation as infallible with `!`, Boa treats the
11+
//! corresponding condition as an internal bytecode invariant. In those cases, malformed
12+
//! bytecode is treated as an engine bug and may trip an assertion instead of returning a
13+
//! recoverable JavaScript exception.
14+
//!
15+
//! [spec]: https://tc39.es/ecma262/#sec-runtime-semantics-evaluation
316
use crate::{
417
Context,
518
vm::{completion_record::CompletionRecord, completion_record::IntoCompletionRecord},

0 commit comments

Comments
 (0)