Refactored code structure
This commit is contained in:
parent
9e52e2dd1c
commit
fd6e874b44
54 changed files with 583 additions and 450 deletions
58
src/build/core/state.go
Normal file
58
src/build/core/state.go
Normal file
|
@ -0,0 +1,58 @@
|
|||
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
|
||||
definitions map[string]*Definition
|
||||
variables map[string]*Variable
|
||||
functions map[string]*Function
|
||||
finished chan struct{}
|
||||
assembler asm.Assembler
|
||||
cpu cpu.CPU
|
||||
count counter
|
||||
sideEffects int
|
||||
}
|
||||
|
||||
// counter stores how often a certain statement appeared so we can generate a unique label from it.
|
||||
type counter struct {
|
||||
loop int
|
||||
tmps 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("╰────────────────────────────────────────────────╯")
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue