Simplified file structure

This commit is contained in:
2024-08-07 19:39:10 +02:00
parent 1b13539b22
commit 66569446b1
219 changed files with 453 additions and 457 deletions

View File

@ -0,0 +1,43 @@
package core
import (
"git.akyoto.dev/cli/q/src/arch/x64"
"git.akyoto.dev/cli/q/src/asm"
"git.akyoto.dev/cli/q/src/ast"
"git.akyoto.dev/cli/q/src/errors"
)
// CompileAssignDivision compiles an assign statement that has quotient and remainder on the left side and division on the right.
func (f *Function) CompileAssignDivision(node *ast.Assign) error {
left := node.Expression.Children[0]
right := node.Expression.Children[1]
quotient := left.Children[0]
name := quotient.Token.Text(f.File.Bytes)
quotientVariable := f.VariableByName(name)
if quotientVariable == nil {
return errors.New(&errors.UnknownIdentifier{Name: name}, f.File, quotient.Token.Position)
}
remainder := left.Children[1]
name = remainder.Token.Text(f.File.Bytes)
remainderVariable := f.VariableByName(name)
if remainderVariable == nil {
return errors.New(&errors.UnknownIdentifier{Name: name}, f.File, remainder.Token.Position)
}
dividend := right.Children[0]
_, dividendRegister, err := f.Evaluate(dividend)
if err != nil {
return err
}
divisor := right.Children[1]
err = f.Execute(right.Token, dividendRegister, divisor)
f.RegisterRegister(asm.MOVE, quotientVariable.Register, x64.RAX)
f.RegisterRegister(asm.MOVE, remainderVariable.Register, x64.RDX)
return err
}