luaur_code_gen/functions/
to_string_ir_dump_alt_f.rs1use alloc::string::String;
2
3use crate::functions::get_bytecode_type_name::get_bytecode_type_name;
4use crate::records::bytecode_types::BytecodeTypes;
5
6const LBC_TYPE_OPTIONAL_BIT: u8 = 0x80;
7
8pub(crate) fn to_string_string_bytecode_types_c_char(
9 result: &mut String,
10 bc_types: &BytecodeTypes,
11 userdata_types: *const *const core::ffi::c_char,
12) {
13 let optional_suffix = |t: u8| {
14 if (t & LBC_TYPE_OPTIONAL_BIT) != 0 {
15 "?"
16 } else {
17 ""
18 }
19 };
20
21 unsafe {
22 let result_ty = get_bytecode_type_name(bc_types.result, userdata_types);
23 let a_ty = get_bytecode_type_name(bc_types.a, userdata_types);
24 let b_ty = get_bytecode_type_name(bc_types.b, userdata_types);
25
26 let result_ty_str = core::ffi::CStr::from_ptr(result_ty).to_string_lossy();
27 let a_ty_str = core::ffi::CStr::from_ptr(a_ty).to_string_lossy();
28 let b_ty_str = core::ffi::CStr::from_ptr(b_ty).to_string_lossy();
29
30 result.push_str(&result_ty_str);
31 result.push_str(optional_suffix(bc_types.result));
32
33 result.push_str(" <- ");
34
35 result.push_str(&a_ty_str);
36 result.push_str(optional_suffix(bc_types.a));
37
38 result.push_str(", ");
39
40 result.push_str(&b_ty_str);
41 result.push_str(optional_suffix(bc_types.b));
42
43 if bc_types.c != crate::records::bytecode_types::LBC_TYPE_ANY {
44 let c_ty = get_bytecode_type_name(bc_types.c, userdata_types);
45 let c_ty_str = core::ffi::CStr::from_ptr(c_ty).to_string_lossy();
46 result.push_str(", ");
47 result.push_str(&c_ty_str);
48 result.push_str(optional_suffix(bc_types.c));
49 }
50 }
51}