| 1 |
function testConst(type, str, expected) { |
| 2 |
if (type === 'i64') |
| 3 |
wasmFullPassI64(`(module (func $run (result i64) (i64.const ${str})))`, expected); |
| 4 |
else |
| 5 |
wasmFullPass(`(module (func (result ${type}) (${type}.const ${str})) (export "run" (func 0)))`, expected); |
| 6 |
} |
| 7 |
|
| 8 |
function testConstError(type, str) { |
| 9 |
assertErrorMessage(() => wasmEvalText(`(module (func (result ${type}) (${type}.const ${str})) (export "" (func 0)))`).exports[""](), Error, /wasm text error/); |
| 10 |
} |
| 11 |
|
| 12 |
testConst('i32', '0', 0); |
| 13 |
testConst('i32', '-0', 0); |
| 14 |
testConst('i32', '23', 23); |
| 15 |
testConst('i32', '-23', -23); |
| 16 |
testConst('i32', '0x23', 35); |
| 17 |
testConst('i32', '-0x23', -35); |
| 18 |
testConst('i32', '2147483647', 2147483647); |
| 19 |
testConst('i32', '4294967295', -1); |
| 20 |
testConst('i32', '-2147483648', -2147483648); |
| 21 |
testConst('i32', '0x7fffffff', 2147483647); |
| 22 |
testConst('i32', '0x80000000', -2147483648); |
| 23 |
testConst('i32', '-0x80000000', -2147483648); |
| 24 |
testConst('i32', '0xffffffff', -1); |
| 25 |
|
| 26 |
testConst('i64', '0', 0); |
| 27 |
testConst('i64', '-0', 0); |
| 28 |
|
| 29 |
testConst('i64', '23', 23); |
| 30 |
testConst('i64', '-23', -23); |
| 31 |
|
| 32 |
testConst('i64', '0x23', 35); |
| 33 |
testConst('i64', '-0x23', -35); |
| 34 |
|
| 35 |
testConst('i64', '-0x1', -1); |
| 36 |
testConst('i64', '-1', -1); |
| 37 |
testConst('i64', '0xffffffffffffffff', -1); |
| 38 |
|
| 39 |
testConst('i64', '0xdeadc0de', 0xdeadc0de); |
| 40 |
testConst('i64', '0x1337c0de00000000', '0x1337c0de00000000'); |
| 41 |
|
| 42 |
testConst('i64', '0x0102030405060708', '0x0102030405060708'); |
| 43 |
testConst('i64', '-0x0102030405060708', '-0x0102030405060708'); |
| 44 |
|
| 45 |
// INT64_MAX |
| 46 |
testConst('i64', '9223372036854775807', '0x7fffffffffffffff'); |
| 47 |
testConst('i64', '0x7fffffffffffffff', '0x7fffffffffffffff'); |
| 48 |
|
| 49 |
// INT64_MAX + 1 |
| 50 |
testConst('i64', '9223372036854775808', '0x8000000000000000'); |
| 51 |
testConst('i64', '0x8000000000000000', '0x8000000000000000'); |
| 52 |
|
| 53 |
// UINT64_MAX |
| 54 |
testConst('i64', '18446744073709551615', '0xffffffffffffffff'); |
| 55 |
|
| 56 |
// INT64_MIN |
| 57 |
testConst('i64', '-9223372036854775808', '0x8000000000000000'); |
| 58 |
testConst('i64', '-0x8000000000000000', '0x8000000000000000'); |
| 59 |
|
| 60 |
// INT64_MIN - 1 |
| 61 |
testConstError('i64', '-9223372036854775809'); |
| 62 |
|
| 63 |
testConstError('i64', ''); |
| 64 |
testConstError('i64', '0.0'); |
| 65 |
testConstError('i64', 'not an i64'); |
| 66 |
|
| 67 |
testConst('f32', '0.0', 0.0); |
| 68 |
testConst('f32', '-0', -0.0); |
| 69 |
testConst('f32', '-0.0', -0.0); |
| 70 |
testConst('f32', '0x0.0', 0.0); |
| 71 |
testConst('f32', '-0x0.0', -0.0); |
| 72 |
testConst('f32', '-0x0', -0.0); |
| 73 |
testConst('f32', '0x0.0p0', 0.0); |
| 74 |
testConst('f32', '-0x0.0p0', -0.0); |
| 75 |
testConst('f32', 'inf', Infinity); |
| 76 |
testConst('f32', '-inf', -Infinity); |
| 77 |
testConst('f32', '+inf', Infinity); |
| 78 |
testConst('f32', 'nan', NaN); |
| 79 |
//testConst('f32', '-nan', NaN); // TODO: NYI |
| 80 |
testConst('f32', '+nan', NaN); |
| 81 |
//testConst('f32', 'nan:0x789', NaN); // TODO: NYI |
| 82 |
//testConst('f32', '-nan:0x789', NaN); // TODO: NYI |
| 83 |
//testConst('f32', '+nan:0x789', NaN); // TODO: NYI |
| 84 |
testConst('f32', '0x01p-149', 1.401298464324817e-45); |
| 85 |
testConst('f32', '0x1p-149', 1.401298464324817e-45); |
| 86 |
testConst('f32', '0x1p-150', 0); |
| 87 |
testConst('f32', '0x2p-150', 1.401298464324817e-45); |
| 88 |
testConst('f32', '0x1.2p-149', 1.401298464324817e-45); |
| 89 |
testConst('f32', '0x2.0p-149', 2.802596928649634e-45); |
| 90 |
testConst('f32', '0x2.2p-149', 2.802596928649634e-45); |
| 91 |
testConst('f32', '0x01p-148', 2.802596928649634e-45); |
| 92 |
testConst('f32', '0x0.1p-148', 0); |
| 93 |
testConst('f32', '0x0.1p-145', 1.401298464324817e-45); |
| 94 |
testConst('f32', '0x1p-148', 2.802596928649634e-45); |
| 95 |
testConst('f32', '0x1.111p-148', 2.802596928649634e-45); |
| 96 |
testConst('f32', '0x1.2p-148', 2.802596928649634e-45); |
| 97 |
testConst('f32', '0x2.0p-148', 5.605193857299268e-45); |
| 98 |
testConst('f32', '0x2.2p-148', 5.605193857299268e-45); |
| 99 |
testConst('f32', '0x1p-147', 5.605193857299268e-45); |
| 100 |
testConst('f32', '0x1p-126', 1.1754943508222875e-38); |
| 101 |
testConst('f32', '0x0.1fffffep+131', 3.4028234663852886e+38); |
| 102 |
testConst('f32', '0x1.fffffep+127', 3.4028234663852886e+38); |
| 103 |
testConstError('f32', '0x2.0p+127'); |
| 104 |
testConstError('f32', '0x1.fffffep+128'); |
| 105 |
testConst('f32', '0x0.1fffffep+128', 4.2535293329816107e+37); |
| 106 |
testConst('f32', '0x1p2', 4); |
| 107 |
testConst('f32', '0x10p2', 64); |
| 108 |
testConst('f32', '0x100p2', 1024); |
| 109 |
testConst('f32', '0x2p2', 8); |
| 110 |
testConst('f32', '0x4p2', 16); |
| 111 |
testConst('f32', '0x1p3', 8); |
| 112 |
testConst('f32', '0x1p4', 16); |
| 113 |
testConst('f32', '-0x1p+3', -8); |
| 114 |
testConst('f32', '0x3p-2', .75); |
| 115 |
testConst('f32', '-0x76.54p-32', -2.7550413506105542e-8); |
| 116 |
testConst('f32', '0xf.ffffffffffffffffp+123', 170141183460469231731687303715884105728); |
| 117 |
testConstError('f32', '0xf.ffffffffffffffffp+124'); |
| 118 |
testConst('f32', '1.1754943508222875e-38', 1.1754943508222875e-38); |
| 119 |
testConst('f32', '3.4028234663852886e+38', 3.4028234663852886e+38); |
| 120 |
testConst('f32', '1.1754943508222875e-35', 1.1754943508222875e-35); |
| 121 |
testConst('f32', '3.4028234663852886e+35', 3.4028234346940236e+35); |
| 122 |
testConst('f32', '1.1754943508222875e-30', 1.1754943508222875e-30); |
| 123 |
testConst('f32', '3.4028234663852886e+30', 3.4028233462973677e+30); |
| 124 |
testConst('f32', '4.0', 4); |
| 125 |
testConst('f32', '-8.', -8); |
| 126 |
testConst('f32', '-2.7550413506105542e-8', -2.7550413506105542e-8); |
| 127 |
testConst('f32', '2.138260e+05', 2.138260e+05); |
| 128 |
testConst('f32', '3.891074380317903e-33', 3.891074380317903e-33); |
| 129 |
testConst('f32', '-9465807272673280.0', -9465807272673280); |
| 130 |
testConst('f32', '1076.1376953125', 1076.1376953125); |
| 131 |
testConst('f32', '-13364.1376953125', -13364.1376953125); |
| 132 |
testConst('f32', '4.133607864379883', 4.133607864379883); |
| 133 |
testConst('f32', '2.0791168212890625', 2.0791168212890625); |
| 134 |
testConst('f32', '0.000002414453774690628', 0.000002414453774690628); |
| 135 |
testConst('f32', '0.5312881469726562', 0.5312881469726562); |
| 136 |
testConst('f32', '5.570960e+05', 5.570960e+05); |
| 137 |
testConst('f32', '5.066758603788912e-7', 5.066758603788912e-7); |
| 138 |
testConst('f32', '-5.066758603788912e-7', -5.066758603788912e-7); |
| 139 |
testConst('f32', '1.875000e-01', 1.875000e-01); |
| 140 |
testConst('f32', '-0x1.b021fb98e9a17p-104', -8.322574059965897e-32); |
| 141 |
testConst('f32', '0x1.08de5bf3f784cp-129', 1.5202715065429227e-39); |
| 142 |
testConstError('f32', '0x1.d50b969fbbfb3p+388'); |
| 143 |
testConst('f32', '0x3434.2p4', 2.138260e+05); |
| 144 |
testConst('f32', '0x1434.2p-120', 3.891074380317903e-33); |
| 145 |
testConst('f32', '-0x0434.234p43', -9465807272673280); |
| 146 |
testConst('f32', '0x0434.234p0', 1076.1376953125); |
| 147 |
testConst('f32', '-0x3434.234p0', -13364.1376953125); |
| 148 |
testConst('f32', '0x4.22342p0', 4.133607864379883); |
| 149 |
testConst('f32', '0x30000p-20', 1.875000e-01); |
| 150 |
testConst('f32', '0x0.533fcccp-125', 7.645233588931088e-39); |
| 151 |
testConst('f32', '0', 0); |
| 152 |
|
| 153 |
testConst('f64', '0.0', 0.0); |
| 154 |
testConst('f64', '-0.0', -0.0); |
| 155 |
testConst('f64', '-0', -0.0); |
| 156 |
testConst('f64', '0x0.0', 0.0); |
| 157 |
testConst('f64', '-0x0.0', -0.0); |
| 158 |
testConst('f64', '-0x0', -0.0); |
| 159 |
testConst('f64', '0x0.0p0', 0.0); |
| 160 |
testConst('f64', '-0x0.0p0', -0.0); |
| 161 |
testConst('f64', 'inf', Infinity); |
| 162 |
testConst('f64', '-inf', -Infinity); |
| 163 |
testConst('f64', '+inf', Infinity); |
| 164 |
testConst('f64', 'nan', NaN); |
| 165 |
//testConst('f64', '-nan', NaN); // TODO: NYI |
| 166 |
testConst('f64', '+nan', NaN); |
| 167 |
//testConst('f64', 'nan:0x789', NaN); // TODO: NYI |
| 168 |
//testConst('f64', '-nan:0x789', NaN); // TODO: NYI |
| 169 |
//testConst('f64', '+nan:0x789', NaN); // TODO: NYI |
| 170 |
testConst('f64', '0x01p-149', 1.401298464324817e-45); |
| 171 |
testConst('f64', '0x1p-149', 1.401298464324817e-45); |
| 172 |
testConst('f64', '0x1p-150', 7.006492321624085e-46); |
| 173 |
testConst('f64', '0x2p-150', 1.401298464324817e-45); |
| 174 |
testConst('f64', '0x1.2p-149', 1.5764607723654192e-45); |
| 175 |
testConst('f64', '0x2.0p-149', 2.802596928649634e-45); |
| 176 |
testConst('f64', '0x2.2p-149', 2.977759236690236e-45); |
| 177 |
testConst('f64', '0x01p-148', 2.802596928649634e-45); |
| 178 |
testConst('f64', '0x0.1p-148', 1.7516230804060213e-46); |
| 179 |
testConst('f64', '0x0.1p-145', 1.401298464324817e-45); |
| 180 |
testConst('f64', '0x1p-148', 2.802596928649634e-45); |
| 181 |
testConst('f64', '0x1.111p-148', 2.9893911087085575e-45); |
| 182 |
testConst('f64', '0x1.2p-148', 3.1529215447308384e-45); |
| 183 |
testConst('f64', '0x2.0p-148', 5.605193857299268e-45); |
| 184 |
testConst('f64', '0x2.2p-148', 5.955518473380473e-45); |
| 185 |
testConst('f64', '0x1p-147', 5.605193857299268e-45); |
| 186 |
testConst('f64', '0x1p-126', 1.1754943508222875e-38); |
| 187 |
testConst('f64', '0x0.1fffffep+131', 3.4028234663852886e+38); |
| 188 |
testConst('f64', '0x1.fffffep+127', 3.4028234663852886e+38); |
| 189 |
testConst('f64', '0x2.0p+127', 3.402823669209385e+38); |
| 190 |
testConst('f64', '0x1.fffffep+128', 6.805646932770577e+38); |
| 191 |
testConst('f64', '0x0.1fffffep+128', 4.2535293329816107e+37); |
| 192 |
testConst('f64', '0x1p2', 4); |
| 193 |
testConst('f64', '0x10p2', 64); |
| 194 |
testConst('f64', '0x100p2', 1024); |
| 195 |
testConst('f64', '0x2p2', 8); |
| 196 |
testConst('f64', '0x4p2', 16); |
| 197 |
testConst('f64', '0x1p3', 8); |
| 198 |
testConst('f64', '0x1p4', 16); |
| 199 |
testConst('f64', '-0x1p+3', -8); |
| 200 |
testConst('f64', '0x3p-2', .75); |
| 201 |
testConst('f64', '-0x76.54p-32', -2.7550413506105542e-8); |
| 202 |
testConst('f64', '1.1754943508222875e-38', 1.1754943508222875e-38); |
| 203 |
testConst('f64', '3.4028234663852886e+38', 3.4028234663852886e+38); |
| 204 |
testConst('f64', '1.1754943508222875e-35', 1.1754943508222875e-35); |
| 205 |
testConst('f64', '3.4028234663852886e+35', 3.4028234663852886e+35); |
| 206 |
testConst('f64', '1.1754943508222875e-30', 1.1754943508222875e-30); |
| 207 |
testConst('f64', '3.4028234663852886e+30', 3.402823466385289e+30); |
| 208 |
testConst('f64', '4.0', 4); |
| 209 |
testConst('f64', '-8.', -8); |
| 210 |
testConst('f64', '-2.7550413506105542e-8', -2.7550413506105542e-8); |
| 211 |
testConst('f64', '2.138260e+05', 2.138260e+05); |
| 212 |
testConst('f64', '3.891074380317903e-33', 3.891074380317903e-33); |
| 213 |
testConst('f64', '-9465807272673280.0', -9465807272673280); |
| 214 |
testConst('f64', '1076.1376953125', 1076.1376953125); |
| 215 |
testConst('f64', '-13364.1376953125', -13364.1376953125); |
| 216 |
testConst('f64', '4.133607864379883', 4.133607864379883); |
| 217 |
testConst('f64', '2.0791168212890625', 2.0791168212890625); |
| 218 |
testConst('f64', '0.000002414453774690628', 0.000002414453774690628); |
| 219 |
testConst('f64', '0.5312881469726562', 0.5312881469726562); |
| 220 |
testConst('f64', '5.570960e+05', 5.570960e+05); |
| 221 |
testConst('f64', '5.066758603788912e-7', 5.066758603788912e-7); |
| 222 |
testConst('f64', '-5.066758603788912e-7', -5.066758603788912e-7); |
| 223 |
testConst('f64', '1.875000e-01', 1.875000e-01); |
| 224 |
testConst('f64', '0x3434.2p4', 2.138260e+05); |
| 225 |
testConst('f64', '0x1434.2p-120', 3.891074380317903e-33); |
| 226 |
testConst('f64', '-0x0434.234p43', -9465807272673280); |
| 227 |
testConst('f64', '0x0434.234p0', 1076.1376953125); |
| 228 |
testConst('f64', '-0x3434.234p0', -13364.1376953125); |
| 229 |
testConst('f64', '0x4.22342p0', 4.133607864379883); |
| 230 |
testConst('f64', '0x4.2882000p-1', 2.0791168212890625); |
| 231 |
testConst('f64', '0x30000p-20', 1.875000e-01); |
| 232 |
testConst('f64', '0x2f05.000bef2113p-1036', 1.634717678224908e-308); |
| 233 |
testConst('f64', '0x24c6.004d0deaa3p-1036', 1.2784941357502007e-308); |
| 234 |
testConst('f64', '0', 0); |
| 235 |
|
| 236 |
testConstError('i32', ''); |
| 237 |
testConstError('i32', '0.0'); |
| 238 |
testConstError('i32', 'not an i32'); |
| 239 |
testConstError('i32', '4294967296'); |
| 240 |
testConstError('i32', '-2147483649'); |
| 241 |
|
| 242 |
testConstError('f32', ''); |
| 243 |
testConstError('f32', 'not an f32'); |
| 244 |
testConstError('f32', 'nan:'); |
| 245 |
testConstError('f32', 'nan:0'); |
| 246 |
testConstError('f32', 'nan:0x'); |
| 247 |
testConstError('f32', 'nan:0x0'); |
| 248 |
|
| 249 |
testConstError('f64', ''); |
| 250 |
testConstError('f64', 'not an f64'); |
| 251 |
testConstError('f64', 'nan:'); |
| 252 |
testConstError('f64', 'nan:0'); |
| 253 |
testConstError('f64', 'nan:0x'); |
| 254 |
testConstError('f64', 'nan:0x0'); |