Skip to main content

ruau_bytecode/
lib.rs

1//! Luau bytecode codec and compiler entry points.
2//!
3//! Application embedders usually compile through `ruau::surface::Surface`, or
4//! through `ruau::vm::RuntimeCapabilities` when using the lower-level VM API
5//! directly. Those paths apply runtime-capability restrictions before calling
6//! into this crate.
7//!
8//! `BuiltinFunction`, `ProtoFlag`, and related opcode-domain constants are
9//! deliberately exposed as constant namespaces rather than Rust enums. The
10//! serialized bytecode format is byte-oriented and occasionally reserves
11//! values that are not meaningful in safe high-level APIs, so callers that
12//! inspect or rewrite bytecode need the exact numeric constants without an enum
13//! exhaustiveness promise.
14
15mod builder;
16mod codec;
17mod compile;
18mod disassemble;
19#[path = "opcodes.rs"]
20mod opcodes_inner;
21mod types;
22mod validate;
23mod version_policy;
24
25#[doc(hidden)]
26pub use builder::FIXTURE_TOOLING_MAX_VERSION;
27pub use builder::{DEFAULT_TYPE_VERSION, DEFAULT_VERSION};
28pub use codec::{DecodeError, EncodeError, decode_chunk, encode_chunk};
29#[doc(hidden)]
30pub use codec::{decode_upstream_fixture_chunk, encode_upstream_fixture_chunk};
31pub use compile::{
32    CompileError, CompileErrorKind, CompileOptions, FastFlag, FastInt, KnownMember,
33    KnownMemberValue, UpstreamCompilerOptions, UpstreamParseOptions, chunkify_parse_error,
34    compile_source, compile_source_bytes, compile_source_bytes_strict,
35    compile_source_bytes_strict_with_upstream_options, compile_source_strict,
36    compile_source_strict_with_upstream_options, effective_compile_options,
37};
38/// Opcode constants and instruction operand helpers.
39pub mod opcodes {
40    pub use crate::opcodes_inner::{
41        BuiltinFunction, CaptureType, FORGLOOP_INEXT_BIT, FORGLOOP_VARS_MASK, FeedbackType,
42        IMPORT_PATH_COMPONENT_BITS, IMPORT_PATH_COMPONENT_MASK, IMPORT_PATH_COUNT_SHIFT,
43        JUMPX_K_INDEX_MASK, JUMPX_K_NOT_BIT, Opcode, import_component_shift,
44    };
45    pub(crate) use crate::opcodes_inner::{ConstantTag, ProtoFlag, TypeTag};
46}
47/// Human-readable bytecode disassembly.
48pub mod disasm {
49    pub use crate::disassemble::disassemble_chunk;
50}
51pub use types::{
52    BytecodeChunk, ClassShape, Constant, DebugInfo, DebugLocal, FeedbackSlot, Instruction,
53    LineInfo, Proto, TableEntry, TypeInfo, UserdataTypeMapping, code_word_count,
54    instruction_word_offsets, jump_target_instruction_index,
55};
56#[doc(hidden)]
57pub use validate::validate_upstream_fixture_chunk;
58pub use validate::{ValidationError, ValidationErrorKind, validate_chunk};
59#[doc(hidden)]
60pub use version_policy::BytecodeVersionPolicy;