This commit is contained in:
Nilton Constantino
2026-01-30 15:52:05 +00:00
parent a534b226fb
commit ca3a5d4d3f
10 changed files with 371 additions and 61 deletions
+17 -3
View File
@@ -32,7 +32,7 @@ pub struct Label(pub String);
/// The various types of operations that can be performed in the IR.
///
/// The IR uses a stack-based model, similar to the final Prometeu ByteCode.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub enum InstrKind {
/// Does nothing.
Nop,
@@ -154,6 +154,15 @@ pub enum InstrKind {
GateEndBorrow,
GateBeginMutate,
GateEndMutate,
// --- Reference Counting ---
/// Increments the reference count of a gate handle on the stack.
/// Stack: [..., Gate(g)] -> [..., Gate(g)]
GateRetain,
/// Decrements the reference count of a gate handle and pops it from the stack.
/// Stack: [..., Gate(g)] -> [...]
GateRelease,
}
/// List of instructions that are sensitive to Reference Counting (RC).
@@ -237,6 +246,8 @@ mod tests {
InstrKind::GateEndBorrow,
InstrKind::GateBeginMutate,
InstrKind::GateEndMutate,
InstrKind::GateRetain,
InstrKind::GateRelease,
];
let serialized = serde_json::to_string_pretty(&instructions).unwrap();
@@ -332,7 +343,9 @@ mod tests {
"GateBeginBorrow",
"GateEndBorrow",
"GateBeginMutate",
"GateEndMutate"
"GateEndMutate",
"GateRetain",
"GateRelease"
]"#;
assert_eq!(serialized, expected_json);
}
@@ -346,7 +359,8 @@ mod tests {
"GateLoad", "GateStore", "Alloc",
"GateBeginPeek", "GateEndPeek",
"GateBeginBorrow", "GateEndBorrow",
"GateBeginMutate", "GateEndMutate"
"GateBeginMutate", "GateEndMutate",
"GateRetain", "GateRelease"
];
for name in instructions {
@@ -131,9 +131,11 @@ mod tests {
],
terminator: ir_core::Terminator::Return,
}],
local_types: std::collections::HashMap::new(),
}],
}],
field_offsets: std::collections::HashMap::new(),
field_types: std::collections::HashMap::new(),
};
let vm_module = lower_program(&program).expect("Lowering failed");