fn write_const_value(f: &mut File, constant: P<Value>) {
    use std::io::Write;

    let ref ty = constant.ty;

    let inner = match constant.v {
        Value_::Constant(ref c) => c,
        _ => panic!("expected constant, found {}", constant)
    };

    match inner {
        &Constant::Int(val) => {
            let len = ty.get_int_length().unwrap();
            match len {
                8 => {
                    f.write_fmt(format_args!("\t.byte {}\n", val as u8))
                        .unwrap()
                }
                16 => {
                    f.write_fmt(format_args!("\t.word {}\n", val as u16))
                        .unwrap()
                }
                32 => {
                    f.write_fmt(format_args!("\t.long {}\n", val as u32))
                        .unwrap()
                }
                64 => {
                    f.write_fmt(format_args!("\t.quad {}\n", val as u64))
                        .unwrap()
                }
                _ => panic!("unimplemented int length: {}", len)
            }
        }
        &Constant::IntEx(ref val) => {
            assert!(val.len() == 2);
            f.write_fmt(format_args!("\t.quad {}\n", val[0] as u64))
                .unwrap();
            f.write_fmt(format_args!("\t.quad {}\n", val[1] as u64))
                .unwrap();
        }
        &Constant::Float(val) => {
            use utils::mem::f32_to_raw;
            f.write_fmt(format_args!("\t.long {}\n", f32_to_raw(val) as u32))
                .unwrap();
        }
        &Constant::Double(val) => {
            use utils::mem::f64_to_raw;
            f.write_fmt(format_args!("\t.quad {}\n", f64_to_raw(val) as u64))
                .unwrap();
        }
        &Constant::NullRef => f.write_fmt(format_args!("\t.quad 0\n")).unwrap(),
        &Constant::ExternSym(ref name) => f.write_fmt(format_args!("\t.quad {}\n", name)).unwrap(),
        &Constant::List(ref vals) => {
            for val in vals {
                write_const_value(f, val.clone())
            }
        }
        _ => unimplemented!()
    }
}
/// writes a constant value based on its type and value
writes a constant value based on its type and value
writes a constant value based on its type and value
fn write_const_value(f: &mut File, constant: P<Value>) {
    use std::io::Write;
    let ref ty = constant.ty;
    let inner = match constant.v {
        Value_::Constant(ref c) => c,
        _ => panic!("expected constant, found {}", constant)
    };
    match inner {
        &Constant::Int(val) => {
            let len = ty.get_int_length().unwrap();
            match len {
                8 => {
                    f.write_fmt(format_args!("\t.byte {}\n", val as u8))
                        .unwrap()
                }
                16 => {
                    f.write_fmt(format_args!("\t.word {}\n", val as u16))
                        .unwrap()
                }
                32 => {
                    f.write_fmt(format_args!("\t.long {}\n", val as u32))
                        .unwrap()
                }
                64 => {
                    f.write_fmt(format_args!("\t.quad {}\n", val as u64))
                        .unwrap()
                }
                _ => panic!("unimplemented int length: {}", len)
            }
        }
        &Constant::IntEx(ref val) => {
            assert!(val.len() == 2);
            f.write_fmt(format_args!("\t.quad {}\n", val[0] as u64))
                .unwrap();
            f.write_fmt(format_args!("\t.quad {}\n", val[1] as u64))
                .unwrap();
        }
        &Constant::Float(val) => {
            use utils::mem::f32_to_raw;
            f.write_fmt(format_args!("\t.long {}\n", f32_to_raw(val) as u32))
                .unwrap();
        }
        &Constant::Double(val) => {
            use utils::mem::f64_to_raw;
            f.write_fmt(format_args!("\t.quad {}\n", f64_to_raw(val) as u64))
                .unwrap();
        }
        &Constant::NullRef => f.write_fmt(format_args!("\t.quad 0\n")).unwrap(),
        &Constant::ExternSym(ref name) => f.write_fmt(format_args!("\t.quad {}\n", name)).unwrap(),
        &Constant::List(ref vals) => {
            for val in vals {
                write_const_value(f, val.clone())
            }
        }
        _ => unimplemented!()
    }
}
fn write_const_value ( f : & mut File , constant : P < Value > ) { use std :: io :: Write ; let ref ty = constant . ty ; let inner = match constant . v { Value_ :: Constant ( ref c ) => c , _ => panic ! ( " " constant ) } ; match inner { & Constant :: Int ( val ) => { let len = ty . get_int_length ( ) . unwrap ( ) ; match len { 8 => { f . write_fmt ( format_args ! ( " \t \n " val as u8 ) ) . unwrap ( ) } 16 => { f . write_fmt ( format_args ! ( " \t \n " val as u16 ) ) . unwrap ( ) } 32 => { f . write_fmt ( format_args ! ( " \t \n " val as u32 ) ) . unwrap ( ) } 64 => { f . write_fmt ( format_args ! ( " \t \n " val as u64 ) ) . unwrap ( ) } _ => panic ! ( " " len ) } } & Constant :: IntEx ( ref val ) => { assert ! ( val len ( ) 2 ) ; f . write_fmt ( format_args ! ( " \t \n " val [ 0 ] as u64 ) ) . unwrap ( ) ; f . write_fmt ( format_args ! ( " \t \n " val [ 1 ] as u64 ) ) . unwrap ( ) ; } & Constant :: Float ( val ) => { use utils :: mem :: f32_to_raw ; f . write_fmt ( format_args ! ( " \t \n " f32_to_raw ( val ) as u32 ) ) . unwrap ( ) ; } & Constant :: Double ( val ) => { use utils :: mem :: f64_to_raw ; f . write_fmt ( format_args ! ( " \t \n " f64_to_raw ( val ) as u64 ) ) . unwrap ( ) ; } & Constant :: NullRef => f . write_fmt ( format_args ! ( " \t \n " ) ) . unwrap ( ) , & Constant :: ExternSym ( ref name ) => f . write_fmt ( format_args ! ( " \t \n " name ) ) . unwrap ( ) , & Constant :: List ( ref vals ) => { for val in vals { write_const_value ( f , val . clone ( ) ) } } _ => unimplemented ! ( ) } }
writes a constant value based on its type and value
writes a constant value based on its type and value
f
&mut File
constant
P<Value>
f
&mut File
constant
P<Value>