Simplified file structure

This commit is contained in:
2024-08-07 19:39:10 +02:00
parent 1b13539b22
commit 66569446b1
219 changed files with 453 additions and 457 deletions

View File

@ -0,0 +1,38 @@
package core
import (
"git.akyoto.dev/cli/q/src/asm"
"git.akyoto.dev/cli/q/src/ast"
"git.akyoto.dev/cli/q/src/errors"
)
// CompileAssignArray compiles an assign statement for array elements.
func (f *Function) CompileAssignArray(node *ast.Assign) error {
left := node.Expression.Children[0]
right := node.Expression.Children[1]
name := left.Children[0].Token.Text(f.File.Bytes)
variable := f.VariableByName(name)
if variable == nil {
return errors.New(&errors.UnknownIdentifier{Name: name}, f.File, left.Children[0].Token.Position)
}
defer f.UseVariable(variable)
index := left.Children[1]
offset, err := f.Number(index.Token)
if err != nil {
return err
}
memory := asm.Memory{
Base: variable.Register,
Offset: byte(offset),
Length: byte(1),
}
_, err = f.ExpressionToMemory(right, memory)
return err
}