luaur_bytecode/records/
bc_call.rs1use core::marker::PhantomData;
2
3use alloc::vec::Vec;
4use luaur_common::enums::luau_opcode::LuauOpcode;
5
6use crate::methods::bc_function_as::BcInstType;
7use crate::methods::bc_inst_helper_create::BcInstHelperCreate;
8use crate::records::bc_function::{BcFunction, VmConst};
9use crate::records::bc_inst::BcInst;
10use crate::records::bc_inst_helper::BcInstHelper;
11use crate::records::bc_op::BcOp;
12use crate::records::bc_ref::BcRef;
13
14#[derive(Debug)]
15pub struct BcCall<'a, T = VmConst> {
16 pub(crate) base: BcInstHelper<'a>,
17 _marker: PhantomData<T>,
18}
19
20impl<'a, T> BcCall<'a, T> {
21 pub const K_PARAM_START_INPUT: u32 = 3;
22
23 pub fn from(graph: *mut BcFunction, inst: BcRef<'a, BcInst>) -> Self {
24 Self {
25 base: BcInstHelper::new(unsafe { &mut *graph }, inst),
26 _marker: PhantomData,
27 }
28 }
29
30 pub fn params(&self) -> Vec<BcOp> {
31 self.base.slice_inputs(Self::K_PARAM_START_INPUT)
32 }
33
34 pub fn param_count(&mut self) -> i32 {
35 self.base.int_imm_input(0)
36 }
37
38 pub fn set_param_count(&mut self, value: u32) {
39 self.base.set_imm_input(0, value as i32);
40 }
41
42 pub fn return_count(&mut self) -> i32 {
43 self.base.int_imm_input(1)
44 }
45
46 pub fn set_return_count(&mut self, value: u32) {
47 self.base.set_imm_input(1, value as i32);
48 }
49
50 pub fn target(&mut self) -> BcOp {
51 self.base.get_bc_op(2)
52 }
53
54 pub fn set_target(&mut self, value: BcOp) {
55 self.base.set_bc_op(2, value);
56 }
57}
58
59impl<T> BcInstType for BcCall<'_, T> {
60 const OPCODE: i32 = LuauOpcode::LOP_CALL as i32;
61}
62
63impl<T> BcInstHelperCreate for BcCall<'_, T> {
64 const OPCODE: LuauOpcode = LuauOpcode::LOP_CALL;
65}