pub fn assign(
    context: &Context,
    stmt: &Spanned<fe::FuncStmt>,
) -> Result<yul::Statement, CompileError> {
    if let fe::FuncStmt::Assign { targets, value } = &stmt.node {
        if targets.len() > 1 {
            unimplemented!("multiple assignment targets")
        }

        if let Some(first_target) = targets.first() {
            if let (Some(target_attributes), Some(value_attributes)) = (
                context.get_expression(first_target),
                context.get_expression(value),
            ) {
                let target = expressions::expr(&context, first_target)?;
                let value = expressions::expr(&context, value)?;

                let typ = FixedSize::try_from(target_attributes.typ.to_owned())
                    .map_err(|_| CompileError::static_str("invalid attributes"))?;

                return Ok(
                    match (
                        value_attributes.final_location(),
                        target_attributes.final_location(),
                    ) {
                        (Location::Memory, Location::Storage { .. }) => {
                            data_operations::mcopys(typ, target, value)
                        }
                        (Location::Memory, Location::Value) => {
                            let target = expr_as_ident(target)?;
                            let value = data_operations::mload(typ, value);
                            statement! { [target] := [value] }
                        }
                        (Location::Memory, Location::Memory) => {
                            let target = expr_as_ident(target)?;
                            statement! { [target] := [value] }
                        }
                        (Location::Storage { .. }, Location::Storage { .. }) => {
                            data_operations::scopys(typ, target, value)
                        }
                        (Location::Storage { .. }, Location::Value) => {
                            let target = expr_as_ident(target)?;
                            let value = data_operations::sload(typ, value);
                            statement! { [target] := [value] }
                        }
                        (Location::Storage { .. }, Location::Memory) => {
                            unreachable!("raw sto to mem assign")
                        }
                        (Location::Value, Location::Memory) => {
                            data_operations::mstore(typ, target, value)
                        }
                        (Location::Value, Location::Storage { .. }) => {
                            data_operations::sstore(typ, target, value)
                        }
                        (Location::Value, Location::Value) => {
                            let target = expr_as_ident(target)?;
                            statement! { [target] := [value] }
                        }
                    },
                );
            }
        }
    }

    unreachable!()
}
/// Builds a Yul statement from a Fe assignment.
Builds a Yul statement from a Fe assignment.
Builds a Yul statement from a Fe assignment .
pub fn assign(
    context: &Context,
    stmt: &Spanned<fe::FuncStmt>,
) -> Result<yul::Statement, CompileError> {
    if let fe::FuncStmt::Assign { targets, value } = &stmt.node {
        if targets.len() > 1 {
            unimplemented!("multiple assignment targets")
        }
        if let Some(first_target) = targets.first() {
            if let (Some(target_attributes), Some(value_attributes)) = (
                context.get_expression(first_target),
                context.get_expression(value),
            ) {
                let target = expressions::expr(&context, first_target)?;
                let value = expressions::expr(&context, value)?;
                let typ = FixedSize::try_from(target_attributes.typ.to_owned())
                    .map_err(|_| CompileError::static_str("invalid attributes"))?;
                return Ok(
                    match (
                        value_attributes.final_location(),
                        target_attributes.final_location(),
                    ) {
                        (Location::Memory, Location::Storage { .. }) => {
                            data_operations::mcopys(typ, target, value)
                        }
                        (Location::Memory, Location::Value) => {
                            let target = expr_as_ident(target)?;
                            let value = data_operations::mload(typ, value);
                            statement! { [target] := [value] }
                        }
                        (Location::Memory, Location::Memory) => {
                            let target = expr_as_ident(target)?;
                            statement! { [target] := [value] }
                        }
                        (Location::Storage { .. }, Location::Storage { .. }) => {
                            data_operations::scopys(typ, target, value)
                        }
                        (Location::Storage { .. }, Location::Value) => {
                            let target = expr_as_ident(target)?;
                            let value = data_operations::sload(typ, value);
                            statement! { [target] := [value] }
                        }
                        (Location::Storage { .. }, Location::Memory) => {
                            unreachable!("raw sto to mem assign")
                        }
                        (Location::Value, Location::Memory) => {
                            data_operations::mstore(typ, target, value)
                        }
                        (Location::Value, Location::Storage { .. }) => {
                            data_operations::sstore(typ, target, value)
                        }
                        (Location::Value, Location::Value) => {
                            let target = expr_as_ident(target)?;
                            statement! { [target] := [value] }
                        }
                    },
                );
            }
        }
    }
    unreachable!()
}
pub fn assign ( context : & Context , stmt : & Spanned < fe :: FuncStmt > , ) -> Result < yul :: Statement , CompileError > { if let fe :: FuncStmt :: Assign { targets , value } = & stmt . node { if targets . len ( ) > 1 { unimplemented ! ( " " ) } if let Some ( first_target ) = targets . first ( ) { if let ( Some ( target_attributes ) , Some ( value_attributes ) ) = ( context . get_expression ( first_target ) , context . get_expression ( value ) , ) { let target = expressions :: expr ( & context , first_target ) ? ; let value = expressions :: expr ( & context , value ) ? ; let typ = FixedSize :: try_from ( target_attributes . typ . to_owned ( ) ) . map_err ( | _ | CompileError :: static_str ( " " ) ) ? ; return Ok ( match ( value_attributes . final_location ( ) , target_attributes . final_location ( ) , ) { ( Location :: Memory , Location :: Storage { .. } ) => { data_operations :: mcopys ( typ , target , value ) } ( Location :: Memory , Location :: Value ) => { let target = expr_as_ident ( target ) ? ; let value = data_operations :: mload ( typ , value ) ; statement ! { [ target ] [ value ] } } ( Location :: Memory , Location :: Memory ) => { let target = expr_as_ident ( target ) ? ; statement ! { [ target ] [ value ] } } ( Location :: Storage { .. } , Location :: Storage { .. } ) => { data_operations :: scopys ( typ , target , value ) } ( Location :: Storage { .. } , Location :: Value ) => { let target = expr_as_ident ( target ) ? ; let value = data_operations :: sload ( typ , value ) ; statement ! { [ target ] [ value ] } } ( Location :: Storage { .. } , Location :: Memory ) => { unreachable ! ( " " ) } ( Location :: Value , Location :: Memory ) => { data_operations :: mstore ( typ , target , value ) } ( Location :: Value , Location :: Storage { .. } ) => { data_operations :: sstore ( typ , target , value ) } ( Location :: Value , Location :: Value ) => { let target = expr_as_ident ( target ) ? ; statement ! { [ target ] [ value ] } } } , ) ; } } } unreachable ! ( ) }
Builds a Yul statement from a Fe assignment.
Builds a Yul statement from a Fe assignment .
context
&Context
stmt
&Spanned<fe::FuncStmt>
context
&Context
stmt
&Spanned<fe::FuncStmt>