pub enum Const {
Bool(bool),
Int(i64),
UInt(u64),
F32(u32),
F64(u64),
Char(char),
Str(StrId),
Bytes(Vec<u8>),
Array(Vec<ConstId>),
Map(Vec<(ConstId, ConstId)>),
}Expand description
An entry of the module’s constant pool.
Constants are exact and independent of any runtime value layout: a
64-bit integer is a 64-bit integer, floats are kept as IEEE bit patterns
(so NaN payloads and -0.0 survive encoding bit for bit), and strings
are referenced from the string table. A VM converts a constant into its
own representation when it loads the module (see
Inst::LoadConst and
Inst::DLoadConst).
Aggregate constants (Array, Map) refer
only to earlier constants, so the pool is a DAG by construction and
its depth is a cheap, enforced decoding budget.
§Examples
use bytecode_lang::Const;
let half = Const::f64(0.5);
assert_eq!(half, Const::F64(0.5f64.to_bits()));
assert_eq!(half.to_string(), "f64 0.5");
assert_eq!(Const::Int(-3).to_string(), "int -3");Variants§
Bool(bool)
A boolean.
Int(i64)
A signed integer, loadable into any integer type it fits.
UInt(u64)
An unsigned integer, for u64 values above i64::MAX.
F32(u32)
A binary32 float, as its IEEE bit pattern.
F64(u64)
A binary64 float, as its IEEE bit pattern.
Char(char)
A Unicode scalar value.
Str(StrId)
A UTF-8 string from the string table, loaded as a str.
Bytes(Vec<u8>)
An arbitrary byte string, loaded as a str (PHP strings are bytes).
Array(Vec<ConstId>)
An immutable array of earlier constants.
Map(Vec<(ConstId, ConstId)>)
An immutable insertion-ordered map of earlier constants.
Implementations§
Trait Implementations§
Source§impl Display for Const
Floats print with Rust’s shortest round-trip form; NaNs print their bit
pattern, since the value alone would lose the payload.
impl Display for Const
Floats print with Rust’s shortest round-trip form; NaNs print their bit pattern, since the value alone would lose the payload.