Skip to content

Mutable as_fn? #8

@N3rdL0rd

Description

@N3rdL0rd

In my codebase for hlbc-python, I want to add functions to modify and reserialize the bytecode, but this code does not work - as_fn does not return a mutable Function. I assume this is intentional, but is there some way to get around it?

    fn copy_function_from(&self, other: &Self, source_idx: String, dest_idx: String) -> PyResult<()> {
        catch_panic(|| {
            let source = RefFun(source_idx.parse::<usize>().unwrap()).as_fn(&other.bytecode).ok_or_else(|| 
                PyErr::new::<pyo3::exceptions::PyException, _>(format!("Source function with index {} not found!", source_idx)))?;
            let mut dest = RefFun(dest_idx.parse::<usize>().unwrap()).as_fn(&self.bytecode).ok_or_else(|| 
                PyErr::new::<pyo3::exceptions::PyException, _>(format!("Destination function with index {} not found!", dest_idx)))?;
            dest.ops = source.ops.clone();
            dest.regs = source.regs.clone();
            dest.debug_info = source.debug_info.clone();
            dest.assigns = source.assigns.clone();
            Ok(())
        })
    }

PS: Forgive me for my lack of knowledge of Rust, I'm a bit of a beginner with the language...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions