Simplified file structure
This commit is contained in:
38
src/core/CompileAssignArray.go
Normal file
38
src/core/CompileAssignArray.go
Normal 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
|
||||
}
|
Reference in New Issue
Block a user