package core import ( "git.akyoto.dev/cli/q/src/build/arch/x64" "git.akyoto.dev/cli/q/src/build/asm" "git.akyoto.dev/cli/q/src/build/cpu" "git.akyoto.dev/cli/q/src/build/fs" "git.akyoto.dev/cli/q/src/build/token" ) // Function represents the smallest unit of code. type Function struct { Name string File *fs.File Body token.List State } // NewFunction creates a new function. func NewFunction(name string, file *fs.File, body token.List) *Function { return &Function{ Name: name, File: file, Body: body, State: State{ Assembler: asm.Assembler{ Instructions: make([]asm.Instruction, 0, 32), }, cpu: cpu.CPU{ All: x64.AllRegisters, Input: x64.CallRegisters, General: x64.GeneralRegisters, Syscall: x64.SyscallRegisters, Output: x64.ReturnValueRegisters, }, scopes: []*Scope{ {variables: map[string]*Variable{}}, }, finished: make(chan struct{}), }, } } // String returns the function name. func (f *Function) String() string { return f.Name } // Wait will block until the compilation finishes. func (f *Function) Wait() { <-f.finished }