mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-24 04:01:46 +00:00
Fixes; Builtins; Testing in the interpreter
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
(module
|
||||
(type $v (func))
|
||||
(global $binary/i (mut i32) (i32.const 0))
|
||||
(global $binary/b (mut i32) (i32.const -1))
|
||||
(global $binary/b (mut i32) (i32.const 0))
|
||||
(global $binary/I (mut i64) (i64.const 0))
|
||||
(global $binary/f (mut f32) (f32.const 0))
|
||||
(global $binary/F (mut f64) (f64.const 0))
|
||||
@ -112,9 +112,6 @@
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(set_global $binary/b
|
||||
(i32.const 0)
|
||||
)
|
||||
(set_global $binary/b
|
||||
(i32.lt_s
|
||||
(get_global $binary/i)
|
||||
@ -835,8 +832,12 @@
|
||||
nearest
|
||||
sqrt
|
||||
trunc
|
||||
current_memory
|
||||
grow_memory
|
||||
unreachable
|
||||
isNaN
|
||||
isFinite
|
||||
assert
|
||||
binary/b
|
||||
binary/i
|
||||
binary/I
|
||||
|
106
tests/compiler/builtins.ts
Normal file
106
tests/compiler/builtins.ts
Normal file
@ -0,0 +1,106 @@
|
||||
let b: bool;
|
||||
|
||||
let i: i32;
|
||||
|
||||
clz<i32>(1);
|
||||
ctz<i32>(1);
|
||||
popcnt<i32>(1);
|
||||
rotl<i32>(1, 1);
|
||||
rotr<i32>(1, 1);
|
||||
|
||||
i = clz<i32>(1);
|
||||
i = ctz<i32>(1);
|
||||
i = popcnt<i32>(1);
|
||||
i = rotl<i32>(1, 1);
|
||||
i = rotr<i32>(1, 1);
|
||||
|
||||
let I: i64;
|
||||
|
||||
clz<i64>(1);
|
||||
ctz<i64>(1);
|
||||
popcnt<i64>(1);
|
||||
rotl<i64>(1, 1);
|
||||
rotr<i64>(1, 1);
|
||||
|
||||
I = clz<i64>(1);
|
||||
I = ctz<i64>(1);
|
||||
I = popcnt<i64>(1);
|
||||
I = rotl<i64>(1, 1);
|
||||
I = rotr<i64>(1, 1);
|
||||
|
||||
let f: f32;
|
||||
|
||||
<f32>NaN;
|
||||
<f32>Infinity;
|
||||
abs<f32>(1.25);
|
||||
ceil<f32>(1.25);
|
||||
copysign<f32>(1.25, 2.5);
|
||||
floor<f32>(1.25);
|
||||
max<f32>(1.25, 2.5);
|
||||
min<f32>(1.25, 2.5);
|
||||
nearest<f32>(1.25);
|
||||
// reinterpret
|
||||
sqrt<f32>(1.25);
|
||||
trunc<f32>(1.25);
|
||||
isNaN<f32>(1.25);
|
||||
isFinite<f32>(1.25);
|
||||
|
||||
f = NaN;
|
||||
f = Infinity;
|
||||
f = abs<f32>(1.25);
|
||||
f = ceil<f32>(1.25);
|
||||
f = copysign<f32>(1.25, 2.5);
|
||||
f = floor<f32>(1.25);
|
||||
f = max<f32>(1.25, 2.5);
|
||||
f = min<f32>(1.25, 2.5);
|
||||
f = nearest<f32>(1.25);
|
||||
// reinterpret
|
||||
f = sqrt<f32>(1.25);
|
||||
f = trunc<f32>(1.25);
|
||||
b = isNaN<f32>(1.25);
|
||||
b = isFinite<f32>(1.25);
|
||||
|
||||
let F: f64;
|
||||
|
||||
<f64>NaN;
|
||||
<f64>Infinity;
|
||||
NaN;
|
||||
Infinity;
|
||||
abs<f64>(1.25);
|
||||
ceil<f64>(1.25);
|
||||
copysign<f64>(1.25, 2.5);
|
||||
floor<f64>(1.25);
|
||||
max<f64>(1.25, 2.5);
|
||||
min<f64>(1.25, 2.5);
|
||||
nearest<f64>(1.25);
|
||||
// reinterpret
|
||||
sqrt<f64>(1.25);
|
||||
trunc<f64>(1.25);
|
||||
isNaN<f64>(1.25);
|
||||
isFinite<f64>(1.25);
|
||||
|
||||
F = NaN;
|
||||
F = Infinity;
|
||||
F = abs<f64>(1.25);
|
||||
F = ceil<f64>(1.25);
|
||||
F = copysign<f64>(1.25, 2.5);
|
||||
F = floor<f64>(1.25);
|
||||
F = max<f64>(1.25, 2.5);
|
||||
F = min<f64>(1.25, 2.5);
|
||||
F = nearest<f64>(1.25);
|
||||
// reinterpret
|
||||
F = sqrt<f64>(1.25);
|
||||
F = trunc<f64>(1.25);
|
||||
b = isNaN<f64>(1.25);
|
||||
b = isFinite<f64>(1.25);
|
||||
|
||||
let s: usize;
|
||||
|
||||
current_memory();
|
||||
grow_memory(1);
|
||||
|
||||
s = current_memory();
|
||||
s = grow_memory(1);
|
||||
if (0) unreachable();
|
||||
|
||||
assert(true);
|
510
tests/compiler/builtins.wast
Normal file
510
tests/compiler/builtins.wast
Normal file
@ -0,0 +1,510 @@
|
||||
(module
|
||||
(type $v (func))
|
||||
(global $builtins/i (mut i32) (i32.const 0))
|
||||
(global $builtins/I (mut i64) (i64.const 0))
|
||||
(global $builtins/f (mut f32) (f32.const 0))
|
||||
(global $builtins/b (mut i32) (i32.const 0))
|
||||
(global $builtins/F (mut f64) (f64.const 0))
|
||||
(global $builtins/s (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)
|
||||
(local $0 f32)
|
||||
(local $1 f32)
|
||||
(local $2 f32)
|
||||
(local $3 f32)
|
||||
(local $4 f64)
|
||||
(local $5 f64)
|
||||
(local $6 f64)
|
||||
(local $7 f64)
|
||||
(drop
|
||||
(i32.clz
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(drop
|
||||
(i32.ctz
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(drop
|
||||
(i32.popcnt
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(drop
|
||||
(i32.rotl
|
||||
(i32.const 1)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(drop
|
||||
(i32.rotr
|
||||
(i32.const 1)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(set_global $builtins/i
|
||||
(i32.clz
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(set_global $builtins/i
|
||||
(i32.ctz
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(set_global $builtins/i
|
||||
(i32.popcnt
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(set_global $builtins/i
|
||||
(i32.rotl
|
||||
(i32.const 1)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(set_global $builtins/i
|
||||
(i32.rotr
|
||||
(i32.const 1)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(drop
|
||||
(i64.clz
|
||||
(i64.const 1)
|
||||
)
|
||||
)
|
||||
(drop
|
||||
(i64.ctz
|
||||
(i64.const 1)
|
||||
)
|
||||
)
|
||||
(drop
|
||||
(i64.popcnt
|
||||
(i64.const 1)
|
||||
)
|
||||
)
|
||||
(drop
|
||||
(i64.rotl
|
||||
(i64.const 1)
|
||||
(i64.const 1)
|
||||
)
|
||||
)
|
||||
(drop
|
||||
(i64.rotr
|
||||
(i64.const 1)
|
||||
(i64.const 1)
|
||||
)
|
||||
)
|
||||
(set_global $builtins/I
|
||||
(i64.clz
|
||||
(i64.const 1)
|
||||
)
|
||||
)
|
||||
(set_global $builtins/I
|
||||
(i64.ctz
|
||||
(i64.const 1)
|
||||
)
|
||||
)
|
||||
(set_global $builtins/I
|
||||
(i64.popcnt
|
||||
(i64.const 1)
|
||||
)
|
||||
)
|
||||
(set_global $builtins/I
|
||||
(i64.rotl
|
||||
(i64.const 1)
|
||||
(i64.const 1)
|
||||
)
|
||||
)
|
||||
(set_global $builtins/I
|
||||
(i64.rotr
|
||||
(i64.const 1)
|
||||
(i64.const 1)
|
||||
)
|
||||
)
|
||||
(drop
|
||||
(f32.const nan:0x400000)
|
||||
)
|
||||
(drop
|
||||
(f32.const inf)
|
||||
)
|
||||
(drop
|
||||
(f32.abs
|
||||
(f32.const 1.25)
|
||||
)
|
||||
)
|
||||
(drop
|
||||
(f32.ceil
|
||||
(f32.const 1.25)
|
||||
)
|
||||
)
|
||||
(drop
|
||||
(f32.copysign
|
||||
(f32.const 1.25)
|
||||
(f32.const 2.5)
|
||||
)
|
||||
)
|
||||
(drop
|
||||
(f32.floor
|
||||
(f32.const 1.25)
|
||||
)
|
||||
)
|
||||
(drop
|
||||
(f32.max
|
||||
(f32.const 1.25)
|
||||
(f32.const 2.5)
|
||||
)
|
||||
)
|
||||
(drop
|
||||
(f32.min
|
||||
(f32.const 1.25)
|
||||
(f32.const 2.5)
|
||||
)
|
||||
)
|
||||
(drop
|
||||
(f32.nearest
|
||||
(f32.const 1.25)
|
||||
)
|
||||
)
|
||||
(drop
|
||||
(f32.sqrt
|
||||
(f32.const 1.25)
|
||||
)
|
||||
)
|
||||
(drop
|
||||
(f32.trunc
|
||||
(f32.const 1.25)
|
||||
)
|
||||
)
|
||||
(drop
|
||||
(f32.ne
|
||||
(tee_local $0
|
||||
(f32.const 1.25)
|
||||
)
|
||||
(get_local $0)
|
||||
)
|
||||
)
|
||||
(drop
|
||||
(select
|
||||
(i32.const 0)
|
||||
(f32.ne
|
||||
(f32.abs
|
||||
(get_local $1)
|
||||
)
|
||||
(f32.const inf)
|
||||
)
|
||||
(f32.ne
|
||||
(tee_local $1
|
||||
(f32.const 1.25)
|
||||
)
|
||||
(get_local $1)
|
||||
)
|
||||
)
|
||||
)
|
||||
(set_global $builtins/f
|
||||
(f32.const nan:0x400000)
|
||||
)
|
||||
(set_global $builtins/f
|
||||
(f32.const inf)
|
||||
)
|
||||
(set_global $builtins/f
|
||||
(f32.abs
|
||||
(f32.const 1.25)
|
||||
)
|
||||
)
|
||||
(set_global $builtins/f
|
||||
(f32.ceil
|
||||
(f32.const 1.25)
|
||||
)
|
||||
)
|
||||
(set_global $builtins/f
|
||||
(f32.copysign
|
||||
(f32.const 1.25)
|
||||
(f32.const 2.5)
|
||||
)
|
||||
)
|
||||
(set_global $builtins/f
|
||||
(f32.floor
|
||||
(f32.const 1.25)
|
||||
)
|
||||
)
|
||||
(set_global $builtins/f
|
||||
(f32.max
|
||||
(f32.const 1.25)
|
||||
(f32.const 2.5)
|
||||
)
|
||||
)
|
||||
(set_global $builtins/f
|
||||
(f32.min
|
||||
(f32.const 1.25)
|
||||
(f32.const 2.5)
|
||||
)
|
||||
)
|
||||
(set_global $builtins/f
|
||||
(f32.nearest
|
||||
(f32.const 1.25)
|
||||
)
|
||||
)
|
||||
(set_global $builtins/f
|
||||
(f32.sqrt
|
||||
(f32.const 1.25)
|
||||
)
|
||||
)
|
||||
(set_global $builtins/f
|
||||
(f32.trunc
|
||||
(f32.const 1.25)
|
||||
)
|
||||
)
|
||||
(set_global $builtins/b
|
||||
(f32.ne
|
||||
(tee_local $2
|
||||
(f32.const 1.25)
|
||||
)
|
||||
(get_local $2)
|
||||
)
|
||||
)
|
||||
(set_global $builtins/b
|
||||
(select
|
||||
(i32.const 0)
|
||||
(f32.ne
|
||||
(f32.abs
|
||||
(get_local $3)
|
||||
)
|
||||
(f32.const inf)
|
||||
)
|
||||
(f32.ne
|
||||
(tee_local $3
|
||||
(f32.const 1.25)
|
||||
)
|
||||
(get_local $3)
|
||||
)
|
||||
)
|
||||
)
|
||||
(drop
|
||||
(f64.const nan:0x8000000000000)
|
||||
)
|
||||
(drop
|
||||
(f64.const inf)
|
||||
)
|
||||
(drop
|
||||
(f64.const nan:0x8000000000000)
|
||||
)
|
||||
(drop
|
||||
(f64.const inf)
|
||||
)
|
||||
(drop
|
||||
(f64.abs
|
||||
(f64.const 1.25)
|
||||
)
|
||||
)
|
||||
(drop
|
||||
(f64.ceil
|
||||
(f64.const 1.25)
|
||||
)
|
||||
)
|
||||
(drop
|
||||
(f64.copysign
|
||||
(f64.const 1.25)
|
||||
(f64.const 2.5)
|
||||
)
|
||||
)
|
||||
(drop
|
||||
(f64.floor
|
||||
(f64.const 1.25)
|
||||
)
|
||||
)
|
||||
(drop
|
||||
(f64.max
|
||||
(f64.const 1.25)
|
||||
(f64.const 2.5)
|
||||
)
|
||||
)
|
||||
(drop
|
||||
(f64.min
|
||||
(f64.const 1.25)
|
||||
(f64.const 2.5)
|
||||
)
|
||||
)
|
||||
(drop
|
||||
(f64.nearest
|
||||
(f64.const 1.25)
|
||||
)
|
||||
)
|
||||
(drop
|
||||
(f64.sqrt
|
||||
(f64.const 1.25)
|
||||
)
|
||||
)
|
||||
(drop
|
||||
(f64.trunc
|
||||
(f64.const 1.25)
|
||||
)
|
||||
)
|
||||
(drop
|
||||
(f64.ne
|
||||
(tee_local $4
|
||||
(f64.const 1.25)
|
||||
)
|
||||
(get_local $4)
|
||||
)
|
||||
)
|
||||
(drop
|
||||
(select
|
||||
(i32.const 0)
|
||||
(f64.ne
|
||||
(f64.abs
|
||||
(get_local $5)
|
||||
)
|
||||
(f64.const inf)
|
||||
)
|
||||
(f64.ne
|
||||
(tee_local $5
|
||||
(f64.const 1.25)
|
||||
)
|
||||
(get_local $5)
|
||||
)
|
||||
)
|
||||
)
|
||||
(set_global $builtins/F
|
||||
(f64.const nan:0x8000000000000)
|
||||
)
|
||||
(set_global $builtins/F
|
||||
(f64.const inf)
|
||||
)
|
||||
(set_global $builtins/F
|
||||
(f64.abs
|
||||
(f64.const 1.25)
|
||||
)
|
||||
)
|
||||
(set_global $builtins/F
|
||||
(f64.ceil
|
||||
(f64.const 1.25)
|
||||
)
|
||||
)
|
||||
(set_global $builtins/F
|
||||
(f64.copysign
|
||||
(f64.const 1.25)
|
||||
(f64.const 2.5)
|
||||
)
|
||||
)
|
||||
(set_global $builtins/F
|
||||
(f64.floor
|
||||
(f64.const 1.25)
|
||||
)
|
||||
)
|
||||
(set_global $builtins/F
|
||||
(f64.max
|
||||
(f64.const 1.25)
|
||||
(f64.const 2.5)
|
||||
)
|
||||
)
|
||||
(set_global $builtins/F
|
||||
(f64.min
|
||||
(f64.const 1.25)
|
||||
(f64.const 2.5)
|
||||
)
|
||||
)
|
||||
(set_global $builtins/F
|
||||
(f64.nearest
|
||||
(f64.const 1.25)
|
||||
)
|
||||
)
|
||||
(set_global $builtins/F
|
||||
(f64.sqrt
|
||||
(f64.const 1.25)
|
||||
)
|
||||
)
|
||||
(set_global $builtins/F
|
||||
(f64.trunc
|
||||
(f64.const 1.25)
|
||||
)
|
||||
)
|
||||
(set_global $builtins/b
|
||||
(f64.ne
|
||||
(tee_local $6
|
||||
(f64.const 1.25)
|
||||
)
|
||||
(get_local $6)
|
||||
)
|
||||
)
|
||||
(set_global $builtins/b
|
||||
(select
|
||||
(i32.const 0)
|
||||
(f64.ne
|
||||
(f64.abs
|
||||
(get_local $7)
|
||||
)
|
||||
(f64.const inf)
|
||||
)
|
||||
(f64.ne
|
||||
(tee_local $7
|
||||
(f64.const 1.25)
|
||||
)
|
||||
(get_local $7)
|
||||
)
|
||||
)
|
||||
)
|
||||
(drop
|
||||
(current_memory)
|
||||
)
|
||||
(drop
|
||||
(grow_memory
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(set_global $builtins/s
|
||||
(current_memory)
|
||||
)
|
||||
(set_global $builtins/s
|
||||
(grow_memory
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(if
|
||||
(i32.const 0)
|
||||
(unreachable)
|
||||
)
|
||||
(if
|
||||
(i32.eqz
|
||||
(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
|
||||
builtins/b
|
||||
builtins/i
|
||||
builtins/I
|
||||
builtins/f
|
||||
builtins/F
|
||||
builtins/s
|
||||
[program.exports]
|
||||
|
||||
;)
|
@ -71,8 +71,12 @@
|
||||
nearest
|
||||
sqrt
|
||||
trunc
|
||||
current_memory
|
||||
grow_memory
|
||||
unreachable
|
||||
isNaN
|
||||
isFinite
|
||||
assert
|
||||
do/loopDo
|
||||
do/loopDoInDo
|
||||
[program.exports]
|
||||
|
@ -40,8 +40,12 @@
|
||||
nearest
|
||||
sqrt
|
||||
trunc
|
||||
current_memory
|
||||
grow_memory
|
||||
unreachable
|
||||
isNaN
|
||||
isFinite
|
||||
assert
|
||||
export/add
|
||||
export/sub
|
||||
export/a
|
||||
|
@ -62,8 +62,12 @@
|
||||
nearest
|
||||
sqrt
|
||||
trunc
|
||||
current_memory
|
||||
grow_memory
|
||||
unreachable
|
||||
isNaN
|
||||
isFinite
|
||||
assert
|
||||
if/ifThenElse
|
||||
if/ifThen
|
||||
if/ifThenElseBlock
|
||||
|
@ -54,8 +54,12 @@
|
||||
nearest
|
||||
sqrt
|
||||
trunc
|
||||
current_memory
|
||||
grow_memory
|
||||
unreachable
|
||||
isNaN
|
||||
isFinite
|
||||
assert
|
||||
export/add
|
||||
export/sub
|
||||
export/a
|
||||
|
@ -42,7 +42,3 @@
|
||||
0b1;
|
||||
true;
|
||||
false;
|
||||
NaN;
|
||||
Infinity;
|
||||
<f32>NaN;
|
||||
<f32>Infinity;
|
||||
|
@ -137,18 +137,6 @@
|
||||
(drop
|
||||
(i32.const 0)
|
||||
)
|
||||
(drop
|
||||
(f64.const nan:0x8000000000000)
|
||||
)
|
||||
(drop
|
||||
(f64.const inf)
|
||||
)
|
||||
(drop
|
||||
(f32.const nan:0x400000)
|
||||
)
|
||||
(drop
|
||||
(f32.const inf)
|
||||
)
|
||||
)
|
||||
)
|
||||
(;
|
||||
@ -167,8 +155,12 @@
|
||||
nearest
|
||||
sqrt
|
||||
trunc
|
||||
current_memory
|
||||
grow_memory
|
||||
unreachable
|
||||
isNaN
|
||||
isFinite
|
||||
assert
|
||||
[program.exports]
|
||||
|
||||
;)
|
||||
|
@ -56,8 +56,12 @@
|
||||
nearest
|
||||
sqrt
|
||||
trunc
|
||||
current_memory
|
||||
grow_memory
|
||||
unreachable
|
||||
isNaN
|
||||
isFinite
|
||||
assert
|
||||
export/add
|
||||
export/sub
|
||||
export/a
|
||||
|
@ -161,8 +161,12 @@
|
||||
nearest
|
||||
sqrt
|
||||
trunc
|
||||
current_memory
|
||||
grow_memory
|
||||
unreachable
|
||||
isNaN
|
||||
isFinite
|
||||
assert
|
||||
switch/doSwitch
|
||||
switch/doSwitchDefaultFirst
|
||||
switch/doSwitchDefaultOmitted
|
||||
|
@ -649,8 +649,12 @@
|
||||
nearest
|
||||
sqrt
|
||||
trunc
|
||||
current_memory
|
||||
grow_memory
|
||||
unreachable
|
||||
isNaN
|
||||
isFinite
|
||||
assert
|
||||
unary/i
|
||||
unary/I
|
||||
unary/f
|
||||
|
@ -80,8 +80,12 @@
|
||||
nearest
|
||||
sqrt
|
||||
trunc
|
||||
current_memory
|
||||
grow_memory
|
||||
unreachable
|
||||
isNaN
|
||||
isFinite
|
||||
assert
|
||||
while/loopWhile
|
||||
while/loopWhileInWhile
|
||||
[program.exports]
|
||||
|
Reference in New Issue
Block a user