package core import ( "fmt" "git.akyoto.dev/cli/q/src/asm" "git.akyoto.dev/cli/q/src/ast" ) // CompileLoop compiles a loop instruction. func (f *Function) CompileLoop(loop *ast.Loop) error { for _, register := range f.CPU.Input { f.SaveRegister(register) } f.count.loop++ label := fmt.Sprintf("%s_loop_%d", f.UniqueName, f.count.loop) f.AddLabel(label) scope := f.PushScope(loop.Body, f.File.Bytes) scope.InLoop = true err := f.CompileAST(loop.Body) f.Jump(asm.JUMP, label) f.PopScope() return err }