Added more tests
This commit is contained in:
@ -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 "!=":
|
||||
|
Reference in New Issue
Block a user