Improved branch code generation
This commit is contained in:
@ -10,13 +10,14 @@ import (
|
||||
// CompileIf compiles a branch instruction.
|
||||
func (f *Function) CompileIf(branch *ast.If) error {
|
||||
condition := branch.Condition
|
||||
tmpRight := f.cpu.Input[1]
|
||||
tmpRight := f.cpu.MustFindFree(f.cpu.General)
|
||||
err := f.ExpressionToRegister(condition.Children[1], tmpRight)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
f.cpu.Use(tmpRight)
|
||||
tmpLeft := f.cpu.Input[0]
|
||||
err = f.ExpressionToRegister(condition.Children[0], tmpLeft)
|
||||
|
||||
@ -25,6 +26,7 @@ func (f *Function) CompileIf(branch *ast.If) error {
|
||||
}
|
||||
|
||||
f.assembler.RegisterRegister(asm.COMPARE, tmpLeft, tmpRight)
|
||||
f.cpu.Free(tmpRight)
|
||||
elseLabel := fmt.Sprintf("%s_if_%d_else", f.Name, f.count.branch)
|
||||
|
||||
switch condition.Token.Text() {
|
||||
|
Reference in New Issue
Block a user