@@ -2780,8 +2780,8 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G)
2780
2780
* But must be replaced by the tail-jump-this local variable if there
2781
2781
* is one.
2782
2782
*/
2783
- private def genThis ()(implicit pos : Position ): js.Tree = {
2784
- thisLocalVarName.fold[js.Tree ] {
2783
+ private def genThis ()(implicit pos : Position ): js.VarRef = {
2784
+ thisLocalVarName.fold[js.VarRef ] {
2785
2785
if (isJSFunctionDef(currentClassSym)) {
2786
2786
abort(
2787
2787
" Unexpected `this` reference inside the body of a JS function class: " +
@@ -7359,7 +7359,7 @@ private object GenJSCode {
7359
7359
7360
7360
private abstract class JavalibOpBody {
7361
7361
/** Generates the body of this special method, given references to the receiver and parameters. */
7362
- def generate (receiver : js.Tree , args : List [js.Tree ])(implicit pos : ir.Position ): js.Tree
7362
+ def generate (receiver : js.VarRef , args : List [js.VarRef ])(implicit pos : ir.Position ): js.Tree
7363
7363
}
7364
7364
7365
7365
private object JavalibOpBody {
@@ -7373,35 +7373,51 @@ private object GenJSCode {
7373
7373
7374
7374
/** UnaryOp applying to the `this` parameter. */
7375
7375
final case class ThisUnaryOp (op : js.UnaryOp .Code ) extends JavalibOpBody {
7376
- def generate (receiver : js.Tree , args : List [js.Tree ])(implicit pos : ir.Position ): js.Tree = {
7376
+ def generate (receiver : js.VarRef , args : List [js.VarRef ])(implicit pos : ir.Position ): js.Tree = {
7377
7377
assert(args.isEmpty)
7378
7378
js.UnaryOp (op, receiver)
7379
7379
}
7380
7380
}
7381
7381
7382
7382
/** BinaryOp applying to the `this` parameter and the regular parameter. */
7383
7383
final case class ThisBinaryOp (op : js.BinaryOp .Code , checkNulls : Boolean = false ) extends JavalibOpBody {
7384
- def generate (receiver : js.Tree , args : List [js.Tree ])(implicit pos : ir.Position ): js.Tree = {
7384
+ def generate (receiver : js.VarRef , args : List [js.VarRef ])(implicit pos : ir.Position ): js.Tree = {
7385
7385
val List (rhs) = args : @ unchecked
7386
7386
js.BinaryOp (op, receiver, checkNotNullIf(rhs, checkNulls))
7387
7387
}
7388
7388
}
7389
7389
7390
7390
/** UnaryOp applying to the only regular parameter (`this` is ignored). */
7391
7391
final case class ArgUnaryOp (op : js.UnaryOp .Code , checkNulls : Boolean = false ) extends JavalibOpBody {
7392
- def generate (receiver : js.Tree , args : List [js.Tree ])(implicit pos : ir.Position ): js.Tree = {
7392
+ def generate (receiver : js.VarRef , args : List [js.VarRef ])(implicit pos : ir.Position ): js.Tree = {
7393
7393
val List (arg) = args : @ unchecked
7394
7394
js.UnaryOp (op, checkNotNullIf(arg, checkNulls))
7395
7395
}
7396
7396
}
7397
7397
7398
- /** BinaryOp applying to the two regular paramters (`this` is ignored). */
7398
+ /** BinaryOp applying to the two regular parameters (`this` is ignored). */
7399
7399
final case class ArgBinaryOp (op : js.BinaryOp .Code , checkNulls : Boolean = false ) extends JavalibOpBody {
7400
- def generate (receiver : js.Tree , args : List [js.Tree ])(implicit pos : ir.Position ): js.Tree = {
7400
+ def generate (receiver : js.VarRef , args : List [js.VarRef ])(implicit pos : ir.Position ): js.Tree = {
7401
7401
val List (lhs, rhs) = args : @ unchecked
7402
7402
js.BinaryOp (op, checkNotNullIf(lhs, checkNulls), checkNotNullIf(rhs, checkNulls))
7403
7403
}
7404
7404
}
7405
+
7406
+ /** Body of a `compare` method, with a less-than and an equal operator. */
7407
+ final case class ArgCompareOp (ltOp : js.BinaryOp .Code , eqOp : js.BinaryOp .Code ) extends JavalibOpBody {
7408
+ def generate (receiver : js.VarRef , args : List [js.VarRef ])(implicit pos : ir.Position ): js.Tree = {
7409
+ val List (lhs, rhs) = args : @ unchecked
7410
+ js.If (
7411
+ js.BinaryOp (ltOp, lhs, rhs),
7412
+ js.IntLiteral (- 1 ),
7413
+ js.If (
7414
+ js.BinaryOp (eqOp, lhs, rhs),
7415
+ js.IntLiteral (0 ),
7416
+ js.IntLiteral (1 )
7417
+ )(jstpe.IntType )
7418
+ )(jstpe.IntType )
7419
+ }
7420
+ }
7405
7421
}
7406
7422
7407
7423
/** Methods of the javalib whose body must be replaced by a dedicated
@@ -7425,11 +7441,14 @@ private object GenJSCode {
7425
7441
7426
7442
val byClass : Map [ClassName , Map [MethodName , JavalibOpBody ]] = Map (
7427
7443
jswkn.BoxedIntegerClass .withSuffix(" $" ) -> Map (
7444
+ m(" compareUnsigned" , List (I , I ), I ) -> ArgCompareOp (binop.Int_unsigned_< , binop.Int_== ),
7445
+ m(" toUnsignedLong" , List (I ), J ) -> ArgUnaryOp (unop.UnsignedIntToLong ),
7428
7446
m(" divideUnsigned" , List (I , I ), I ) -> ArgBinaryOp (binop.Int_unsigned_/ ),
7429
7447
m(" remainderUnsigned" , List (I , I ), I ) -> ArgBinaryOp (binop.Int_unsigned_% ),
7430
7448
m(" numberOfLeadingZeros" , List (I ), I ) -> ArgUnaryOp (unop.Int_clz )
7431
7449
),
7432
7450
jswkn.BoxedLongClass .withSuffix(" $" ) -> Map (
7451
+ m(" compareUnsigned" , List (J , J ), I ) -> ArgCompareOp (binop.Long_unsigned_< , binop.Long_== ),
7433
7452
m(" divideUnsigned" , List (J , J ), J ) -> ArgBinaryOp (binop.Long_unsigned_/ ),
7434
7453
m(" remainderUnsigned" , List (J , J ), J ) -> ArgBinaryOp (binop.Long_unsigned_% ),
7435
7454
m(" numberOfLeadingZeros" , List (J ), I ) -> ArgUnaryOp (unop.Long_clz )
0 commit comments