36 lines
854 B
Go
36 lines
854 B
Go
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/scope"
|
|
"git.akyoto.dev/cli/q/src/build/token"
|
|
)
|
|
|
|
// NewFunction creates a new function.
|
|
func NewFunction(name string, file *fs.File, body []token.Token) *Function {
|
|
return &Function{
|
|
Name: name,
|
|
File: file,
|
|
Body: body,
|
|
Assembler: asm.Assembler{
|
|
Instructions: make([]asm.Instruction, 0, 32),
|
|
},
|
|
Stack: scope.Stack{
|
|
Scopes: []*scope.Scope{
|
|
{Variables: map[string]*scope.Variable{}},
|
|
},
|
|
},
|
|
cpu: cpu.CPU{
|
|
All: x64.AllRegisters,
|
|
Input: x64.CallRegisters,
|
|
General: x64.GeneralRegisters,
|
|
Syscall: x64.SyscallRegisters,
|
|
Output: x64.ReturnValueRegisters,
|
|
},
|
|
finished: make(chan struct{}),
|
|
}
|
|
}
|