q/src/core/Compile.go
Eduard Urbach 3301cf5542
All checks were successful
/ test (push) Successful in 15s
Improved ssa compiler
2025-07-02 16:55:24 +02:00

39 lines
No EOL
643 B
Go

package core
import "git.urbach.dev/cli/q/src/types"
// Compile turns a function into machine code.
func (f *Function) Compile() {
offset := 0
for i, input := range f.Input {
if input.Name == "_" {
continue
}
input.Index = uint8(offset + i)
f.Append(input)
f.Identifiers[input.Name] = input
structure, isStruct := input.Typ.(*types.Struct)
if isStruct {
offset += len(structure.Fields) - 1
}
}
for instr := range f.Body.Instructions {
f.Err = f.CompileInstruction(instr)
if f.Err != nil {
return
}
}
f.Err = f.CheckDeadCode()
if f.Err != nil {
return
}
f.GenerateAssembly(f.IR, f.IsLeaf())
}