Reordered counters
This commit is contained in:
parent
24d3e8f2be
commit
448af0707a
@ -11,8 +11,8 @@ import (
|
||||
func (f *Function) CompileCondition(condition *expression.Expression, successLabel string, failLabel string) error {
|
||||
switch condition.Token.Text() {
|
||||
case "||":
|
||||
leftFailLabel := fmt.Sprintf("%s_false_%d", f.Name, f.count.subBranch)
|
||||
f.count.subBranch++
|
||||
leftFailLabel := fmt.Sprintf("%s_false_%d", f.Name, f.count.subBranch)
|
||||
|
||||
// Left
|
||||
left := condition.Children[0]
|
||||
@ -38,8 +38,8 @@ func (f *Function) CompileCondition(condition *expression.Expression, successLab
|
||||
return err
|
||||
|
||||
case "&&":
|
||||
leftSuccessLabel := fmt.Sprintf("%s_true_%d", f.Name, f.count.subBranch)
|
||||
f.count.subBranch++
|
||||
leftSuccessLabel := fmt.Sprintf("%s_true_%d", f.Name, f.count.subBranch)
|
||||
|
||||
// Left
|
||||
left := condition.Children[0]
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
|
||||
// CompileIf compiles a branch instruction.
|
||||
func (f *Function) CompileIf(branch *ast.If) error {
|
||||
f.count.branch++
|
||||
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)
|
||||
@ -16,7 +17,6 @@ func (f *Function) CompileIf(branch *ast.If) error {
|
||||
return err
|
||||
}
|
||||
|
||||
f.count.branch++
|
||||
f.AddLabel(success)
|
||||
f.pushScope()
|
||||
err = f.CompileAST(branch.Body)
|
||||
|
@ -9,9 +9,12 @@ import (
|
||||
|
||||
// CompileLoop compiles a loop instruction.
|
||||
func (f *Function) CompileLoop(loop *ast.Loop) error {
|
||||
f.count.loop++
|
||||
label := fmt.Sprintf("%s_loop_%d", f.Name, f.count.loop)
|
||||
f.AddLabel(label)
|
||||
defer f.Jump(asm.JUMP, label)
|
||||
f.count.loop++
|
||||
return f.CompileAST(loop.Body)
|
||||
f.pushScope()
|
||||
err := f.CompileAST(loop.Body)
|
||||
f.popScope()
|
||||
f.Jump(asm.JUMP, label)
|
||||
return err
|
||||
}
|
||||
|
@ -38,11 +38,11 @@ func (f *Function) TokenToRegister(t token.Token, register cpu.Register) error {
|
||||
return nil
|
||||
|
||||
case token.String:
|
||||
value := t.Text()[1 : len(t.Bytes)-1]
|
||||
f.count.data++
|
||||
label := fmt.Sprintf("%s_data_%d", f.Name, f.count.data)
|
||||
value := t.Text()[1 : len(t.Bytes)-1]
|
||||
f.assembler.Data[label] = []byte(value)
|
||||
f.RegisterLabel(asm.MOVE, register, label)
|
||||
f.count.data++
|
||||
return nil
|
||||
|
||||
default:
|
||||
|
Loading…
Reference in New Issue
Block a user