fn reduce_global(&mut self, global: Value, mut argtuple: Vec<Value>) -> Result<()> {
        match global {
            Value::Global(Global::Set) => {
                match self.resolve(argtuple.pop()) {
                    Some(Value::List(items)) => {
                        self.stack.push(Value::Set(items));
                        Ok(())
                    }
                    _ => self.error(ErrorCode::InvalidValue("set() arg".into())),
                }
            }
            Value::Global(Global::Frozenset) => {
                match self.resolve(argtuple.pop()) {
                    Some(Value::List(items)) => {
                        self.stack.push(Value::FrozenSet(items));
                        Ok(())
                    }
                    _ => self.error(ErrorCode::InvalidValue("frozenset() arg".into())),
                }
            }
            Value::Global(Global::Bytearray) => {
                // On Py2, the call is encoded as bytearray(u"foo", "latin-1").
                argtuple.truncate(1);
                match self.resolve(argtuple.pop()) {
                    Some(Value::Bytes(bytes)) => {
                        self.stack.push(Value::Bytes(bytes));
                        Ok(())
                    }
                    Some(Value::String(string)) => {
                        // The code points in the string are actually bytes values.
                        // So we need to collect them individually.
                        self.stack.push(Value::Bytes(
                            string.chars().map(|ch| ch as u32 as u8).collect()));
                        Ok(())
                    }
                    _ => self.error(ErrorCode::InvalidValue("bytearray() arg".into())),
                }
            }
            Value::Global(Global::List) => {
                match self.resolve(argtuple.pop()) {
                    Some(Value::List(items)) => {
                        self.stack.push(Value::List(items));
                        Ok(())
                    }
                    _ => self.error(ErrorCode::InvalidValue("list() arg".into())),
                }
            }
            Value::Global(Global::Int) => {
                match self.resolve(argtuple.pop()) {
                    Some(Value::Int(integer)) => {
                        self.stack.push(Value::Int(integer));
                        Ok(())
                    }
                    _ => self.error(ErrorCode::InvalidValue("int() arg".into())),
                }
            }
            Value::Global(Global::Encode) => {
                // Byte object encoded as _codecs.encode(x, 'latin1')
                match self.resolve(argtuple.pop()) {  // Encoding, always latin1
                    Some(Value::String(_)) => { }
                    _ => return self.error(ErrorCode::InvalidValue("encode() arg".into())),
                }
                match self.resolve(argtuple.pop()) {
                    Some(Value::String(s)) => {
                        // Now we have to convert the string to latin-1
                        // encoded bytes.  It never contains codepoints
                        // above 0xff.
                        let bytes = s.chars().map(|ch| ch as u8).collect();
                        self.stack.push(Value::Bytes(bytes));
                        Ok(())
                    }
                    _ => self.error(ErrorCode::InvalidValue("encode() arg".into())),
                }
            }
            Value::Global(Global::Other) => {
                // Anything else; just keep it on the stack as an opaque object.
                // If it is a class object, it will get replaced later when the
                // class is instantiated.
                self.stack.push(Value::Global(Global::Other));
                Ok(())
            }
            other => Self::stack_error("global reference", &other, self.pos),
        }
    }
// Handle the REDUCE opcode for the few Global objects we support.
Handle the REDUCE opcode for the few Global objects we support.
Handle the REDUCE opcode for the few Global objects we support .
fn reduce_global(&mut self, global: Value, mut argtuple: Vec<Value>) -> Result<()> {
        match global {
            Value::Global(Global::Set) => {
                match self.resolve(argtuple.pop()) {
                    Some(Value::List(items)) => {
                        self.stack.push(Value::Set(items));
                        Ok(())
                    }
                    _ => self.error(ErrorCode::InvalidValue("set() arg".into())),
                }
            }
            Value::Global(Global::Frozenset) => {
                match self.resolve(argtuple.pop()) {
                    Some(Value::List(items)) => {
                        self.stack.push(Value::FrozenSet(items));
                        Ok(())
                    }
                    _ => self.error(ErrorCode::InvalidValue("frozenset() arg".into())),
                }
            }
            Value::Global(Global::Bytearray) => {
                // On Py2, the call is encoded as bytearray(u"foo", "latin-1").
                argtuple.truncate(1);
                match self.resolve(argtuple.pop()) {
                    Some(Value::Bytes(bytes)) => {
                        self.stack.push(Value::Bytes(bytes));
                        Ok(())
                    }
                    Some(Value::String(string)) => {
                        // The code points in the string are actually bytes values.
                        // So we need to collect them individually.
                        self.stack.push(Value::Bytes(
                            string.chars().map(|ch| ch as u32 as u8).collect()));
                        Ok(())
                    }
                    _ => self.error(ErrorCode::InvalidValue("bytearray() arg".into())),
                }
            }
            Value::Global(Global::List) => {
                match self.resolve(argtuple.pop()) {
                    Some(Value::List(items)) => {
                        self.stack.push(Value::List(items));
                        Ok(())
                    }
                    _ => self.error(ErrorCode::InvalidValue("list() arg".into())),
                }
            }
            Value::Global(Global::Int) => {
                match self.resolve(argtuple.pop()) {
                    Some(Value::Int(integer)) => {
                        self.stack.push(Value::Int(integer));
                        Ok(())
                    }
                    _ => self.error(ErrorCode::InvalidValue("int() arg".into())),
                }
            }
            Value::Global(Global::Encode) => {
                // Byte object encoded as _codecs.encode(x, 'latin1')
                match self.resolve(argtuple.pop()) {  // Encoding, always latin1
                    Some(Value::String(_)) => { }
                    _ => return self.error(ErrorCode::InvalidValue("encode() arg".into())),
                }
                match self.resolve(argtuple.pop()) {
                    Some(Value::String(s)) => {
                        // Now we have to convert the string to latin-1
                        // encoded bytes.  It never contains codepoints
                        // above 0xff.
                        let bytes = s.chars().map(|ch| ch as u8).collect();
                        self.stack.push(Value::Bytes(bytes));
                        Ok(())
                    }
                    _ => self.error(ErrorCode::InvalidValue("encode() arg".into())),
                }
            }
            Value::Global(Global::Other) => {
                // Anything else; just keep it on the stack as an opaque object.
                // If it is a class object, it will get replaced later when the
                // class is instantiated.
                self.stack.push(Value::Global(Global::Other));
                Ok(())
            }
            other => Self::stack_error("global reference", &other, self.pos),
        }
    }
fn reduce_global ( & mut self , global : Value , mut argtuple : Vec < Value > ) -> Result < ( ) > { match global { Value :: Global ( Global :: Set ) => { match self . resolve ( argtuple . pop ( ) ) { Some ( Value :: List ( items ) ) => { self . stack . push ( Value :: Set ( items ) ) ; Ok ( ( ) ) } _ => self . error ( ErrorCode :: InvalidValue ( " " . into ( ) ) ) , } } Value :: Global ( Global :: Frozenset ) => { match self . resolve ( argtuple . pop ( ) ) { Some ( Value :: List ( items ) ) => { self . stack . push ( Value :: FrozenSet ( items ) ) ; Ok ( ( ) ) } _ => self . error ( ErrorCode :: InvalidValue ( " " . into ( ) ) ) , } } Value :: Global ( Global :: Bytearray ) => { // On Py2, the call is encoded as bytearray(u"foo", "latin-1"). argtuple . truncate ( 1 ) ; match self . resolve ( argtuple . pop ( ) ) { Some ( Value :: Bytes ( bytes ) ) => { self . stack . push ( Value :: Bytes ( bytes ) ) ; Ok ( ( ) ) } Some ( Value :: String ( string ) ) => { // The code points in the string are actually bytes values. // So we need to collect them individually. self . stack . push ( Value :: Bytes ( string . chars ( ) . map ( | ch | ch as u32 as u8 ) . collect ( ) ) ) ; Ok ( ( ) ) } _ => self . error ( ErrorCode :: InvalidValue ( " " . into ( ) ) ) , } } Value :: Global ( Global :: List ) => { match self . resolve ( argtuple . pop ( ) ) { Some ( Value :: List ( items ) ) => { self . stack . push ( Value :: List ( items ) ) ; Ok ( ( ) ) } _ => self . error ( ErrorCode :: InvalidValue ( " " . into ( ) ) ) , } } Value :: Global ( Global :: Int ) => { match self . resolve ( argtuple . pop ( ) ) { Some ( Value :: Int ( integer ) ) => { self . stack . push ( Value :: Int ( integer ) ) ; Ok ( ( ) ) } _ => self . error ( ErrorCode :: InvalidValue ( " " . into ( ) ) ) , } } Value :: Global ( Global :: Encode ) => { // Byte object encoded as _codecs.encode(x, 'latin1') match self . resolve ( argtuple . pop ( ) ) { // Encoding, always latin1 Some ( Value :: String ( _ ) ) => { } _ => return self . error ( ErrorCode :: InvalidValue ( " " . into ( ) ) ) , } match self . resolve ( argtuple . pop ( ) ) { Some ( Value :: String ( s ) ) => { // Now we have to convert the string to latin-1 // encoded bytes.  It never contains codepoints // above 0xff. let bytes = s . chars ( ) . map ( | ch | ch as u8 ) . collect ( ) ; self . stack . push ( Value :: Bytes ( bytes ) ) ; Ok ( ( ) ) } _ => self . error ( ErrorCode :: InvalidValue ( " " . into ( ) ) ) , } } Value :: Global ( Global :: Other ) => { // Anything else; just keep it on the stack as an opaque object. // If it is a class object, it will get replaced later when the // class is instantiated. self . stack . push ( Value :: Global ( Global :: Other ) ) ; Ok ( ( ) ) } other => Self :: stack_error ( " " , & other , self . pos ) , } }
Handle the REDUCE opcode for the few Global objects we support.
Handle the REDUCE opcode for the few Global objects we support .
&mut self
global
Value
argtuple
Vec<Value>
&mut self
global
Value
argtuple
Vec<Value>