use crate::{wasm::ToLSBytes, Error, MacroAssembler, Result};
use wasmparser::ValType;
impl MacroAssembler {
pub(crate) fn handle_empty_return(&mut self) -> Result<()> {
self._push0()?;
self._push0()?;
self.asm._return()?;
Ok(())
}
pub fn main_return(&mut self, results: &[ValType]) -> Result<()> {
if results.is_empty() {
return self.handle_empty_return();
}
let size = self.memory_write(results)?.size;
let offset =
self.mp_offset(|mp| mp.checked_sub(size).ok_or_else(|| Error::InvalidMP(0)))?;
self.push(&size.to_ls_bytes())?;
self.push(&offset)?;
self.asm._return()?;
Ok(())
}
pub fn call_return(&mut self, results: &[ValType]) -> Result<()> {
let len = results.len() as u16;
tracing::trace!("cleaning frame stack, target: {}", len + 1);
while self.sp() > len + 1 {
self._drop()?;
}
self.shift_stack(len, false)?;
self._jump()
}
}