// buildFunction compiles the given function. func (a *assembler) buildFunction(f *parser.Function) (err error) { nodes := f.Children() name := nodes[0].(*parser.Label) a.debug.SetFunctionStart(cpu.Word(len(a.code)), f.Line(), name.Data) for i := range nodes { switch tt := nodes[i].(type) { case *parser.Comment: /* ignore */ case *parser.Label: a.labels[tt.Data] = cpu.Word(len(a.code)) case *parser.Instruction: err = a.buildInstruction(tt.Children()) default: err = NewBuildError( a.ast.Files[tt.File()], tt.Line(), tt.Col(), "Unexpected node %T. Want Comment, Label, Instruction.", tt, ) } if err != nil { return } } a.debug.SetFunctionEnd(cpu.Word(len(a.code)), nodes[len(nodes)-1].Line()) return }