Reduced memory usage

This commit is contained in:
2024-07-22 22:54:24 +02:00
parent c027208369
commit eb160afd91
6 changed files with 22 additions and 31 deletions

View File

@ -3,6 +3,7 @@ package core
import (
"git.akyoto.dev/cli/q/src/build/ast"
"git.akyoto.dev/cli/q/src/build/errors"
"git.akyoto.dev/cli/q/src/build/scope"
"git.akyoto.dev/cli/q/src/build/token"
)
@ -20,5 +21,15 @@ func (f *Function) CompileDefinition(node *ast.Define) error {
return errors.New(&errors.UnusedVariable{Name: name}, f.File, node.Name.Position)
}
return f.storeVariableInRegister(name, node.Value, uses)
register := f.CurrentScope().MustFindFree(f.cpu.General)
f.CurrentScope().Reserve(register)
err := f.ExpressionToRegister(node.Value, register)
f.AddVariable(&scope.Variable{
Name: name,
Register: register,
Alive: uses,
})
return err
}