diff options
| -rw-r--r-- | src/librustc_i128/lib.rs | 2 | ||||
| -rw-r--r-- | src/libserialize/leb128.rs | 48 | ||||
| -rw-r--r-- | src/libsyntax/ast.rs | 4 |
3 files changed, 27 insertions, 27 deletions
diff --git a/src/librustc_i128/lib.rs b/src/librustc_i128/lib.rs index 5b50c2b493a..65533b5011b 100644 --- a/src/librustc_i128/lib.rs +++ b/src/librustc_i128/lib.rs @@ -1,5 +1,5 @@ #![allow(non_camel_case_types)] -#![feature(i128_type)] +#![cfg_attr(not(stage0), feature(i128_type))] #[cfg(stage0)] pub type i128 = i64; diff --git a/src/libserialize/leb128.rs b/src/libserialize/leb128.rs index 7a4d1c7a0e4..04ebffd47f2 100644 --- a/src/libserialize/leb128.rs +++ b/src/libserialize/leb128.rs @@ -87,12 +87,14 @@ pub fn write_signed_leb128_to<W>(mut value: i128, mut write: W) -> usize value >>= 7; let more = !((((value == 0) && ((byte & 0x40) == 0)) || ((value == -1) && ((byte & 0x40) != 0)))); + if more { byte |= 0x80; // Mark this byte to show that more bytes will follow. } write(position, byte); position += 1; + if !more { break; } @@ -106,30 +108,28 @@ pub fn write_signed_leb128(out: &mut Vec<u8>, start_position: usize, value: i128 #[inline] pub fn read_signed_leb128(data: &[u8], start_position: usize) -> (i128, usize) { - let (l, r) = read_unsigned_leb128(data, start_position); - (l as i128, r) - // let mut result = 0; - // let mut shift = 0; - // let mut position = start_position; - // let mut byte; - - // loop { - // byte = data[position]; - // position += 1; - // result |= ((byte & 0x7F) as i128) << shift; - // shift += 7; - - // if (byte & 0x80) == 0 { - // break; - // } - // } - - // if (shift < 64) && ((byte & 0x40) != 0) { - // // sign extend - // result |= -(1 << shift); - // } - - // (result, position - start_position) + let mut result = 0; + let mut shift = 0; + let mut position = start_position; + let mut byte; + + loop { + byte = data[position]; + position += 1; + result |= ((byte & 0x7F) as i128) << shift; + shift += 7; + + if (byte & 0x80) == 0 { + break; + } + } + + if (shift < 64) && ((byte & 0x40) != 0) { + // sign extend + result |= -(1 << shift); + } + + (result, position - start_position) } #[test] diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 60402fe1a66..da4b787160f 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1201,8 +1201,8 @@ impl IntTy { } pub fn val_to_string(&self, val: i128) -> String { - // cast to a u64 so we can correctly print INT64_MIN. All integral types - // are parsed as u64, so we wouldn't want to print an extra negative + // cast to a u128 so we can correctly print INT128_MIN. All integral types + // are parsed as u128, so we wouldn't want to print an extra negative // sign. format!("{}{}", val as u128, self.ty_to_string()) } |
