Implemented compilation to SSA form
All checks were successful
/ test (push) Successful in 31s

This commit is contained in:
Eduard Urbach 2025-06-23 00:17:05 +02:00
parent f7be86a3d9
commit 31c5ed614c
Signed by: akyoto
GPG key ID: 49226B848C78F6C8
27 changed files with 548 additions and 61 deletions

View file

@ -1,4 +1,29 @@
package core
import (
"git.urbach.dev/cli/q/src/cpu"
"git.urbach.dev/cli/q/src/token"
)
// Compile turns a function into machine code.
func (f *Function) Compile() {}
func (f *Function) Compile() {
registerCount := 0
for _, input := range f.Input {
f.Identifiers[input.Name] = f.AppendRegister(cpu.Register(registerCount))
registerCount++
if input.TypeTokens[0].Kind == token.ArrayStart {
f.Identifiers[input.Name+".length"] = f.AppendRegister(cpu.Register(registerCount))
registerCount++
}
}
for instr := range f.Body.Instructions {
f.Err = f.CompileInstruction(instr)
if f.Err != nil {
return
}
}
}