From 3ea2f280d98916bdecc6eada44f7672d23134575 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Sun, 21 Jul 2024 15:45:49 +0200 Subject: [PATCH] Reduced memory usage --- src/build/core/AddVariable.go | 13 +++++++++---- src/build/core/NewFunction.go | 6 ++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/build/core/AddVariable.go b/src/build/core/AddVariable.go index 522f1df..8b36a56 100644 --- a/src/build/core/AddVariable.go +++ b/src/build/core/AddVariable.go @@ -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) } diff --git a/src/build/core/NewFunction.go b/src/build/core/NewFunction.go index 2dc683d..8ad25ba 100644 --- a/src/build/core/NewFunction.go +++ b/src/build/core/NewFunction.go @@ -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,