mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-12 06:21:29 +00:00
Implement ternary using if, see AssemblyScript/assemblyscript#123
This commit is contained in:
@ -121,3 +121,14 @@ sizeof<f64>();
|
||||
|
||||
i = load<i32>(4);
|
||||
store<i32>(4, i);
|
||||
|
||||
if (NaN == NaN)
|
||||
unreachable();
|
||||
if (!isNaN<f32>(NaN))
|
||||
unreachable();
|
||||
if (isFinite<f32>(NaN))
|
||||
unreachable();
|
||||
if (isFinite<f32>(Infinity))
|
||||
unreachable();
|
||||
if (!isFinite<f64>(0))
|
||||
unreachable();
|
||||
|
@ -19,6 +19,10 @@
|
||||
(local $5 f64)
|
||||
(local $6 f64)
|
||||
(local $7 f64)
|
||||
(local $8 f32)
|
||||
(local $9 f32)
|
||||
(local $10 f32)
|
||||
(local $11 f64)
|
||||
(drop
|
||||
(i32.clz
|
||||
(i32.const 1)
|
||||
@ -191,17 +195,17 @@
|
||||
)
|
||||
(drop
|
||||
(select
|
||||
(i32.const 0)
|
||||
(f32.ne
|
||||
(f32.abs
|
||||
(get_local $1)
|
||||
(tee_local $1
|
||||
(f32.const 1.25)
|
||||
)
|
||||
)
|
||||
(f32.const inf)
|
||||
)
|
||||
(f32.ne
|
||||
(tee_local $1
|
||||
(f32.const 1.25)
|
||||
)
|
||||
(i32.const 0)
|
||||
(f32.eq
|
||||
(get_local $1)
|
||||
(get_local $1)
|
||||
)
|
||||
)
|
||||
@ -270,17 +274,17 @@
|
||||
)
|
||||
(set_global $builtins/b
|
||||
(select
|
||||
(i32.const 0)
|
||||
(f32.ne
|
||||
(f32.abs
|
||||
(get_local $3)
|
||||
(tee_local $3
|
||||
(f32.const 1.25)
|
||||
)
|
||||
)
|
||||
(f32.const inf)
|
||||
)
|
||||
(f32.ne
|
||||
(tee_local $3
|
||||
(f32.const 1.25)
|
||||
)
|
||||
(i32.const 0)
|
||||
(f32.eq
|
||||
(get_local $3)
|
||||
(get_local $3)
|
||||
)
|
||||
)
|
||||
@ -355,17 +359,17 @@
|
||||
)
|
||||
(drop
|
||||
(select
|
||||
(i32.const 0)
|
||||
(f64.ne
|
||||
(f64.abs
|
||||
(get_local $5)
|
||||
(tee_local $5
|
||||
(f64.const 1.25)
|
||||
)
|
||||
)
|
||||
(f64.const inf)
|
||||
)
|
||||
(f64.ne
|
||||
(tee_local $5
|
||||
(f64.const 1.25)
|
||||
)
|
||||
(i32.const 0)
|
||||
(f64.eq
|
||||
(get_local $5)
|
||||
(get_local $5)
|
||||
)
|
||||
)
|
||||
@ -434,17 +438,17 @@
|
||||
)
|
||||
(set_global $builtins/b
|
||||
(select
|
||||
(i32.const 0)
|
||||
(f64.ne
|
||||
(f64.abs
|
||||
(get_local $7)
|
||||
(tee_local $7
|
||||
(f64.const 1.25)
|
||||
)
|
||||
)
|
||||
(f64.const inf)
|
||||
)
|
||||
(f64.ne
|
||||
(tee_local $7
|
||||
(f64.const 1.25)
|
||||
)
|
||||
(i32.const 0)
|
||||
(f64.eq
|
||||
(get_local $7)
|
||||
(get_local $7)
|
||||
)
|
||||
)
|
||||
@ -523,6 +527,80 @@
|
||||
(i32.const 4)
|
||||
(get_global $builtins/i)
|
||||
)
|
||||
(if
|
||||
(f64.eq
|
||||
(f64.const nan:0x8000000000000)
|
||||
(f64.const nan:0x8000000000000)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
(if
|
||||
(i32.eqz
|
||||
(f32.ne
|
||||
(tee_local $8
|
||||
(f32.const nan:0x400000)
|
||||
)
|
||||
(get_local $8)
|
||||
)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
(if
|
||||
(select
|
||||
(f32.ne
|
||||
(f32.abs
|
||||
(tee_local $9
|
||||
(f32.const nan:0x400000)
|
||||
)
|
||||
)
|
||||
(f32.const inf)
|
||||
)
|
||||
(i32.const 0)
|
||||
(f32.eq
|
||||
(get_local $9)
|
||||
(get_local $9)
|
||||
)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
(if
|
||||
(select
|
||||
(f32.ne
|
||||
(f32.abs
|
||||
(tee_local $10
|
||||
(f32.const inf)
|
||||
)
|
||||
)
|
||||
(f32.const inf)
|
||||
)
|
||||
(i32.const 0)
|
||||
(f32.eq
|
||||
(get_local $10)
|
||||
(get_local $10)
|
||||
)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
(if
|
||||
(i32.eqz
|
||||
(select
|
||||
(f64.ne
|
||||
(f64.abs
|
||||
(tee_local $11
|
||||
(f64.const 0)
|
||||
)
|
||||
)
|
||||
(f64.const inf)
|
||||
)
|
||||
(i32.const 0)
|
||||
(f64.eq
|
||||
(get_local $11)
|
||||
(get_local $11)
|
||||
)
|
||||
)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
)
|
||||
)
|
||||
(;
|
||||
|
5
tests/compiler/ternary.ts
Normal file
5
tests/compiler/ternary.ts
Normal file
@ -0,0 +1,5 @@
|
||||
let a: i32;
|
||||
|
||||
a = 0 ? unreachable() : 1;
|
||||
a = 1 ? 1 : unreachable();
|
||||
a = (0 ? unreachable() : 1) ? 1 : unreachable();
|
64
tests/compiler/ternary.wast
Normal file
64
tests/compiler/ternary.wast
Normal file
@ -0,0 +1,64 @@
|
||||
(module
|
||||
(type $v (func))
|
||||
(global $ternary/a (mut i32) (i32.const 0))
|
||||
(memory $0 1)
|
||||
(data (i32.const 4) "\08\00\00\00")
|
||||
(export "memory" (memory $0))
|
||||
(start $start)
|
||||
(func $start (; 0 ;) (type $v)
|
||||
(set_global $ternary/a
|
||||
(if (result i32)
|
||||
(i32.const 0)
|
||||
(unreachable)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(set_global $ternary/a
|
||||
(if (result i32)
|
||||
(i32.const 1)
|
||||
(i32.const 1)
|
||||
(unreachable)
|
||||
)
|
||||
)
|
||||
(set_global $ternary/a
|
||||
(if (result i32)
|
||||
(if (result i32)
|
||||
(i32.const 0)
|
||||
(unreachable)
|
||||
(i32.const 1)
|
||||
)
|
||||
(i32.const 1)
|
||||
(unreachable)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(;
|
||||
[program.elements]
|
||||
clz
|
||||
ctz
|
||||
popcnt
|
||||
rotl
|
||||
rotr
|
||||
abs
|
||||
ceil
|
||||
copysign
|
||||
floor
|
||||
max
|
||||
min
|
||||
nearest
|
||||
sqrt
|
||||
trunc
|
||||
current_memory
|
||||
grow_memory
|
||||
unreachable
|
||||
isNaN
|
||||
isFinite
|
||||
assert
|
||||
sizeof
|
||||
load
|
||||
store
|
||||
ternary/a
|
||||
[program.exports]
|
||||
|
||||
;)
|
Reference in New Issue
Block a user