q/src/core/NewFunction.go

38 lines
973 B
Go

package core
import (
"git.akyoto.dev/cli/q/src/asm"
"git.akyoto.dev/cli/q/src/cpu"
"git.akyoto.dev/cli/q/src/fs"
"git.akyoto.dev/cli/q/src/register"
"git.akyoto.dev/cli/q/src/scope"
"git.akyoto.dev/cli/q/src/token"
"git.akyoto.dev/cli/q/src/x64"
)
// NewFunction creates a new function.
func NewFunction(pkg string, name string, file *fs.File, body []token.Token) *Function {
return &Function{
Package: pkg,
Name: name,
UniqueName: pkg + "." + name,
File: file,
Body: body,
Machine: register.Machine{
Assembler: asm.Assembler{
Instructions: make([]asm.Instruction, 0, 8),
},
Stack: scope.Stack{
Scopes: []*scope.Scope{{}},
},
CPU: cpu.CPU{
All: x64.AllRegisters,
General: x64.GeneralRegisters,
Input: x64.InputRegisters,
Output: x64.OutputRegisters,
SyscallInput: x64.SyscallInputRegisters,
SyscallOutput: x64.SyscallOutputRegisters,
},
},
}
}