55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
package core
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.akyoto.dev/cli/q/src/build/asm"
|
|
"git.akyoto.dev/cli/q/src/build/cpu"
|
|
"git.akyoto.dev/go/color/ansi"
|
|
)
|
|
|
|
// state is the data structure we embed in each function to preserve compilation state.
|
|
type state struct {
|
|
err error
|
|
variables map[string]*Variable
|
|
functions map[string]*Function
|
|
finished chan struct{}
|
|
assembler asm.Assembler
|
|
cpu cpu.CPU
|
|
count counter
|
|
}
|
|
|
|
// counter stores how often a certain statement appeared so we can generate a unique label from it.
|
|
type counter struct {
|
|
loop int
|
|
}
|
|
|
|
// PrintInstructions shows the assembly instructions.
|
|
func (s *state) PrintInstructions() {
|
|
ansi.Dim.Println("╭────────────────────────────────────────────────╮")
|
|
|
|
for _, x := range s.assembler.Instructions {
|
|
ansi.Dim.Print("│ ")
|
|
|
|
switch x.Mnemonic {
|
|
case asm.LABEL:
|
|
ansi.Yellow.Printf("%-46s", x.Data.String()+":")
|
|
|
|
case asm.COMMENT:
|
|
ansi.Dim.Printf("%-46s", x.Data.String())
|
|
|
|
default:
|
|
ansi.Green.Printf("%-8s", x.Mnemonic.String())
|
|
|
|
if x.Data != nil {
|
|
fmt.Printf("%-38s", x.Data.String())
|
|
} else {
|
|
fmt.Printf("%-38s", "")
|
|
}
|
|
}
|
|
|
|
ansi.Dim.Print(" │\n")
|
|
}
|
|
|
|
ansi.Dim.Println("╰────────────────────────────────────────────────╯")
|
|
}
|