Implemented boolean operators

This commit is contained in:
Eduard Urbach 2024-07-08 13:38:44 +02:00
parent 13161f5021
commit 1c4d2d4f88
Signed by: eduard
GPG key ID: 49226B848C78F6C8
9 changed files with 198 additions and 24 deletions

View file

@ -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)
}