q/src/build/Assignment.go

19 lines
492 B
Go

package build
import (
"git.akyoto.dev/cli/q/src/build/expression"
"git.akyoto.dev/cli/q/src/errors"
)
// CompileAssignment compiles an assignment.
func (f *Function) CompileAssignment(expr *expression.Expression) error {
name := expr.Children[0].Token.Text()
variable, exists := f.Variables[name]
if !exists {
return errors.New(&errors.UnknownIdentifier{Name: name}, f.File, expr.Children[0].Token.Position)
}
return f.Execute(expr.Token, variable.Register, expr.Children[1])
}