Fixed missing register move in if statements
This commit is contained in:
@ -1,8 +1,10 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"git.akyoto.dev/cli/q/src/asm"
|
||||
"git.akyoto.dev/cli/q/src/ast"
|
||||
"git.akyoto.dev/cli/q/src/errors"
|
||||
"git.akyoto.dev/cli/q/src/expression"
|
||||
"git.akyoto.dev/cli/q/src/token"
|
||||
)
|
||||
|
||||
@ -32,5 +34,28 @@ func (f *Function) CompileAssign(node *ast.Assign) error {
|
||||
return f.CompileAssignDivision(node)
|
||||
}
|
||||
|
||||
return errors.New(errors.NotImplemented, f.File, left.Token.Position)
|
||||
if !ast.IsFunctionCall(right) {
|
||||
return errors.New(errors.NotImplemented, f.File, node.Expression.Token.Position)
|
||||
}
|
||||
|
||||
count := 0
|
||||
_, err := f.CompileCall(right)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return left.EachLeaf(func(leaf *expression.Expression) error {
|
||||
name := leaf.Token.Text(f.File.Bytes)
|
||||
variable := f.VariableByName(name)
|
||||
|
||||
if variable == nil {
|
||||
return errors.New(&errors.UnknownIdentifier{Name: name}, f.File, left.Token.Position)
|
||||
}
|
||||
|
||||
f.RegisterRegister(asm.MOVE, variable.Register, f.CPU.Output[count])
|
||||
f.UseVariable(variable)
|
||||
count++
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
@ -9,6 +9,10 @@ import (
|
||||
|
||||
// CompileIf compiles a branch instruction.
|
||||
func (f *Function) CompileIf(branch *ast.If) error {
|
||||
for _, register := range f.CPU.Input {
|
||||
f.SaveRegister(register)
|
||||
}
|
||||
|
||||
f.count.branch++
|
||||
|
||||
var (
|
||||
|
Reference in New Issue
Block a user