Implemented number output
This commit is contained in:
parent
e4f041be41
commit
8b1af4bea7
12 changed files with 185 additions and 46 deletions
40
src/build/core/CompileAssignDivision.go
Normal file
40
src/build/core/CompileAssignDivision.go
Normal file
|
@ -0,0 +1,40 @@
|
|||
package core
|
||||
|
||||
import (
|
||||
"git.akyoto.dev/cli/q/src/build/arch/x64"
|
||||
"git.akyoto.dev/cli/q/src/build/asm"
|
||||
"git.akyoto.dev/cli/q/src/build/ast"
|
||||
"git.akyoto.dev/cli/q/src/build/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]
|
||||
name = dividend.Token.Text(f.File.Bytes)
|
||||
dividendVariable := f.VariableByName(name)
|
||||
|
||||
divisor := right.Children[1]
|
||||
err := f.Execute(right.Token, dividendVariable.Register, divisor)
|
||||
f.RegisterRegister(asm.MOVE, quotientVariable.Register, x64.RAX)
|
||||
f.RegisterRegister(asm.MOVE, remainderVariable.Register, x64.RDX)
|
||||
return err
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue