use prometeu_compiler::ir::module::{Module, Function}; use prometeu_compiler::ir::instr::{Instruction, InstrKind}; use prometeu_compiler::ir::types::Type; use prometeu_compiler::ir_core::ids::FunctionId; use prometeu_compiler::ir_core::const_pool::ConstantValue; use prometeu_compiler::backend::emit_module; use prometeu_compiler::common::files::FileManager; use prometeu_bytecode::pbc::parse_pbc; use prometeu_bytecode::pbc::ConstantPoolEntry; #[test] fn test_emit_module_with_const_pool() { let mut module = Module::new("test".to_string()); // Insert constants into IR module let id_int = module.const_pool.insert(ConstantValue::Int(12345)); let id_str = module.const_pool.insert(ConstantValue::String("hello".to_string())); let function = Function { id: FunctionId(0), name: "main".to_string(), params: vec![], return_type: Type::Void, body: vec![ Instruction::new(InstrKind::PushConst(id_int), None), Instruction::new(InstrKind::PushConst(id_str), None), Instruction::new(InstrKind::Ret, None), ], }; module.functions.push(function); let file_manager = FileManager::new(); let result = emit_module(&module, &file_manager).expect("Failed to emit module"); let pbc = parse_pbc(&result.rom).expect("Failed to parse emitted PBC"); // Check constant pool in PBC // PBC CP has Null at index 0, so our constants should be at 1 and 2 assert_eq!(pbc.cp.len(), 3); assert_eq!(pbc.cp[0], ConstantPoolEntry::Null); assert_eq!(pbc.cp[1], ConstantPoolEntry::Int64(12345)); assert_eq!(pbc.cp[2], ConstantPoolEntry::String("hello".to_string())); }