Skip to main content

lua_assembler/instructions/
mod.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
4pub enum LuacInstruction {
5    Resume,
6    PushNull,
7    LoadName(u8),
8    LoadFast(u8),
9    CallFunction(u8),
10    PopTop,
11    ReturnValue,
12    ReturnConst(u8),
13    LoadConst(u8),
14}
15
16impl LuacInstruction {
17    pub fn to_bytecode(&self) -> impl Iterator<Item = u32> {
18        let bytecode_value = match self {
19            LuacInstruction::Resume => 0x00000000,                            // Placeholder
20            LuacInstruction::PushNull => 0x01000000,                          // Placeholder
21            LuacInstruction::LoadName(arg) => 0x02000000 | (*arg as u32),     // Placeholder
22            LuacInstruction::LoadFast(arg) => 0x03000000 | (*arg as u32),     // Placeholder
23            LuacInstruction::CallFunction(arg) => 0x04000000 | (*arg as u32), // Placeholder
24            LuacInstruction::PopTop => 0x05000000,                            // Placeholder
25            LuacInstruction::ReturnValue => 0x06000000,                       // Placeholder
26            LuacInstruction::ReturnConst(arg) => 0x07000000 | (*arg as u32),  // Placeholder
27            LuacInstruction::LoadConst(arg) => 0x08000000 | (*arg as u32),    // Placeholder
28        };
29        vec![bytecode_value].into_iter()
30    }
31}