@grain/stdlib 0.6.4 → 0.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -402,31 +402,31 @@ provide let boxedRationalDenominator = xptr => {
402
402
 
403
403
  @unsafe
404
404
  provide let coerceNumberToWasmF32 = (x: Number) => {
405
- let x = WasmI32.fromGrain(x)
406
- if (isSimpleNumber(x)) {
407
- WasmF32.convertI32S(untagSimple(x))
405
+ let xVal = WasmI32.fromGrain(x)
406
+ let result = if (isSimpleNumber(xVal)) {
407
+ WasmF32.convertI32S(untagSimple(xVal))
408
408
  } else {
409
- let xtag = boxedNumberTag(x)
409
+ let xtag = boxedNumberTag(xVal)
410
410
  match (xtag) {
411
411
  t when t == Tags._GRAIN_INT64_BOXED_NUM_TAG => {
412
- WasmF32.convertI64S(boxedInt64Number(x))
412
+ WasmF32.convertI64S(boxedInt64Number(xVal))
413
413
  },
414
414
  t when t == Tags._GRAIN_BIGINT_BOXED_NUM_TAG => {
415
- BI.toFloat32(x)
415
+ BI.toFloat32(xVal)
416
416
  },
417
417
  t when t == Tags._GRAIN_RATIONAL_BOXED_NUM_TAG => {
418
418
  use WasmF32.{ (/) }
419
- BI.toFloat32(boxedRationalNumerator(x)) /
420
- BI.toFloat32(boxedRationalDenominator(x))
419
+ BI.toFloat32(boxedRationalNumerator(xVal)) /
420
+ BI.toFloat32(boxedRationalDenominator(xVal))
421
421
  },
422
422
  t when t == Tags._GRAIN_FLOAT64_BOXED_NUM_TAG => {
423
423
  use WasmF64.{ (<), (>) }
424
- let xval = boxedFloat64Number(x)
425
- if (xval > _F32_MAX || xval < _F32_MIN) {
424
+ let boxedVal = boxedFloat64Number(xVal)
425
+ if (boxedVal > _F32_MAX || boxedVal < _F32_MIN) {
426
426
  // Not an actual return value
427
427
  throw Exception.Overflow
428
428
  } else {
429
- WasmF32.demoteF64(xval)
429
+ WasmF32.demoteF64(boxedVal)
430
430
  }
431
431
  },
432
432
  _ => {
@@ -434,50 +434,54 @@ provide let coerceNumberToWasmF32 = (x: Number) => {
434
434
  },
435
435
  }
436
436
  }
437
+ ignore(x)
438
+ result
437
439
  }
438
440
 
439
441
  @unsafe
440
442
  provide let coerceNumberToWasmF64 = (x: Number) => {
441
- let x = WasmI32.fromGrain(x)
442
- if (isSimpleNumber(x)) {
443
- WasmF64.convertI32S(untagSimple(x))
443
+ let xVal = WasmI32.fromGrain(x)
444
+ let result = if (isSimpleNumber(xVal)) {
445
+ WasmF64.convertI32S(untagSimple(xVal))
444
446
  } else {
445
- let xtag = boxedNumberTag(x)
447
+ let xtag = boxedNumberTag(xVal)
446
448
  match (xtag) {
447
449
  t when t == Tags._GRAIN_INT64_BOXED_NUM_TAG => {
448
- WasmF64.convertI64S(boxedInt64Number(x))
450
+ WasmF64.convertI64S(boxedInt64Number(xVal))
449
451
  },
450
452
  t when t == Tags._GRAIN_BIGINT_BOXED_NUM_TAG => {
451
- BI.toFloat64(x)
453
+ BI.toFloat64(xVal)
452
454
  },
453
455
  t when t == Tags._GRAIN_RATIONAL_BOXED_NUM_TAG => {
454
456
  use WasmF64.{ (/) }
455
- BI.toFloat64(boxedRationalNumerator(x)) /
456
- BI.toFloat64(boxedRationalDenominator(x))
457
+ BI.toFloat64(boxedRationalNumerator(xVal)) /
458
+ BI.toFloat64(boxedRationalDenominator(xVal))
457
459
  },
458
460
  t when t == Tags._GRAIN_FLOAT64_BOXED_NUM_TAG => {
459
- boxedFloat64Number(x)
461
+ boxedFloat64Number(xVal)
460
462
  },
461
463
  _ => {
462
464
  throw UnknownNumberTag
463
465
  },
464
466
  }
465
467
  }
468
+ ignore(x)
469
+ result
466
470
  }
467
471
 
468
472
  @unsafe
469
473
  provide let coerceNumberToWasmI64 = (x: Number) => {
470
- let x = WasmI32.fromGrain(x)
471
- if (isSimpleNumber(x)) {
472
- WasmI64.extendI32S(untagSimple(x))
474
+ let xVal = WasmI32.fromGrain(x)
475
+ let result = if (isSimpleNumber(xVal)) {
476
+ WasmI64.extendI32S(untagSimple(xVal))
473
477
  } else {
474
- let xtag = boxedNumberTag(x)
478
+ let xtag = boxedNumberTag(xVal)
475
479
  match (xtag) {
476
480
  t when t == Tags._GRAIN_INT64_BOXED_NUM_TAG => {
477
- boxedInt64Number(x)
481
+ boxedInt64Number(xVal)
478
482
  },
479
483
  t when t == Tags._GRAIN_BIGINT_BOXED_NUM_TAG => {
480
- BI.toInt64(x)
484
+ BI.toInt64(xVal)
481
485
  },
482
486
  _ => {
483
487
  // rationals are never integral, and we refuse to coerce floats to ints
@@ -485,26 +489,28 @@ provide let coerceNumberToWasmI64 = (x: Number) => {
485
489
  },
486
490
  }
487
491
  }
492
+ ignore(x)
493
+ result
488
494
  }
489
495
 
490
496
  @unsafe
491
497
  provide let coerceNumberToWasmI32 = (x: Number) => {
492
498
  use WasmI64.{ (<), (>) }
493
- let x = WasmI32.fromGrain(x)
494
- if (isSimpleNumber(x)) {
495
- untagSimple(x)
499
+ let xVal = WasmI32.fromGrain(x)
500
+ let result = if (isSimpleNumber(xVal)) {
501
+ untagSimple(xVal)
496
502
  } else {
497
- let xtag = boxedNumberTag(x)
503
+ let xtag = boxedNumberTag(xVal)
498
504
  match (xtag) {
499
505
  t when t == Tags._GRAIN_INT64_BOXED_NUM_TAG => {
500
- let int64 = boxedInt64Number(x)
506
+ let int64 = boxedInt64Number(xVal)
501
507
  if (int64 > _I32_MAX || int64 < _I32_MIN) {
502
508
  throw Exception.Overflow
503
509
  }
504
510
  WasmI32.wrapI64(int64)
505
511
  },
506
512
  t when t == Tags._GRAIN_BIGINT_BOXED_NUM_TAG => {
507
- BI.toInt32(x)
513
+ BI.toInt32(xVal)
508
514
  },
509
515
  _ => {
510
516
  // rationals are never integral, and we refuse to coerce floats to ints
@@ -512,31 +518,33 @@ provide let coerceNumberToWasmI32 = (x: Number) => {
512
518
  },
513
519
  }
514
520
  }
521
+ ignore(x)
522
+ result
515
523
  }
516
524
 
517
525
  @unsafe
518
526
  provide let coerceNumberToUnsignedWasmI64 = (x: Number) => {
519
527
  use WasmI32.{ (<) }
520
- let x = WasmI32.fromGrain(x)
521
- if (isSimpleNumber(x)) {
522
- let num = untagSimple(x)
528
+ let xVal = WasmI32.fromGrain(x)
529
+ let result = if (isSimpleNumber(xVal)) {
530
+ let num = untagSimple(xVal)
523
531
  if (num < 0n) {
524
532
  throw Exception.Overflow
525
533
  }
526
534
  WasmI64.extendI32U(num)
527
535
  } else {
528
- let xtag = boxedNumberTag(x)
536
+ let xtag = boxedNumberTag(xVal)
529
537
  match (xtag) {
530
538
  t when t == Tags._GRAIN_INT64_BOXED_NUM_TAG => {
531
539
  use WasmI64.{ (<) }
532
- let int64 = boxedInt64Number(x)
540
+ let int64 = boxedInt64Number(xVal)
533
541
  if (int64 < 0N) {
534
542
  throw Exception.Overflow
535
543
  }
536
544
  int64
537
545
  },
538
546
  t when t == Tags._GRAIN_BIGINT_BOXED_NUM_TAG => {
539
- BI.toUnsignedInt64(x)
547
+ BI.toUnsignedInt64(xVal)
540
548
  },
541
549
  _ => {
542
550
  // rationals are never integral, and we refuse to coerce floats to ints
@@ -544,31 +552,33 @@ provide let coerceNumberToUnsignedWasmI64 = (x: Number) => {
544
552
  },
545
553
  }
546
554
  }
555
+ ignore(x)
556
+ result
547
557
  }
548
558
 
549
559
  @unsafe
550
560
  provide let coerceNumberToUnsignedWasmI32 = (x: Number) => {
551
561
  use WasmI32.{ (<) }
552
- let x = WasmI32.fromGrain(x)
553
- if (isSimpleNumber(x)) {
554
- let num = untagSimple(x)
562
+ let xVal = WasmI32.fromGrain(x)
563
+ let result = if (isSimpleNumber(xVal)) {
564
+ let num = untagSimple(xVal)
555
565
  if (num < 0n) {
556
566
  throw Exception.Overflow
557
567
  }
558
568
  num
559
569
  } else {
560
- let xtag = boxedNumberTag(x)
570
+ let xtag = boxedNumberTag(xVal)
561
571
  match (xtag) {
562
572
  t when t == Tags._GRAIN_INT64_BOXED_NUM_TAG => {
563
573
  use WasmI64.{ (<), (>) }
564
- let int64 = boxedInt64Number(x)
574
+ let int64 = boxedInt64Number(xVal)
565
575
  if (int64 > _U32_MAX || int64 < _U32_MIN) {
566
576
  throw Exception.Overflow
567
577
  }
568
578
  WasmI32.wrapI64(int64)
569
579
  },
570
580
  t when t == Tags._GRAIN_BIGINT_BOXED_NUM_TAG => {
571
- BI.toInt32(x)
581
+ BI.toInt32(xVal)
572
582
  },
573
583
  _ => {
574
584
  // rationals are never integral, and we refuse to coerce floats to ints
@@ -576,22 +586,24 @@ provide let coerceNumberToUnsignedWasmI32 = (x: Number) => {
576
586
  },
577
587
  }
578
588
  }
589
+ ignore(x)
590
+ result
579
591
  }
580
592
 
581
593
  @unsafe
582
594
  let coerceNumberToBigInt = (x: Number) => {
583
- let x = WasmI32.fromGrain(x)
584
- if (isSimpleNumber(x)) {
585
- BI.makeWrappedInt32(untagSimple(x))
595
+ let xVal = WasmI32.fromGrain(x)
596
+ let result = if (isSimpleNumber(xVal)) {
597
+ BI.makeWrappedInt32(untagSimple(xVal))
586
598
  } else {
587
- let xtag = boxedNumberTag(x)
599
+ let xtag = boxedNumberTag(xVal)
588
600
  match (xtag) {
589
601
  t when t == Tags._GRAIN_INT64_BOXED_NUM_TAG => {
590
- BI.makeWrappedInt64(boxedInt64Number(x))
602
+ BI.makeWrappedInt64(boxedInt64Number(xVal))
591
603
  },
592
604
  t when t == Tags._GRAIN_BIGINT_BOXED_NUM_TAG => {
593
- Memory.incRef(x)
594
- x
605
+ Memory.incRef(xVal)
606
+ xVal
595
607
  },
596
608
  _ => {
597
609
  // rationals are never integral, and we refuse to coerce floats to ints
@@ -599,6 +611,8 @@ let coerceNumberToBigInt = (x: Number) => {
599
611
  },
600
612
  }
601
613
  }
614
+ ignore(x)
615
+ result
602
616
  }
603
617
 
604
618
  @unsafe
@@ -1165,8 +1179,9 @@ provide let cmpRationals = (x, y) => {
1165
1179
  */
1166
1180
  @unsafe
1167
1181
  provide let rationalNumerator = (x: Rational) => {
1168
- let x = WasmI32.fromGrain(x)
1169
- let num = boxedRationalNumerator(x)
1182
+ let xVal = WasmI32.fromGrain(x)
1183
+ let num = boxedRationalNumerator(xVal)
1184
+ ignore(x)
1170
1185
  Memory.incRef(num)
1171
1186
  WasmI32.toGrain(reducedBigInteger(num)): Number
1172
1187
  }
@@ -1181,8 +1196,9 @@ provide let rationalNumerator = (x: Rational) => {
1181
1196
  */
1182
1197
  @unsafe
1183
1198
  provide let rationalDenominator = (x: Rational) => {
1184
- let x = WasmI32.fromGrain(x)
1185
- let num = boxedRationalDenominator(x)
1199
+ let xVal = WasmI32.fromGrain(x)
1200
+ let num = boxedRationalDenominator(xVal)
1201
+ ignore(x)
1186
1202
  Memory.incRef(num)
1187
1203
  WasmI32.toGrain(reducedBigInteger(num)): Number
1188
1204
  }
@@ -1912,7 +1928,10 @@ provide let (<) = (num1: Number, num2: Number) => {
1912
1928
  use WasmI32.{ (<) }
1913
1929
  let x = WasmI32.fromGrain(num1)
1914
1930
  let y = WasmI32.fromGrain(num2)
1915
- !isNaN(x) && !isNaN(y) && cmp(x, y) < 0n
1931
+ let result = !isNaN(x) && !isNaN(y) && cmp(x, y) < 0n
1932
+ ignore(num1)
1933
+ ignore(num2)
1934
+ result
1916
1935
  }
1917
1936
 
1918
1937
  /**
@@ -1929,7 +1948,10 @@ provide let (>) = (num1: Number, num2: Number) => {
1929
1948
  use WasmI32.{ (>) }
1930
1949
  let x = WasmI32.fromGrain(num1)
1931
1950
  let y = WasmI32.fromGrain(num2)
1932
- !isNaN(x) && !isNaN(y) && cmp(x, y) > 0n
1951
+ let result = !isNaN(x) && !isNaN(y) && cmp(x, y) > 0n
1952
+ ignore(num1)
1953
+ ignore(num2)
1954
+ result
1933
1955
  }
1934
1956
 
1935
1957
  /**
@@ -1946,7 +1968,10 @@ provide let (<=) = (num1: Number, num2: Number) => {
1946
1968
  use WasmI32.{ (<=) }
1947
1969
  let x = WasmI32.fromGrain(num1)
1948
1970
  let y = WasmI32.fromGrain(num2)
1949
- !isNaN(x) && !isNaN(y) && cmp(x, y) <= 0n
1971
+ let result = !isNaN(x) && !isNaN(y) && cmp(x, y) <= 0n
1972
+ ignore(num1)
1973
+ ignore(num2)
1974
+ result
1950
1975
  }
1951
1976
 
1952
1977
  /**
@@ -1963,14 +1988,20 @@ provide let (>=) = (num1: Number, num2: Number) => {
1963
1988
  use WasmI32.{ (>=) }
1964
1989
  let x = WasmI32.fromGrain(num1)
1965
1990
  let y = WasmI32.fromGrain(num2)
1966
- !isNaN(x) && !isNaN(y) && cmp(x, y) >= 0n
1991
+ let result = !isNaN(x) && !isNaN(y) && cmp(x, y) >= 0n
1992
+ ignore(num1)
1993
+ ignore(num2)
1994
+ result
1967
1995
  }
1968
1996
 
1969
1997
  @unsafe
1970
1998
  provide let compare = (x: Number, y: Number) => {
1971
- let x = WasmI32.fromGrain(x)
1972
- let y = WasmI32.fromGrain(y)
1973
- WasmI32.toGrain(tagSimple(cmp(x, y))): Number
1999
+ let xVal = WasmI32.fromGrain(x)
2000
+ let yVal = WasmI32.fromGrain(y)
2001
+ let result = WasmI32.toGrain(tagSimple(cmp(xVal, yVal))): Number
2002
+ ignore(x)
2003
+ ignore(y)
2004
+ result
1974
2005
  }
1975
2006
 
1976
2007
  /*
@@ -1979,9 +2010,12 @@ provide let compare = (x: Number, y: Number) => {
1979
2010
 
1980
2011
  @unsafe
1981
2012
  provide let numberEq = (x: Number, y: Number) => {
1982
- let x = WasmI32.fromGrain(x)
1983
- let y = WasmI32.fromGrain(y)
1984
- numberEqual(x, y)
2013
+ let xVal = WasmI32.fromGrain(x)
2014
+ let yVal = WasmI32.fromGrain(y)
2015
+ let result = numberEqual(xVal, yVal)
2016
+ ignore(x)
2017
+ ignore(y)
2018
+ result
1985
2019
  }
1986
2020
 
1987
2021
  /*
@@ -2001,12 +2035,14 @@ provide let numberEq = (x: Number, y: Number) => {
2001
2035
  @unsafe
2002
2036
  provide let lnot = (value: Number) => {
2003
2037
  let xw32 = WasmI32.fromGrain(value)
2004
- if (isBigInt(xw32)) {
2038
+ let result = if (isBigInt(xw32)) {
2005
2039
  WasmI32.toGrain(reducedBigInteger(BI.bitwiseNot(xw32))): Number
2006
2040
  } else {
2007
2041
  let xval = coerceNumberToWasmI64(value)
2008
2042
  WasmI32.toGrain(reducedInteger(i64not(xval))): Number
2009
2043
  }
2044
+ ignore(value)
2045
+ result
2010
2046
  }
2011
2047
 
2012
2048
  /**
@@ -2024,7 +2060,7 @@ provide let lnot = (value: Number) => {
2024
2060
  provide let (<<) = (value: Number, amount: Number) => {
2025
2061
  use WasmI64.{ (-), (<<) }
2026
2062
  let xw32 = WasmI32.fromGrain(value)
2027
- if (isBigInt(xw32)) {
2063
+ let result = if (isBigInt(xw32)) {
2028
2064
  let yval = coerceNumberToWasmI32(amount)
2029
2065
  WasmI32.toGrain(reducedBigInteger(BI.shl(xw32, yval))): Number
2030
2066
  } else {
@@ -2040,6 +2076,8 @@ provide let (<<) = (value: Number, amount: Number) => {
2040
2076
  WasmI32.toGrain(reducedInteger(xval << yval)): Number
2041
2077
  }
2042
2078
  }
2079
+ ignore(value)
2080
+ result
2043
2081
  }
2044
2082
 
2045
2083
  /**
@@ -2057,7 +2095,7 @@ provide let (<<) = (value: Number, amount: Number) => {
2057
2095
  provide let (>>>) = (value: Number, amount: Number) => {
2058
2096
  use WasmI64.{ (>>>) }
2059
2097
  let xw32 = WasmI32.fromGrain(value)
2060
- if (isBigInt(xw32)) {
2098
+ let result = if (isBigInt(xw32)) {
2061
2099
  let yval = coerceNumberToWasmI32(amount)
2062
2100
  // [NOTE]: For BigInts, shrU is the same as shrS because there
2063
2101
  // are an *infinite* number of leading ones
@@ -2067,6 +2105,8 @@ provide let (>>>) = (value: Number, amount: Number) => {
2067
2105
  let yval = coerceNumberToWasmI64(amount)
2068
2106
  WasmI32.toGrain(reducedInteger(xval >>> yval)): Number
2069
2107
  }
2108
+ ignore(value)
2109
+ result
2070
2110
  }
2071
2111
 
2072
2112
  /**
@@ -2085,7 +2125,7 @@ provide let (&) = (value1: Number, value2: Number) => {
2085
2125
  use WasmI64.{ (&) }
2086
2126
  let xw32 = WasmI32.fromGrain(value1)
2087
2127
  let yw32 = WasmI32.fromGrain(value2)
2088
- if (isBigInt(xw32) || isBigInt(yw32)) {
2128
+ let result = if (isBigInt(xw32) || isBigInt(yw32)) {
2089
2129
  let xval = coerceNumberToBigInt(value1)
2090
2130
  let yval = coerceNumberToBigInt(value2)
2091
2131
  let ret = WasmI32.toGrain(reducedBigInteger(BI.bitwiseAnd(xval, yval))):
@@ -2104,6 +2144,9 @@ provide let (&) = (value1: Number, value2: Number) => {
2104
2144
  let yval = coerceNumberToWasmI64(value2)
2105
2145
  WasmI32.toGrain(reducedInteger(xval & yval)): Number
2106
2146
  }
2147
+ ignore(value1)
2148
+ ignore(value2)
2149
+ result
2107
2150
  }
2108
2151
 
2109
2152
  /**
@@ -2122,7 +2165,7 @@ provide let (|) = (value1: Number, value2: Number) => {
2122
2165
  use WasmI64.{ (|) }
2123
2166
  let xw32 = WasmI32.fromGrain(value1)
2124
2167
  let yw32 = WasmI32.fromGrain(value2)
2125
- if (isBigInt(xw32) || isBigInt(yw32)) {
2168
+ let result = if (isBigInt(xw32) || isBigInt(yw32)) {
2126
2169
  let xval = coerceNumberToBigInt(value1)
2127
2170
  let yval = coerceNumberToBigInt(value2)
2128
2171
  let ret = WasmI32.toGrain(reducedBigInteger(BI.bitwiseOr(xval, yval))):
@@ -2141,6 +2184,9 @@ provide let (|) = (value1: Number, value2: Number) => {
2141
2184
  let yval = coerceNumberToWasmI64(value2)
2142
2185
  WasmI32.toGrain(reducedInteger(xval | yval)): Number
2143
2186
  }
2187
+ ignore(value1)
2188
+ ignore(value2)
2189
+ result
2144
2190
  }
2145
2191
 
2146
2192
  /**
@@ -2160,7 +2206,7 @@ provide let (^) = (value1: Number, value2: Number) => {
2160
2206
  use WasmI64.{ (^) }
2161
2207
  let xw32 = WasmI32.fromGrain(value1)
2162
2208
  let yw32 = WasmI32.fromGrain(value2)
2163
- if (isBigInt(xw32) || isBigInt(yw32)) {
2209
+ let result = if (isBigInt(xw32) || isBigInt(yw32)) {
2164
2210
  let xval = coerceNumberToBigInt(value1)
2165
2211
  let yval = coerceNumberToBigInt(value2)
2166
2212
  let ret = WasmI32.toGrain(reducedBigInteger(BI.bitwiseXor(xval, yval))):
@@ -2179,6 +2225,9 @@ provide let (^) = (value1: Number, value2: Number) => {
2179
2225
  let yval = coerceNumberToWasmI64(value2)
2180
2226
  WasmI32.toGrain(reducedInteger(xval ^ yval)): Number
2181
2227
  }
2228
+ ignore(value1)
2229
+ ignore(value2)
2230
+ result
2182
2231
  }
2183
2232
 
2184
2233
  /**
@@ -2196,7 +2245,7 @@ provide let (^) = (value1: Number, value2: Number) => {
2196
2245
  provide let (>>) = (value: Number, amount: Number) => {
2197
2246
  use WasmI64.{ (>>) }
2198
2247
  let xw32 = WasmI32.fromGrain(value)
2199
- if (isBigInt(xw32)) {
2248
+ let result = if (isBigInt(xw32)) {
2200
2249
  let yval = coerceNumberToWasmI32(amount)
2201
2250
  // [NOTE]: For BigInts, shrU is the same as shrS because there
2202
2251
  // are an *infinite* number of leading ones
@@ -2206,6 +2255,8 @@ provide let (>>) = (value: Number, amount: Number) => {
2206
2255
  let yval = coerceNumberToWasmI64(amount)
2207
2256
  WasmI32.toGrain(reducedInteger(xval >> yval)): Number
2208
2257
  }
2258
+ ignore(value)
2259
+ result
2209
2260
  }
2210
2261
 
2211
2262
  /// USER-EXPOSED COERCION FUNCTIONS
@@ -2216,22 +2267,22 @@ provide let (>>) = (value: Number, amount: Number) => {
2216
2267
  @unsafe
2217
2268
  let coerceNumberToShortUint = (x: Number, max32, max64, is8bit) => {
2218
2269
  use WasmI32.{ (&), (<), (>) }
2219
- let x = WasmI32.fromGrain(x)
2220
- let int32 = if (isSimpleNumber(x)) {
2221
- untagSimple(x)
2270
+ let xVal = WasmI32.fromGrain(x)
2271
+ let int32 = if (isSimpleNumber(xVal)) {
2272
+ untagSimple(xVal)
2222
2273
  } else {
2223
- let xtag = boxedNumberTag(x)
2274
+ let xtag = boxedNumberTag(xVal)
2224
2275
  match (xtag) {
2225
2276
  t when t == Tags._GRAIN_INT64_BOXED_NUM_TAG => {
2226
2277
  use WasmI64.{ (<), (>) }
2227
- let int64 = boxedInt64Number(x)
2278
+ let int64 = boxedInt64Number(xVal)
2228
2279
  if (int64 > max64 || int64 < 0N) {
2229
2280
  throw Exception.Overflow
2230
2281
  }
2231
2282
  WasmI32.wrapI64(int64)
2232
2283
  },
2233
2284
  t when t == Tags._GRAIN_BIGINT_BOXED_NUM_TAG => {
2234
- BI.toInt32(x)
2285
+ BI.toInt32(xVal)
2235
2286
  },
2236
2287
  _ => {
2237
2288
  // rationals are never integral, and we refuse to coerce floats to ints
@@ -2239,6 +2290,7 @@ let coerceNumberToShortUint = (x: Number, max32, max64, is8bit) => {
2239
2290
  },
2240
2291
  }
2241
2292
  }
2293
+ ignore(x)
2242
2294
  if (int32 > max32 || int32 < 0n) {
2243
2295
  throw Exception.Overflow
2244
2296
  }
@@ -2248,22 +2300,22 @@ let coerceNumberToShortUint = (x: Number, max32, max64, is8bit) => {
2248
2300
  @unsafe
2249
2301
  let coerceNumberToShortInt = (x: Number, min32, max32, min64, max64, is8bit) => {
2250
2302
  use WasmI32.{ (<), (>) }
2251
- let x = WasmI32.fromGrain(x)
2252
- let int32 = if (isSimpleNumber(x)) {
2253
- untagSimple(x)
2303
+ let xVal = WasmI32.fromGrain(x)
2304
+ let int32 = if (isSimpleNumber(xVal)) {
2305
+ untagSimple(xVal)
2254
2306
  } else {
2255
- let xtag = boxedNumberTag(x)
2307
+ let xtag = boxedNumberTag(xVal)
2256
2308
  match (xtag) {
2257
2309
  t when t == Tags._GRAIN_INT64_BOXED_NUM_TAG => {
2258
2310
  use WasmI64.{ (<), (>) }
2259
- let int64 = boxedInt64Number(x)
2311
+ let int64 = boxedInt64Number(xVal)
2260
2312
  if (int64 > max64 || int64 < min64) {
2261
2313
  throw Exception.Overflow
2262
2314
  }
2263
2315
  WasmI32.wrapI64(int64)
2264
2316
  },
2265
2317
  t when t == Tags._GRAIN_BIGINT_BOXED_NUM_TAG => {
2266
- BI.toInt32(x)
2318
+ BI.toInt32(xVal)
2267
2319
  },
2268
2320
  _ => {
2269
2321
  // rationals are never integral, and we refuse to coerce floats to ints
@@ -2271,6 +2323,7 @@ let coerceNumberToShortInt = (x: Number, min32, max32, min64, max64, is8bit) =>
2271
2323
  },
2272
2324
  }
2273
2325
  }
2326
+ ignore(x)
2274
2327
  if (int32 > max32 || int32 < min32) {
2275
2328
  throw Exception.Overflow
2276
2329
  }
@@ -2384,6 +2437,7 @@ provide let coerceNumberToInt64 = (number: Number) => {
2384
2437
  Memory.incRef(x)
2385
2438
  newInt64(coerceNumberToWasmI64(WasmI32.toGrain(x): Number))
2386
2439
  }
2440
+ ignore(number)
2387
2441
  WasmI32.toGrain(result): Int64
2388
2442
  }
2389
2443
 
@@ -2430,6 +2484,7 @@ provide let coerceNumberToRational = (number: Number) => {
2430
2484
  throw Exception.NumberNotRational
2431
2485
  }
2432
2486
  }
2487
+ ignore(number)
2433
2488
  WasmI32.toGrain(result): Rational
2434
2489
  }
2435
2490
 
@@ -2470,6 +2525,7 @@ provide let coerceNumberToFloat64 = (number: Number) => {
2470
2525
  Memory.incRef(x)
2471
2526
  newFloat64(coerceNumberToWasmF64(WasmI32.toGrain(x): Number))
2472
2527
  }
2528
+ ignore(number)
2473
2529
  WasmI32.toGrain(result): Float64
2474
2530
  }
2475
2531
 
@@ -2541,6 +2597,7 @@ provide let coerceUint16ToNumber = (value: Uint16) => {
2541
2597
  provide let coerceInt32ToNumber = (value: Int32) => {
2542
2598
  let x = WasmI32.load(WasmI32.fromGrain(value), 4n)
2543
2599
  let result = reducedInteger(WasmI64.extendI32S(x))
2600
+ ignore(value)
2544
2601
  WasmI32.toGrain(result): Number
2545
2602
  }
2546
2603
 
@@ -2554,8 +2611,10 @@ provide let coerceInt32ToNumber = (value: Int32) => {
2554
2611
  */
2555
2612
  @unsafe
2556
2613
  provide let coerceInt64ToNumber = (value: Int64) => {
2557
- WasmI32.toGrain(reducedInteger(boxedInt64Number(WasmI32.fromGrain(value)))):
2558
- Number
2614
+ let x = WasmI32.fromGrain(value)
2615
+ let result = WasmI32.toGrain(reducedInteger(boxedInt64Number(x))): Number
2616
+ ignore(value)
2617
+ result
2559
2618
  }
2560
2619
 
2561
2620
  /**
@@ -2572,7 +2631,9 @@ provide let coerceBigIntToNumber = (num: BigInt) => {
2572
2631
  // reducedBigInteger assumes that the bigint is dead,
2573
2632
  // but in our case, it is not
2574
2633
  Memory.incRef(x)
2575
- WasmI32.toGrain(reducedBigInteger(x)): Number
2634
+ let result = WasmI32.toGrain(reducedBigInteger(x)): Number
2635
+ ignore(num)
2636
+ result
2576
2637
  }
2577
2638
 
2578
2639
  /**
@@ -2594,7 +2655,9 @@ provide let coerceRationalToNumber = (rational: Rational) => {
2594
2655
  }
2595
2656
  // incRef x to reuse it via WasmI32.toGrain
2596
2657
  Memory.incRef(x)
2597
- WasmI32.toGrain(x): Number
2658
+ let result = WasmI32.toGrain(x): Number
2659
+ ignore(rational)
2660
+ result
2598
2661
  }
2599
2662
 
2600
2663
  /**
@@ -2609,7 +2672,9 @@ provide let coerceRationalToNumber = (rational: Rational) => {
2609
2672
  provide let coerceFloat32ToNumber = (float: Float32) => {
2610
2673
  let x = WasmF32.load(WasmI32.fromGrain(float), 4n)
2611
2674
  let x64 = WasmF64.promoteF32(x)
2612
- WasmI32.toGrain(newFloat64(x64)): Number
2675
+ let result = WasmI32.toGrain(newFloat64(x64)): Number
2676
+ ignore(float)
2677
+ result
2613
2678
  }
2614
2679
 
2615
2680
  /**
@@ -2625,7 +2690,9 @@ provide let coerceFloat64ToNumber = (float: Float64) => {
2625
2690
  let x = WasmI32.fromGrain(float)
2626
2691
  // incRef x to reuse it via WasmI32.toGrain
2627
2692
  Memory.incRef(x)
2628
- WasmI32.toGrain(x): Number
2693
+ let result = WasmI32.toGrain(x): Number
2694
+ ignore(float)
2695
+ result
2629
2696
  }
2630
2697
 
2631
2698
  /// USER-EXPOSED CONVERSION FUNCTIONS
@@ -2666,7 +2733,10 @@ let convertInexactToExactHelp = x => {
2666
2733
 
2667
2734
  @unsafe
2668
2735
  provide let convertInexactToExact = (x: Number) => {
2669
- WasmI32.toGrain(convertInexactToExactHelp(WasmI32.fromGrain(x))): Number
2736
+ let xVal = WasmI32.fromGrain(x)
2737
+ let result = WasmI32.toGrain(convertInexactToExactHelp(xVal)): Number
2738
+ ignore(x)
2739
+ result
2670
2740
  }
2671
2741
 
2672
2742
  /**
@@ -2751,7 +2821,10 @@ provide let (/) = (num1: Number, num2: Number) => {
2751
2821
  provide let (%) = (num1: Number, num2: Number) => {
2752
2822
  let x = WasmI32.fromGrain(num1)
2753
2823
  let y = WasmI32.fromGrain(num2)
2754
- WasmI32.toGrain(numberMod(x, y)): Number
2824
+ let result = WasmI32.toGrain(numberMod(x, y)): Number
2825
+ ignore(num1)
2826
+ ignore(num2)
2827
+ result
2755
2828
  }
2756
2829
 
2757
2830
  // inc/dec
@@ -2782,8 +2855,10 @@ provide let decr = value => {
2782
2855
 
2783
2856
  @unsafe
2784
2857
  provide let isBigInt = x => {
2785
- let x = WasmI32.fromGrain(x)
2786
- isBigInt(x)
2858
+ let xVal = WasmI32.fromGrain(x)
2859
+ let result = isBigInt(xVal)
2860
+ ignore(x)
2861
+ result
2787
2862
  }
2788
2863
 
2789
2864
  // Scalbn is based on https://git.musl-libc.org/cgit/musl/tree/src/math/scalbn.c
@@ -2874,13 +2949,13 @@ provide let (**) = (base, power) => {
2874
2949
  let (!=) = (x, y) => !numberEq(x, y)
2875
2950
  let basePtr = WasmI32.fromGrain(base)
2876
2951
  let powerPtr = WasmI32.fromGrain(power)
2877
- if (base == 1 && power != 0) {
2878
- return 1
2952
+ let result = if (base == 1 && power != 0) {
2953
+ 1
2879
2954
  } else if (isInteger(basePtr) && isInteger(powerPtr)) {
2880
2955
  if (power < 0)
2881
- return expBySquaring(1, 1 / base, power * -1)
2956
+ expBySquaring(1, 1 / base, power * -1)
2882
2957
  else
2883
- return expBySquaring(1, base, power)
2958
+ expBySquaring(1, base, power)
2884
2959
  } else if (isRational(basePtr) && isInteger(powerPtr)) {
2885
2960
  // Apply expBySquaring to numerator and denominator
2886
2961
  let numerator = WasmI32.fromGrain(base)
@@ -2899,7 +2974,7 @@ provide let (**) = (base, power) => {
2899
2974
  expBySquaring(1, 1 / denominator, power * -1)
2900
2975
  else
2901
2976
  expBySquaring(1, denominator, power)
2902
- return numerator / denominator
2977
+ numerator / denominator
2903
2978
  } else {
2904
2979
  // Based on https://git.musl-libc.org/cgit/musl/tree/src/math/pow.c
2905
2980
  use WasmF64.{ (==), (!=), (<=), (/), (*), (+) }
@@ -3248,6 +3323,12 @@ provide let (**) = (base, power) => {
3248
3323
  WasmI64.reinterpretF64(z) & 0xFFFFFFFFN | WasmI64.extendI32S(j) << 32N
3249
3324
  )
3250
3325
  }
3251
- return WasmI32.toGrain(newFloat64(s * z)): Number
3326
+ WasmI32.toGrain(newFloat64(s * z)): Number
3252
3327
  }
3328
+
3329
+ ignore(base)
3330
+ ignore(power)
3331
+
3332
+ // This return is never hit but is here because we need to hold on to references
3333
+ return result
3253
3334
  }