This commit is contained in:
parent
f7be86a3d9
commit
31c5ed614c
27 changed files with 548 additions and 61 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue