neo_solidity/
regalloc.rs

1//! Register Allocation
2//!
3//! Allocates local variables to NeoVM slots.
4
5/// Slot allocation result
6#[derive(Debug, Clone)]
7pub struct SlotAllocation {
8    pub var_name: String,
9    pub slot_index: u8,
10}
11
12/// Simple slot allocator
13#[derive(Default)]
14pub struct SlotAllocator {
15    next_slot: u8,
16}
17
18impl SlotAllocator {
19    pub fn new() -> Self {
20        Self::default()
21    }
22
23    pub fn allocate(&mut self, name: &str) -> SlotAllocation {
24        let slot = self.next_slot;
25        self.next_slot += 1;
26        SlotAllocation {
27            var_name: name.to_string(),
28            slot_index: slot,
29        }
30    }
31}