Implemented boolean operators

This commit is contained in:
2024-07-08 13:38:44 +02:00
parent ee16774fe7
commit b5bb291e47
9 changed files with 198 additions and 24 deletions

@ -9,16 +9,16 @@ import (
// CompileIf compiles a branch instruction.
func (f *Function) CompileIf(branch *ast.If) error {
startLabel := fmt.Sprintf("%s_if_start_%d", f.Name, f.count.branch)
endLabel := fmt.Sprintf("%s_if_end_%d", f.Name, f.count.branch)
err := f.CompileCondition(branch.Condition, startLabel, endLabel)
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.assembler.Label(asm.LABEL, startLabel)
defer f.assembler.Label(asm.LABEL, endLabel)
f.assembler.Label(asm.LABEL, success)
defer f.assembler.Label(asm.LABEL, fail)
f.count.branch++
return f.CompileAST(branch.Body)
}