27 lines
536 B
Go
27 lines
536 B
Go
package core
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.akyoto.dev/cli/q/src/build/ast"
|
|
)
|
|
|
|
// CompileIf compiles a branch instruction.
|
|
func (f *Function) CompileIf(branch *ast.If) error {
|
|
f.count.branch++
|
|
success := fmt.Sprintf("%s_if_%d_true", f.Name, f.count.branch)
|
|
fail := fmt.Sprintf("%s_if_%d_false", f.Name, f.count.branch)
|
|
err := f.CompileCondition(branch.Condition, success, fail)
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
f.AddLabel(success)
|
|
f.pushScope(branch.Body)
|
|
err = f.CompileAST(branch.Body)
|
|
f.popScope()
|
|
f.AddLabel(fail)
|
|
return err
|
|
}
|