Fix test number generation
This commit is contained in:
parent
987a19ed8e
commit
65cd89c6d7
@ -4,6 +4,7 @@ local linked = {}
|
||||
local LUA_NAN_ARITHMETIC = 0 / 0
|
||||
local LUA_NAN_CANONICAL = 0 / 0
|
||||
local LUA_NAN_DEFAULT = 0 / 0
|
||||
local LUA_INFINITY = math.huge
|
||||
|
||||
local function is_number_equality(lhs, rhs)
|
||||
if type(lhs) ~= "number" or type(rhs) ~= "number" then
|
||||
|
@ -5,7 +5,6 @@ use std::{
|
||||
|
||||
use wast::{
|
||||
core::{Expression, Instruction},
|
||||
token::{Float32, Float64},
|
||||
AssertExpression, WastExecute, WastInvoke,
|
||||
};
|
||||
|
||||
@ -26,21 +25,18 @@ impl LuaJIT {
|
||||
match &data[0] {
|
||||
Instruction::I32Const(v) => write!(w, "{v}"),
|
||||
Instruction::I64Const(v) => write!(w, "{v}LL"),
|
||||
Instruction::F32Const(v) => write!(w, "{}", f32::from_bits(v.bits)),
|
||||
Instruction::F64Const(v) => write!(w, "{}", f64::from_bits(v.bits)),
|
||||
Instruction::F32Const(v) => target::write_f32(f32::from_bits(v.bits), w),
|
||||
Instruction::F64Const(v) => target::write_f64(f64::from_bits(v.bits), w),
|
||||
_ => panic!("Unsupported instruction"),
|
||||
}
|
||||
}
|
||||
|
||||
write_assert_number!(write_assert_maybe_f32, Float32, f32);
|
||||
write_assert_number!(write_assert_maybe_f64, Float64, f64);
|
||||
|
||||
fn write_simple_expression(data: &AssertExpression, w: &mut dyn Write) -> Result<()> {
|
||||
match data {
|
||||
AssertExpression::I32(v) => write!(w, "{v}"),
|
||||
AssertExpression::I64(v) => write!(w, "{v}LL"),
|
||||
AssertExpression::F32(v) => Self::write_assert_maybe_f32(v, w),
|
||||
AssertExpression::F64(v) => Self::write_assert_maybe_f64(v, w),
|
||||
AssertExpression::F32(v) => target::write_f32_nan(v, w),
|
||||
AssertExpression::F64(v) => target::write_f64_nan(v, w),
|
||||
_ => panic!("Unsupported expression"),
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ use std::{
|
||||
|
||||
use wast::{
|
||||
core::{Expression, Instruction},
|
||||
token::{Float32, Float64},
|
||||
AssertExpression, WastExecute, WastInvoke,
|
||||
};
|
||||
|
||||
@ -22,7 +21,7 @@ impl Luau {
|
||||
let data_1 = (data & 0xFFFFFFFF) as u32;
|
||||
let data_2 = (data >> 32 & 0xFFFFFFFF) as u32;
|
||||
|
||||
write!(w, "rt.num.from_u32({data_1}, {data_2})")
|
||||
write!(w, "{{{data_1}, {data_2}}}")
|
||||
}
|
||||
|
||||
fn write_expression(data: &Expression, w: &mut dyn Write) -> Result<()> {
|
||||
@ -33,21 +32,18 @@ impl Luau {
|
||||
match &data[0] {
|
||||
Instruction::I32Const(v) => write!(w, "{v}"),
|
||||
Instruction::I64Const(v) => Self::write_i64(*v, w),
|
||||
Instruction::F32Const(v) => write!(w, "{}", f32::from_bits(v.bits)),
|
||||
Instruction::F64Const(v) => write!(w, "{}", f64::from_bits(v.bits)),
|
||||
Instruction::F32Const(v) => target::write_f32(f32::from_bits(v.bits), w),
|
||||
Instruction::F64Const(v) => target::write_f64(f64::from_bits(v.bits), w),
|
||||
_ => panic!("Unsupported instruction"),
|
||||
}
|
||||
}
|
||||
|
||||
write_assert_number!(write_assert_maybe_f32, Float32, f32);
|
||||
write_assert_number!(write_assert_maybe_f64, Float64, f64);
|
||||
|
||||
fn write_simple_expression(data: &AssertExpression, w: &mut dyn Write) -> Result<()> {
|
||||
match data {
|
||||
AssertExpression::I32(v) => write!(w, "{v}"),
|
||||
AssertExpression::I64(v) => Self::write_i64(*v, w),
|
||||
AssertExpression::F32(v) => Self::write_assert_maybe_f32(v, w),
|
||||
AssertExpression::F64(v) => Self::write_assert_maybe_f64(v, w),
|
||||
AssertExpression::F32(v) => target::write_f32_nan(v, w),
|
||||
AssertExpression::F64(v) => target::write_f64_nan(v, w),
|
||||
_ => panic!("Unsupported expression"),
|
||||
}
|
||||
}
|
||||
|
@ -12,17 +12,9 @@ use wast::{
|
||||
|
||||
use wasm_ast::builder::TypeInfo;
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! write_assert_number {
|
||||
($name:ident, $generic:ty, $reader:ty) => {
|
||||
fn $name(data: &wast::NanPattern<$generic>, w: &mut dyn Write) -> Result<()> {
|
||||
use wast::NanPattern;
|
||||
|
||||
match data {
|
||||
NanPattern::CanonicalNan => write!(w, "LUA_NAN_CANONICAL"),
|
||||
NanPattern::ArithmeticNan => write!(w, "LUA_NAN_ARITHMETIC"),
|
||||
NanPattern::Value(data) => {
|
||||
let number = <$reader>::from_bits(data.bits);
|
||||
macro_rules! impl_write_number_nan {
|
||||
($name:ident, $name_nan:ident, $numeric:ty, $pattern:ty) => {
|
||||
pub fn $name(number: $numeric, w: &mut dyn Write) -> Result<()> {
|
||||
let sign = if number.is_sign_negative() { "-" } else { "" };
|
||||
|
||||
if number.is_infinite() {
|
||||
@ -33,11 +25,26 @@ macro_rules! write_assert_number {
|
||||
write!(w, "{number}")
|
||||
}
|
||||
}
|
||||
|
||||
pub fn $name_nan(data: &wast::NanPattern<$pattern>, w: &mut dyn Write) -> Result<()> {
|
||||
use wast::NanPattern;
|
||||
|
||||
match data {
|
||||
NanPattern::CanonicalNan => write!(w, "LUA_NAN_CANONICAL"),
|
||||
NanPattern::ArithmeticNan => write!(w, "LUA_NAN_ARITHMETIC"),
|
||||
NanPattern::Value(data) => {
|
||||
let number = <$numeric>::from_bits(data.bits);
|
||||
|
||||
$name(number, w)
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl_write_number_nan!(write_f32, write_f32_nan, f32, wast::token::Float32);
|
||||
impl_write_number_nan!(write_f64, write_f64_nan, f64, wast::token::Float64);
|
||||
|
||||
pub struct TypedModule<'a> {
|
||||
name: &'a str,
|
||||
module: &'a BinModule,
|
||||
|
Loading…
x
Reference in New Issue
Block a user