@@ -2673,14 +2673,14 @@ function builtin_atomic_cmpxchg(ctx: BuiltinContext): ExpressionRef {
2673
2673
}
2674
2674
builtins . set ( BuiltinNames . atomic_cmpxchg , builtin_atomic_cmpxchg ) ;
2675
2675
2676
- // atomic.wait<T!>(ptr: usize, expected: T, timeout: i64) -> i32
2676
+ // atomic.wait<T!>(ptr: usize, expected: T, timeout? : i64) -> i32
2677
2677
function builtin_atomic_wait ( ctx : BuiltinContext ) : ExpressionRef {
2678
2678
var compiler = ctx . compiler ;
2679
2679
var module = compiler . module ;
2680
2680
if (
2681
2681
checkFeatureEnabled ( ctx , Feature . THREADS ) |
2682
2682
checkTypeRequired ( ctx ) |
2683
- checkArgsRequired ( ctx , 3 )
2683
+ checkArgsOptional ( ctx , 2 , 3 )
2684
2684
) {
2685
2685
compiler . currentType = Type . i32 ;
2686
2686
return module . unreachable ( ) ;
@@ -2690,7 +2690,9 @@ function builtin_atomic_wait(ctx: BuiltinContext): ExpressionRef {
2690
2690
var type = typeArguments ! [ 0 ] ;
2691
2691
var arg0 = compiler . compileExpression ( operands [ 0 ] , compiler . options . usizeType , Constraints . CONV_IMPLICIT ) ;
2692
2692
var arg1 = compiler . compileExpression ( operands [ 1 ] , type , Constraints . CONV_IMPLICIT ) ;
2693
- var arg2 = compiler . compileExpression ( operands [ 2 ] , Type . i64 , Constraints . CONV_IMPLICIT ) ;
2693
+ var arg2 = operands . length == 3
2694
+ ? compiler . compileExpression ( operands [ 2 ] , Type . i64 , Constraints . CONV_IMPLICIT )
2695
+ : module . i64 ( - 1 , - 1 ) ; // Infinite timeout
2694
2696
compiler . currentType = Type . i32 ;
2695
2697
switch ( type . kind ) {
2696
2698
case TypeKind . I32 :
@@ -2708,21 +2710,23 @@ function builtin_atomic_wait(ctx: BuiltinContext): ExpressionRef {
2708
2710
}
2709
2711
builtins . set ( BuiltinNames . atomic_wait , builtin_atomic_wait ) ;
2710
2712
2711
- // atomic.notify(ptr: usize, count: i32) -> i32
2713
+ // atomic.notify(ptr: usize, count? : i32) -> i32
2712
2714
function builtin_atomic_notify ( ctx : BuiltinContext ) : ExpressionRef {
2713
2715
var compiler = ctx . compiler ;
2714
2716
var module = compiler . module ;
2715
2717
if (
2716
2718
checkFeatureEnabled ( ctx , Feature . THREADS ) |
2717
2719
checkTypeAbsent ( ctx ) |
2718
- checkArgsRequired ( ctx , 2 )
2720
+ checkArgsOptional ( ctx , 1 , 2 )
2719
2721
) {
2720
2722
compiler . currentType = Type . i32 ;
2721
2723
return module . unreachable ( ) ;
2722
2724
}
2723
2725
var operands = ctx . operands ;
2724
2726
var arg0 = compiler . compileExpression ( operands [ 0 ] , compiler . options . usizeType , Constraints . CONV_IMPLICIT ) ;
2725
- var arg1 = compiler . compileExpression ( operands [ 1 ] , Type . i32 , Constraints . CONV_IMPLICIT ) ;
2727
+ var arg1 = operands . length == 2
2728
+ ? compiler . compileExpression ( operands [ 1 ] , Type . i32 , Constraints . CONV_IMPLICIT )
2729
+ : module . i32 ( - 1 ) ; // Inifinity count of waiters
2726
2730
compiler . currentType = Type . i32 ;
2727
2731
return module . atomic_notify ( arg0 , arg1 ) ;
2728
2732
}
0 commit comments