package core import ( "git.urbach.dev/cli/q/src/ast" "git.urbach.dev/cli/q/src/errors" "git.urbach.dev/cli/q/src/token" "git.urbach.dev/cli/q/src/types" ) // CompileDefinition compiles a variable definition. func (f *Function) CompileDefinition(node *ast.Define) error { left := node.Expression.Children[0] right := node.Expression.Children[1] if left.IsLeaf() { variable, err := f.Define(left) if err != nil { return err } typ, err := f.ExpressionToRegister(right, variable.Value.Register) if err != nil { return err } if typ == nil { return errors.New(errors.UntypedExpression, f.File, node.Expression.Token.End()) } if typ == types.AnyInt { typ = types.Int } variable.Value.Typ = typ f.AddVariable(variable) return nil } if left.Token.Kind == token.Separator && right.Token.Kind == token.Div { return f.CompileAssignDivision(node.Expression) } if !ast.IsFunctionCall(right) { return errors.New(errors.NotImplemented, f.File, node.Expression.Token.Position) } return f.MultiDefine(left, right) }