luaur-compiler 0.1.3

Luau source-to-bytecode compiler (Rust).
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use crate::records::compiler::Compiler;
use luaur_common::enums::luau_opcode::LuauOpcode;
use luaur_common::macros::luau_assert::LUAU_ASSERT;

impl Compiler {
    pub fn emit_load_k(&mut self, target: u8, cid: i32) {
        LUAU_ASSERT!(cid >= 0);

        let bytecode = unsafe { &mut *self.bytecode };

        if cid < 32768 {
            bytecode.emit_ad(LuauOpcode::LOP_LOADK, target, cid as i16);
        } else {
            bytecode.emit_ad(LuauOpcode::LOP_LOADKX, target, 0);
            bytecode.emit_aux(cid as u32);
        }
    }
}