From 87be54418f0568e7f8a3bd655e44d6e0cbb97cfc Mon Sep 17 00:00:00 2001 From: Mark Canlas Date: Sun, 20 Nov 2022 02:16:26 -0500 Subject: [PATCH] drop names --- .../com/htmlism/scratchpad/Encoded.scala | 2 +- .../scala/com/htmlism/scratchpad/Load.scala | 2 +- .../com/htmlism/scratchpad/Loadable.scala | 2 +- .../com/htmlism/scratchpad/Register.scala | 37 ++++++++++++++++--- .../com/htmlism/scratchpad/ScratchPad.scala | 6 +-- .../scala/com/htmlism/scratchpad/Store.scala | 2 +- .../htmlism/scratchpad/syntax/package.scala | 8 ++-- .../scratchpad/ComplicatedResourceSuite.scala | 7 ++-- 8 files changed, 46 insertions(+), 20 deletions(-) diff --git a/scratchpad/src/main/scala/com/htmlism/scratchpad/Encoded.scala b/scratchpad/src/main/scala/com/htmlism/scratchpad/Encoded.scala index b859df5..aaceab1 100644 --- a/scratchpad/src/main/scala/com/htmlism/scratchpad/Encoded.scala +++ b/scratchpad/src/main/scala/com/htmlism/scratchpad/Encoded.scala @@ -4,6 +4,6 @@ object Encoded: trait Byte[A] object Byte: - given intByte: Encoded.Byte[Int] with {} + given Encoded.Byte[Int] with {} trait Word[A] diff --git a/scratchpad/src/main/scala/com/htmlism/scratchpad/Load.scala b/scratchpad/src/main/scala/com/htmlism/scratchpad/Load.scala index c9264ae..5019796 100644 --- a/scratchpad/src/main/scala/com/htmlism/scratchpad/Load.scala +++ b/scratchpad/src/main/scala/com/htmlism/scratchpad/Load.scala @@ -12,4 +12,4 @@ object Load: case class Const[R, A: Encoded.Byte](x: A)(using R: Register[R]) extends Asm1[R]: def xs: List[String] = - List("LD" + R.name) + List(R.load) diff --git a/scratchpad/src/main/scala/com/htmlism/scratchpad/Loadable.scala b/scratchpad/src/main/scala/com/htmlism/scratchpad/Loadable.scala index 786cf50..3a9a8ac 100644 --- a/scratchpad/src/main/scala/com/htmlism/scratchpad/Loadable.scala +++ b/scratchpad/src/main/scala/com/htmlism/scratchpad/Loadable.scala @@ -4,6 +4,6 @@ trait Loadable[A]: def show(x: A): String object Loadable: - given intLoadable: Loadable[Int] with + given Loadable[Int] with def show(x: Int): String = x.toString diff --git a/scratchpad/src/main/scala/com/htmlism/scratchpad/Register.scala b/scratchpad/src/main/scala/com/htmlism/scratchpad/Register.scala index 648c4be..530dc98 100644 --- a/scratchpad/src/main/scala/com/htmlism/scratchpad/Register.scala +++ b/scratchpad/src/main/scala/com/htmlism/scratchpad/Register.scala @@ -5,21 +5,46 @@ package com.htmlism.scratchpad sealed trait Register[A]: def name: String + def load: String + + def store: String + object Register: object A: - given registerA: Register[A] with - def name: String = "A" + given Register[A] with + def name: String = + "A" + + def load: String = + "LDA" + + def store: String = + "STA" class A object X: - given registerX: Register[X] with - def name: String = "X" + given Register[X] with + def name: String = + "X" + + def load: String = + "LDX" + + def store: String = + "STX" class X object Y: - given registerY: Register[Y] with - def name: String = "Y" + given Register[Y] with + def name: String = + "Y" + + def load: String = + "LDY" + + def store: String = + "STY" class Y diff --git a/scratchpad/src/main/scala/com/htmlism/scratchpad/ScratchPad.scala b/scratchpad/src/main/scala/com/htmlism/scratchpad/ScratchPad.scala index 2dc061e..169bb01 100644 --- a/scratchpad/src/main/scala/com/htmlism/scratchpad/ScratchPad.scala +++ b/scratchpad/src/main/scala/com/htmlism/scratchpad/ScratchPad.scala @@ -39,20 +39,20 @@ object ScratchPad: class Accumulator object Accumulator extends Accumulator: - given registerA: Reg[Accumulator] with + given Reg[Accumulator] with def hello: Boolean = true class RegisterX object RegisterX: - given registerX: Reg[RegisterX] with + given Reg[RegisterX] with def hello: Boolean = true class RegisterY object RegisterY: - given registerY: Reg[RegisterY] with + given Reg[RegisterY] with def hello: Boolean = true diff --git a/scratchpad/src/main/scala/com/htmlism/scratchpad/Store.scala b/scratchpad/src/main/scala/com/htmlism/scratchpad/Store.scala index 75a426b..4ef95cf 100644 --- a/scratchpad/src/main/scala/com/htmlism/scratchpad/Store.scala +++ b/scratchpad/src/main/scala/com/htmlism/scratchpad/Store.scala @@ -12,4 +12,4 @@ object Store: case class Byte[R, A](dest: WriteLease.ByteAddress[A])(using R: Register[R]) extends Asm2[R, A]: def xs: List[String] = - List("ST" + R.name) + List(R.store) diff --git a/scratchpad/src/main/scala/com/htmlism/scratchpad/syntax/package.scala b/scratchpad/src/main/scala/com/htmlism/scratchpad/syntax/package.scala index 01e5a24..0d9c2f0 100644 --- a/scratchpad/src/main/scala/com/htmlism/scratchpad/syntax/package.scala +++ b/scratchpad/src/main/scala/com/htmlism/scratchpad/syntax/package.scala @@ -14,13 +14,13 @@ package object syntax: summon[Loadable[Addr]].show(x) val register = - summon[Register[R]].name + summon[Register[R]] val loadInstruction = - "LD" + register // TODO load action needs to interact with encoder + register.load // TODO load action needs to interact with encoder val storeInstruction = - "ST" + register // TODO store action needs to interact with encoder + register.store // TODO store action needs to interact with encoder val first = s"$loadInstruction $literal" @@ -29,6 +29,6 @@ package object syntax: s"$storeInstruction ${reg.n.toString}" val desc = - s"${reg.alias} = $literal, via $register" + s"${reg.alias} = $literal, via ${register.name}" s"$first $second ; $desc" diff --git a/scratchpad/src/test/scala/com/htmlism/scratchpad/ComplicatedResourceSuite.scala b/scratchpad/src/test/scala/com/htmlism/scratchpad/ComplicatedResourceSuite.scala index ff5e280..0bc3bec 100644 --- a/scratchpad/src/test/scala/com/htmlism/scratchpad/ComplicatedResourceSuite.scala +++ b/scratchpad/src/test/scala/com/htmlism/scratchpad/ComplicatedResourceSuite.scala @@ -15,17 +15,18 @@ object ComplicatedResourceSuite extends FunSuite: class PlayerOne extends Player[PlayerOne](40) object PlayerOne extends PlayerOne: - given write: WriteLease[PlayerOne] with + given WriteLease[PlayerOne] with def canon: PlayerOne = PlayerOne class PlayerTwo extends Player[PlayerTwo](80) object PlayerTwo extends PlayerTwo: - given write: WriteLease[PlayerTwo] with + given WriteLease[PlayerTwo] with def canon: PlayerTwo = PlayerTwo test("use write lease") { - expect.eql(List("LDA", "STA"), PlayerOne.setHead(0)(using PlayerOne.write).xs) + // TODO actually this doesn't make sense. the lease shouldn't be canonical/globally available. only when lease is given... + expect.eql(List("LDA", "STA"), PlayerOne.setHead(0).xs) }