From 0b7fb76f8af9558eb19a09b515a5bd9cfb8600bd Mon Sep 17 00:00:00 2001 From: Mark Canlas Date: Tue, 17 May 2022 23:13:36 -0400 Subject: [PATCH] wip --- .../scala/com/htmlism/scratchpad/Reg.scala | 8 ++++ .../com/htmlism/scratchpad/ScratchPad.scala | 37 ++++++++++++------- .../htmlism/scratchpad/StatefulRegister.scala | 4 ++ 3 files changed, 36 insertions(+), 13 deletions(-) create mode 100644 scratchpad/src/main/scala/com/htmlism/scratchpad/Reg.scala create mode 100644 scratchpad/src/main/scala/com/htmlism/scratchpad/StatefulRegister.scala diff --git a/scratchpad/src/main/scala/com/htmlism/scratchpad/Reg.scala b/scratchpad/src/main/scala/com/htmlism/scratchpad/Reg.scala new file mode 100644 index 0000000..a8151cf --- /dev/null +++ b/scratchpad/src/main/scala/com/htmlism/scratchpad/Reg.scala @@ -0,0 +1,8 @@ +package com.htmlism.scratchpad + +trait Reg[A]: + def hello: Boolean + +given tuple2reg[A, B](using a: Reg[A], b: Reg[B]): Reg[(A, B)] with + def hello: Boolean = + true diff --git a/scratchpad/src/main/scala/com/htmlism/scratchpad/ScratchPad.scala b/scratchpad/src/main/scala/com/htmlism/scratchpad/ScratchPad.scala index f478325..585bc14 100644 --- a/scratchpad/src/main/scala/com/htmlism/scratchpad/ScratchPad.scala +++ b/scratchpad/src/main/scala/com/htmlism/scratchpad/ScratchPad.scala @@ -17,18 +17,28 @@ object Write: implicit val writeLease: Lease[Write] = new Lease { } -class Reg[A] - object ScratchPad: + def reg[A : Reg]: PartialUsing[A] = + new PartialUsing[A] + + class PartialUsing[A](using a: Reg[A]): + def use[B](f: Reg[A] => B): B = + f(a) + + reg[Accumulator].use { a => + AsmProgram(startA, "") + .widen[RegisterX] + } + trait ReadWrite[A] extends Read[A] with Write[A] - val startA = + lazy val startA = ??? : StatefulRegister[Accumulator, Unknown] - val startX = + lazy val startX = ??? : StatefulRegister[RegisterX, Unknown] - val startY = + lazy val startY = ??? : StatefulRegister[RegisterY, Unknown] (AsmProgram(startA, "") : AsmProgram[Accumulator, Unknown, String]) @@ -45,19 +55,20 @@ object ScratchPad: class Accumulator object Accumulator extends Accumulator: - implicit val registerA: Reg[Accumulator] = - new Reg + given registerA: Reg[Accumulator] with + def hello: Boolean = + true class RegisterX object RegisterX: - implicit val registerX: Reg[RegisterX] = - new Reg + given registerX: Reg[RegisterX] with + def hello: Boolean = + true class RegisterY object RegisterY: - implicit val registerY: Reg[RegisterY] = - new Reg - -trait StatefulRegister[A : Reg, F <: MutationStatus] + given registerY: Reg[RegisterY] with + def hello: Boolean = + true diff --git a/scratchpad/src/main/scala/com/htmlism/scratchpad/StatefulRegister.scala b/scratchpad/src/main/scala/com/htmlism/scratchpad/StatefulRegister.scala new file mode 100644 index 0000000..ead3a62 --- /dev/null +++ b/scratchpad/src/main/scala/com/htmlism/scratchpad/StatefulRegister.scala @@ -0,0 +1,4 @@ +package com.htmlism.scratchpad + + +trait StatefulRegister[A : Reg, F <: MutationStatus]