diff --git a/valuescript_compiler/src/asm.rs b/valuescript_compiler/src/asm.rs index 372c430..0768b7f 100644 --- a/valuescript_compiler/src/asm.rs +++ b/valuescript_compiler/src/asm.rs @@ -142,6 +142,7 @@ impl std::fmt::Display for Function { FnLine::Label(label) => write!(f, "{}\n", label)?, FnLine::Empty => write!(f, "\n")?, FnLine::Comment(message) => write!(f, " // {}\n", message)?, + FnLine::Release(reg) => write!(f, " (release {})\n", reg)?, } } write!(f, "}}") @@ -297,21 +298,17 @@ pub enum FnLine { Label(Label), Empty, Comment(String), + Release(Register), } impl std::fmt::Display for FnLine { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { match self { - FnLine::Instruction(instruction) => { - write!(f, "{}", instruction) - } - FnLine::Label(label) => { - write!(f, "{}", label) - } + FnLine::Instruction(instruction) => write!(f, "{}", instruction), + FnLine::Label(label) => write!(f, "{}", label), FnLine::Empty => Ok(()), - FnLine::Comment(message) => { - write!(f, "// {}", message) - } + FnLine::Comment(message) => write!(f, "// {}", message), + FnLine::Release(reg) => write!(f, "(release {})", reg), } } } @@ -890,6 +887,7 @@ impl std::fmt::Display for Lazy { FnLine::Label(label) => write!(f, "{}\n", label)?, FnLine::Empty => write!(f, "\n")?, FnLine::Comment(message) => write!(f, " // {}\n", message)?, + FnLine::Release(reg) => write!(f, " (release {})\n", reg)?, } } diff --git a/valuescript_compiler/src/assembler.rs b/valuescript_compiler/src/assembler.rs index eff86b6..9905c5e 100644 --- a/valuescript_compiler/src/assembler.rs +++ b/valuescript_compiler/src/assembler.rs @@ -102,7 +102,7 @@ impl Assembler { FnLine::Label(label) => { self.label(label); } - FnLine::Empty | FnLine::Comment(..) => {} + FnLine::Empty | FnLine::Comment(..) | FnLine::Release(..) => {} } } @@ -130,7 +130,7 @@ impl Assembler { FnLine::Label(label) => { self.label(label); } - FnLine::Empty | FnLine::Comment(..) => {} + FnLine::Empty | FnLine::Comment(..) | FnLine::Release(..) => {} } } diff --git a/valuescript_compiler/src/assembly_parser.rs b/valuescript_compiler/src/assembly_parser.rs index 8177de0..683c969 100644 --- a/valuescript_compiler/src/assembly_parser.rs +++ b/valuescript_compiler/src/assembly_parser.rs @@ -497,6 +497,19 @@ impl<'a> AssemblyParser<'a> { continue; } + if c == '(' { + self.parse_exact("(release"); + self.parse_whitespace(); + + let reg = self.assemble_register(); + self.parse_optional_whitespace(); + self.parse_exact(")\n"); + + function.body.push(FnLine::Release(reg)); + + continue; + } + let optional_label = self.test_label(); if optional_label.is_some() { diff --git a/valuescript_compiler/src/function_compiler.rs b/valuescript_compiler/src/function_compiler.rs index bcf9a5d..66fc53c 100644 --- a/valuescript_compiler/src/function_compiler.rs +++ b/valuescript_compiler/src/function_compiler.rs @@ -216,6 +216,7 @@ impl FunctionCompiler { pub fn release_reg(&mut self, reg: &Register) { self.reg_allocator.release(reg); + self.current.body.push(FnLine::Release(reg.clone())); } pub fn compile( diff --git a/valuescript_compiler/src/optimization/simplify.rs b/valuescript_compiler/src/optimization/simplify.rs index 627ca49..f610614 100644 --- a/valuescript_compiler/src/optimization/simplify.rs +++ b/valuescript_compiler/src/optimization/simplify.rs @@ -123,7 +123,7 @@ impl FnState { Instruction::Next(_, _) => {} Instruction::UnpackIterRes(_, _, _) => {} }, - FnLine::Label(..) | FnLine::Empty | FnLine::Comment(..) => {} + FnLine::Label(..) | FnLine::Empty | FnLine::Comment(..) | FnLine::Release(..) => {} } } @@ -285,6 +285,9 @@ impl FnState { }, FnLine::Label(..) => self.clear(), FnLine::Empty | FnLine::Comment(..) => {} + FnLine::Release(_reg) => { + // TODO + } } } diff --git a/valuescript_compiler/src/visit_pointers.rs b/valuescript_compiler/src/visit_pointers.rs index 7746efc..f072275 100644 --- a/valuescript_compiler/src/visit_pointers.rs +++ b/valuescript_compiler/src/visit_pointers.rs @@ -170,7 +170,7 @@ where FnLine::Instruction(instruction) => { self.instruction(owner, instruction); } - FnLine::Label(..) | FnLine::Empty | FnLine::Comment(..) => {} + FnLine::Label(..) | FnLine::Empty | FnLine::Comment(..) | FnLine::Release(..) => {} } } }