mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-15 07:51:32 +00:00
Comma expressions fwiw
This commit is contained in:
152
tests/compiler/comma.optimized.wast
Normal file
152
tests/compiler/comma.optimized.wast
Normal file
@ -0,0 +1,152 @@
|
||||
(module
|
||||
(type $v (func))
|
||||
(global $comma/a (mut i32) (i32.const 0))
|
||||
(global $comma/b (mut i32) (i32.const 0))
|
||||
(memory $0 1)
|
||||
(export "memory" (memory $0))
|
||||
(start $start)
|
||||
(func $start (; 0 ;) (type $v)
|
||||
(local $0 i32)
|
||||
(set_global $comma/b
|
||||
(block (result i32)
|
||||
(set_global $comma/a
|
||||
(i32.add
|
||||
(tee_local $0
|
||||
(get_global $comma/a)
|
||||
)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(get_local $0)
|
||||
)
|
||||
)
|
||||
(if
|
||||
(i32.ne
|
||||
(get_global $comma/a)
|
||||
(i32.const 1)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
(if
|
||||
(get_global $comma/b)
|
||||
(unreachable)
|
||||
)
|
||||
(set_global $comma/a
|
||||
(i32.add
|
||||
(get_global $comma/a)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(set_global $comma/b
|
||||
(get_global $comma/a)
|
||||
)
|
||||
(if
|
||||
(i32.ne
|
||||
(get_global $comma/a)
|
||||
(i32.const 2)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
(if
|
||||
(i32.ne
|
||||
(get_global $comma/b)
|
||||
(i32.const 2)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
(set_global $comma/a
|
||||
(block (result i32)
|
||||
(set_global $comma/b
|
||||
(i32.const 0)
|
||||
)
|
||||
(get_global $comma/b)
|
||||
)
|
||||
)
|
||||
(set_global $comma/b
|
||||
(block (result i32)
|
||||
(set_global $comma/a
|
||||
(i32.add
|
||||
(get_global $comma/a)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(get_global $comma/a)
|
||||
)
|
||||
)
|
||||
(if
|
||||
(i32.ne
|
||||
(get_global $comma/a)
|
||||
(i32.const 1)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
(if
|
||||
(i32.ne
|
||||
(get_global $comma/b)
|
||||
(i32.const 1)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
(set_global $comma/a
|
||||
(block (result i32)
|
||||
(set_global $comma/a
|
||||
(i32.add
|
||||
(get_global $comma/a)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(set_global $comma/b
|
||||
(get_global $comma/a)
|
||||
)
|
||||
(get_global $comma/b)
|
||||
)
|
||||
)
|
||||
(if
|
||||
(i32.ne
|
||||
(get_global $comma/a)
|
||||
(i32.const 2)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
(if
|
||||
(i32.ne
|
||||
(get_global $comma/b)
|
||||
(i32.const 2)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
(set_local $0
|
||||
(i32.const 0)
|
||||
)
|
||||
(loop $continue|0
|
||||
(if
|
||||
(i32.lt_u
|
||||
(get_local $0)
|
||||
(get_global $comma/a)
|
||||
)
|
||||
(block
|
||||
(set_global $comma/a
|
||||
(i32.sub
|
||||
(get_global $comma/a)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(set_local $0
|
||||
(i32.add
|
||||
(get_local $0)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(br $continue|0)
|
||||
)
|
||||
)
|
||||
)
|
||||
(if
|
||||
(i32.ne
|
||||
(get_local $0)
|
||||
(i32.const 1)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
)
|
||||
)
|
24
tests/compiler/comma.ts
Normal file
24
tests/compiler/comma.ts
Normal file
@ -0,0 +1,24 @@
|
||||
var a = 0, b = 0;
|
||||
|
||||
b = a++, a; // lower precedence (like separate expressions)
|
||||
assert(a == 1);
|
||||
assert(b == 0);
|
||||
|
||||
a++, b = a;
|
||||
assert(a == 2);
|
||||
assert(b == 2);
|
||||
|
||||
a = b = 0;
|
||||
|
||||
b = (a++, a); // higher precedence
|
||||
assert(a == 1);
|
||||
assert(b == 1);
|
||||
|
||||
a = (a++, b = a);
|
||||
assert(a == 2);
|
||||
assert(b == 2);
|
||||
|
||||
for (var c = 0; c < a; a--, c++);
|
||||
assert(c == 1);
|
||||
|
||||
1, 2, 3; // tsc doesn't allow this
|
294
tests/compiler/comma.wast
Normal file
294
tests/compiler/comma.wast
Normal file
@ -0,0 +1,294 @@
|
||||
(module
|
||||
(type $v (func))
|
||||
(global $comma/a (mut i32) (i32.const 0))
|
||||
(global $comma/b (mut i32) (i32.const 0))
|
||||
(global $HEAP_BASE i32 (i32.const 4))
|
||||
(memory $0 1)
|
||||
(export "memory" (memory $0))
|
||||
(start $start)
|
||||
(func $start (; 0 ;) (type $v)
|
||||
(local $0 i32)
|
||||
(local $1 i32)
|
||||
(block
|
||||
(set_global $comma/b
|
||||
(block (result i32)
|
||||
(set_local $0
|
||||
(get_global $comma/a)
|
||||
)
|
||||
(set_global $comma/a
|
||||
(i32.add
|
||||
(get_local $0)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(get_local $0)
|
||||
)
|
||||
)
|
||||
(drop
|
||||
(get_global $comma/a)
|
||||
)
|
||||
)
|
||||
(if
|
||||
(i32.eqz
|
||||
(i32.eq
|
||||
(get_global $comma/a)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
(if
|
||||
(i32.eqz
|
||||
(i32.eq
|
||||
(get_global $comma/b)
|
||||
(i32.const 0)
|
||||
)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
(block
|
||||
(drop
|
||||
(block (result i32)
|
||||
(set_local $0
|
||||
(get_global $comma/a)
|
||||
)
|
||||
(set_global $comma/a
|
||||
(i32.add
|
||||
(get_local $0)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(get_local $0)
|
||||
)
|
||||
)
|
||||
(set_global $comma/b
|
||||
(get_global $comma/a)
|
||||
)
|
||||
)
|
||||
(if
|
||||
(i32.eqz
|
||||
(i32.eq
|
||||
(get_global $comma/a)
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
(if
|
||||
(i32.eqz
|
||||
(i32.eq
|
||||
(get_global $comma/b)
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
(set_global $comma/a
|
||||
(block (result i32)
|
||||
(set_global $comma/b
|
||||
(i32.const 0)
|
||||
)
|
||||
(get_global $comma/b)
|
||||
)
|
||||
)
|
||||
(set_global $comma/b
|
||||
(block (result i32)
|
||||
(drop
|
||||
(block (result i32)
|
||||
(set_local $0
|
||||
(get_global $comma/a)
|
||||
)
|
||||
(set_global $comma/a
|
||||
(i32.add
|
||||
(get_local $0)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(get_local $0)
|
||||
)
|
||||
)
|
||||
(get_global $comma/a)
|
||||
)
|
||||
)
|
||||
(if
|
||||
(i32.eqz
|
||||
(i32.eq
|
||||
(get_global $comma/a)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
(if
|
||||
(i32.eqz
|
||||
(i32.eq
|
||||
(get_global $comma/b)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
(set_global $comma/a
|
||||
(block (result i32)
|
||||
(drop
|
||||
(block (result i32)
|
||||
(set_local $0
|
||||
(get_global $comma/a)
|
||||
)
|
||||
(set_global $comma/a
|
||||
(i32.add
|
||||
(get_local $0)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(get_local $0)
|
||||
)
|
||||
)
|
||||
(block (result i32)
|
||||
(set_global $comma/b
|
||||
(get_global $comma/a)
|
||||
)
|
||||
(get_global $comma/b)
|
||||
)
|
||||
)
|
||||
)
|
||||
(if
|
||||
(i32.eqz
|
||||
(i32.eq
|
||||
(get_global $comma/a)
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
(if
|
||||
(i32.eqz
|
||||
(i32.eq
|
||||
(get_global $comma/b)
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
(block $break|0
|
||||
(block
|
||||
(set_local $1
|
||||
(i32.const 0)
|
||||
)
|
||||
)
|
||||
(loop $continue|0
|
||||
(if
|
||||
(i32.lt_u
|
||||
(get_local $1)
|
||||
(get_global $comma/a)
|
||||
)
|
||||
(block
|
||||
(nop)
|
||||
(block
|
||||
(drop
|
||||
(block (result i32)
|
||||
(set_local $0
|
||||
(get_global $comma/a)
|
||||
)
|
||||
(set_global $comma/a
|
||||
(i32.sub
|
||||
(get_local $0)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(get_local $0)
|
||||
)
|
||||
)
|
||||
(drop
|
||||
(block (result i32)
|
||||
(set_local $0
|
||||
(get_local $1)
|
||||
)
|
||||
(set_local $1
|
||||
(i32.add
|
||||
(get_local $0)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(get_local $0)
|
||||
)
|
||||
)
|
||||
)
|
||||
(br $continue|0)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(if
|
||||
(i32.eqz
|
||||
(i32.eq
|
||||
(get_local $1)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
(block
|
||||
(drop
|
||||
(i32.const 1)
|
||||
)
|
||||
(drop
|
||||
(i32.const 2)
|
||||
)
|
||||
(drop
|
||||
(i32.const 3)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(;
|
||||
[program.elements]
|
||||
GLOBAL: NaN
|
||||
GLOBAL: Infinity
|
||||
FUNCTION_PROTOTYPE: isNaN
|
||||
FUNCTION_PROTOTYPE: isFinite
|
||||
FUNCTION_PROTOTYPE: clz
|
||||
FUNCTION_PROTOTYPE: ctz
|
||||
FUNCTION_PROTOTYPE: popcnt
|
||||
FUNCTION_PROTOTYPE: rotl
|
||||
FUNCTION_PROTOTYPE: rotr
|
||||
FUNCTION_PROTOTYPE: abs
|
||||
FUNCTION_PROTOTYPE: max
|
||||
FUNCTION_PROTOTYPE: min
|
||||
FUNCTION_PROTOTYPE: ceil
|
||||
FUNCTION_PROTOTYPE: floor
|
||||
FUNCTION_PROTOTYPE: copysign
|
||||
FUNCTION_PROTOTYPE: nearest
|
||||
FUNCTION_PROTOTYPE: reinterpret
|
||||
FUNCTION_PROTOTYPE: sqrt
|
||||
FUNCTION_PROTOTYPE: trunc
|
||||
FUNCTION_PROTOTYPE: load
|
||||
FUNCTION_PROTOTYPE: store
|
||||
FUNCTION_PROTOTYPE: sizeof
|
||||
FUNCTION_PROTOTYPE: select
|
||||
FUNCTION_PROTOTYPE: unreachable
|
||||
FUNCTION_PROTOTYPE: current_memory
|
||||
FUNCTION_PROTOTYPE: grow_memory
|
||||
FUNCTION_PROTOTYPE: parseInt
|
||||
FUNCTION_PROTOTYPE: parseFloat
|
||||
FUNCTION_PROTOTYPE: changetype
|
||||
FUNCTION_PROTOTYPE: assert
|
||||
FUNCTION_PROTOTYPE: i8
|
||||
FUNCTION_PROTOTYPE: i16
|
||||
FUNCTION_PROTOTYPE: i32
|
||||
FUNCTION_PROTOTYPE: i64
|
||||
FUNCTION_PROTOTYPE: u8
|
||||
FUNCTION_PROTOTYPE: u16
|
||||
FUNCTION_PROTOTYPE: u32
|
||||
FUNCTION_PROTOTYPE: u64
|
||||
FUNCTION_PROTOTYPE: bool
|
||||
FUNCTION_PROTOTYPE: f32
|
||||
FUNCTION_PROTOTYPE: f64
|
||||
FUNCTION_PROTOTYPE: isize
|
||||
FUNCTION_PROTOTYPE: usize
|
||||
GLOBAL: HEAP_BASE
|
||||
GLOBAL: comma/a
|
||||
GLOBAL: comma/b
|
||||
[program.exports]
|
||||
|
||||
;)
|
@ -51,6 +51,8 @@
|
||||
GLOBAL: HEAP_BASE
|
||||
CLASS_PROTOTYPE: std:array/Array
|
||||
CLASS_PROTOTYPE: Array
|
||||
CLASS_PROTOTYPE: std:array/CArray
|
||||
CLASS_PROTOTYPE: CArray
|
||||
CLASS_PROTOTYPE: std:error/Error
|
||||
CLASS_PROTOTYPE: Error
|
||||
CLASS_PROTOTYPE: std:error/RangeError
|
||||
@ -79,6 +81,7 @@
|
||||
FUNCTION_PROTOTYPE: std:string/isWhiteSpaceOrLineTerminator
|
||||
[program.exports]
|
||||
CLASS_PROTOTYPE: std:array/Array
|
||||
CLASS_PROTOTYPE: std:array/CArray
|
||||
CLASS_PROTOTYPE: std:error/Error
|
||||
CLASS_PROTOTYPE: std:error/RangeError
|
||||
CLASS_PROTOTYPE: std:heap/Heap
|
||||
|
@ -2600,6 +2600,8 @@
|
||||
GLOBAL: HEAP_BASE
|
||||
CLASS_PROTOTYPE: std:array/Array
|
||||
CLASS_PROTOTYPE: Array
|
||||
CLASS_PROTOTYPE: std:array/CArray
|
||||
CLASS_PROTOTYPE: CArray
|
||||
CLASS_PROTOTYPE: std:error/Error
|
||||
CLASS_PROTOTYPE: Error
|
||||
CLASS_PROTOTYPE: std:error/RangeError
|
||||
@ -2632,6 +2634,7 @@
|
||||
GLOBAL: std/heap/i
|
||||
[program.exports]
|
||||
CLASS_PROTOTYPE: std:array/Array
|
||||
CLASS_PROTOTYPE: std:array/CArray
|
||||
CLASS_PROTOTYPE: std:error/Error
|
||||
CLASS_PROTOTYPE: std:error/RangeError
|
||||
CLASS_PROTOTYPE: std:heap/Heap
|
||||
|
Reference in New Issue
Block a user