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