Added more tests

This commit is contained in:
Eduard Urbach 2024-07-07 17:13:22 +02:00
parent b5efc533ea
commit 78ae050d18
Signed by: eduard
GPG key ID: 49226B848C78F6C8
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 "!=":