diff --git a/crates/wast/src/lexer.rs b/crates/wast/src/lexer.rs index c1a04deb8f..6829f30871 100644 --- a/crates/wast/src/lexer.rs +++ b/crates/wast/src/lexer.rs @@ -261,13 +261,13 @@ pub enum Float<'a> { }, /// A parsed and separated floating point value Val { - /// Whether or not the `integral` and `decimal` are specified in hex + /// Whether or not the `integral` and `fractional` are specified in hex hex: bool, /// The float parts before the `.` integral: Cow<'a, str>, /// The float parts after the `.` - decimal: Option>, - /// The exponent to multiple this `integral.decimal` portion of the + fractional: Option>, + /// The exponent to multiple this `integral.fractional` portion of the /// float by. If `hex` is true this is `2^exponent` and otherwise it's /// `10^exponent` exponent: Option>, @@ -673,7 +673,7 @@ impl<'a> Lexer<'a> { } } - // A number can optionally be after the decimal so only actually try to + // A number can optionally be after the dot so only actually try to // parse one if it's there. if it.clone().next() == Some(&b'.') { it.next(); @@ -1079,7 +1079,7 @@ impl Token { hex, } => { let src = self.src(s); - let (integral, decimal, exponent) = match src.find('.') { + let (integral, fractional, exponent) = match src.find('.') { Some(i) => { let integral = &src[..i]; let rest = &src[i + 1..]; @@ -1106,7 +1106,7 @@ impl Token { } }; let mut integral = Cow::Borrowed(integral.strip_prefix('+').unwrap_or(integral)); - let mut decimal = decimal.and_then(|s| { + let mut fractional = fractional.and_then(|s| { if s.is_empty() { None } else { @@ -1117,8 +1117,8 @@ impl Token { exponent.map(|s| Cow::Borrowed(s.strip_prefix('+').unwrap_or(s))); if has_underscores { *integral.to_mut() = integral.replace("_", ""); - if let Some(decimal) = &mut decimal { - *decimal.to_mut() = decimal.replace("_", ""); + if let Some(fractional) = &mut fractional { + *fractional.to_mut() = fractional.replace("_", ""); } if let Some(exponent) = &mut exponent { *exponent.to_mut() = exponent.replace("_", ""); @@ -1130,7 +1130,7 @@ impl Token { Float::Val { hex, integral, - decimal, + fractional, exponent, } } @@ -1501,7 +1501,7 @@ mod tests { get_float("1.2"), Float::Val { integral: "1".into(), - decimal: Some("2".into()), + fractional: Some("2".into()), exponent: None, hex: false, }, @@ -1510,7 +1510,7 @@ mod tests { get_float("1.2e3"), Float::Val { integral: "1".into(), - decimal: Some("2".into()), + fractional: Some("2".into()), exponent: Some("3".into()), hex: false, }, @@ -1519,7 +1519,7 @@ mod tests { get_float("-1_2.1_1E+0_1"), Float::Val { integral: "-12".into(), - decimal: Some("11".into()), + fractional: Some("11".into()), exponent: Some("01".into()), hex: false, }, @@ -1528,7 +1528,7 @@ mod tests { get_float("+1_2.1_1E-0_1"), Float::Val { integral: "12".into(), - decimal: Some("11".into()), + fractional: Some("11".into()), exponent: Some("-01".into()), hex: false, }, @@ -1537,7 +1537,7 @@ mod tests { get_float("0x1_2.3_4p5_6"), Float::Val { integral: "12".into(), - decimal: Some("34".into()), + fractional: Some("34".into()), exponent: Some("56".into()), hex: true, }, @@ -1546,7 +1546,7 @@ mod tests { get_float("+0x1_2.3_4P-5_6"), Float::Val { integral: "12".into(), - decimal: Some("34".into()), + fractional: Some("34".into()), exponent: Some("-56".into()), hex: true, }, @@ -1555,7 +1555,7 @@ mod tests { get_float("1."), Float::Val { integral: "1".into(), - decimal: None, + fractional: None, exponent: None, hex: false, }, @@ -1564,7 +1564,7 @@ mod tests { get_float("0x1p-24"), Float::Val { integral: "1".into(), - decimal: None, + fractional: None, exponent: Some("-24".into()), hex: true, }, diff --git a/crates/wast/src/token.rs b/crates/wast/src/token.rs index c161ee4975..2443c87a01 100644 --- a/crates/wast/src/token.rs +++ b/crates/wast/src/token.rs @@ -410,7 +410,7 @@ macro_rules! float { $parse(&Float::Val { hex: base == 16, integral: s.into(), - decimal: None, + fractional: None, exponent: None, }), rest, @@ -436,7 +436,7 @@ macro_rules! float { let signif_mask = (1 << exp_offset) - 1; let bias = (1 << ($exp_bits - 1)) - 1; - let (hex, integral, decimal, exponent_str) = match val { + let (hex, integral, fractional, exponent_str) = match val { // Infinity is when the exponent bits are all set and // the significand is zero. Float::Inf { negative } => { @@ -471,8 +471,8 @@ macro_rules! float { } // This is trickier, handle this below - Float::Val { hex, integral, decimal, exponent } => { - (hex, integral, decimal, exponent) + Float::Val { hex, integral, fractional, exponent } => { + (hex, integral, fractional, exponent) } }; @@ -480,9 +480,9 @@ macro_rules! float { // correctly. if !*hex { let mut s = integral.to_string(); - if let Some(decimal) = decimal { + if let Some(fractional) = fractional { s.push_str("."); - s.push_str(&decimal); + s.push_str(&fractional); } if let Some(exponent) = exponent_str { s.push_str("e"); @@ -501,7 +501,7 @@ macro_rules! float { // this below does. It was copied from Gecko's implementation in // `WasmTextToBinary.cpp`. Would love comments on this if you have // them! - let decimal = decimal.as_ref().map(|s| &**s).unwrap_or(""); + let fractional = fractional.as_ref().map(|s| &**s).unwrap_or(""); let negative = integral.starts_with('-'); let integral = integral.trim_start_matches('-').trim_start_matches('0'); @@ -510,15 +510,15 @@ macro_rules! float { // adjustments depending on where the digit was found, but the // general idea here is that I'm not really sure why things are // calculated the way they are but it should match Gecko. - let decimal_no_leading = decimal.trim_start_matches('0'); - let decimal_iter = if integral.is_empty() { - decimal_no_leading.chars() + let fractional_no_leading = fractional.trim_start_matches('0'); + let fractional_iter = if integral.is_empty() { + fractional_no_leading.chars() } else { - decimal.chars() + fractional.chars() }; let mut digits = integral.chars() .map(|c| (to_hex(c) as $int, false)) - .chain(decimal_iter.map(|c| (to_hex(c) as $int, true))); + .chain(fractional_iter.map(|c| (to_hex(c) as $int, true))); let lead_nonzero_digit = match digits.next() { Some((c, _)) => c, // No digits? Must be `+0` or `-0`, being careful to handle the @@ -530,7 +530,7 @@ macro_rules! float { let mut exponent = if !integral.is_empty() { 1 } else { - -((decimal.len() - decimal_no_leading.len() + 1) as i32) + 1 + -((fractional.len() - fractional_no_leading.len() + 1) as i32) + 1 }; let lz = (lead_nonzero_digit as u8).leading_zeros() as i32 - 4; exponent = exponent.checked_mul(4)?.checked_sub(lz + 1)?; @@ -542,8 +542,8 @@ macro_rules! float { // digits. Again, not entirely sure why everything is the way it is // here! This is copied frmo gecko. let mut discarded_extra_nonzero = false; - for (digit, decimal) in digits { - if !decimal { + for (digit, is_fractional) in digits { + if !is_fractional { exponent += 4; } if significand_pos > -4 { @@ -699,7 +699,7 @@ mod tests { (@mk $a:tt, $b:expr, $e:expr) => (crate::lexer::Float::Val { hex: true, integral: $a.into(), - decimal: $b, + fractional: $b, exponent: $e }); }