2022-12-04 23:36:11 +00:00
|
|
|
package com.htmlism.firepower.core
|
2022-11-20 06:17:07 +00:00
|
|
|
|
|
|
|
import weaver.*
|
|
|
|
object ComplicatedResourceSuite extends FunSuite:
|
2024-01-01 00:08:32 +00:00
|
|
|
class Player[A <: Player[?]](address: Int):
|
2022-11-20 06:17:07 +00:00
|
|
|
def headAddr: Int =
|
|
|
|
address
|
|
|
|
|
2022-11-20 06:59:32 +00:00
|
|
|
def tailAddr: Int =
|
2022-11-20 06:17:07 +00:00
|
|
|
address + 1
|
|
|
|
|
2022-11-20 06:59:32 +00:00
|
|
|
def setHead(x: Int)(using W: WriteLease[A]): Asm2[Register.A, A] =
|
|
|
|
Move.constA(x, W.to(_.headAddr))
|
2022-11-20 06:17:07 +00:00
|
|
|
|
2022-11-20 07:25:19 +00:00
|
|
|
class FastLease[A](x: A) extends WriteLease[A]:
|
|
|
|
def canon: A =
|
|
|
|
x
|
|
|
|
|
2022-11-20 06:17:07 +00:00
|
|
|
class PlayerOne extends Player[PlayerOne](40)
|
|
|
|
|
2022-11-20 07:53:29 +00:00
|
|
|
object PlayerOne extends PlayerOne with GrantsWriteLeases[PlayerOne]:
|
|
|
|
given Companion[PlayerOne] with
|
|
|
|
def canon: PlayerOne =
|
|
|
|
PlayerOne
|
2022-11-20 06:59:32 +00:00
|
|
|
|
2022-11-20 06:17:07 +00:00
|
|
|
class PlayerTwo extends Player[PlayerTwo](80)
|
2022-11-20 06:59:32 +00:00
|
|
|
|
2022-11-20 07:53:29 +00:00
|
|
|
object PlayerTwo extends PlayerTwo with GrantsWriteLeases[PlayerTwo]:
|
|
|
|
given Companion[PlayerTwo] with
|
|
|
|
def canon: PlayerTwo =
|
|
|
|
PlayerTwo
|
2022-11-20 06:59:32 +00:00
|
|
|
|
2023-06-13 18:01:45 +00:00
|
|
|
test("use write lease"):
|
2022-11-20 07:53:29 +00:00
|
|
|
val asm =
|
|
|
|
PlayerOne
|
|
|
|
.withWriteLease { implicit w =>
|
|
|
|
PlayerOne.setHead(23).xs
|
|
|
|
}
|
|
|
|
|
|
|
|
expect.eql(List("LDA 23", "STA 40"), asm)
|