Skip to content

Truly independent web browser

1.6 KB
Raw Blame
/*
 * Copyright (c) 2026-present, the Ladybird developers.
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

//! Bytecode instruction types generated from interpreter.flap.
//!
//! The `OpCode` enum, `Instruction` enum, and all encoding/visiting methods
//! are generated by build.rs from interpreter.flap. This is the single source
//! of truth for instruction definitions.

include!(concat!(env!("OUT_DIR"), "/instruction_generated.rs"));

#[cfg(test)]
mod tests {
    use super::*;
    use crate::bytecode::executable_data::ConstantValue;

    #[test]
    fn selects_declarative_int32_specializations() {
        let instruction = Instruction::Add {
            arith_feedback: 3,
            dst: Operand::register(Register(0)),
            lhs: Operand::register(Register(1)),
            rhs: Operand::constant(0),
        };
        let constants = [ConstantValue::Number(42.0)];

        let specialized = specialize_instruction(&instruction, &constants).expect("Add should specialize");

        assert!(matches!(
            specialized,
            Instruction::AddRhsInt32 {
                arith_feedback: 3,
                rhs: 42,
                ..
            }
        ));
    }

    #[test]
    fn selects_declarative_undefined_move_specializations() {
        let instruction = Instruction::Mov {
            dst: Operand::register(Register(0)),
            src: Operand::constant(0),
        };
        let constants = [ConstantValue::Undefined];

        let specialized = specialize_instruction(&instruction, &constants).expect("Mov should specialize");
        assert!(matches!(specialized, Instruction::MovSrcUndefined { .. }));
    }
}