Reduced memory usage

This commit is contained in:
Eduard Urbach 2024-07-21 15:45:49 +02:00
parent 04ba68a075
commit 3ea2f280d9
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
2 changed files with 11 additions and 8 deletions

View File

@ -11,8 +11,13 @@ func (f *Function) AddVariable(variable *scope.Variable) {
f.Comment("%s = %s (%d uses)", variable.Name, variable.Register, variable.Alive)
}
scope := f.CurrentScope()
variable.Scope = scope
scope.Variables[variable.Name] = variable
scope.Use(variable.Register)
s := f.CurrentScope()
variable.Scope = s
if s.Variables == nil {
s.Variables = map[string]*scope.Variable{}
}
s.Variables[variable.Name] = variable
s.Use(variable.Register)
}

View File

@ -16,12 +16,10 @@ func NewFunction(name string, file *fs.File, body []token.Token) *Function {
File: file,
Body: body,
Assembler: asm.Assembler{
Instructions: make([]asm.Instruction, 0, 32),
Instructions: make([]asm.Instruction, 0, 8),
},
Stack: scope.Stack{
Scopes: []*scope.Scope{
{Variables: map[string]*scope.Variable{}},
},
Scopes: []*scope.Scope{{}},
},
cpu: cpu.CPU{
All: x64.AllRegisters,