Implemented length storage of allocated memory

This commit is contained in:
2025-02-09 14:14:41 +01:00
parent 1ff56e0856
commit 2b2e707520
27 changed files with 134 additions and 49 deletions

26
src/core/CompileLen.go Normal file
View File

@ -0,0 +1,26 @@
package core
import (
"math"
"git.akyoto.dev/cli/q/src/asm"
"git.akyoto.dev/cli/q/src/expression"
)
// CompileLen returns the length of a slice.
func (f *Function) CompileLen(root *expression.Expression) error {
_, register, isTemporary, err := f.Evaluate(root.Children[1])
if err != nil {
return err
}
f.SaveRegister(f.CPU.Output[0])
f.MemoryRegister(asm.LOAD, asm.Memory{Base: register, Offset: -8, OffsetRegister: math.MaxUint8, Length: 8}, f.CPU.Output[0])
if isTemporary {
f.FreeRegister(register)
}
return nil
}