Added more tests

This commit is contained in:
2024-07-07 17:13:22 +02:00
parent 23b4e6442d
commit 9f341a6146
7 changed files with 157 additions and 13 deletions

View File

@ -9,25 +9,15 @@ import (
// CompileIf compiles a branch instruction.
func (f *Function) CompileIf(branch *ast.If) error {
condition := branch.Condition
tmp := f.cpu.MustFindFree(f.cpu.General)
err := f.ExpressionToRegister(condition.Children[0], tmp)
err := f.Evaluate(branch.Condition)
if err != nil {
return err
}
f.cpu.Use(tmp)
err = f.Execute(condition.Token, tmp, condition.Children[1])
if err != nil {
return err
}
f.cpu.Free(tmp)
endLabel := fmt.Sprintf("%s_end_if_%d", f.Name, f.count.branch)
switch condition.Token.Text() {
switch branch.Condition.Token.Text() {
case "==":
f.assembler.Label(asm.JNE, endLabel)
case "!=":