Added Value type

This commit is contained in:
2025-02-27 14:16:25 +01:00
parent ae6530aadb
commit 9f78733d5d
8 changed files with 65 additions and 34 deletions

View File

@ -58,20 +58,24 @@ func (f *Function) CompileAssignDivision(expr *expression.Expression) error {
defer f.UseVariable(remainderVariable)
}
dividend := right.Children[0]
_, dividendRegister, isTemporary, err := f.Evaluate(dividend)
dividendExpr := right.Children[0]
dividend, isTemporary, err := f.Evaluate(dividendExpr)
if err != nil {
return err
}
if !types.Is(dividend.Type, types.AnyInt) {
return errors.New(&errors.TypeMismatch{Encountered: dividend.Type.Name(), Expected: types.AnyInt.Name()}, f.File, dividendExpr.Token.Position)
}
divisor := right.Children[1]
err = f.Execute(right.Token, dividendRegister, divisor)
err = f.Execute(right.Token, dividend.Register, divisor)
f.RegisterRegister(asm.MOVE, quotientVariable.Register, x86.RAX)
f.RegisterRegister(asm.MOVE, remainderVariable.Register, x86.RDX)
if isTemporary {
f.FreeRegister(dividendRegister)
f.FreeRegister(dividend.Register)
}
return err