Added scope package
This commit is contained in:
@ -1,52 +1,32 @@
|
||||
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"
|
||||
)
|
||||
|
||||
// Function represents the smallest unit of code.
|
||||
type Function struct {
|
||||
Name string
|
||||
File *fs.File
|
||||
Body token.List
|
||||
State
|
||||
scope.Stack
|
||||
Name string
|
||||
File *fs.File
|
||||
Body token.List
|
||||
Assembler asm.Assembler
|
||||
Functions map[string]*Function
|
||||
Err error
|
||||
registerHistory []uint64
|
||||
finished chan struct{}
|
||||
cpu cpu.CPU
|
||||
count counter
|
||||
}
|
||||
|
||||
// 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
|
||||
// counter stores how often a certain statement appeared so we can generate a unique label from it.
|
||||
type counter struct {
|
||||
branch int
|
||||
data int
|
||||
loop int
|
||||
subBranch int
|
||||
}
|
||||
|
Reference in New Issue
Block a user