pub(crate) fn call_with_vm(&self, vm: &mut Vm, args: usize) -> Result<Option<VmHalt>, VmError> {
        let reason = match &self.inner {
            Inner::FnHandler(handler) => {
                (handler.handler)(&mut vm.stack, args)?;
                None
            }
            Inner::FnOffset(fn_offset) => {
                if let Some(vm_call) = fn_offset.call_with_vm(vm, args, ())? {
                    return Ok(Some(VmHalt::VmCall(vm_call)));
                }

                None
            }
            Inner::FnClosureOffset(closure) => {
                if let Some(vm_call) = closure.fn_offset.call_with_vm(
                    vm,
                    args,
                    (Tuple::from(closure.environment.clone()),),
                )? {
                    return Ok(Some(VmHalt::VmCall(vm_call)));
                }

                None
            }
            Inner::FnUnitStruct(empty) => {
                Self::check_args(args, 0)?;
                vm.stack_mut().push(Value::unit_struct(empty.rtti.clone()));
                None
            }
            Inner::FnTupleStruct(tuple) => {
                Self::check_args(args, tuple.args)?;

                let value =
                    Value::tuple_struct(tuple.rtti.clone(), vm.stack_mut().pop_sequence(args)?);
                vm.stack_mut().push(value);
                None
            }
            Inner::FnUnitVariant(tuple) => {
                Self::check_args(args, 0)?;

                let value = Value::unit_variant(tuple.rtti.clone());
                vm.stack_mut().push(value);
                None
            }
            Inner::FnTupleVariant(tuple) => {
                Self::check_args(args, tuple.args)?;

                let value =
                    Value::tuple_variant(tuple.rtti.clone(), vm.stack_mut().pop_sequence(args)?);
                vm.stack_mut().push(value);
                None
            }
        };

        Ok(reason)
    }
/// Call with the given virtual machine. This allows for certain
/// optimizations, like avoiding the allocation of a new vm state in case
/// the call is internal.
///
/// A stop reason will be returned in case the function call results in
/// a need to suspend the execution.
Call with the given virtual machine. This allows for certain
optimizations, like avoiding the allocation of a new vm state in case
the call is internal.

A stop reason will be returned in case the function call results in
a need to suspend the execution.
Call with the given virtual machine . This allows for certain optimizations like avoiding the allocation of a new vm state in case the call is internal . A stop reason will be returned in case the function call results in a need to suspend the execution .
pub(crate) fn call_with_vm(&self, vm: &mut Vm, args: usize) -> Result<Option<VmHalt>, VmError> {
        let reason = match &self.inner {
            Inner::FnHandler(handler) => {
                (handler.handler)(&mut vm.stack, args)?;
                None
            }
            Inner::FnOffset(fn_offset) => {
                if let Some(vm_call) = fn_offset.call_with_vm(vm, args, ())? {
                    return Ok(Some(VmHalt::VmCall(vm_call)));
                }
                None
            }
            Inner::FnClosureOffset(closure) => {
                if let Some(vm_call) = closure.fn_offset.call_with_vm(
                    vm,
                    args,
                    (Tuple::from(closure.environment.clone()),),
                )? {
                    return Ok(Some(VmHalt::VmCall(vm_call)));
                }
                None
            }
            Inner::FnUnitStruct(empty) => {
                Self::check_args(args, 0)?;
                vm.stack_mut().push(Value::unit_struct(empty.rtti.clone()));
                None
            }
            Inner::FnTupleStruct(tuple) => {
                Self::check_args(args, tuple.args)?;
                let value =
                    Value::tuple_struct(tuple.rtti.clone(), vm.stack_mut().pop_sequence(args)?);
                vm.stack_mut().push(value);
                None
            }
            Inner::FnUnitVariant(tuple) => {
                Self::check_args(args, 0)?;
                let value = Value::unit_variant(tuple.rtti.clone());
                vm.stack_mut().push(value);
                None
            }
            Inner::FnTupleVariant(tuple) => {
                Self::check_args(args, tuple.args)?;
                let value =
                    Value::tuple_variant(tuple.rtti.clone(), vm.stack_mut().pop_sequence(args)?);
                vm.stack_mut().push(value);
                None
            }
        };
        Ok(reason)
    }
pub ( crate ) fn call_with_vm ( & self , vm : & mut Vm , args : usize ) -> Result < Option < VmHalt > , VmError > { let reason = match & self . inner { Inner :: FnHandler ( handler ) => { ( handler . handler ) ( & mut vm . stack , args ) ? ; None } Inner :: FnOffset ( fn_offset ) => { if let Some ( vm_call ) = fn_offset . call_with_vm ( vm , args , ( ) ) ? { return Ok ( Some ( VmHalt :: VmCall ( vm_call ) ) ) ; } None } Inner :: FnClosureOffset ( closure ) => { if let Some ( vm_call ) = closure . fn_offset . call_with_vm ( vm , args , ( Tuple :: from ( closure . environment . clone ( ) ) , ) , ) ? { return Ok ( Some ( VmHalt :: VmCall ( vm_call ) ) ) ; } None } Inner :: FnUnitStruct ( empty ) => { Self :: check_args ( args , 0 ) ? ; vm . stack_mut ( ) . push ( Value :: unit_struct ( empty . rtti . clone ( ) ) ) ; None } Inner :: FnTupleStruct ( tuple ) => { Self :: check_args ( args , tuple . args ) ? ; let value = Value :: tuple_struct ( tuple . rtti . clone ( ) , vm . stack_mut ( ) . pop_sequence ( args ) ? ) ; vm . stack_mut ( ) . push ( value ) ; None } Inner :: FnUnitVariant ( tuple ) => { Self :: check_args ( args , 0 ) ? ; let value = Value :: unit_variant ( tuple . rtti . clone ( ) ) ; vm . stack_mut ( ) . push ( value ) ; None } Inner :: FnTupleVariant ( tuple ) => { Self :: check_args ( args , tuple . args ) ? ; let value = Value :: tuple_variant ( tuple . rtti . clone ( ) , vm . stack_mut ( ) . pop_sequence ( args ) ? ) ; vm . stack_mut ( ) . push ( value ) ; None } } ; Ok ( reason ) }
Call with the given virtual machine.
Call with the given virtual machine .
&self
vm
&mut Vm
args
usize
&self
vm
&mut Vm
args
usize