Added missing register deallocation
This commit is contained in:
parent
e62eaba6e6
commit
fb40059113
@ -42,13 +42,17 @@ func (f *Function) CompileAssignArray(node *ast.Assign) error {
|
||||
|
||||
memory.Offset = byte(offset)
|
||||
} else {
|
||||
_, indexRegister, err := f.Evaluate(index)
|
||||
_, indexRegister, isTemporary, err := f.Evaluate(index)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
memory.OffsetRegister = indexRegister
|
||||
|
||||
if isTemporary {
|
||||
defer f.FreeRegister(indexRegister)
|
||||
}
|
||||
}
|
||||
|
||||
_, err := f.ExpressionToMemory(right, memory)
|
||||
|
@ -29,7 +29,7 @@ func (f *Function) CompileAssignDivision(node *ast.Assign) error {
|
||||
}
|
||||
|
||||
dividend := right.Children[0]
|
||||
_, dividendRegister, err := f.Evaluate(dividend)
|
||||
_, dividendRegister, isTemporary, err := f.Evaluate(dividend)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
@ -39,5 +39,10 @@ func (f *Function) CompileAssignDivision(node *ast.Assign) error {
|
||||
err = f.Execute(right.Token, dividendRegister, divisor)
|
||||
f.RegisterRegister(asm.MOVE, quotientVariable.Register, x64.RAX)
|
||||
f.RegisterRegister(asm.MOVE, remainderVariable.Register, x64.RDX)
|
||||
|
||||
if isTemporary {
|
||||
f.FreeRegister(dividendRegister)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
@ -8,18 +8,18 @@ import (
|
||||
)
|
||||
|
||||
// Evaluate evaluates an expression and returns a register that contains the value of the expression.
|
||||
func (f *Function) Evaluate(expr *expression.Expression) (*types.Type, cpu.Register, error) {
|
||||
func (f *Function) Evaluate(expr *expression.Expression) (*types.Type, cpu.Register, bool, error) {
|
||||
if expr.Token.Kind == token.Identifier {
|
||||
name := expr.Token.Text(f.File.Bytes)
|
||||
variable := f.VariableByName(name)
|
||||
|
||||
if variable.Alive == 1 {
|
||||
f.UseVariable(variable)
|
||||
return variable.Type, variable.Register, nil
|
||||
return variable.Type, variable.Register, false, nil
|
||||
}
|
||||
}
|
||||
|
||||
tmp := f.NewRegister()
|
||||
typ, err := f.ExpressionToRegister(expr, tmp)
|
||||
return typ, tmp, err
|
||||
return typ, tmp, true, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user