This commit is contained in:
Nilton Constantino
2026-01-31 01:33:19 +00:00
parent 180c7e19e0
commit adcb34826c
12 changed files with 191 additions and 202 deletions
@@ -92,6 +92,10 @@ pub fn lower_function(
stack_types.push(ty);
vm_func.body.push(ir_vm::Instruction::new(ir_vm::InstrKind::PushConst(ir_vm::ConstId(id.0)), None));
}
ir_core::Instr::PushBounded(val) => {
stack_types.push(ir_core::Type::Bounded);
vm_func.body.push(ir_vm::Instruction::new(ir_vm::InstrKind::PushBounded(*val), None));
}
ir_core::Instr::Call(func_id, arg_count) => {
// Pop arguments from type stack
for _ in 0..*arg_count {
@@ -106,10 +110,12 @@ pub fn lower_function(
arg_count: *arg_count
}, None));
}
ir_core::Instr::HostCall(id) => {
ir_core::Instr::HostCall(id, slots) => {
// HostCall return types are not easily known without a registry,
// but usually they return Int or Void in v0.
stack_types.push(ir_core::Type::Int);
// but we now pass the number of slots.
for _ in 0..*slots {
stack_types.push(ir_core::Type::Int);
}
vm_func.body.push(ir_vm::Instruction::new(ir_vm::InstrKind::Syscall(*id), None));
}
ir_core::Instr::GetLocal(slot) => {
@@ -366,6 +372,7 @@ fn lower_type(ty: &ir_core::Type) -> ir_vm::Type {
ir_core::Type::Float => ir_vm::Type::Float,
ir_core::Type::Bool => ir_vm::Type::Bool,
ir_core::Type::String => ir_vm::Type::String,
ir_core::Type::Bounded => ir_vm::Type::Bounded,
ir_core::Type::Optional(inner) => ir_vm::Type::Array(Box::new(lower_type(inner))),
ir_core::Type::Result(ok, _) => lower_type(ok),
ir_core::Type::Struct(_)
@@ -411,7 +418,7 @@ mod tests {
Block {
id: 1,
instrs: vec![
Instr::HostCall(42),
Instr::HostCall(42, 1),
],
terminator: Terminator::Return,
},