Skip to content

Instantly share code, notes, and snippets.

@azolotko
Last active April 26, 2025 09:59
Show Gist options
  • Select an option

  • Save azolotko/ef32811f8154476067f751bbbd6d8f41 to your computer and use it in GitHub Desktop.

Select an option

Save azolotko/ef32811f8154476067f751bbbd6d8f41 to your computer and use it in GitHub Desktop.
package td4
import weaver.SimpleIOSuite
import cats.syntax.applicative.*
import cats.syntax.flatMap.*
import td4.free.*
import td4.Register.*
object TD4Suite extends SimpleIOSuite:
pureTest("compiler"):
val program: Asm =
mov(A, 15: Byte) >>
block { loop =>
mov(B, A) >>
out(B) >>
add(A, nibble(-1)) >>
jz(loop.exit) >>
jmp(loop.entry) >>
mov(A, 0: Byte).replicateA_(8)
} >>
mov(B, A) >>
out(B)
val compiled = compile(program)
val expected = cats.data.Chain(63, 64, -112, 15, -18, -15, 48, 48, 48, 48, 48, 48, 48, 48, 64, -112)
expect(compiled == expected)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment