fn gather_elements(
        &mut self,
        before: u32,
        elements: &[ast::Expr],
    ) -> CompileResult<(u32, bool)> {
        // First determine if we have starred elements:
        let has_stars = elements
            .iter()
            .any(|e| matches!(e.node, ast::ExprKind::Starred { .. }));

        let size = if has_stars {
            let mut size = 0;

            if before > 0 {
                self.emit(Instruction::BuildTuple {
                    size: before,
                    unpack: false,
                });
                size += 1;
            }

            let groups = elements
                .iter()
                .map(|element| {
                    if let ast::ExprKind::Starred { value, .. } = &element.node {
                        (true, value.as_ref())
                    } else {
                        (false, element)
                    }
                })
                .group_by(|(starred, _)| *starred);

            for (starred, run) in &groups {
                let mut run_size = 0;
                for (_, value) in run {
                    self.compile_expression(value)?;
                    run_size += 1
                }
                if starred {
                    size += run_size
                } else {
                    self.emit(Instruction::BuildTuple {
                        size: run_size,
                        unpack: false,
                    });
                    size += 1
                }
            }

            size
        } else {
            for element in elements {
                self.compile_expression(element)?;
            }
            before + elements.len() as u32
        };

        Ok((size, has_stars))
    }
// Given a vector of expr / star expr generate code which gives either
// a list of expressions on the stack, or a list of tuples.
Given a vector of expr / star expr generate code which gives either
a list of expressions on the stack, or a list of tuples.
Given a vector of expr / star expr generate code which gives either a list of expressions on the stack or a list of tuples .
fn gather_elements(
        &mut self,
        before: u32,
        elements: &[ast::Expr],
    ) -> CompileResult<(u32, bool)> {
        // First determine if we have starred elements:
        let has_stars = elements
            .iter()
            .any(|e| matches!(e.node, ast::ExprKind::Starred { .. }));
        let size = if has_stars {
            let mut size = 0;
            if before > 0 {
                self.emit(Instruction::BuildTuple {
                    size: before,
                    unpack: false,
                });
                size += 1;
            }
            let groups = elements
                .iter()
                .map(|element| {
                    if let ast::ExprKind::Starred { value, .. } = &element.node {
                        (true, value.as_ref())
                    } else {
                        (false, element)
                    }
                })
                .group_by(|(starred, _)| *starred);
            for (starred, run) in &groups {
                let mut run_size = 0;
                for (_, value) in run {
                    self.compile_expression(value)?;
                    run_size += 1
                }
                if starred {
                    size += run_size
                } else {
                    self.emit(Instruction::BuildTuple {
                        size: run_size,
                        unpack: false,
                    });
                    size += 1
                }
            }
            size
        } else {
            for element in elements {
                self.compile_expression(element)?;
            }
            before + elements.len() as u32
        };
        Ok((size, has_stars))
    }
fn gather_elements ( & mut self , before : u32 , elements : & [ ast :: Expr ] , ) -> CompileResult < ( u32 , bool ) > { // First determine if we have starred elements: let has_stars = elements . iter ( ) . any ( | e | matches ! ( e node ast ExprKind Starred { } ) ) ; let size = if has_stars { let mut size = 0 ; if before > 0 { self . emit ( Instruction :: BuildTuple { size : before , unpack : false , } ) ; size += 1 ; } let groups = elements . iter ( ) . map ( | element | { if let ast :: ExprKind :: Starred { value , .. } = & element . node { ( true , value . as_ref ( ) ) } else { ( false , element ) } } ) . group_by ( | ( starred , _ ) | * starred ) ; for ( starred , run ) in & groups { let mut run_size = 0 ; for ( _ , value ) in run { self . compile_expression ( value ) ? ; run_size += 1 } if starred { size += run_size } else { self . emit ( Instruction :: BuildTuple { size : run_size , unpack : false , } ) ; size += 1 } } size } else { for element in elements { self . compile_expression ( element ) ? ; } before + elements . len ( ) as u32 } ; Ok ( ( size , has_stars ) ) }
Given a vector of expr / star expr generate code which gives either
a list of expressions on the stack, or a list of tuples.
Given a vector of expr / star expr generate code which gives either a list of expressions on the stack or a list of tuples .
&mut self
before
u32
elements
&[ast::Expr]