rust_jvm::vm::native::WRITE [] [src]

const WRITE: &'static Fn(Vec<Value>) -> Option<Value> = &(|args| {
    if let Value::ArrayReference(ref b_rc) = args[1] {
        if let Value::Int(Wrapping(off)) = args[2] {
            if let Value::Int(Wrapping(len)) = args[3] {
                let b = b_rc.borrow();
                let mut bytes = vec![];
                for i in 0..len {
                    // TODO error condition is probably not right here
                    let value = b.get(off + i);
                    if let Value::Int(Wrapping(byte)) = value {
                        bytes.push(byte as u8);
                    } else {
                        panic!("bad value");
                    }
                }
                io::stdout().write_all(&bytes).expect("IOException");
                None
            } else {
                panic!("len must be an int")
            }
        } else {
            panic!("off must be an int")
        }
    } else {
        panic!("b must be an array")
    }
})